repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

chore(pi): mutants skill lives in the project; recipes match the wrapper

857f1ac05253a888fc10a2599bab96d6fd501a52

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (1)

+95 / −0 text lines

Diff layout

.pi/skills/mutants/SKILL.md

Added
new file mode 100644

+95 / −0 text lines

1---
2name: mutants
3description: Use when writing or editing tests and checking whether they actually catch mutations; fast scoped cargo-mutants workflows, flag choices, and result triage.
4---
5
6# Mutants
7
8Test strength, not coverage. One run answers: which bugs could ship because no test notices them?
9
10## Speed model (why it feels slow)
12Every run copies the tree into a scratch dir and builds cold once per job; every mutant then rebuilds incrementally and runs tests.
13Cost ≈ (cold build × jobs) + (mutants × test time).
14So: narrow scope first, jobs low, invocations chunky.
16## Recipes, fastest first
181. Preview mutants — free, no build:
20```bash
21cargo-mutants mutants --list -f src/thing.rs --line-col true
22cargo-mutants mutants --list --json | jq length
23```
25(`--list` builds nothing; call the binary directly or through `cargo x mutants -f … -- --list`.)
272. One-file loop — the default while editing tests:
29```bash
30cargo x mutants -f smith-core/src/session.rs
31```
33The wrapper skips the baseline; run `cargo x test` first.
34First invocation pays one cold build; mutants after are incremental.
363. Changed lines only — after editing existing code:
38```bash
39jj diff --git > /tmp/d.patch
40cargo x mutants -D /tmp/d.patch
41```
43The diff matches code under test only: test-only diffs produce zero mutants.
44Git-style `b/` prefixes or bare paths both work; composes with `-p`.
464. Tightening loop — fix tests, then skip what is already caught:
48```bash
49cargo x mutants -f smith-core/src/session.rs --iterate
50```
525. Whole tree, one shard at a time; never the whole tree in one go:
54```bash
55cargo x mutants --shard 0/8 # then 1/8 … 7/8, each its own invocation
56```
58`cargo x mutants` refuses an unscoped run (`--all` exists for CI only): a
59full run copies the tree per job and has crashed the machine. One job,
60`nice -n 19`, 120 s per-mutant timeout are the wrapper's defaults.
62## Flags, decided
64- 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.
65- `-D/--in-diff` — best scope tool for edits.
66- `--iterate` — reuses prior outcomes; only reruns missed and unviable mutants.
67- `-f/-e` file globs, `-F/-E` mutant-name regexes — narrower beats faster.
68- `--list [--json] [--line-col]` — free inventory; `--json` is list-only, not run output.
69- Never `--in-place` — mutating the real tree under jj invites snapshot churn and loses the safety copy.
70- No `--fail-fast` on cargo-mutants; nextest's fail-fast comes from the project's `mutants` nextest profile.
72## Reading results
74```text
75missed.txt the worklist: tests did not catch these mutants
76caught.txt healthy
77timeout.txt tests hang under this mutation — often a real finding
78unviable.txt mutation breaks compilation; ignore
79outcomes.json machine-readable, feeds --iterate
80```
82Found under `target/mutants.out/`.
84## Triage a missed mutant
861. Meaningful behavior → write the test that fails under it; rerun with `--iterate`.
872. Untestable by design (debug formatting, trivial getters) → exclude:
88 `-E 'Debug|fmt'` ad hoc, or `exclude_re` in the project's mutants config.
893. Never add the `mutants` crate for `#[mutants::skip]` unless the project already ships it — config excludes are dependency-free.
91## Don'ts
93- Don't run workspace-wide locally; shard (`--shard k/n`) or file-scope. `--all` is CI's.
94- Don't raise jobs when a run is slow — narrow the scope instead.
95- Don't trust a green run whose baseline you skipped without a prior green suite.