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
- Parent 1: 65d72b1d7dda
There are many coding harnesses - but this one is fast
5dc5105b0ae54e4d974e49dec62878558562d60b
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+185 / −26 text lines
+7 / −3 text lines
new file mode 100644+10 / −0 text lines
+6 / −0 text lines
+1 / −0 text lines
- coverage: `cargo-llvm-cov` over every tier; reported per push as a diff, never a percentage gate; uncovered spec sentences are the backlog.- 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).- 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.+3 / −3 text lines
6. Snapshots with `insta`: `eval --json`, rpc line sequences, `build_trace`, `--help`; ids and timestamps redacted.7. Golden corpus: `smith-core/tests/golden/*.smh` plus `*.trace.json`; byte-identical replay; `SMITH_GOLDEN=regenerate` with a frame-version bump only.9. Coverage: `cargo llvm-cov nextest` across tiers; lcov artifact and summary in the CI log; no threshold.9. 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.10. Research: supersede RSCH0013 with the measured state; remove dev dependencies no test uses; fix the criterion bench.11. Frontend e2e stubs: one harness skeleton per `smith-ui` consumer, filled when the frontend lands (tui first, PTY via `expectrl`).- `xtask`: `e2e`, `coverage`; `arch` gains the spec-reference check.- `xtask`: `e2e`, `coverage`, `report`; `arch` gains the spec-reference check.+3 / −2 text lines
| architecture/spec-reference | `cargo x arch` | n/a (manifest, mutex, spec-citation checks; also runs `cargo-machete`) | every commit || coverage | `cargo x coverage` | `cargo-llvm-cov nextest`, both tiers (`default` then `--profile e2e`), lcov + summary | report, no threshold || 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 || mutation | `cargo x mutants [-f <path>]` | `mutants`: `retries = 0`, `fail-fast = true`, `slow-timeout = 30s` | nightly, or scoped on demand |`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.`.ci/check.kdl`: job `check`, push to `trunk`, runs `cargo run -p xtask -- ci` (check + lint + test + arch).`.ci/nightly.kdl`: job `nightly`, cron `0 3 * * *`, `bootstrap` then `coverage` then `mutants`.All three exist and match the plan's step-1 wiring; not modified by this step.`.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}`.`.ci/report.kdl`: job `report`, manual only, `bootstrap`, `report`, publishes under `smith/report/${rev}`.+155 / −18 text lines
"usage: cargo x <check|lint|fmt|test|e2e|coverage|doc|arch|mutants [args...]|audit|ci|release|bootstrap>\n", "usage: cargo x <check|lint|fmt|test|e2e|coverage|report|doc|arch|mutants [args...]|audit|ci|release|bootstrap>\n", Some("report") => report(&rest), let ran = coverage_tiers(extra); if ran != ExitCode::SUCCESS { return ran; } let lcov = target_dir().join("coverage").join("lcov.info"); let wrote = coverage_report(&["--lcov", "--output-path"], &lcov); if wrote != ExitCode::SUCCESS { return wrote; } run_os( "cargo", &["llvm-cov", "report", "--summary-only"].map(OsString::from), )}/// Run both nextest tiers instrumented, accumulating one profile set.fn coverage_tiers(extra: &[OsString]) -> ExitCode { let lcov = [ "llvm-cov", "report", "--lcov", "--output-path", "target/coverage/lcov.info", ]; let wrote = run_os("cargo", &lcov.map(OsString::from)); if wrote != ExitCode::SUCCESS { return wrote; ExitCode::SUCCESS}/// One `cargo llvm-cov report` invocation with an output path.fn coverage_report(flags: &[&str], output: &Path) -> ExitCode { let mut args: Vec<OsString> = ["llvm-cov", "report"].map(OsString::from).to_vec(); args.extend(flags.iter().map(OsString::from)); args.push(output.as_os_str().to_owned()); run_os("cargo", &args)}/// Every tier's evidence in one bundle under `target/report/`: `JUnit` per/// tier, lcov plus HTML coverage, the last mutation run, and an `index.md`/// that summarizes them. Mutation results are read, never run here; the/// nightly job runs `mutants` first. Passthrough scopes the test tiers.fn report(extra: &[OsString]) -> ExitCode { use std::fmt::Write as _; let ran = coverage_tiers(extra); if ran != ExitCode::SUCCESS { return ran; let out = target_dir().join("report"); let _ = std::fs::remove_dir_all(&out); if std::fs::create_dir_all(out.join("junit")).is_err() { return fail("cannot create target/report\n"); } let lcov = coverage_report(&["--lcov", "--output-path"], &out.join("lcov.info")); if lcov != ExitCode::SUCCESS { return lcov; } let html = coverage_report(&["--html", "--output-dir"], &out.join("coverage")); if html != ExitCode::SUCCESS { return html; } let summary = Command::new("cargo") .args(["llvm-cov", "report", "--summary-only"]) .output() .map_or_else( |error| format!("summary unavailable: {error}"), |output| String::from_utf8_lossy(&output.stdout).into_owned(), ); let mut index = String::from("# Smith test report\n\n"); index.push_str("## Tiers\n\n| tier | tests | failures | errors |\n|---|---|---|---|\n"); for tier in ["default", "e2e"] { // nextest keeps its store under the workspace target dir even when // llvm-cov redirects build output. let source = target_dir().join("nextest").join(tier).join("junit.xml"); let copied = out.join("junit").join(format!("{tier}.xml")); let row = std::fs::read_to_string(&source).map_or_else( |_| format!("| {tier} | no junit.xml | | |\n"), |xml| { let _ = std::fs::write(&copied, &xml); let [tests, failures, errors] = junit_counts(&xml); format!("| {tier} | {tests} | {failures} | {errors} |\n") }, ); index.push_str(&row); } index.push_str( "\n## Coverage\n\nHTML: `coverage/html/index.html`; lcov: `lcov.info`.\n\n```text\n", ); index.push_str(summary.trim_end()); index.push_str("\n```\n\n## Mutation\n\n"); let mutants = target_dir().join("mutants.out"); match mutants_counts(&mutants) { Some([caught, missed, timeout, unviable]) => { let _ = write!( index, "| caught | missed | timeout | unviable |\n|---|---|---|---|\n| {caught} | {missed} | {timeout} | {unviable} |\n" ); for name in ["missed.txt", "caught.txt", "timeout.txt", "unviable.txt"] { let _ = std::fs::copy(mutants.join(name), out.join(name)); } if missed > 0 { index.push_str("\nMissed mutants are the test backlog; see `missed.txt`.\n"); } } None => index.push_str("No mutation run found; run `cargo x mutants` first.\n"), } if std::fs::write(out.join("index.md"), index).is_err() { return fail("cannot write target/report/index.md\n"); } let _ignored = std::io::stdout().write_all(b"report: target/report/index.md\n"); ExitCode::SUCCESS}/// `tests`, `failures`, `errors` from a `JUnit` `<testsuites>` root.fn junit_counts(xml: &str) -> [u64; 3] { let root = xml .find("<testsuites") .map(|at| &xml[at..]) .and_then(|rest| rest.find('>').map(|end| &rest[..end])) .unwrap_or(""); ["tests", "failures", "errors"].map(|attribute| { let key = format!(" {attribute}=\""); root.find(&key) .map(|at| &root[at + key.len()..]) .and_then(|rest| rest.split('"').next()) .and_then(|value| value.parse().ok()) .unwrap_or(0) })}/// Line counts of a cargo-mutants outcome directory: caught, missed,/// timeout, unviable; `None` without a run.fn mutants_counts(dir: &Path) -> Option<[usize; 4]> { let count = |name: &str| { std::fs::read_to_string(dir.join(name)) .map(|text| text.lines().filter(|line| !line.trim().is_empty()).count()) }; Some([ count("caught.txt").ok()?, count("missed.txt").ok()?, count("timeout.txt").unwrap_or(0), count("unviable.txt").unwrap_or(0), ]) #[test] fn junit_counts_read_the_testsuites_root() { let xml = r#"<?xml version="1.0"?><testsuites name="nextest-run" tests="19" failures="1" errors="0"><testsuite tests="7"/></testsuites>"#; assert_eq!(super::junit_counts(xml), [19, 1, 0]); assert_eq!(super::junit_counts("<nothing/>"), [0, 0, 0]); } #[test] fn mutants_counts_need_a_run() { let dir = std::env::temp_dir().join(format!("smith_mutants_probe_{}", std::process::id())); let _ = std::fs::remove_dir_all(&dir); assert_eq!(super::mutants_counts(&dir), None); std::fs::create_dir_all(&dir).unwrap(); std::fs::write(dir.join("caught.txt"), "a\nb\n").unwrap(); std::fs::write(dir.join("missed.txt"), "c\n").unwrap(); assert_eq!(super::mutants_counts(&dir), Some([2, 1, 0, 0])); let _ = std::fs::remove_dir_all(&dir); }