Skip to the content
Howdah

being built · no release yet

Search

Skip the list of pages

ADR-0005: What a change reaches is what is mutated, package by package, judged by the tests that hold it

Status: Accepted Date: 2026-09-29

Context

Mutating everything on every pull request is the honest default and the expensive one. The in-house gate's full run is about twenty shards of ten minutes. Most pull requests touch a few files, and most of those shards judge code the change cannot have affected.

The in-house gate narrows a run to what a change reaches, and the seed carries the same rules:

  • a changed source file is mutated;
  • a changed test reaches every file it executes, read from the coverage map;
  • changed test support reaches the tests that name it;
  • a change to what decides how the gate runs reaches everything, unless all it did was move a workflow's action pins;
  • anything else reaches nothing by itself.

On the default branch it mutates what was reached since the last commit that passed. It mutates nothing when every commit in between is the tree of a pull request that already passed.

The same repository has two more needs.

  • Code that every test runs through. The composition root and each module's service provider are covered by the whole suite. So every mutant there is run against the whole suite, which on its runners makes one shard take fifteen to thirty minutes, mostly in timeouts. A test file there can declare pest()->group('holds:<path>'). That path is then mutated against its group alone, once the group is shown to cover all of it.
  • Monorepos. That repository is a monorepo of modules, each with a manifest that declares its floor.

Decision

  1. A unit is what a verdict and a proof are about. It is either one source file in a tree, or a path a holding group judges, mutated as one unit against that group. A path held only from the suites tests.holding lists stays the source files of its tree, each its own unit.

  2. Two modes.

    • Full: every unit is considered, as --full asks, and as a run asked for no mode does where run.full is true.
    • Change-scoped: only the units the change reaches are considered.
      • --changed-since=<ref>, accepted by plan and by run without a plan, selects it. <ref> is anything git resolves, last-passed or last-run.
      • A run asked for no mode reads its change since last-passed, unless run.full is true (it is false by default). run.full decides how the gate runs but no result, so it is compared, not keyed (ADR-0007).
      • last-passed means the newest commit of this scope whose verdict passed, which the ledger records (ADR-0007). With none recorded, the run is full.
      • last-run means the commit this scope's last run judged, which the ledger records beside it (ADR-0007), for a run off the default branch:
        • the change is read from that commit itself, not from a merge base, so a history rewritten since is still diffed file by file. Where git no longer has it, as a pull request's merge commit is gone once a newer push replaces it, git 2.38 or newer merges its two recorded parents again (merge-tree --write-tree), and the change is read from the tree that gives only where it is the tree the commit held;
        • the fetched default branch still gives the new code, and every file changed since it carries only this scope's own result, so a newer result of the default branch's code never stands in for the branch's;
        • such a result is carried only where it records the unit's source and what decides its mutant set as they are now, so a race between two runs or a ledger evicted from a cache reaches the unit instead;
        • the run falls back to the fetched default branch where the scope records no last run, where that run was of another kind (its kill matrix, --security or --suite) or reported under another check, or where git can read neither its commit nor a merge of its parents giving the tree it held: after a force-push, a merge that does not come out clean, or with an older git. On the default branch last-run reads the change since last-passed.
      • The package's GitHub action and reusable workflow pass the pull request's base on pull_request, the default branch on any other branch, and last-passed on the default branch (ADR-0011).
    • --full asks for a full run by name. It is accepted wherever --changed-since is, and the two together are an error (exit code 2).

    The run mode in CI. The action and the reusable workflow take a mode input: auto, full or changed, auto by default.

    • auto is change-scoped on pull_request and on a push, from the base the bullet above names, and full on schedule, workflow_dispatch, release and a pushed tag.
    • full passes --full whatever the event.
    • changed is change-scoped whatever the event. On an event with no base it runs from the base the bullet above names for its branch.
    • The release workflow (ADR-0011) runs the gate with mode: full before it moves the major tag, so a release is judged over all its code.

    In both modes the proof ledger then decides which considered units actually run (ADR-0007). A unit the change does not reach carries its newest result from the ledgers the run reads, its own scope's and the default branch's, into its tree's score (ADR-0003). A unit with no result to carry is treated as reached, so a change-scoped run on an empty ledger is a full run.

  3. What counts as changed.

    • Paths: the diff from the merge base of <ref> and HEAD to the working tree, with renames detected (git diff --find-renames). Using the merge base means a branch behind its base never counts the base's newer commits as its own. A last-run change is the diff from the last run's commit itself.
    • Changed lines: the lines on the new side of git diff --unified=0 that were added or modified, in PHP files inside a tree. The new-code floor judges the mutants on these lines (ADR-0003).
    • A pure rename reaches its unit and changes no lines.
    • A deleted source file leaves its tree, and has nothing to mutate.
    • Uncommitted changes count, so pre-push and watch mode (ADR-0010) see what is on disk.
  4. What a change reaches. The first matching rule decides, and every decision is printed ("phpunit.xml decides how the gate runs, so every unit is reached").

    1. A file that decides how the gate runs reaches everything in its package. Those files are:

      • the gate's config and each package's composer.json;
      • each package's composer.lock and vendor/composer/installed.json: a dependency that moves changes what every mutant runs against, and no coverage map shows it; ADR-0030 narrows the lock: where reach.lockPackages is set, a change to it decides only where it moved a package that setting names;
      • each file the gate's config file reads beside itself, as the loader of its format finds it from its code without running it. In a mutation-gate.php, a require or include of a literal path, or of __DIR__ and a literal, names that file wherever PHP looks for it: from the working directory, and from the including file's own for a path that does not begin with a dot. What that file includes is read in turn. A config file that reads a file its loader cannot name makes every change reach everything. That covers an include of a path built as it runs, a call to any function outside those that read nothing, a class outside the gate's builder, a call by a name held as it runs, eval, a shell command, and a path outside the project. JSON, YAML and NEON configs read no other file: NEON's includes: is no key of the gate's config, which refuses it;
      • the PHPUnit config and the test bootstrap it names;
      • the files that define the runner, which the runner names itself (ADR-0004): Pest's tests/Pest.php, and Infection's config (infection.json5) and the PHPUnit config in its phpUnit.configDir;
      • the paths a preset lists, such as Laravel's bootstrap/**, config/** and routes/** (ADR-0008);
      • the paths matched by reach.everything, a list of globs spelt from the repository's root, empty by default. Each of the files above is spelt from its package's directory instead.

      A file a composer.json lists under files in its autoload or autoload-dev is not one of these, though Composer's autoloader loads it in every process: a change to it changes no other file's code, so it reaches what rules 2 to 5 say of it. It leaves every kill a time budget would carry across it unjudged instead (ADR-0008).

      A root file reaches every package. The CI definition that runs the gate is one of these files: under GitHub Actions the workflow GITHUB_WORKFLOW_REF names; on GitLab the file CI_CONFIG_PATH names (.gitlab-ci.yml by default) and the file ci.gitlab.template names; on Buildkite the file ci.buildkite.definition names (.buildkite/pipeline.yml by default); on CircleCI .circleci/config.yml; and none under the JSON plan or locally.

      Two of these files reach everything only where what they decide changed, and only where the change leaves the file in its place. A change that renames, moves, adds or deletes either of them, or any other file on this list, decides anew where the gate looks, so it reaches everything however alike the file reads. Carried results are never checked against the key (ADR-0007), so each comparison keeps everything it cannot prove decides nothing:

      • The gate's config file the run reads. It reaches everything where any setting but those that only judge or report differs between the base and now, each version read by the loader the run reads it with, with the presets and the command line the run lays over it. That compares the settings that affect results (key item 3), the settings that decide how the gate runs without changing a result, such as reach.everything, ci.check or proofs.store (ADR-0007), and any key no setting declares. A change to a floor, an ignore, a report or another setting that only judges or reports reaches nothing: every proof still stands, and the verdict judges the carried results by the settings as they are now. Where either version cannot be read, the file reaches everything.
      • A CI definition that runs the gate. It reaches everything unless the change moved only its comment lines between nodes, read as key item 6 reads it. A blank line, a comment after a value or inside one, a line of a block scalar and the commit an action is pinned at all count: a pin can move the gate's own action or the runtime it runs on. Where the definition holds YAML whose values cannot be bounded line by line (an anchor, an alias, a tag, a merge key, a complex key, a second document, a directive, a quote or a flow collection left open, or a value carried onto the next line), or a carriage return, a tab, another control character, a byte order mark, NEL or a Unicode line or paragraph separator, every line counts.

      Every other file on this list reaches everything whenever it changes.

    2. A changed source file in a tree reaches that unit.

    3. A changed test reaches every unit its tests execute, according to the coverage map.

      • A changed test inside a module's directory also reaches every tree of that module.
      • A changed test in a suite tests.holding lists (ADR-0002) reaches what it executes inside the paths it holds, which is all the map keeps of it.
      • A test that asserts less changes no line of the code it judged. The map is the only way to find that code again.
      • A deleted test, or no map to read, reaches everything in its package. A package's units are judged by its own suite alone, so no other package's verdict reads that test.
    4. Changed test support reaches the tests that use it. Test support is a file under a test directory that is not a file of test cases, such as a fake or a helper.

      • The gate finds the tests that name a class or function it declares, through any other support that names it in turn. Those tests reach what they execute, as in rule 3.
      • Support that runs code when it is loaded reaches everything in its package, and so does support named by anything other than a test or support, and support none of whose versions can be read.
    5. Anything else reaches nothing by itself: documentation, templates, translations, the lock file, other CI files. The content key still covers these files (ADR-0007). A unit reached for another reason is therefore run again when they moved, and the scheduled full run catches the rest.

    Where git cannot say what changed, everything is reached.

  5. On the default branch, a tree a pull request already proved may be spared a re-check, where the config asks for it. On a push, the reach runs from last-passed. Where ci.trustMergedPullRequests is true (false by default), the GitHub ChangeSource, which reads pull requests and check-runs through GitHub's API with GITHUB_TOKEN, spares a commit whose tree is the tree of the head of a pull request merged into the repository's default branch, and whose verdict passed on that head: it reaches nothing, since the branch was up to date and its run judged exactly the tree that landed. A pull request merged into any other branch, which no protection of the default branch guards, proves nothing. The gate asks at most twenty commits back. A longer range, or one commit it cannot prove, is mutated in full.

    • A pull request's verdict passed where its own ledger records that head as passed under the check ci.check names (mutation / verdict by default, the reusable workflow's verdict job) with ownScopeProofs of 0 (ADR-0007). A verdict that used a proof of its own scope is not trusted, because the pull request's own code could have written that proof.
    • The latest check-run GitHub Actions completed on the head under that name must also have concluded in success, so a failed re-run outweighs an earlier success. The check-run is a hint, not a proof: any workflow run at that commit, the pull request's own included, can make one under any name.
    • Where the run cannot read the pull requests' ledgers, it proves nothing this way, and the range is mutated in full.
    • The shortcut works only where pull request runs write their own scope's ledger. That write is untrusted: the pull request's own code runs where the ledger is computed and written, and no setup this package ships gives a pull request's run the keys to write a store. Turning the shortcut on trusts the pull request's own computed result, so anyone who can open a pull request whose run writes its scope can make the default branch skip re-checking its tree once it is merged. Off, every merged range is mutated in full.
    • ADR-0022 and ADR-0049 extend this rule to merge groups: a commit on which a merge group's verdict passed is spared too, and so is a group whose commit holds its pull request's head tree, under the same setting.
  6. A scheduled full run is part of the design, not an extra. Reach cannot see everything:

    • a template that decides what a screen test asserts;
    • a dependency the lock moved;
    • a module whose tests run the code another module changed.

    Every documented CI setup includes a weekly scheduled full run on the default branch. Proofs keep that run to the units whose key moved (ADR-0007).

  7. Monorepos: modules share a suite, packages have their own.

    • A module is a directory with its own composer.json inside one project, sharing that project's test suite, coverage map and vendor.
      • Each is one or more trees.
      • A tree's declared floor is read from its trees entry in the config or, failing that, from the nearest composer.json above it that declares extra.mutation-gate.floor (a number from 0 to 100). A floor of 0 needs extra.mutation-gate.floorReason beside it.
      • extra.mutation-gate.newCodeFloor (a number from 0 to 100) in the same manifest sets the floor for the new lines in that module's trees, in place of newCode.floor (ADR-0003).
    • A package is a directory with its own composer.json and its own PHPUnit config. It is its own project: the runner runs in its directory, with its own coverage map, trees and floors.
      • The Runner port's rootedAt(package, tests) gives the runner in that directory, with the package's vendor and gate directory there and its tests in the directories the package's own PHPUnit config names. The CLI reads that config as it reads the root's, wildcards expanded, and hands the runner the directories; tests where it names none. There is no config key for it. A directory where the runner is not installed cannot be judged.
      • Packages come from packages, a list of globs in the root config, empty by default, and from the root composer.json's path repositories that hold a PHPUnit config.
      • A package reads no config file of its own. The root config applies to every package, the tree source finds its trees in its own directory, and its manifest declares floors with the same extra.mutation-gate keys a module uses. The root baseline holds every package's trees.
      • A shard never mixes packages.
    • Reach follows the dependency graph. A change that reaches everything in package A (rule 1) also reaches everything in each package that depends on A through a path repository, transitively, because A's manifest or test setup is part of how their tests run. A change to one of A's source files reaches that unit, as it would inside one project. A package that nothing reaches is not planned at all.
  8. The tree source is data. treeSource chooses the TreeSource adapter (ADR-0001) that finds the trees when the config lists none: phpunit, the default, reads phpunit.xml's <source> and falls back to the preset's trees (ADR-0002); composer takes one tree per autoload path of the project's composer.json, and of each package's. Declared floors come from manifests as for monorepos. A layout the built-ins do not read is an extension, not a fork.

  9. Holding tests: a path can be judged by the tests that hold it.

    • How a test declares it. The attribute is #[NightWorksIO\MutationGate\Attribute\Holds('<path>')], repeatable, and allowed on a class, a method or a function, which in PHP includes a closure.

      • In Pest: #[Holds] on the closure passed to it(), test() or arch(), which holds that test, or on the closure passed to describe(), which holds every test inside it at any depth. Groups work too: ->group('holds:<path>') on one test or one describe, or pest()->group('holds:<path>') for a whole file, which makes the file one every narrowed run loads (ADR-0004). The package's Pest plugin turns each #[Holds] into the matching group before Pest builds the test (ADR-0004), so Pest selects both kinds the same way.
      • In PHPUnit classes: #[Holds] on a class or a method, or PHPUnit's own #[Group('holds:<path>')]. Under Pest, a PHPUnit class also needs the #[Group] beside its #[Holds], because Pest cannot add a group to a class it did not build.
    • How the gate reads it.

      • Groups come from the runner's own listing (ADR-0004), so the answer is the groups the runner will actually select by.
      • #[Holds] is read from test files by their tokens, without loading them, so reading it runs no test code.
      • Under Pest the group listing is the answer, because the plugin has turned every #[Holds] into a group. Every path that tokens find must appear there as holds:<path>. Otherwise the run stops with exit code 2 and says the package's Pest plugin is not loaded.
    • What the gate refuses (exit code 2, with the file and line), each for a reason at source:

      • #[Holds] on a beforeEach or dataset closure, or on a named function. Pest never passes those to the filter, so no group could follow from them.
      • #[Holds] on a closure kept in a variable. Tokens cannot tell which test the closure becomes, so the gate cannot check it against the group listing.
      • #[Holds] in tests/Pest.php. Pest loads that file before it starts any plugin, so its tests register before the filter exists.
      • Under Pest, #[Holds] on a PHPUnit class or method without the matching #[Group]. Pest loads a PHPUnit class file with a plain include, and only its own closure tests pass through the filter. PHPUnit reads groups only from its own attributes, and its Group is final (the Alternatives below). The gate reads both attributes from tokens, and the message prints the exact line to add: #[Group('holds:<path>')].
      • Under Infection, a path that is not one string literal, such as a constant. The gate reads #[Holds] from tokens there, and tokens cannot evaluate an expression. Under Pest such a path works on a closure, because the plugin evaluates it and the group listing reports it.
      • Under Pest, a path that is not one string literal on a PHPUnit class or method. The plugin never sees that class, and tokens cannot check that its #[Group] matches.

      Each message names the group form to use instead. A held test chained with ->depends() on a test outside its group is not refused: PHPUnit skips it, it covers nothing, and the group's coverage check names the lines the group then misses.

    • What the path must be. It has to be a tree, or a file or directory that exists inside one, spelt as the repository spells it. Anything else stops the run with exit code 2. A misspelt path would otherwise be mutated against the whole suite, correct and slow, with no sign the declaration was never read.

    • How a held path runs. Where any test that holds it is in a suite whose tests judge every unit (tests.suites, ADR-0002), it is one unit, mutated against its holding tests alone, those in the suites tests.holding lists among them, and never with the shared coverage map. For Pest that is --group. For Infection it is the group or, for #[Holds], a --filter naming the holding tests (ADR-0004). The runs of the tree around it leave it out (Pest's --ignore), so no mutant is judged twice or by the wrong tests.

    • How a path held only from holding suites runs. Where every test that holds a path is in a suite tests.holding lists, the hold adds judges and narrows nothing. Such a suite's tests judge nothing unless they hold it, so narrowing the path to them would drop every killer the other suites give it.

      • The path's files stay units of their trees, run with the tree around them and judged through the shared coverage map.
      • The coverage run runs the holding suites too, and the map keeps each of their tests only on the lines it runs inside the paths it holds. There it is a covering test like any other, in everything that reads the map: what a change reaches (rule 3), the test files the key reads (ADR-0007), the coverage input the gate writes for the runner (ADR-0023), the shard's result and the proof's judging (ADR-0007). A run of mutants that any of these tests judges runs the holding suites too. A holding suite's test is on no other path's lines, so it judges no other unit.
      • The gate reads which tests hold a path, and in which suites, from the runner's own listing of each test's groups, once over each list of suites (ADR-0004). A #[Holds] read from tokens is in the suite that holds its file.
      • Pest without pest.patch runs its own opening suite and takes no coverage input from the gate, so it cannot add tests to one path's lines alone. There, a path held only from holding suites fails the run with exit code 2, naming pest.patch.
  10. A group must cover what it holds before it may judge it. Before a held path is mutated, its group runs alone under coverage. Every line of the path that the whole suite covers must be covered by the group. Otherwise the held unit fails (exit code 1) and the message lists the lines it misses:

    holds:src/Kernel.php does not cover src/Kernel.php, so its mutants cannot be judged by it.
    Not reached: src/Kernel.php:48, src/Kernel.php:61
    Add the test that runs them to the group.

    A group that does not pass on its own is cannot judge. A path with no file in the group's report is unreached as a whole, never "nothing missed".

    A hold only from the suites tests.holding lists need not cover every line, since the suites that judge every unit still judge the rest. It must run at least one line of the path it holds. A hold that runs none declares what cannot be true, so, as with a misspelt path, the run stops with exit code 2 and names it:

    holds:src/Kernel.php in the holding suites runs no line of src/Kernel.php, so it judges none of its mutants.
    Add the test that runs it to the group, or remove the hold.

    The tests of the group that run any line of a path it covers are the tests that judge its mutants. The shard's result lists them as covered, and the unit's proof keeps them as judging (ADR-0007), so a proved or carried result names them as a run does (ADR-0009).

  11. A path every test runs through, and nothing holds, is named. After the coverage run, a warning names each source file whose lines are executed by at least holds.hotPath of the suite's tests (a fraction from 0 to 1, 0.8 by default, and only in suites of 20 tests or more), when no group holds it from the suites that judge every unit: a hold from a holding suite adds judges and narrows nothing, so it leaves the cost as it was. The warning appears in the console, the step summary and the PR comment (ADR-0009): src/Kernel.php is run by 412 of 430 tests and nothing holds it; each of its mutants runs most of the suite. The verdict finds them in the coverage map the plan hands it (ADR-0014), among the files of the units the run considered. It is a warning, not a failure, because the verdict stays correct and only its cost is at stake.

  12. A change nothing the gate judges touches plans nothing. A standard run (no --security, no --suite, first killers) that reads its change since last-passed runs no coverage, keys nothing and cuts no shard, and its verdict passes, saying The earlier verdict at <commit> stands. in place of the project's score, when all of these hold:

    • the newest commit of the scope whose verdict passed was judged under the run's own ci.check, and its record says when it passed (ADR-0007, passed.at);
    • every path the change since that commit touched, as it is and, for a rename, as it was, is no PHP file and lies outside every directory of tests;
    • no such path decides how the gate runs (rule 1: the config and every file it reads, composer.json, composer.lock, vendor/composer/installed.json, the runner's definitions, the CI definitions that run the gate, and reach.everything with its presets), and none is the baseline;
    • no ignore that applied when that commit passed has expired since, judged on the days of the clock that reads now. The verdict checks this again, and cannot judge where one expired after the plan.

    The plan still writes plan.json, with no shard and the commit whose verdict stands, so every CI's chain runs the verdict as ever. The verdict reports, and records the commit the plan was made on as passed at its own instant, with the earlier commit's ownScopeProofs and ownScopeCoverage. It writes no proof and no lesson, and drops the scope's lastRun, as any other run does. Anything else, and the plan runs as ever.

Alternatives considered

OptionWhy it lost
Always mutate everythingCorrect and unaffordable: a twenty-shard run on every push to every pull request. It stays available as full mode, and as the scheduled run.
Infection's --git-diff-filter/--git-diff-linesOnly one runner has it, and it knows nothing of tests reaching code, holding groups or packages. The gate computes changes once, for every runner.
The diff against the base commit rather than the merge baseOn a branch behind its base, the base's newer commits read as the branch's own changes.
Reach only through the coverage map, even for source changesA changed file is always mutated, whether or not a map exists. The map is needed for what a changed test reaches, where the diff shows no source change.
A changed source file also reaches every unit whose tests run itWould re-run most of a project for a change to shared code, to catch mutants whose killing test changed behaviour indirectly. The scheduled full run catches those at a fraction of the cost. The in-house gate makes the same trade.
Reach every dependent package whenever a package's source changesEvery change to a shared core package would re-mutate the whole monorepo. Kept for changes that alter how a package's tests run (its manifest and test setup), which is where a dependent's verdict genuinely moves.
A config file per packageTwo places answer for one monorepo, and a package's file could quietly contradict the root's. One root config, with floors in the manifests beside the code they hold, keeps one answer.
Holds from a holding suite narrow, as other holds doA holding suite's tests judge nothing they do not hold, so a held path would lose every killer the suites that judge every unit give it. On the gate's own suite, a process-starting test file that held src/Core/Runner/MemoryCap.php would cut it off from 1,488 covering tests in 139 files. Spreading the group onto every covering test keeps them, but the groups go stale as tests change.
Declaring held paths in config instead of in testsPuts the claim "these tests hold that code" away from the tests that make it. A group or attribute moves with the test, and the coverage check keeps it honest.
Reading #[Holds] by reflectionLoads test classes, which can run code at load time. Tokens are enough to read an attribute's argument. The Pest plugin reads it by reflection only inside Pest's own runs, which load the test files anyway.
#[Holds] refused under Pest, with groups as the only Pest formOne attribute would then mean different things per runner. The plugin can add the group at the point Pest adds its own, so the attribute works with both.
Translating #[Holds] on a PHPUnit class run by PestPHPUnit takes groups only from its own Group attribute, which is final, and the only other hook is PHPUnit's @internal metadata registry. Asking for the #[Group] beside it costs one line and patches nothing.
Working out the reach before any coverage run, for every changeA reach worked out on an empty map records other digests than the map's test files give, which risks carrying results it should not. The kept map (ADR-0023) already runs no coverage for a change that moves no test entry.
Skipping wherever the change reaches nothing, by rule 5 aloneThe verdict also reads the ignores' days, the baseline and the reports' config, which no reach rule counts. Only a change that touches none of those, and no PHP, leaves a verdict standing.
Failing, not warning, on an unheld hot pathThe verdict is still right, only slow. A failure would make adopting the gate on a framework app mean restructuring tests first.

Consequences

A typical pull request mutates what it touched and what its changed tests run, and carries every other unit's result from its base.

Correctness rests on three things together: reach narrows the run, proofs check it (ADR-0007), and the scheduled full run catches what reach cannot see. The README says so, and its example workflows include the schedule.

Code every test passes through gets a cheap, honest judge, where the group covers it, instead of timeouts.

  • ADR-0003: carried results and the new-code floor
  • ADR-0004: how each runner selects a group
  • ADR-0006: held units in shards
  • ADR-0007: the ledger, last-passed and what reach does not cover
  • ADR-0008: the paths presets add to rule 1
  • ADR-0030: the lock file, which decides by the packages it moved