Skip to content

fix(mutation): say which files are never mutated, refuse mutants that die of a redeclaration - #142

Merged
ogorzalka merged 1 commit into
mainfrom
fix/mutation-preloaded-files
Dec 3, 2026
Merged

ogorzalka merged 1 commit into
mainfrom
fix/mutation-preloaded-files

Conversation

@ogorzalka

Copy link
Copy Markdown
Member

Closes #139.

The blind spot

A source file PHP includes before Pest puts its stream wrapper on file (an autoload.files entry and what it loads, tests/Pest.php and what it loads) is never served mutated. The whole-repository canary only probed a file the harness writes itself, so a run said nothing of it. Reproduced with a real mutation run: a fully tested class loaded at startup read 50 %, all its mutants surviving.

Reproducing it showed the opposite error too: with the test bootstrap the README gave (give file back, then require PEST_MUTATION_FILE), the processes of such a file's mutants die of Cannot redeclare class, which Pest counts as caught. The same project, with a test asserting nothing about the class, read 100 % and the harness accepted it.

Behaviour

  • Whole repository: the score is unchanged and passes as before; the files a test covers that were already included are listed after it (Never mutated (N)), also by check --mutation-canary. Nothing is removed from the score.
  • Whole repository: when the canary test, run as an unchanged mutant of one of those files, dies, no score is given.
  • Limited scopes: such a file was already refused, blaming Patchwork; the message now says it is loaded at startup.
  • README bootstrap snippet: skips an original get_included_files() already lists.

The list is read from the order of get_included_files() in the canary process: what precedes pest-plugin-mutate's StreamWrapper.php (or, when a bootstrap loads the mutant itself, what precedes the mutant).

Cost

Whole-repository runs only: one more run of the canary test, plus one per listed file.

Not seen

A file included between the wrapper starting and a bootstrap giving file back is only listed when that bootstrap loads the mutant under a name of its own. A file a test includes again is listed although that later inclusion is mutated (the notice says so). A bootstrap that loads again an already included file without any declaration is not refused.

… die of a redeclaration

A source file PHP includes before Pest serves mutants is never replaced. A run of
the whole repository now lists those a test covers; its score is not corrected. A
test bootstrap that loads the mutant of such a file anyway dies of the
redeclaration, which counted every mutant of the file as caught: no score then.

Closes #139
@ogorzalka
ogorzalka merged commit 9557cf1 into main Dec 3, 2026
7 checks passed
@ogorzalka ogorzalka mentioned this pull request Dec 3, 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.

Mutation: a file already loaded when Pest starts is never mutated, and the canary does not see it

1 participant