repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

build(xtask): local mutants pinned to one job and a third of the cores, jobs flag rejected; mutants skill rewritten to the wrapper

3b195f93e73f8be25766c90db13983dbae5d2aba

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (5)

+64 / −92 text lines

Diff layout

.pi/skills/data-oriented-rust/SKILL.md

Modified

+0 / −6 text lines

88Memory is the cost; the CPU is free.
99Shape data for how it is accessed, not for how it is named.
11## Trigger
13- New or edited `struct` | `enum` | container field | `Box` | `Arc` | `Vec<Vec<_>>` | `HashMap` on a type with many instances or on a per-frame, per-turn, per-request path.
14- Choosing between `Vec`, arena, map, tree, linked structure.
15- Any loop over more than a cache's worth of records.
1711## Before shaping
19131. Name the access pattern: which fields, in which order, how many instances, how often.

.pi/skills/mutants/SKILL.md

Modified

+26 / −74 text lines

11---
22name: 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.
3description: "Use when writing or editing tests, or triaging a missed mutant: scoped cargo-mutants runs through `cargo x mutants` and what to do with each outcome."
44---
66# Mutants
8Test strength, not coverage. One run answers: which bugs could ship because no test notices them?
8Test strength, not coverage: which bugs ship because no test notices.
10## Speed model (why it feels slow)
10## Run
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:
12Always through `cargo x mutants`, always scoped; the wrapper refuses an unscoped run.
13Locally it is pinned: one job, `nice -n 19`, a third of the cores for build and tests, 120 s per mutant, 300 s per build, output under `target/mutants.out/`.
14Those pins are not overridable locally (`-j` is rejected); `--all` is CI's and follows its own rules.
2016```bash
21cargo-mutants mutants --list -f src/thing.rs --line-col true
22cargo-mutants mutants --list --json | jq length
17cargo x mutants --list -f smith-core/src/session.rs # inventory, no build
18cargo x mutants -f smith-core/src/session.rs # one file, while editing tests
19jj diff --git > /tmp/d.patch; cargo x mutants -D /tmp/d.patch # changed lines only
20cargo x mutants -f smith-core/src/session.rs --iterate # rerun only missed and unviable
21cargo x mutants --shard 0/8 # whole tree: one shard per invocation, 0..7
2322```
25(`--list` builds nothing; call the binary directly or through `cargo x mutants -f … -- --list`.)
24Run `cargo x test` first; the wrapper skips the baseline.
25A shard is 5–10 min; a full tree in one process is what crashed this machine.
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
27## Read
7429```text
75missed.txt the worklist: tests did not catch these mutants
30missed.txt the worklist
7631caught.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
32timeout.txt tests hang under the mutation, or the mutation hangs rustc; a finding either way
33unviable.txt does not compile; ignore
8034```
82Found under `target/mutants.out/`.
36## Triage a miss
84## Triage a missed mutant
381. Meaningful behavior → write the test that fails under it (regression-first), rerun with `--iterate`.
392. Not observable → the code is dead or the guard is redundant; delete it.
403. Untestable by design (`Debug` output) → `exclude_re` in `.cargo/mutants.toml`, never a `#[mutants::skip]` dependency.
414. A miss that needs a production change is a bug: fix it with the test that failed first.
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.
43## Do not
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.
45- Run cargo-mutants directly or with `--in-place`.
46- Raise jobs; narrow the scope.
47- Let two runs share `target/mutants.out`; one at a time.

.pi/skills/property-testing/SKILL.md

Modified

+1 / −1 text lines

2020- One property per law; the name is the law.
2121- Strategies from the domain: build valid values by construction, not by filtering; filter only for rare exclusions.
22- Keep the default case count small enough for the commit tier; raise it via `PROPTEST_CASES` in nightly.
22- Keep the default case count small enough for the commit tier; raise `PROPTEST_CASES` when hunting.
2323- Check in the `proptest-regressions/` file; a shrunk counterexample is a permanent test.
2424- When a property fails, add the shrunk input as a plain example test too; it reads better in a diff.

.pi/skills/snapshot-testing/SKILL.md

Modified

+1 / −1 text lines

1212- One snapshot per rendered surface; name it after the surface and state (`help_top_level`, `rpc_prompt_then_abort`).
1313- Redact identity and time before snapshotting (ids, timestamps, paths, versions); a snapshot that changes every run is noise.
1414- Use structured snapshots (`assert_json_snapshot!`, `assert_yaml_snapshot!`) for data; string snapshots for text people read.
15- Review every changed snapshot as code: `cargo insta review` or read the `.snap.new` diff; accept only what the change intended.
15- Review every changed snapshot as code: read the `.snap.new` diff, accept only what the change intended, then rename it over the `.snap`.
1616- Snapshots live next to the test in `snapshots/`; commit them.
1818## Do not

xtask/src/main.rs

Modified

+36 / −10 text lines

200200 return fail(MUTANTS_SCOPE_HELP);
201201 }
202202 let passthrough: Vec<&OsString> = extra.iter().filter(|arg| *arg != "--all").collect();
203 let jobs = std::env::var("CARGO_MUTANTS_JOBS").unwrap_or_else(|_| "1".to_string());
204 // Lowest scheduling priority: a mutants run is a background chore and
205 // must never starve the shell, even with one job its nextest fans out.
206 let threads = std::env::var("NEXTEST_TEST_THREADS").unwrap_or_else(|_| {
207 std::thread::available_parallelism()
208 .map_or(2, |cores| (cores.get() / 3).max(2))
209 .to_string()
210 });
203 // Local runs are pinned to one job and a third of the cores for both
204 // the build and the test phase: four jobs and a full fan-out crashed
205 // this machine. Only `--all` (CI) reads `CARGO_MUTANTS_JOBS`.
206 if !all && passthrough.iter().any(|arg| jobs_flag(arg)) {
207 return fail("cargo x mutants runs one job locally; drop -j/--jobs\n");
208 }
209 let jobs = if all {
210 std::env::var("CARGO_MUTANTS_JOBS").unwrap_or_else(|_| "1".to_string())
211 } else {
212 "1".to_string()
213 };
214 let cores = std::thread::available_parallelism().map_or(2, |cores| (cores.get() / 3).max(2));
211215 let mut command = Command::new("nice");
212216 command
213217 .args(["-n", "19", "cargo-mutants"])
214218 .env("TMPDIR", &scratch)
215 // A third of the cores per mutant's test run keeps the shell alive.
216 .env("NEXTEST_TEST_THREADS", &threads)
217219 .args([
218220 "mutants",
219221 "--output",
229231 "300",
230232 "--no-shuffle",
231233 ]);
234 if !all {
235 command
236 .env("NEXTEST_TEST_THREADS", cores.to_string())
237 .env("CARGO_BUILD_JOBS", cores.to_string());
238 }
232239 // Passthrough args come last and override the defaults above.
233240 command.args(passthrough);
234241 match command.status() {
253260 --all the whole workspace; CI only
254261";
263fn jobs_flag(arg: &OsString) -> bool {
264 let arg = arg.to_string_lossy();
265 arg == "-j"
266 || arg == "--jobs"
267 || arg.starts_with("-j") && arg[2..].bytes().all(|b| b.is_ascii_digit())
268 || arg.starts_with("--jobs=")
269}
256271/// Whether the passthrough arguments narrow a mutants run.
257272fn mutants_scoped(extra: &[OsString]) -> bool {
258273 extra.iter().any(|arg| {
15381553 assert!(!scoped(&["-j4", "--baseline", "run"]));
1556 #[test]
1557 fn local_mutants_reject_a_job_count() {
1558 let flag = |arg: &str| super::jobs_flag(&std::ffi::OsString::from(arg));
1559 assert!(flag("-j"));
1560 assert!(flag("-j4"));
1561 assert!(flag("--jobs"));
1562 assert!(flag("--jobs=2"));
1563 assert!(!flag("-jx"));
1564 assert!(!flag("--shard"));
1565 }
15411567 #[test]
15421568 fn junit_counts_read_the_testsuites_root() {
15431569 let xml = r#"<?xml version="1.0"?><testsuites name="nextest-run" tests="19" failures="1" errors="0"><testsuite tests="7"/></testsuites>"#;