repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

test(report): cargo x report bundles junit, coverage, and mutation evidence; nightly and manual CI jobs publish it

5dc5105b0ae54e4d974e49dec62878558562d60b

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (7)

+185 / −26 text lines

Diff layout

.ci/nightly.kdl

Modified

+7 / −3 text lines

33 trigger {
44 schedule "0 3 * * *"
55 }
6 run "rustup component add rustfmt clippy"
6 run "rustup component add rustfmt clippy llvm-tools"
77 run "cargo run -p xtask -- bootstrap"
8 run "cargo run -p xtask -- coverage"
9 run "cargo run -p xtask -- mutants"
8 run "cargo run -p xtask -- mutants || echo 'missed mutants recorded in the report'"
9 run "cargo run -p xtask -- report"
10 publish "site" {
11 from "target/report"
12 to "smith/nightly/${rev}"
13 }

.ci/report.kdl

Added
new file mode 100644

+10 / −0 text lines

1job "report" {
2 image "docker.io/library/rust:latest"
3 run "rustup component add rustfmt clippy llvm-tools"
4 run "cargo run -p xtask -- bootstrap"
5 run "cargo run -p xtask -- report"
6 publish "site" {
7 from "target/report"
8 to "smith/report/${rev}"
9 }
10}

.config/nextest.toml

Modified

+6 / −0 text lines

99fail-fast = false
1010default-filter = 'not binary(/^e2e_/)'
12[profile.default.junit]
13path = "junit.xml"
1215# Every push: the real binary through cli, eval, and rpc.
1316[profile.e2e]
1417retries = 0
1619fail-fast = false
1720default-filter = 'binary(/^e2e_/)'
22[profile.e2e.junit]
23path = "junit.xml"
1925# Selected by cargo-mutants via additional_cargo_test_args.
2026[profile.mutants]
2127retries = 0

.system/RULES.md

Modified

+1 / −0 text lines

6868 - mutation: all first-party crates nightly; missed mutants become issues.
6969 - coverage: `cargo-llvm-cov` over every tier; reported per push as a diff, never a percentage gate; uncovered spec sentences are the backlog.
7070- Tiers: `cargo x test` (unit, property, snapshot, bounds; every commit) → `cargo x e2e` (binary; every push) → `cargo x coverage` (report) → nightly (`mutants`, golden regeneration check).
71- Evidence bundles: `cargo x report` collects every tier (JUnit, coverage, last mutation run) into `target/report/`; the nightly job and a manual `report` job publish it.
7172- A dev dependency earns its place by a test that uses it.
7374## Architecture

.system/plans/SMH-PLAN-DFOG846Z-testing-methodology/index.md

Modified

+3 / −3 text lines

33336. Snapshots with `insta`: `eval --json`, rpc line sequences, `build_trace`, `--help`; ids and timestamps redacted.
34347. Golden corpus: `smith-core/tests/golden/*.smh` plus `*.trace.json`; byte-identical replay; `SMITH_GOLDEN=regenerate` with a frame-version bump only.
35358. Mutation: scope every first-party crate; fix the seven `config.rs` misses; nightly job.
369. Coverage: `cargo llvm-cov nextest` across tiers; lcov artifact and summary in the CI log; no threshold.
369. Coverage and reports: `cargo llvm-cov nextest` across tiers; `cargo x report` bundles JUnit per tier, lcov plus HTML coverage, and the last mutation run into `target/report/` with an `index.md`; nightly and a manual `report` job publish the bundle; no threshold.
373710. Research: supersede RSCH0013 with the measured state; remove dev dependencies no test uses; fix the criterion bench.
383811. Frontend e2e stubs: one harness skeleton per `smith-ui` consumer, filled when the frontend lands (tui first, PTY via `expectrl`).
4040## Interfaces
42- `xtask`: `e2e`, `coverage`; `arch` gains the spec-reference check.
42- `xtask`: `e2e`, `coverage`, `report`; `arch` gains the spec-reference check.
4343- `.config/nextest.toml`: profiles `default`, `e2e`, `mutants`.
44- `.ci/`: `check.kdl` (push), `e2e.kdl` (push), `nightly.kdl` (schedule).
44- `.ci/`: `check.kdl` (push), `e2e.kdl` (push), `nightly.kdl` (schedule, publishes the report), `report.kdl` (manual, publishes the report).
4545- `smith-cli/tests/e2e_*.rs`: the core e2e suite.
4646- `smith-core/tests/golden/`: the replay corpus.

.system/research/SMH-RESEARCH-MQ9DOLVM-testing-methodology/index.md

Modified

+3 / −2 text lines

5050| architecture/spec-reference | `cargo x arch` | n/a (manifest, mutex, spec-citation checks; also runs `cargo-machete`) | every commit |
5151| lint | `cargo x lint` | n/a (rustfmt + clippy `-D warnings`) | every commit |
5252| coverage | `cargo x coverage` | `cargo-llvm-cov nextest`, both tiers (`default` then `--profile e2e`), lcov + summary | report, no threshold |
53| report bundle | `cargo x report` | both tiers instrumented once (JUnit per profile), lcov + HTML coverage, last `target/mutants.out`; `target/report/index.md` | on demand, nightly, manual CI job |
5354| mutation | `cargo x mutants [-f <path>]` | `mutants`: `retries = 0`, `fail-fast = true`, `slow-timeout = 30s` | nightly, or scoped on demand |
5556`cargo x check`, `cargo x lint`, `cargo x arch` all confirmed exit 0 as part of this step; `cargo x test` 202/202; `cargo x e2e` 19/19.
5960`.ci/check.kdl`: job `check`, push to `trunk`, runs `cargo run -p xtask -- ci` (check + lint + test + arch).
6061`.ci/e2e.kdl`: job `e2e`, push to `trunk`, `bootstrap` then `cargo run -p xtask -- e2e`.
61`.ci/nightly.kdl`: job `nightly`, cron `0 3 * * *`, `bootstrap` then `coverage` then `mutants`.
62All three exist and match the plan's step-1 wiring; not modified by this step.
62`.ci/nightly.kdl`: job `nightly`, cron `0 3 * * *`, `bootstrap`, `mutants` (missed mutants do not fail the job; they are recorded), `report`, then publishes `target/report` as a site under `smith/nightly/${rev}`.
63`.ci/report.kdl`: job `report`, manual only, `bootstrap`, `report`, publishes under `smith/report/${rev}`.
6465## Mutation scope and last per-file result

xtask/src/main.rs

Modified

+155 / −18 text lines

1919};
2121const HELP: &str = concat!(
22 "usage: cargo x <check|lint|fmt|test|e2e|coverage|doc|arch|mutants [args...]|audit|ci|release|bootstrap>\n",
22 "usage: cargo x <check|lint|fmt|test|e2e|coverage|report|doc|arch|mutants [args...]|audit|ci|release|bootstrap>\n",
2323 " cargo x dev [args...] build and launch the dev smith binary\n",
2424);
6363 Some("test") => cargo_nextest(&rest),
6464 Some("e2e") => cargo_e2e(&rest),
6565 Some("coverage") => cargo_coverage(&rest),
66 Some("report") => report(&rest),
6667 Some("doc") => cargo_doc(&rest),
6768 Some("arch") => arch(&rest),
6869 Some("mutants") => cargo_mutants(&rest),
327328 nextest_run_os(&args)
330/// Coverage report over every tier; informational, never a percentage gate.
331/// Both tiers accumulate into one profile set, then `target/coverage/lcov.info`
332/// and the per-file summary are produced from it.
331/// Coverage over every tier; informational, never a percentage gate.
332/// Writes `target/coverage/lcov.info` and prints the per-file summary.
333333fn cargo_coverage(extra: &[OsString]) -> ExitCode {
334 let ran = coverage_tiers(extra);
335 if ran != ExitCode::SUCCESS {
336 return ran;
337 }
338 let lcov = target_dir().join("coverage").join("lcov.info");
339 let wrote = coverage_report(&["--lcov", "--output-path"], &lcov);
340 if wrote != ExitCode::SUCCESS {
341 return wrote;
342 }
343 run_os(
344 "cargo",
345 &["llvm-cov", "report", "--summary-only"].map(OsString::from),
346 )
347}
349/// Run both nextest tiers instrumented, accumulating one profile set.
350fn coverage_tiers(extra: &[OsString]) -> ExitCode {
334351 let installed = install_llvm_cov(&[]);
335352 if installed != ExitCode::SUCCESS {
336353 return installed;
364381 return ran;
365382 }
366383 }
367 let lcov = [
368 "llvm-cov",
369 "report",
370 "--lcov",
371 "--output-path",
372 "target/coverage/lcov.info",
373 ];
374 let wrote = run_os("cargo", &lcov.map(OsString::from));
375 if wrote != ExitCode::SUCCESS {
376 return wrote;
384 ExitCode::SUCCESS
385}
387/// One `cargo llvm-cov report` invocation with an output path.
388fn coverage_report(flags: &[&str], output: &Path) -> ExitCode {
389 let mut args: Vec<OsString> = ["llvm-cov", "report"].map(OsString::from).to_vec();
390 args.extend(flags.iter().map(OsString::from));
391 args.push(output.as_os_str().to_owned());
392 run_os("cargo", &args)
393}
395/// Every tier's evidence in one bundle under `target/report/`: `JUnit` per
396/// tier, lcov plus HTML coverage, the last mutation run, and an `index.md`
397/// that summarizes them. Mutation results are read, never run here; the
398/// nightly job runs `mutants` first. Passthrough scopes the test tiers.
399fn report(extra: &[OsString]) -> ExitCode {
400 use std::fmt::Write as _;
401 let ran = coverage_tiers(extra);
402 if ran != ExitCode::SUCCESS {
403 return ran;
377404 }
378 run_os(
379 "cargo",
380 &["llvm-cov", "report", "--summary-only"].map(OsString::from),
381 )
405 let out = target_dir().join("report");
406 let _ = std::fs::remove_dir_all(&out);
407 if std::fs::create_dir_all(out.join("junit")).is_err() {
408 return fail("cannot create target/report\n");
409 }
410 let lcov = coverage_report(&["--lcov", "--output-path"], &out.join("lcov.info"));
411 if lcov != ExitCode::SUCCESS {
412 return lcov;
413 }
414 let html = coverage_report(&["--html", "--output-dir"], &out.join("coverage"));
415 if html != ExitCode::SUCCESS {
416 return html;
417 }
418 let summary = Command::new("cargo")
419 .args(["llvm-cov", "report", "--summary-only"])
420 .output()
421 .map_or_else(
422 |error| format!("summary unavailable: {error}"),
423 |output| String::from_utf8_lossy(&output.stdout).into_owned(),
424 );
425 let mut index = String::from("# Smith test report\n\n");
426 index.push_str("## Tiers\n\n| tier | tests | failures | errors |\n|---|---|---|---|\n");
427 for tier in ["default", "e2e"] {
428 // nextest keeps its store under the workspace target dir even when
429 // llvm-cov redirects build output.
430 let source = target_dir().join("nextest").join(tier).join("junit.xml");
431 let copied = out.join("junit").join(format!("{tier}.xml"));
432 let row = std::fs::read_to_string(&source).map_or_else(
433 |_| format!("| {tier} | no junit.xml | | |\n"),
434 |xml| {
435 let _ = std::fs::write(&copied, &xml);
436 let [tests, failures, errors] = junit_counts(&xml);
437 format!("| {tier} | {tests} | {failures} | {errors} |\n")
438 },
439 );
440 index.push_str(&row);
441 }
442 index.push_str(
443 "\n## Coverage\n\nHTML: `coverage/html/index.html`; lcov: `lcov.info`.\n\n```text\n",
444 );
445 index.push_str(summary.trim_end());
446 index.push_str("\n```\n\n## Mutation\n\n");
447 let mutants = target_dir().join("mutants.out");
448 match mutants_counts(&mutants) {
449 Some([caught, missed, timeout, unviable]) => {
450 let _ = write!(
451 index,
452 "| caught | missed | timeout | unviable |\n|---|---|---|---|\n| {caught} | {missed} | {timeout} | {unviable} |\n"
453 );
454 for name in ["missed.txt", "caught.txt", "timeout.txt", "unviable.txt"] {
455 let _ = std::fs::copy(mutants.join(name), out.join(name));
456 }
457 if missed > 0 {
458 index.push_str("\nMissed mutants are the test backlog; see `missed.txt`.\n");
459 }
460 }
461 None => index.push_str("No mutation run found; run `cargo x mutants` first.\n"),
462 }
463 if std::fs::write(out.join("index.md"), index).is_err() {
464 return fail("cannot write target/report/index.md\n");
465 }
466 let _ignored = std::io::stdout().write_all(b"report: target/report/index.md\n");
467 ExitCode::SUCCESS
468}
470/// `tests`, `failures`, `errors` from a `JUnit` `<testsuites>` root.
471fn junit_counts(xml: &str) -> [u64; 3] {
472 let root = xml
473 .find("<testsuites")
474 .map(|at| &xml[at..])
475 .and_then(|rest| rest.find('>').map(|end| &rest[..end]))
476 .unwrap_or("");
477 ["tests", "failures", "errors"].map(|attribute| {
478 let key = format!(" {attribute}=\"");
479 root.find(&key)
480 .map(|at| &root[at + key.len()..])
481 .and_then(|rest| rest.split('"').next())
482 .and_then(|value| value.parse().ok())
483 .unwrap_or(0)
484 })
485}
487/// Line counts of a cargo-mutants outcome directory: caught, missed,
488/// timeout, unviable; `None` without a run.
489fn mutants_counts(dir: &Path) -> Option<[usize; 4]> {
490 let count = |name: &str| {
491 std::fs::read_to_string(dir.join(name))
492 .map(|text| text.lines().filter(|line| !line.trim().is_empty()).count())
493 };
494 Some([
495 count("caught.txt").ok()?,
496 count("missed.txt").ok()?,
497 count("timeout.txt").unwrap_or(0),
498 count("unviable.txt").unwrap_or(0),
499 ])
384502/// nextest has no warning-deny flag, so config-drift warnings are turned into
9031021#[cfg(test)]
9041022mod tests {
1023 #[test]
1024 fn junit_counts_read_the_testsuites_root() {
1025 let xml = r#"<?xml version="1.0"?><testsuites name="nextest-run" tests="19" failures="1" errors="0"><testsuite tests="7"/></testsuites>"#;
1026 assert_eq!(super::junit_counts(xml), [19, 1, 0]);
1027 assert_eq!(super::junit_counts("<nothing/>"), [0, 0, 0]);
1028 }
1030 #[test]
1031 fn mutants_counts_need_a_run() {
1032 let dir = std::env::temp_dir().join(format!("smith_mutants_probe_{}", std::process::id()));
1033 let _ = std::fs::remove_dir_all(&dir);
1034 assert_eq!(super::mutants_counts(&dir), None);
1035 std::fs::create_dir_all(&dir).unwrap();
1036 std::fs::write(dir.join("caught.txt"), "a\nb\n").unwrap();
1037 std::fs::write(dir.join("missed.txt"), "c\n").unwrap();
1038 assert_eq!(super::mutants_counts(&dir), Some([2, 1, 0, 0]));
1039 let _ = std::fs::remove_dir_all(&dir);
1040 }
9051042 #[test]
9061043 fn production_slice_stops_at_the_test_module() {
9071044 let source = "use std::sync::Arc;\n#[cfg(test)]\nmod tests { use std::sync::Mutex; }";