diff --git a/crates/ledger-mcp/proptest-regressions/local_files.txt b/crates/ledger-core/tests/proptest-regressions/control.txt similarity index 69% rename from crates/ledger-mcp/proptest-regressions/local_files.txt rename to crates/ledger-core/tests/proptest-regressions/control.txt index 7b3625ff..148954af 100644 --- a/crates/ledger-mcp/proptest-regressions/local_files.txt +++ b/crates/ledger-core/tests/proptest-regressions/control.txt @@ -4,4 +4,4 @@ # # It is recommended to check this file in to source control so that # everyone who runs the test benefits from these saved cases. -cc 57a6af235ad283b1483b62c6218bfbfbdb45bb1caaa3946b49f356ad67d11683 # shrinks to start = 1, parts = [6, 2, 0] +cc b1079b286c6681eec98a5c98aff17569e47cb183b7799aa7bb8b04eae4a138b1 # shrinks to f = [0, -1, -79228162514264337593543950335, 0, 5] diff --git a/crates/ledger-core/tests/kernel_bridge.proptest-regressions b/crates/ledger-core/tests/proptest-regressions/main.txt similarity index 100% rename from crates/ledger-core/tests/kernel_bridge.proptest-regressions rename to crates/ledger-core/tests/proptest-regressions/main.txt diff --git a/crates/ledger-core/tests/seed_files.rs b/crates/ledger-core/tests/seed_files.rs new file mode 100644 index 00000000..55208bd0 --- /dev/null +++ b/crates/ledger-core/tests/seed_files.rs @@ -0,0 +1,155 @@ +//! Recorded failures stay replayed (AGENTS.md, "Verification protocol"). +//! +//! When a property test fails, proptest writes the failing case's seed to a +//! file and replays every seed in that file before it tries new cases. It +//! finds the file from the test's own source path, and says nothing when +//! there is none. So a seed file whose test was moved or renamed is never +//! read again, and the failures it records stop being checked without any +//! test going red. +//! +//! That happened here: when the kernel bridge became a folder of modules +//! (`tests/kernel_bridge.rs` to `tests/kernel_bridge/main.rs`), its three +//! recorded failures stayed in `tests/kernel_bridge.proptest-regressions`, +//! which no test read any more (found 2026-11-09, by a marker line in each +//! candidate file and proptest's "unparsable line" warning naming the one +//! it opened). +//! +//! The two places proptest reads, as it resolves them: +//! +//! - `D/X.proptest-regressions` is read by the tests in `D/X.rs` (a test +//! file with no `lib.rs` or `main.rs` above it). +//! - `D/proptest-regressions/R.txt` is read by the tests in `D/C/R.rs`, +//! where `C` is a folder under `D` that holds a `lib.rs` or a `main.rs` +//! (a crate's `src`, or a test that is a folder of modules). +//! +//! Every seed file under `crates/` must have that reader. + +use std::path::{Path, PathBuf}; + +fn root() -> PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../..") + .canonicalize() + .unwrap() +} + +/// Every file under `dir`, skipping build output. +fn files(dir: &Path, out: &mut Vec) { + let entries = std::fs::read_dir(dir).unwrap_or_else(|e| panic!("{}: {e}", dir.display())); + for entry in entries { + let path = entry.unwrap().path(); + if path.is_dir() { + if path.file_name().is_some_and(|n| n != "target") { + files(&path, out); + } + } else { + out.push(path); + } + } +} + +/// The source files whose tests read `seeds` (more than one when two +/// tests that are folders hold a module of the same name: they share the +/// file), or why there is none. +fn readers(seeds: &Path) -> Result, String> { + let dir = seeds.parent().expect("a file has a folder"); + if seeds + .extension() + .is_some_and(|e| e == "proptest-regressions") + { + let source = seeds.with_extension("rs"); + return if source.is_file() { + Ok(vec![source]) + } else { + Err(format!("no test file {}", source.display())) + }; + } + // A file inside a `proptest-regressions` folder: find the folder, then + // every sibling of it that is a crate or test root holding the same path. + let mut folder = dir; + while folder + .file_name() + .is_some_and(|n| n != "proptest-regressions") + { + folder = folder + .parent() + .ok_or("not inside a proptest-regressions folder")?; + } + let rel = seeds + .strip_prefix(folder) + .expect("the folder is an ancestor") + .with_extension("rs"); + let above = folder + .parent() + .ok_or("a proptest-regressions folder at the root")?; + let siblings = std::fs::read_dir(above).map_err(|e| format!("{}: {e}", above.display()))?; + let mut found = Vec::new(); + for sibling in siblings { + let sibling = sibling.unwrap().path(); + let is_root = sibling.join("lib.rs").is_file() || sibling.join("main.rs").is_file(); + if is_root && sibling.join(&rel).is_file() { + found.push(sibling.join(&rel)); + } + } + if found.is_empty() { + return Err(format!( + "no folder beside {} holds a lib.rs or main.rs and a {}", + folder.display(), + rel.display() + )); + } + Ok(found) +} + +#[test] +fn every_recorded_failure_has_a_test_that_replays_it() { + let root = root(); + let mut all = Vec::new(); + files(&root.join("crates"), &mut all); + let seeds: Vec<&PathBuf> = all + .iter() + .filter(|p| { + p.extension().is_some_and(|e| e == "proptest-regressions") + || p.components() + .any(|c| c.as_os_str() == "proptest-regressions") + }) + .collect(); + // The floor: a walk that finds nothing would pass for the wrong reason. + assert!( + seeds.len() >= 20, + "found only {} seed files under crates/; the walk is wrong", + seeds.len() + ); + let mut orphans = Vec::new(); + for path in &seeds { + let shown = path + .strip_prefix(&root) + .unwrap_or(path) + .display() + .to_string(); + match readers(path) { + Ok(sources) => { + let tested = sources + .iter() + .any(|s| std::fs::read_to_string(s).unwrap().contains("proptest!")); + if !tested { + let names: Vec = sources + .iter() + .map(|s| s.strip_prefix(&root).unwrap_or(s).display().to_string()) + .collect(); + orphans.push(format!( + "{shown}: {} holds no property test", + names.join(", ") + )); + } + } + Err(why) => orphans.push(format!("{shown}: {why}")), + } + } + assert!( + orphans.is_empty(), + "seed files no test reads (move each beside the test that owns its cases):\n{}", + orphans.join("\n") + ); + println!("{} seed files, each read by a property test", seeds.len()); +} diff --git a/docs/testing.md b/docs/testing.md index 6df3a221..31c32055 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -42,9 +42,25 @@ CI: `.github/workflows/check.yml` runs `just check` on every push; `scheduled.yml` runs the proofs, the oracle, the coverage report and floor, and the fuzz targets weekly. Mutation ran there in shards until 2026-10-29 (`just mutants-mcp 3/16` runs the fourth of sixteen; GitHub stops a job at six hours), and is now local only (D-59). Test timeouts are three times each run's own baseline, never under the recipe's floor, so a slower runner doesn't report false timeouts. The viewer has no mutation job. Development mutation runs are paused until the P12 max-testing pass (D-33, 2026-10-20): each unit records its targets in a **For P12** paragraph instead. Mutation testing is a local run, not a CI job (the owner, 2026-10-29, D-59): the weekly shards were removed from `scheduled.yml`, and the "weekly" in the mutation rows above is history (the 2026-10-26 run: real survivors and timeouts in every crate, the debt P12 clears). -Seeds and failure databases: proptest's `*.proptest-regressions` files -are checked in and replay on every run. The GnuCash oracle's books come -from fixed seeds (`SEED` in `oracle_gnucash.rs`). Fuzz corpora live in +Seeds and failure databases: proptest's seed files are checked in and +replay on every run. Proptest finds a seed file from the test's source +path, and says nothing when the file it looks for is not there, so a +seed file left behind by a moved test is silently never read again. +There are two places it reads. A test that is one file, `tests/x.rs`, +reads `tests/x.proptest-regressions`. A test that is a folder, +`tests/x/main.rs` with modules beside it, reads +`tests/proptest-regressions/main.txt` for `main.rs` and +`tests/proptest-regressions/.txt` for `.rs`; every +folder test in a crate shares those files. A source file under `src/` +reads `proptest-regressions/.txt` at the crate root. +When a test file becomes a folder, or a module moves, its seed file +moves with it. `crates/ledger-core/tests/seed_files.rs` walks every +crate and fails when a seed file has no property test that reads it +(2026-11-09: the kernel bridge's three recorded failures had not been +replayed since the bridge became a folder, and one found during K-U8 +was never checked in). When proptest writes a new seed file during a +run, check it in with the fix. The GnuCash oracle's books come from +fixed seeds (`SEED` in `oracle_gnucash.rs`). Fuzz corpora live in `fuzz/corpus/`. Golden review: `fixture_company.json` is hand-verified (docs/oracle.md,