Expand description
Mutation testing for Rust (unit mutation --language rust, #201) — the rung
above coverage. A test that runs a line still passes if you delete its
assertions; a surviving mutant proves it. This module wraps
cargo-mutants: it runs the engine,
reads its outcomes.json, and reports the surviving mutants the suite failed
to catch.
The gate is binary, not a percentage (equivalent mutants make a fixed score
unreachable, and a score isn’t comparable across engines) and on by default: any
un-exempted surviving mutant is a finding. This module stays a pure measurement —
measure_rust returns the survivors and unexplained_survivors is the pure
core over a parsed report; the CLI layer turns a non-empty result into the failure.
Diff-scoping (--base) is delegated to cargo-mutants’ own --in-diff: the
<base>...HEAD diff is written out and passed through, so only mutants on changed
lines are tested (“no unexplained surviving mutant on the lines you touched”).
Structs§
- Cosmic
RayLine - One line of
cosmic-ray dumpoutput: a[work_item, result]pair. The result is absent (null) for an un-executed work item. - CrMutation
- One mutation, pared to the location + operator the rule reads. cosmic-ray also
carries
occurrence,end_pos,operator_args; those are ignored. - CrResult
- A work item’s result; only the test outcome is read (
survived/killed/incompetent). - CrWork
Item - A cosmic-ray work item, pared to its one mutation’s location. (cosmic-ray models a list of mutations per item, but the operators here produce one apiece.)
- LineCol
- A line/column position; only the line is read.
- Mutant
Info - The mutant a scenario describes, pared to the location + description the report
needs. cargo-mutants also carries
function,genre,package,replacement; those are ignored. - Mutant
Outcome - One scenario’s outcome.
summaryis cargo-mutants’ result word —Successfor the unmutated baseline,CaughtMutant/MissedMutant(andTimeout/Unviable) for each mutant. - Mutants
Report - A cargo-mutants
outcomes.jsonexport, pared to what the rule reads. Unmodeled fields (total_mutants,caught, timings, …) are ignored. - Normalized
Mutant - One mutant in the normalized result set (#239): the engine-agnostic shape every language adapter emits. Extra fields an adapter includes are ignored.
- Span
- A source span; only the start line is read.
- Survivor
- A surviving mutant — a mutation the unit suite ran but failed to catch.
Enums§
- Mutant
Status - A mutant’s outcome, normalized across the engines (Stryker / cosmic-ray / cargo-mutants)
— the union of their result vocabularies reduced to what the gate needs (#239). Each
language adapter maps its native outcomes onto this so the Rust core gates on one
representation instead of three per-engine report formats. The serialized form is
snake_case(no_coverage,compile_error, …) — the wire contract adapters emit. - Scenario
- The scenario a result came from: the unmutated baseline, or one mutant. Matches
cargo-mutants’ externally-tagged JSON (
"Baseline"vs{"Mutant": {…}}).
Functions§
- cosmic_
ray_ mutated_ lines - The
(file, line)locations cosmic-ray ran a viable (executed) mutant for —survivedorkilled, not theincompetentmutants that never ran (a syntax error) or the un-executed (null-result) work items. The #226 guard reads this the same way as the cargo-mutants / Strykermutated_lines. - evaluate
- The shared whole-file evaluation core: drop the survivors lifted by a file-level
mutationexemption (a file-path match), leaving the rule’s findings. The line-scoped path (evaluate_scoped) generalizes this to per-line exemptions with a determinism guard. - evaluate_
normalized - Gate a normalized result set: drop the survivors lifted by a file- or line-scoped
mutationexemption (with the #226 determinism guard), leaving the rule’s findings. - evaluate_
scoped - Apply file- and line-scoped
mutationexemptions to the rawsurvivors, with the #226 determinism guard.mutatedis the set of(file, line)that produced a viable mutant (caught or survived);whole_fileis the file-level exemptions andline_scopedthe per-line ones. - measure_
python - Run cosmic-ray over the Python project at
rootand return its un-exempted survivors — the Python arm of the mutation rule (#203), parity withmeasure_rustandmeasure_typescript. - measure_
rust - Run cargo-mutants over the crate at
rootand return its un-exempted survivors. - measure_
typescript - Run the bundled TypeScript mutation adapter over the project at
rootand return its un-exempted survivors — the TS arm of the mutation rule (#202), parity withmeasure_rust. - mutated_
lines - The
(file, line)locations cargo-mutants produced a viable, conclusive mutant for — caught or missed (CaughtMutant/MissedMutant), not the inconclusiveTimeout/Unviable. The #226 line-scoped guard reads this to tell an over-exemption (a listed line whose mutants were all caught, no survivor) from an out-of-scope line (no mutant there at all — e.g. outside a--basediff). - parse_
cosmic_ ray_ dump - Parse
cosmic-ray dumpoutput (JSON Lines) into the surviving mutants — the raw list before exemptions. - parse_
mutants_ report - Parse a cargo-mutants
outcomes.jsonexport. - parse_
normalized_ results - Parse the normalized results an engine adapter emits — a flat JSON array of
NormalizedMutant(#239). - unexplained_
survivors - The surviving mutants not lifted by a
mutationexemption — the rule’s findings.
Type Aliases§
- Mutated
Lines - The
(file, line)locations an engine produced a viable mutant for — the input the #226 line-scoped guard reads to tell an over-exemption (a listed line whose mutants were all caught) from an out-of-scope line (no mutant there).