-
Notifications
You must be signed in to change notification settings - Fork 110
Setup mutation testing #686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.0.x
Are you sure you want to change the base?
Conversation
return 'TrinaryLogicMutator'; | ||
} | ||
|
||
public function canMutate(Node $node): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
atm this class replaces any call to a method named yes
, or no
.
for now it is not scoped to the TrinaryLogic
class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current challenge: figure out a way to kill mutants across github action jobs - I will think about that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is failing sporadically after introducing the random order. It's probably because of:
phpstan-doctrine/tests/Rules/Doctrine/ORM/entity-manager.php
Lines 34 to 37 in 5eaf37b
Type::overrideType( | |
'date', | |
DateTimeImmutableType::class, | |
); |
I guess the test that executes this should clean up after itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I don't see PHPStan configured as mutant killer here.
Makefile
Outdated
.PHONY: infection | ||
infection: | ||
composer require --dev infection/infection -W --ignore-platform-req=ext-mongodb | ||
vendor/bin/infection --logger-github=false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why turning off the logger-github?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also personally I wouldn't add this to Makefile
. We'll need a more complex logic in the GHA job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added it to makefile to easy running infection locally (to reproduce CI problems)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why turning off the logger-github?
running infection in 3 php versions likely spams the 'files changed tab' with annotations.
I think we need a separate job which accumulates the separate job results and merges them togehter so we get a single final result with less false positives (mutation job on php 8.3 might error about a mutation which can only be killed in the php 8.1 test-suite)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mutation job on php 8.3 might error about a mutation which can only be killed in the php 8.1 test-suite
I had this concern as well but I talked to Maks about this and given that Infection would only mutate covered lines then this shouldn't happen. If a test ran on PHP 8.3 covers a line and we mutate that line, it should fail the test on 8.3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should fail the test on 8.3.
but the very same mutation will happen on 8.1/8.2 and no test will kill the mutation (in case it is a PHP 8.3 only test)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this was really true Infection would be unusable for us. We'd have to be able to invoke each phase separately and modify the results before feeding them to the next phase. (Run tests on each PHP version, feed the data into Infection, let it mutate the sources, run tests on each PHP version again ourselves and so on.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could run infection on multiple php versions in parallel.. collect the mutations afterwards in a new followup github action and report only those as a problem, which were not killed in any of the previous jobs.
(as long as we do not do source transformations, the mutations should be the same on all 3 jobs)
alternatively we could run infection on a single php version only
Some comments posted by me disappeared. I linked the --git-diff-filter / --git-diff-base / --git-diff-lines options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PHAR distribution is the recommended one for installing Infection. I think we could just add infection
to tools
in setup-php action.
yeah, I did not yet activate these options, because then there would be no results reported in this PR. |
I think this only make sense in case we don't want run infection locally. the more we use GitHub Actions only stuff, the harder it is to run the very same setup on a local computer. |
I did not yet see a test, which started failling more often since random order was enabled. the build on the master branch is broken long before random order with the same errors |
Yeah, I think we don't. Given the support for many PHP versions (and that we only typically have a single PHP version running locally), I think it's unlikely we'd run Infection locally. Also I'm thinking we'll be passing GitHub Actions-specific env variables to the CLI options anyway. |
Why is the build green even when there are escaped mutants? |
because we did not yet define a "min MSI", meaning there is no minimum threshold yet. |
Yeah, I want that, alongside the Git-filtering options. We can demonstrate the failing by adding some new change here in this PR temporarily. |
I think, as long as we only mutate with |
I really want it though. I don't want to write tests for things that would error in PHPStan. Also we'd have more incentives to make it faster 😊 |
mutation-testing: | ||
name: "Mutation Testing" | ||
runs-on: "ubuntu-latest" | ||
needs: ["tests", "static-analysis"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Phpunit killer requires a green test run
Phpstan killer requires a green phpstan run
Make sure to carry over PHPStan's result cache, probably with upload and download-artifact actions. It should speed up the build significantly. |
@maks-rafalko I wonder why infection treats this PHPStan result as a killed mutant? infection.log:
|
I would debug the exit code. Here is the logic how Infection determines if it's killed or escaped for PHPStan process output. We discussed with @ondrejmirtes that checking non-zero exit code is not reliable, but AFAIK nothing has been implemented on PHPStan side to improve it, so we still check (non-)zero exit code. |
local debugging reveals: we get a exit code of
|
Yeah, that's tricky. I suppose we should have a special exit code for when the result is green but result cache was not used (so that Infection does not use it to kill mutants). Or maybe Infection can stop passing --fail-without-result-cache altogether. |
I think thats the way to go. not everyone has the tools to use a result cache in CI. |
I remember I've added it by @staabm's suggestion to avoid the cases when for some (unexpected) reason we miss the cache, so for me this option did make sense so far. Can I ask you why do we have here
Is it the issue that can be fixed here? Or is it expected? |
my guess is that this problem occurs because phpstan-doctrine is a phpstan extension repository (regular non phpstan extension projects would not have this case if I got it right) |
ohh I remember that.. while running infection, we actually have a primed cache (caused by the initial test-run). so we don't need CI tooling for the cache to work. |
This can happen in any project with custom rules or other extensions. When Infection actually decides to mutate an extension file, it's inevitable the result cache won't be used. |
I'm not sure I understand all the cases to make a decision. |
I think what we're facing here is that we want to make sure the user primed the PHPStan cache before running Infection. But it can still be invalidated in these cases. --fail-without-result-cache can sometimes fill this purpose but it's not perfect. |
requires