notes

Mutation testing: the baseline and the triage rule

Milestone 85 (mutation testing over the host crates). script/mutation runs cargo-mutants over the host crates. It rewrites one function at a time (replace a return value, delete a match arm, flip an operator), reruns the mutated package's tests, and records whether anything noticed. Coverage asks whether a line ran under a test; a mutation run asks whether any test would notice if the line were wrong.

The weekly census is a report. The gate is per pull request and diff-scoped (the per-pull-request gate).

This page is enough to run the tool, read its numbers and triage a survivor. The per-crate history lives in the appendices.

Running it

$ script/mutation -p calendar             # one package; minutes
$ script/mutation --list                  # enumerate mutants, run nothing
$ script/mutation --report [DIR...]       # per-crate table from finished run output
$ script/mutation-census --add-run <id>   # record a green weekly run in the tree
$ script/mutation-census --compare 2026-09-19 2026-09-21

A full local run takes hours. The weekly workflow (.github/workflows/mutation.yml) runs the same command eight-way sharded, so each shard is a uniform sample of every crate.

.cargo-mutants-version pins the tool version, today 27.1.0. The pin matters: cargo-mutants changes which mutants it generates between versions, so an unpinned tool moves the numbers with nothing in the tree changed. The host-excluded crates are derived at the call site from helpers/host-excluded-crates.sh; .cargo/mutants.toml holds the judgment exclusions, each with its reason. That file is config, not a code dependency, per ยง46 (thin primitives or whole subsystems).

To ask where a crate's mutants sit before restructuring it for testability, run cargo mutants --list -p <crate>. It attributes every mutant to its enclosing function.

The triage rule

Every survivor becomes exactly one of three things, and nothing stays untriaged:

  1. A test worth writing. The mutant found a property no test asserts; assert it.
  2. A recorded exclusion. The function cannot be tested on the host, or the mutant is semantically equivalent to the original. It goes in .cargo/mutants.toml with the reason next to it. An exclusion without a reason is a hole, not a decision.
  3. An honest deferral, recorded here. A real gap whose test is not worth its cost yet. It is named in this note, so the weekly number has a ledger behind it.

A kill counts only when the named test was seen to fail under the mutation. An equivalence claim counts only when a second run still reports the mutant, or when it is an algebraic identity. The baseline triage learned why: a verdict reached by reading is wrong about ten percent of the time; a verdict reached by running is not (nifeos/nife:notes/mutation-testing/baseline-ledger.md).

How to read the numbers

killed% is caught plus timeouts over viable mutants.

killed% counts a timeout as a kill, because every one of the 96 was checked by hand and every one is a detected hang. That check was made on the 2026-08-03 baseline. A timeout is almost always a loop that never ends, such as += becoming -= on a walker's cursor.

The rate is over viable mutants: an unviable mutant does not compile, which says nothing about the tests. It is still a hole in the measurement. A function whose only mutant is unviable was never tested at all, and scores as though it passed (nifeos/nife:notes/mutation-testing/measured-boot.md).

"Survivors" means missed plus timeouts. That is what script/mutation --report lists as "the survivors themselves".

A census is a whole-corpus run. The weekly run's eight shards together make one; a single shard is a sample. A sample cannot tell an absent mutant from a killed one, so a per-crate rate from one reads as a crate that got worse.

The per-pull-request gate

.github/workflows/mutation-gate.yml runs on every pull request and on the merge queue's entries (milestone 924 (a survivor on a pull request's own lines cannot merge untriaged), provisional). It runs cargo mutants --in-diff over the pull request's own diff through script/mutation, and helpers/mutation_diff_gate.py fails the check while any survivor of that diff has no equivalent or gap row in the ledger. Its rules, each with a selftest case in script/lint: a killed row never clears a survivor, because the gate has just watched that mutant live. A timeout is untriaged, the same as a survivor. A diff whose mutants do not finish inside 20 minutes fails, "split this pull request or triage by hand", and a run that never completed fails too. A pull request whose every changed file is under kernel/ or components/ passes with the summary "no mutants: outside the corpus", which is not a mutation result. A repository split out of this one carries the gate with one uses: line and its own ledger.

The current numbers

The living census record is notes/project-metrics/mutation-census.csv, one row per recorded run, explained in notes/mutation-census.md; the dated facts read from it, and the verdict, are fatal risk 3's to carry. The table below is the baseline and the first full census, kept for the like-for-like reading beside them:

census crates mutants viable survivors killed
2026-08-03, the baseline 38 5,551 5,141 391 92.4%
2026-09-21 66 10,988 10,178 771 92.4%

Here "survivors" is the missed count. Like-for-like, the 38 baseline crates were 94.7% on 2026-09-19 against 92.4% in August. The corpus number sat at the baseline's level while crates were measured for the first time, and the worklist that reading opened is closed (nifeos/nife:notes/mutation-testing/census-2026-09-21-triage.md, which also holds the uefi_loader unbuilt-files reading and the projection onto its counts).

The baseline and its triage

The August baseline was one local run on 2026-08-03, the census record's 2026-08-03 row (nifeos/nife:notes/mutation-testing/baseline-2026-08-03.md). .cargo/mutants-baseline.txt is the fixed point reports diff against, and its second line names the census it holds. Every one of its 391 missed and 96 timeouts was triaged, crate by crate, and none was deferred (abi to ipc (nifeos/nife:notes/mutation-testing/baseline-survivors-abi-to-ipc.md), grant_plan to swish (nifeos/nife:notes/mutation-testing/baseline-survivors-grant-plan-to-swish.md), the ledger (nifeos/nife:notes/mutation-testing/baseline-ledger.md)).

The weekly workflow then failed every scheduled run until 2026-09-14, and nobody noticed until milestone 238 (two scheduled checks have never once succeeded) looked. One shard of eight finished on 2026-09-03 and read as a fall from 92.4% to 85.3%. The first full census, on 2026-09-14, showed the fall was an artifact (nifeos/nife:notes/mutation-testing/first-weekly-runs.md). Three crates had been scored against suites that could not reach them, and a single mutant could exhaust a runner's memory:

Milestone 326 (turn a mutation score upward) then triaged the 2026-09-14 census. Parts 1 and 2 took the crates that regressed from the baseline (capability to dtb (nifeos/nife:notes/mutation-testing/regressions-2026-09-14-capability-to-device-tree-blob.md), clock_contract, swish, file_system_contract (nifeos/nife:notes/mutation-testing/regressions-2026-09-14-clock-contract-swish-filesystem-contract.md), machine_discovery (nifeos/nife:notes/mutation-testing/machine-discovery.md)). Part 3 took the worst of the crates new since the baseline (nifeos/nife:notes/mutation-testing/new-crate-backlog.md and the four appendices after it). Most survivors were missing tests, not bugs. Of the real wrong-accepts, gpt's at the baseline is the one to read first: it accepted a table whose last usable block sat inside the backup array.

The ledger

Every triaged survivor lands in one column: killed (a named test fails under it), equivalent, hang (a timeout confirmed to be a loop that never ends), excluded (with its reason in .cargo/mutants.toml), or recorded gap. The baseline's 487 survivors split 225 killed, 170 equivalent, 95 hangs, and none deferred (nifeos/nife:notes/mutation-testing/baseline-ledger.md). Milestone 326's crates each carry the same split at the head of their own section, in the appendices from 2026-09-19 on. A recorded gap is written beside the crate's accounting, with what would close it.

From milestone 740 (the survivors a merged pull request adds are checked against a triage record), a triage lane also writes a row per survivor into notes/project-metrics/mutation-triage.csv (crate,function,mutation,disposition,reason,kind,verified,home), in addition to the prose. The prose is for a reader; the row is what the weekly inflow job reads, and a survivor a merged pull request adds with no row fails that job. The key is the mutant as cargo-mutants names it without its line number (helpers/mutation_inflow.py has the exact form), the disposition is killed, equivalent or gap, and the reason names the test or the argument. A row also carries a kind, a verified date and, for a gap, a home. The docstring of helpers/mutation_survivor_rows.py defines them, and script/lint holds them to a baseline. Row expiry (nifeos/nife:notes/mutation-testing/row-expiry-replay.md) has its own measurement. The 2026-10-03 backfill is partial and says what it covers (the milestone).

The ledger has no column for unviable mutants, and it should. Milestone 250 (an unviable mutant is a hole in the measurement that reads as a pass) is that work, not started.

What the tool has taught

These recur across the appendices.

Scope and honest caveats

This is the note's BUGS section.

Closed on 2026-09-24: the one survivor nobody had triaged

compositor's replace * with + in Rect::area was the single genuine decay on a line nobody edited. Milestone 517 (what fraction of survivor growth arrives on lines a pull request touched) found it among 142 candidates; the other 141 were already survivors in August. That lane could not hold this file, so the survivor was recorded here as pending. Every fixture rectangle was square, and 2 * 2 == 2 + 2. The test area_multiplies_width_by_height now uses a 3 by 5 rectangle, and fails under the hand-applied mutant.

Appendices

Each holds the dated entries named in its row, so a citation of "notes/mutation-testing.md, the 2026-09-20 section" resolves here. The appendix stems are provisional names; naming is an architect's.

appendix what it verifies holds
nifeos/nife:notes/mutation-testing/baseline-2026-08-03.md the fixed point, and how its counts were derived the baseline; calibration against the exhaustive crates; recurring patterns; gpt's bug
nifeos/nife:notes/mutation-testing/baseline-survivors-abi-to-ipc.md that every baseline survivor was triaged the hand-triaged crates, first half
nifeos/nife:notes/mutation-testing/baseline-survivors-grant-plan-to-swish.md the same the hand-triaged crates, second half
nifeos/nife:notes/mutation-testing/baseline-ledger.md 487 survivors: 225 killed, 170 equivalent, 95 hangs, none deferred the ledger; the alarming survivors
nifeos/nife:notes/mutation-testing/first-weekly-runs.md that the fall to 85.3% was an artifact 2026-09-03 (the weekly report had never run); 2026-09-14 (the first census)
nifeos/nife:notes/mutation-testing/measured-boot.md five equivalences, proved 2026-09-03 (measured_boot re-run)
nifeos/nife:notes/mutation-testing/uefi-loader.md a file nothing compiles scores 0% 2026-09-04
nifeos/nife:notes/mutation-testing/a-memory-bound-per-mutant.md why a whole run can finish 2026-09-12
nifeos/nife:notes/mutation-testing/documentation.md the feature-gated third of a suite 2026-09-13
nifeos/nife:notes/mutation-testing/regressions-2026-09-14-capability-to-device-tree-blob.md milestone 326 parts 1 and 2 2026-09-19: capability, memory_regions, elf, timetable, dtb
nifeos/nife:notes/mutation-testing/regressions-2026-09-14-clock-contract-swish-filesystem-contract.md the same 2026-09-19: clock_contract, swish, file_system_contract
nifeos/nife:notes/mutation-testing/machine-discovery.md 77 survivors: 58 killed, 11 equivalent, 8 gaps 2026-09-19 ### machine_discovery; 2026-09-20 re-derivation
nifeos/nife:notes/mutation-testing/new-crate-backlog.md milestone 326 part 3, and a loop that waits 2026-09-20: work_steal_slot, memory_corruption_canary_gate, soak_page, schedule_store
nifeos/nife:notes/mutation-testing/job-mix-and-jh7110-entropy.md the same 2026-09-20: job_mix, jh7110_entropy
nifeos/nife:notes/mutation-testing/serial-console.md the same 2026-09-20: board_console
nifeos/nife:notes/mutation-testing/video-terminal.md the same 2026-09-20: video_terminal
nifeos/nife:notes/mutation-testing/jh7110-clock-and-reset-non-volatile-memory-express-screen-console.md the same, and what part 3 left 2026-09-21: jh7110_clock_and_reset, non_volatile_memory_express, screen_console
nifeos/nife:notes/mutation-testing/census-2026-09-21-triage.md the 2026-09-21 census's 771, classified; 164 killed 2026-09-24: portable_executable, stick_maker, uefi_loader, paging
nifeos/nife:notes/mutation-testing/census-2026-10-03-triage.md the 2026-10-03 census's 1,004, crate by crate (milestone 637 (triage the crates the 2026-09-21 mutation census measured for the first time)) 2026-10-03: component_plan onward
nifeos/nife:notes/mutation-testing/census-2026-10-03-triage-part-2.md the same, continued 2026-10-03: documentation, file_system_contract, timetable, video_terminal, machine_discovery
nifeos/nife:notes/mutation-testing/census-2026-10-03-triage-part-3.md the same, continued 2026-10-03: grant_plan onward
nifeos/nife:notes/mutation-testing/census-2026-10-03-triage-part-4.md the same, continued 2026-10-03: swish, line_editor, package_archive, pci, manifest_note
nifeos/nife:notes/mutation-testing/census-2026-10-03-triage-part-5.md the same, finished: the last 201 2026-10-07: 39 crates, from abi to stick_maker
nifeos/nife:notes/mutation-testing/inflow-2026-10-03.md survivors merged pull requests added on their own lines, and whether anything triages them 2026-10-03: 600 since 09-21; no weekly report exists
nifeos/nife:notes/mutation-testing/inflow-2026-10-12-triage.md both failed inflow jobs, triaged 2026-10-12: 710 keys
nifeos/nife:notes/mutation-testing/census-2026-10-12-residue.md the 2026-10-12 residue 2026-10-14
nifeos/nife:notes/mutation-testing/inflow-2026-10-14-triage.md the 2026-10-14 inflow 44 keys
nifeos/nife:notes/mutation-testing/survivor-classification.md every survivor of the newest census by mutation shape and triage reason, and the real holes per crate; generated by helpers/mutation_real_holes.py, which the weekly workflow reruns in each census pull request the newest census