From ee6501884a34b2e9cbee8a580f183470f92387b7 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Fri, 9 Oct 2026 08:07:00 -0500 Subject: [PATCH] provenance tests: give every scratch copy its own name; refuse a reused one Main run 37932804024 failed with "FAIL missing_record: waldo_model_bom" in real_slice_done_is_pass_complete_and_the_three_unlanded_cases_are_not. The committed fixture was fine. Two tests in recovery_verdicts.rs both used the scratch directory "m4d-real-done" (the second through format!("m4d-real-{s}") with s = "done"). They run on parallel threads, so one test deleted and refilled the copy while the other was verifying it. - recovery_verdicts.rs: the unknown-state test uses m4d-real-unknown-{s}. - common::scratch: a name may be claimed once per test binary; a second claim panics, so a clash fails every run instead of some runs. - review_hardening.rs: the fixture-class loop reused one name sequentially (no race); each pass now has its own name so the guard stays strict. Evidence (local, aarch64 Spark): unfixed 3/200 runs of recovery_verdicts failed; guard without the rename failed 3/3 with the named clash; fixed 0/200 failed; full provenance suite, fmt and clippy -D warnings clean. Co-Authored-By: Claude Opus 5.5 --- provenance/tests/common/mod.rs | 11 +++++++++++ provenance/tests/recovery_verdicts.rs | 2 +- provenance/tests/review_hardening.rs | 9 ++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/provenance/tests/common/mod.rs b/provenance/tests/common/mod.rs index 9161d4a..dc30ef1 100644 --- a/provenance/tests/common/mod.rs +++ b/provenance/tests/common/mod.rs @@ -4,7 +4,9 @@ use interplane_provenance::gojson::{sha256_hex, waldo_sha256}; use serde_json::{json, Value}; +use std::collections::BTreeSet; use std::path::{Path, PathBuf}; +use std::sync::Mutex; pub fn copy_dir(from: &Path, to: &Path) { std::fs::create_dir_all(to).unwrap(); @@ -19,7 +21,16 @@ pub fn copy_dir(from: &Path, to: &Path) { } } +/// A fresh copy of `fixture` under its own scratch directory. Tests in one binary run on parallel +/// threads, so two tests sharing a name would delete and refill each other's copy mid-check +/// (interplane main run 37932804024: a stray `missing_record`). A name may be claimed once per +/// test binary; a second claim panics, so a clash fails every run instead of some runs. pub fn scratch(fixture: &str, name: &str) -> PathBuf { + static CLAIMED: Mutex> = Mutex::new(BTreeSet::new()); + assert!( + CLAIMED.lock().unwrap().insert(name.to_string()), + "scratch name {name} is already used by another test in this binary" + ); let d = Path::new(env!("CARGO_TARGET_TMPDIR")) .join("verdicts") .join(name); diff --git a/provenance/tests/recovery_verdicts.rs b/provenance/tests/recovery_verdicts.rs index a3b746a..616cfb6 100644 --- a/provenance/tests/recovery_verdicts.rs +++ b/provenance/tests/recovery_verdicts.rs @@ -118,7 +118,7 @@ fn test_records_without_a_section_on_an_unlanded_effect_are_still_refused_as_suc #[test] fn an_unknown_ack_state_is_still_a_generic_mismatch() { for s in ["OPEN", "done", "WRITTEN"] { - let d = scratch(REAL, &format!("m4d-real-{s}")); + let d = scratch(REAL, &format!("m4d-real-unknown-{s}")); set_state(&d, s); let v = verify(&d); assert_eq!(v, format!("FAIL binding_mismatch: ledger_ack.state={s}")); diff --git a/provenance/tests/review_hardening.rs b/provenance/tests/review_hardening.rs index 01f1105..238c41f 100644 --- a/provenance/tests/review_hardening.rs +++ b/provenance/tests/review_hardening.rs @@ -69,7 +69,7 @@ fn a_duplicate_key_inside_a_ledger_note_is_refused() { #[test] fn test_material_never_verifies_as_complete() { - for (class, want) in [ + for (i, (class, want)) in [ ( json!("synthetic"), "FAIL synthetic_complete: fixture.class=synthetic", @@ -79,8 +79,11 @@ fn test_material_never_verifies_as_complete() { "FAIL synthetic_complete: fixture.class=staged", ), (json!(null), "FAIL malformed_companion: fixture.class"), - ] { - let d = scratch(REAL, "fixture_class"); + ] + .into_iter() + .enumerate() + { + let d = scratch(REAL, &format!("fixture_class_{i}")); let mut c = companion(&d); c["fixture"]["class"] = class; write_companion(&d, &c);