Skip to content

fix(mutation): give no score when the tests fail on unchanged code run as a mutant - #137

Merged
ogorzalka merged 4 commits into
mainfrom
fix/mutation-unchanged-code
Nov 27, 2026
Merged

ogorzalka merged 4 commits into
mainfrom
fix/mutation-unchanged-code

Conversation

@ogorzalka

Copy link
Copy Markdown
Member

Problem

Pest counts a mutant's process that fails as a caught mutant, and one that loops as a timeout, also caught. A suite that breaks in that process whatever the file contains therefore scores mutants nothing tested. Measured on pollora/media: 96.95 % reported, about 86 % once its mutants really ran.

Change

Before Pest runs, the harness runs the tests covering the code with PEST_MUTATION_FILE set to an exact copy of the source, the way a mutant is launched, and refuses the score when they fail or run past the limit. check --mutation-canary asks only this question.

Before releasing

Repositories that passed may now be refused, rightly. Each needs its suite fixed before moving to the release carrying this (usually the Patchwork fix, antecedent/patchwork#235; the framework needs Pollora/framework#722).

What this proves, and what it does not

  • Proves: tests fail without the change; on a real project, a score read with Patchwork 2.2.5 is refused and accepted with the fix.
  • Does not prove: that an accepted score is right. Test selection is per file, not per line; Pest's per-mutant timeout is tighter than the limit here; a file already loaded by a Composer files entry is not detected; Semgrep did not run locally.

Pollora maintainer added 4 commits November 27, 2026 14:20
…n as a mutant

Pest counts a mutant's process that fails as a caught mutant, and one that
loops as a timeout, caught too. Before Pest runs, run the tests covering the
code with PEST_MUTATION_FILE an exact copy of PEST_MUTATION_TESTING, as Pest
runs a mutant, and refuse the score when they do not pass.

Add check --mutation-canary to ask only that question.
What a failing or killed run leaves in the shared temporary directory made the
next control fail for a reason that was not its own. Say too that the file
named for the whole repository only stands for the others.
The tests selected as a mutant are now named one by one (in several runs when the filter is too long for PCRE), never
by whole class: a test that covers nothing is run for no mutant, and could refuse a healthy repository.
--parallel is never passed to those runs, as Pest passes it to no mutant. The control takes its coverage in parallel
when a single process fails, and a failing run is tried once more, so that one flaky test does not refuse a score.
…ory ran out, condition the advice

pest-plugin-mutate 3 leaves --coverage-php among the arguments of a mutant (version 4 removes it): the runs as a
mutant now collect coverage too when the installed version does.
A canary run that exhausted its memory says so, and that a -d flag of the command does not reach it.
The advice to give file back now says to do it only when the wrapper of Pest is on it, with the code: done
unconditionally it fails every test PHPUnit isolates in a process of its own.
@ogorzalka
ogorzalka merged commit 91aad3e into main Nov 27, 2026
7 checks passed
@ogorzalka ogorzalka mentioned this pull request Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant