From e9e36e24f0bd939d62f2476c3777ccfce221adf3 Mon Sep 17 00:00:00 2001 From: aien-spark Date: Wed, 4 Nov 2026 19:53:48 -0600 Subject: [PATCH] fix(aien-test): a direct run reuses a receipt only for the same tree (#517) A direct `aien-test run|test|plan|why` keeps one evidence store per repository (~/workspace/evidence-out/) for every commit, and its cache key held only the gate's declared inputs. A gate that reads an undeclared file (SC-TEST reads the root README.md) was reused across commits that changed that file. options() now puts the checkout's tree id in the pins, so every key of a direct run names its tree: a re-push or a squash merge of an up-to-date PR still reuses, any changed file runs the gate again. If the tree id cannot be read the cache is off. The worker is unchanged: it keeps evidence per head and crosses heads by declared inputs only through cache::cross_head. Red/green: judge_once_tests a_direct_run_reuses_only_a_receipt_made_for_ the_same_tree and without_the_tree_a_direct_run_would_reuse_an_older_commit. Co-authored-by: Drake Stapleton Signed-off-by: aien-spark --- tools/aien-test/src/judge_once_tests.rs | 40 +++++++++++++++++++++++++ tools/aien-test/src/main.rs | 9 ++++++ tools/aien-test/src/runner.rs | 13 ++++++++ 3 files changed, 62 insertions(+) diff --git a/tools/aien-test/src/judge_once_tests.rs b/tools/aien-test/src/judge_once_tests.rs index 3525df85..c8783de2 100644 --- a/tools/aien-test/src/judge_once_tests.rs +++ b/tools/aien-test/src/judge_once_tests.rs @@ -501,3 +501,43 @@ fn a_listed_directory_puts_its_names_in_the_key_not_its_bytes() { fx.commit("crates/b/tests/two.rs", "z\n"); assert_ne!(digest(), d0, "a new test target"); } + +// ---- direct runs (#517) ------------------------------------------------- + +/// The options a direct `aien-test run` gives the checkout: one evidence +/// store for every commit (`default_evidence_dir`), no cross-head store. +fn direct(fx: &Fx, pins: Value) -> Outcome { + let mut o = fx.opts(); + o.evidence_dir = fx.ev.path().join("direct"); + o.shared_cache = None; + o.pins = pins; + runner::run_gate(fx.repo.path(), &fx.repo.path().join("tests/a.gate"), &o).unwrap() +} + +#[test] +fn a_direct_run_reuses_only_a_receipt_made_for_the_same_tree() { + let fx = Fx::new(PASS, 1, ""); + direct(&fx, runner::direct_pins(fx.repo.path()).unwrap()); + assert_eq!(fx.runs(), 1); + // An undeclared file changes (SC-TEST reads the root README.md): it runs again. + fx.commit("README", "other head\n"); + let second = direct(&fx, runner::direct_pins(fx.repo.path()).unwrap()); + assert_eq!((fx.runs(), reused(&second)), (2, None)); + // The same tree under a new commit (a re-push) reuses. + let h2 = fx.head(); + fx.same_tree_commit(); + let third = direct(&fx, runner::direct_pins(fx.repo.path()).unwrap()); + assert_eq!(fx.runs(), 2); + assert_eq!(reused(&third).map(|r| r.1), Some(h2.as_str())); +} + +#[test] +fn without_the_tree_a_direct_run_would_reuse_an_older_commit() { + // The red half: the key alone (no tree) lets the README change through. + let fx = Fx::new(PASS, 1, ""); + direct(&fx, Value::Array(vec![])); + fx.commit("README", "other head\n"); + let second = direct(&fx, Value::Array(vec![])); + assert_eq!(fx.runs(), 1); + assert!(reused(&second).is_some()); +} diff --git a/tools/aien-test/src/main.rs b/tools/aien-test/src/main.rs index 6135dfa0..eba64193 100644 --- a/tools/aien-test/src/main.rs +++ b/tools/aien-test/src/main.rs @@ -108,6 +108,15 @@ fn options(cli: &Cli, root: &Path) -> Result { // plain `run` never lifts an operator gate. opts.operator = cli.operator; opts.cargo_target_dir = std::env::var_os("CARGO_TARGET_DIR").map(PathBuf::from); + // One evidence store serves every commit of this checkout, so the tree is + // in every cache key (#517). Without it, no reuse at all. + match runner::direct_pins(root) { + Ok(p) => opts.pins = p, + Err(e) => { + eprintln!("aien-test: cache off, cannot read the tree id ({e})"); + opts.no_cache = true; + } + } Ok(opts) } diff --git a/tools/aien-test/src/runner.rs b/tools/aien-test/src/runner.rs index 9ba5746c..527f605c 100644 --- a/tools/aien-test/src/runner.rs +++ b/tools/aien-test/src/runner.rs @@ -226,6 +226,19 @@ pub fn head_tree(root: &Path) -> Result { } } +/// The cache pins of a direct run (`aien-test run`, `test`, `plan`, `why` +/// from a checkout). Its evidence store is one per repository +/// (`default_evidence_dir`), shared by every commit, and a gate may read +/// files it does not declare (SC-TEST reads the root README.md). So the +/// checkout's tree is part of every key: a receipt is reused only by a head +/// whose files are all identical, a re-push or a squash merge of an +/// up-to-date PR (#517). The worker keeps evidence per head and sets its own +/// pins; reuse by declared inputs alone is its cross-head store's job +/// (`cache::cross_head`). +pub fn direct_pins(root: &Path) -> Result { + Ok(json!([{ "name": "head-tree", "tree": head_tree(root)? }])) +} + fn porcelain(root: &Path) -> Result { git_out(root, &["status", "--porcelain"]) }