chore(pi): mutants skill lives in the project; recipes match the wrapper
857f1ac05253a888fc10a2599bab96d6fd501a52
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: a5d32a1aa345
There are many coding harnesses - but this one is fast
857f1ac05253a888fc10a2599bab96d6fd501a52
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+95 / −0 text lines
new file mode 100644+95 / −0 text lines
---name: mutantsdescription: Use when writing or editing tests and checking whether they actually catch mutations; fast scoped cargo-mutants workflows, flag choices, and result triage.---# MutantsTest strength, not coverage. One run answers: which bugs could ship because no test notices them?## Speed model (why it feels slow)Every run copies the tree into a scratch dir and builds cold once per job; every mutant then rebuilds incrementally and runs tests.Cost ≈ (cold build × jobs) + (mutants × test time).So: narrow scope first, jobs low, invocations chunky.## Recipes, fastest first1. Preview mutants — free, no build:```bashcargo-mutants mutants --list -f src/thing.rs --line-col truecargo-mutants mutants --list --json | jq length```(`--list` builds nothing; call the binary directly or through `cargo x mutants -f … -- --list`.)2. One-file loop — the default while editing tests:```bashcargo x mutants -f smith-core/src/session.rs```The wrapper skips the baseline; run `cargo x test` first.First invocation pays one cold build; mutants after are incremental.3. Changed lines only — after editing existing code:```bashjj diff --git > /tmp/d.patchcargo x mutants -D /tmp/d.patch```The diff matches code under test only: test-only diffs produce zero mutants.Git-style `b/` prefixes or bare paths both work; composes with `-p`.4. Tightening loop — fix tests, then skip what is already caught:```bashcargo x mutants -f smith-core/src/session.rs --iterate```5. Whole tree, one shard at a time; never the whole tree in one go:```bashcargo x mutants --shard 0/8 # then 1/8 … 7/8, each its own invocation````cargo x mutants` refuses an unscoped run (`--all` exists for CI only): afull run copies the tree per job and has crashed the machine. One job,`nice -n 19`, 120 s per-mutant timeout are the wrapper's defaults.## Flags, decided- jobs stay at 1 locally (`CARGO_MUTANTS_JOBS` overrides); each job is a full scratch tree and a full nextest fan-out, four jobs crashed this machine.- `-D/--in-diff` — best scope tool for edits.- `--iterate` — reuses prior outcomes; only reruns missed and unviable mutants.- `-f/-e` file globs, `-F/-E` mutant-name regexes — narrower beats faster.- `--list [--json] [--line-col]` — free inventory; `--json` is list-only, not run output.- Never `--in-place` — mutating the real tree under jj invites snapshot churn and loses the safety copy.- No `--fail-fast` on cargo-mutants; nextest's fail-fast comes from the project's `mutants` nextest profile.## Reading results```textmissed.txt the worklist: tests did not catch these mutantscaught.txt healthytimeout.txt tests hang under this mutation — often a real findingunviable.txt mutation breaks compilation; ignoreoutcomes.json machine-readable, feeds --iterate```Found under `target/mutants.out/`.## Triage a missed mutant1. Meaningful behavior → write the test that fails under it; rerun with `--iterate`.2. Untestable by design (debug formatting, trivial getters) → exclude: `-E 'Debug|fmt'` ad hoc, or `exclude_re` in the project's mutants config.3. Never add the `mutants` crate for `#[mutants::skip]` unless the project already ships it — config excludes are dependency-free.## Don'ts- Don't run workspace-wide locally; shard (`--shard k/n`) or file-scope. `--all` is CI's.- Don't raise jobs when a run is slow — narrow the scope instead.- Don't trust a green run whose baseline you skipped without a prior green suite.