muter-mutation-testing/muter

"error: invalid branch name: 'master'" when running on fresh swift package

Closed this issue · 7 comments

Hi,

I'm trying Muter and it works great when running against an application code.
Unfortunately, I couldn't manage to run it for a standalone Swift Package.

When I run muter, it shows the following output:

                   -:::-.
                   -=--::-:
                  :+---=-.-:
                  .:.:+++.-:
                 =-:--:-=.-:
                  :-:.:=..-:
                    .=:...-:
                      :-:.-:
                   ... =..-+++
                  ++==#=..-**%-
::::::::::::::::+**#==**--**==+##*::::::::::::::::
..................................................
            __ __  _ _  ___  ___  ___
           |  \  \| | ||_ _|| __>| . \
           |     || ' | | | | _> |   /
           |_|_|_|`___' |_| |___>|_\_\

Automated mutation testing for Swift

You are running version 16

Want help? Have suggestions? Want to get involved?
 ↳ https://github.com/muter-mutation-testing/muter/issues
+------------------------------------------------+

🔎 Checking for new versions...
✅ You are already using the latest of Muter
Copying your project to a temporary directory for testing...
Finished copying your project to a temporary directory for mutation testing.
You can find your copied project here:

/Users/anthony.merle/Developer/Other/coding_katas/GildedRose_mutated

This directory will also serve as a backup for any XCTest logs that are generated by running your test suite.
Running tests with coverage enabled to determine which files to mutate
Gathering coverage failed.
Proceeding with mutation testing anyway.
Pass --skip-coverage argument to disable this step
+-----------------+
Discovering Swift files which Muter will analyze...
In total, Muter discovered 2 Swift files

GildedRose.swift
Item.swift
+-----------------+
Analyzing source files to find mutants which can be inserted into your project...
In total, Muter discovered 17 mutants in 1 files

GildedRose.swift (17 mutants)
+-----------------+
Mutation testing will now begin
Running your test suite to determine a baseline for mutation testing...
⚠️ ⚠️ ⚠️ ⚠️ ⚠️  Muter has encountered an error  ⚠️ ⚠️ ⚠️ ⚠️ ⚠️
Muter noticed that your test suite initially failed to compile or produced a test failure.

Assuming you have no build errors, this is usually due to misconfiguring the "executable" and "arguments" options inside of your muter.conf.
Alternatively, it could mean you have a nondeterministic test failure in your test suite.

We recommend you try your settings out in a terminal prior to using Muter for the best configuration experience.
We also recommend removing tests which you know are flaky from the set of tests that Muter exercises.

Here's the log XCTest produced:

error: 'gildedrose_mutated': invalid branch name: 'master'



⚠️ ⚠️ ⚠️ ⚠️ ⚠️  See the Muter error log above this line  ⚠️ ⚠️ ⚠️ ⚠️ ⚠️

If you think this is a bug, or want help figuring out what could be happening, please open an issue at
https://github.com/muter-mutation-testing/muter/issues

Here is a link to a Githup repo with the exact same Package, so that you may test on your end: https://github.com/gsl-anthonymerle/MuterPackageFailure

Do I do anything wrong ? Or is it something else ?

I have an M1 Macbook pro, MacOS Sonoma 14.1 (23B74)
Xcode Version 15.0.1 (15A507)

Best regard,
Anthony

Hello @gsl-anthonymerle
Thank you for taking the time to report this issue I will take a look at it later

My pleasure, thanks @Nikoloutsos

@gsl-anthonymerle Your code helped reproduce the issue.
At first, I tried running without any SPM dependencies and it was working but whenever I added at least one SPM dependency it was always failing.

The problem looks like is that swift test tries to resolve the packages but Github refuses to provide it.
After some debugging I found this on swift forum which explains the problem.

Workaround:
Change the Package.swift to use SSH authentication:

dependencies: [
        .package(
-            url: "https://github.com/approvals/ApprovalTests.Swift",
+            url: "git@github.com:approvals/ApprovalTests.Swift.git"
            branch: "master"
        ),
    ],

In the future I will try to fix this so that muter is running seamlessly on SPM packages with dependencies.

🎁 Bonus tip:
There is no need for you to exclude the Package.swift on the configuration since it is excluded by default. This was added in latest commit d44e78d

@rakaramos @ZevEisenberg
A solution needs to be provided for this problem that will be happening on every muter run on SPM with at least one dependency.
With that in mind, I want your opinion on implementing the following solution:

The developer will have the ability to provide environment variables through muter configuration.
So in this Usecase the user would give the following env var and we would would set it like this which will solve the problem.

process.environment = ["PATH": "/usr/local/bin:/usr/bin:/bin"] // Found this from swift forums

That way not only will we solve this problem but we will also give the ability to developer to set env vars which may be needed.

What do you think about this?

Hi @Nikoloutsos,

Thank you for your answer 🙏 Unfortunately, changing the http url to a git one doesn't change much, and I now get the following error:

Fetching git@github.com:approvals/ApprovalTests.Swift.git from cache
warning: 'approvaltests.swift': skipping cache due to an error: Couldn’t fetch updates from remote repositories:
Fetching git@github.com:approvals/ApprovalTests.Swift.git from cache
warning: 'approvaltests.swift': skipping cache due to an error: Couldn’t fetch updates from remote repositories:
error: Failed to clone repository git@github.com:approvals/ApprovalTests.Swift.git:

Is it something you ran into as well ?

Side note: I was using the Homebrew version, but I think it doesn't ship the latest changes that you talked before (like automatically ignoring Package.swift etc.), so I have now installed muter from the git repository

Hello @gsl-anthonymerle 👋
Sorry for the late response, I just came back from holidays 😄

IIRC it was working fine for me, have you setup ssh for Github?
Probably now if you run the following on your terminal it is going to fail.

git clone git@github.com:gsl-anthonymerle/MuterPackageFailure.git

Take a look here and here on how you can generate an SSH key and add it into Github.

@rakaramos @ZevEisenberg A solution needs to be provided for this problem that will be happening on every muter run on SPM with at least one dependency. With that in mind, I want your opinion on implementing the following solution:

The developer will have the ability to provide environment variables through muter configuration. So in this Usecase the user would give the following env var and we would would set it like this which will solve the problem.

process.environment = ["PATH": "/usr/local/bin:/usr/bin:/bin"] // Found this from swift forums

That way not only will we solve this problem but we will also give the ability to developer to set env vars which may be needed.

What do you think about this?

Thanks for the investigation!
I think that a better approach is to copy all the env vars from the process info to the underlying muter process, I'll run a few tests and will issue a PR if it fixes it.