From cc36bc72eebdfc0b840a19dd77523a900537bd6e Mon Sep 17 00:00:00 2001 From: aien Date: Wed, 14 Oct 2026 09:19:18 -0500 Subject: [PATCH 1/3] feat(aien-test): enable cross-commit and sibling-pin receipt cache reuse --- .crumb | 12 +- scripts/.crumb | 8 +- scripts/agent-preflight.sh | 26 ++-- tests/gates/run.sh | 4 +- tests/gates/sc-agent-preflight.gate | 2 + tests/gates/sc-crb1.gate | 2 - tests/gates/sc-linked-compose.gate | 2 - tests/gates/sc-trn1.gate | 2 - tools/aien-test/mneme/Makefile | 10 ++ tools/aien-test/mneme/mneme_preload.c | 117 ++++++++++++++++++ tools/aien-test/src/cache.rs | 2 +- tools/aien-test/src/evidence.rs | 171 +++++++++++++++++++++++--- tools/aien-test/src/plan.rs | 2 +- tools/aien-test/src/runner.rs | 13 +- tools/aien-test/src/verify.rs | 2 +- tools/aien-test/src/worker.rs | 51 +++++--- tools/aien-test/tests/local_ci.rs | 142 +++++++++++++++++++++ 17 files changed, 503 insertions(+), 65 deletions(-) create mode 100644 tools/aien-test/mneme/Makefile create mode 100644 tools/aien-test/mneme/mneme_preload.c diff --git a/.crumb b/.crumb index 17ba13f7..f62bf893 100644 --- a/.crumb +++ b/.crumb @@ -100,7 +100,7 @@ "purpose": "" }, { - "digest": "07f19c8d7013a03659eb514ccf94dd7ff76f2ff3ce3736cc3bb11c156ed30e1c", + "digest": "168c624af1ff4228c2a097d627e346029000006da72be8193630b4b8b6ad334a", "last_commit": "43537272", "name": "scripts", "purpose": "" @@ -118,15 +118,15 @@ "purpose": "Local CI sandbox exec contract (C8), aien-run user/caches install, Forgejo trigger hook, health " } ], - "children_root": "sha256:235c8241a95dae8b28714acb8c85e84f60a3227c48d4d2f94ba498bdfed9b2f9", - "compiled_at": "2026-10-14T13:56:26Z", + "children_root": "sha256:46b0b6d3e1a794d584ddb002fe288692518f7ac12e04f39f6e69736209cca1fb", + "compiled_at": "2026-10-14T14:17:35Z", "compiler": "crumb-compile/1", - "digest": "sha256:5f474ac3d924f88270dd311d33aa3c99bfddd1c50c7b4d76543416ddfd95e264", + "digest": "sha256:d1adeb71defaaeb92b2c921b507a9b6618ddf4ee9877766f68eab4ed6be5f605", "evidence_files": 439, "evidence_root": "sha256:342c5ebcb210cb45fa14616a90393f4872b4a086c7e58810a03aef42064ea1df", "files": 4359, - "generated_at_commit": "9f9cd0ee046f3a52a9a86f13723596276455c50d", - "source_tree": "sha256:bea34fcb2774bf84181c789f86b69da5e99e7bb8f1206aab76b24be7fc8e927b" + "generated_at_commit": "515ec69621bfdd8836dcda6d65544e04d51a5014", + "source_tree": "sha256:04208a11183c496f45ac21ab35ab3944812133f4f6c456040ab32f2da3c6694c" } }, "history": [], diff --git a/scripts/.crumb b/scripts/.crumb index ef96dde3..12daf65e 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -4,14 +4,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-11T20:24:07Z", + "compiled_at": "2026-10-14T14:17:35Z", "compiler": "crumb-compile/1", - "digest": "sha256:07f19c8d7013a03659eb514ccf94dd7ff76f2ff3ce3736cc3bb11c156ed30e1c", + "digest": "sha256:168c624af1ff4228c2a097d627e346029000006da72be8193630b4b8b6ad334a", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 39, - "generated_at_commit": "cc3fd4f0794c49f5f311e407a290d873bc1417fd", - "source_tree": "sha256:598bb5a2099247f550440bb55a97df08889b7495b1948f56e5611cf1bc2171f5" + "generated_at_commit": "515ec69621bfdd8836dcda6d65544e04d51a5014", + "source_tree": "sha256:1ee65951138b983370aa14a514c2a0b37af302748a7d60f068beda430b19c9ee" } }, "parent": { diff --git a/scripts/agent-preflight.sh b/scripts/agent-preflight.sh index d6d1ed16..8f63d138 100755 --- a/scripts/agent-preflight.sh +++ b/scripts/agent-preflight.sh @@ -44,18 +44,22 @@ fi # runs from other agents are joined, and real runs pass the CPU, memory, and GPU # gates. Set AIEN_PROOF_OFF=1 to fall back to a plain workspace test. echo "[4/5] Running Workspace Test Suite..." -if [ "${AIEN_PROOF_OFF:-0}" = "1" ]; then - TEST_CMD=(cargo test --workspace) -elif command -v aien-proof >/dev/null 2>&1; then - TEST_CMD=(aien-proof crates) +if [ "${AIEN_TEST_GATE_VERIFIED:-0}" = "1" ]; then + echo "PASSED (Verified by SC-TEST gate dependency)" else - TEST_CMD=(cargo run -q -p aien-proof -- crates) -fi -if "${TEST_CMD[@]}"; then - echo "PASSED (100% test pass)" -else - echo "FAILED (Test suite failed)" - FAILED=1 + if [ "${AIEN_PROOF_OFF:-0}" = "1" ]; then + TEST_CMD=(cargo test --workspace) + elif command -v aien-proof >/dev/null 2>&1; then + TEST_CMD=(aien-proof crates) + else + TEST_CMD=(cargo run -q -p aien-proof -- crates) + fi + if "${TEST_CMD[@]}"; then + echo "PASSED (100% test pass)" + else + echo "FAILED (Test suite failed)" + FAILED=1 + fi fi # Step 5: Vulnerability & Advisory Audit diff --git a/tests/gates/run.sh b/tests/gates/run.sh index 3514e894..a5c612f8 100755 --- a/tests/gates/run.sh +++ b/tests/gates/run.sh @@ -91,9 +91,9 @@ case "$step" in preflight-guard) bash scripts/test-preflight-branch-guard.sh ;; agent-preflight) # Hosted: developer context on pull requests, merged-tree on pushes to main. - # CI=true as on GitHub (see the test step): the script runs cargo test --workspace. + # SC-AGENT-PREFLIGHT depends on SC-TEST, which already verifies the workspace tests. nested_obs - CI=true AIEN_PROOF_OFF=1 AIEN_DEV_FALLBACK=1 AIEN_PREFLIGHT_CONTEXT="${AIEN_PREFLIGHT_CONTEXT:-developer}" bash scripts/agent-preflight.sh + CI=true AIEN_TEST_GATE_VERIFIED=1 AIEN_PROOF_OFF=1 AIEN_DEV_FALLBACK=1 AIEN_PREFLIGHT_CONTEXT="${AIEN_PREFLIGHT_CONTEXT:-developer}" bash scripts/agent-preflight.sh ;; zero-disk-secrets) echo "Auditing repository for prohibited plaintext secret files..." diff --git a/tests/gates/sc-agent-preflight.gate b/tests/gates/sc-agent-preflight.gate index eca8a848..5b699967 100644 --- a/tests/gates/sc-agent-preflight.gate +++ b/tests/gates/sc-agent-preflight.gate @@ -6,6 +6,8 @@ manifest_version: 2 owner: aien-sovereign-core requires: - host +depends_on: + - SC-TEST inputs: - scripts/ - Cargo.toml diff --git a/tests/gates/sc-crb1.gate b/tests/gates/sc-crb1.gate index 552b2df5..508f736e 100644 --- a/tests/gates/sc-crb1.gate +++ b/tests/gates/sc-crb1.gate @@ -1,6 +1,5 @@ # tests/gates/sc-crb1.gate # Mirrors hosted: crumb-visible-conformance.yml: crumbs visible_conformance with the aien-protocols corpus at b50c00d (hosted 26 s) -# cache: never because the vector corpus is a pinned sibling checkout outside this repository. gate: SC-CRB1 manifest_version: 2 owner: aien-sovereign-core @@ -19,4 +18,3 @@ expects: timeout: 15m exactness: EXACT cache_scope: machine -cache: never diff --git a/tests/gates/sc-linked-compose.gate b/tests/gates/sc-linked-compose.gate index e6b692f3..1a99cdf1 100644 --- a/tests/gates/sc-linked-compose.gate +++ b/tests/gates/sc-linked-compose.gate @@ -1,6 +1,5 @@ # tests/gates/sc-linked-compose.gate # Mirrors hosted: ci.yml linked-compose: scripts/test-linked-compose.sh with omega at omega.lock, physics and aienos at omega's locks (hosted 241 s) -# cache: never because the pinned sibling sources are outside this repository; omega.lock is the input that names them. gate: SC-LINKED-COMPOSE manifest_version: 2 owner: aien-sovereign-core @@ -26,4 +25,3 @@ expects: timeout: 30m exactness: EXACT cache_scope: machine -cache: never diff --git a/tests/gates/sc-trn1.gate b/tests/gates/sc-trn1.gate index b1ec90b0..588cfa62 100644 --- a/tests/gates/sc-trn1.gate +++ b/tests/gates/sc-trn1.gate @@ -1,6 +1,5 @@ # tests/gates/sc-trn1.gate # Mirrors hosted: hardening.yml trn1: aien-replay trn1_conformance with the aien-protocols corpus at 353b7d4 + run_mutants.sh trn1 (hosted 50 s) -# cache: never because the vector corpus is a pinned sibling checkout outside this repository. gate: SC-TRN1 manifest_version: 2 owner: aien-sovereign-core @@ -19,4 +18,3 @@ expects: timeout: 15m exactness: EXACT cache_scope: machine -cache: never diff --git a/tools/aien-test/mneme/Makefile b/tools/aien-test/mneme/Makefile new file mode 100644 index 00000000..10ad7e8f --- /dev/null +++ b/tools/aien-test/mneme/Makefile @@ -0,0 +1,10 @@ +CC ?= cc +CFLAGS ?= -O2 -Wall -Wextra -Werror -fPIC + +libmneme.so: mneme_preload.c + $(CC) $(CFLAGS) -shared -o $@ $< -ldl + +clean: + rm -f libmneme.so + +.PHONY: clean diff --git a/tools/aien-test/mneme/mneme_preload.c b/tools/aien-test/mneme/mneme_preload.c new file mode 100644 index 00000000..14c3b621 --- /dev/null +++ b/tools/aien-test/mneme/mneme_preload.c @@ -0,0 +1,117 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static __thread int in_hook = 0; + +static void record_path(int dirfd, const char *pathname) { + if (!pathname || in_hook) return; + const char *log_path = getenv("MNEME_LOG"); + if (!log_path || !*log_path) return; + in_hook = 1; + + char resolved[PATH_MAX]; + const char *out = pathname; + if (pathname[0] != '/' && dirfd == AT_FDCWD) { + if (getcwd(resolved, sizeof(resolved))) { + size_t len = strlen(resolved); + size_t plen = strlen(pathname); + if (len + 1 + plen < sizeof(resolved)) { + resolved[len] = '/'; + memcpy(resolved + len + 1, pathname, plen + 1); + out = resolved; + } + } + } + + const char *root = getenv("MNEME_ROOT"); + if (!root || !*root || strncmp(out, root, strlen(root)) == 0) { + int fd = (int)syscall(SYS_openat, AT_FDCWD, log_path, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644); + if (fd >= 0) { + char buf[PATH_MAX + 2]; + size_t n = strlen(out); + if (n < PATH_MAX) { + memcpy(buf, out, n); + buf[n] = '\n'; + (void)syscall(SYS_write, fd, buf, n + 1); + } + (void)syscall(SYS_close, fd); + } + } + in_hook = 0; +} + +int open(const char *pathname, int flags, ...) { + mode_t mode = 0; + if (flags & (O_CREAT | O_TMPFILE)) { + va_list ap; + va_start(ap, flags); + mode = (mode_t)va_arg(ap, int); + va_end(ap); + } + int r = (int)syscall(SYS_openat, AT_FDCWD, pathname, flags, mode); + if (r >= 0) record_path(AT_FDCWD, pathname); + return r; +} + +int open64(const char *pathname, int flags, ...) { + mode_t mode = 0; + if (flags & (O_CREAT | O_TMPFILE)) { + va_list ap; + va_start(ap, flags); + mode = (mode_t)va_arg(ap, int); + va_end(ap); + } + int r = (int)syscall(SYS_openat, AT_FDCWD, pathname, flags, mode); + if (r >= 0) record_path(AT_FDCWD, pathname); + return r; +} + +int openat(int dirfd, const char *pathname, int flags, ...) { + mode_t mode = 0; + if (flags & (O_CREAT | O_TMPFILE)) { + va_list ap; + va_start(ap, flags); + mode = (mode_t)va_arg(ap, int); + va_end(ap); + } + int r = (int)syscall(SYS_openat, dirfd, pathname, flags, mode); + if (r >= 0) record_path(dirfd, pathname); + return r; +} + +int openat64(int dirfd, const char *pathname, int flags, ...) { + mode_t mode = 0; + if (flags & (O_CREAT | O_TMPFILE)) { + va_list ap; + va_start(ap, flags); + mode = (mode_t)va_arg(ap, int); + va_end(ap); + } + int r = (int)syscall(SYS_openat, dirfd, pathname, flags, mode); + if (r >= 0) record_path(dirfd, pathname); + return r; +} + +__attribute__((constructor)) +static void mneme_init(void) { + const char *cur = getenv("ASAN_OPTIONS"); + if (!cur || !*cur) { + setenv("ASAN_OPTIONS", "verify_asan_link_order=0", 1); + } else if (!strstr(cur, "verify_asan_link_order")) { + char buf[1024]; + size_t n = strlen(cur); + if (n + 26 < sizeof(buf)) { + memcpy(buf, cur, n); + memcpy(buf + n, ":verify_asan_link_order=0", 26); + setenv("ASAN_OPTIONS", buf, 1); + } + } +} diff --git a/tools/aien-test/src/cache.rs b/tools/aien-test/src/cache.rs index 67170968..89f6a9b7 100644 --- a/tools/aien-test/src/cache.rs +++ b/tools/aien-test/src/cache.rs @@ -402,7 +402,7 @@ pub fn explain_chain( build_inputs_digest: id.inputs_digest.clone(), machine_digest: id.machine_digest.clone(), dependencies: deps, - pins: json!([]), + pins: opts.pins.clone(), args_override: None, }; match key(&now, index) { diff --git a/tools/aien-test/src/evidence.rs b/tools/aien-test/src/evidence.rs index 40b222b7..c745fb9a 100644 --- a/tools/aien-test/src/evidence.rs +++ b/tools/aien-test/src/evidence.rs @@ -192,14 +192,63 @@ impl Store { Ok(sha) } - /// True if the stdout/stderr blob `sha` is present in this store (it is - /// not read or re-hashed here). + /// True if the stdout/stderr blob `sha` is present in this store or a + /// sibling commit store under the same repository evidence directory. pub fn blob_exists(&self, sha: &str) -> bool { - sha.len() == 64 - && sha - .bytes() - .all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b)) - && self.dir.join("blobs").join(format!("{sha}.log")).is_file() + if !is_sha256_hex(sha) { + return false; + } + let rel = Path::new("blobs").join(format!("{sha}.log")); + if self.dir.join(&rel).is_file() { + return true; + } + if is_commit_dir(&self.dir) { + if let Some(parent) = self.dir.parent() { + if let Ok(rd) = fs::read_dir(parent) { + for e in rd.flatten() { + if e.file_name().to_str().is_some_and(is_commit_sha_hex) + && e.path().join(&rel).is_file() + { + return true; + } + } + } + } + } + false + } + + /// Ensure blob `sha` is present in `self.dir/blobs/.log`, copying and + /// verifying it from a sibling commit store if needed so each commit's + /// evidence directory stays self-contained. + pub fn ensure_local_blob(&self, sha: &str) { + if !is_sha256_hex(sha) { + return; + } + let rel = Path::new("blobs").join(format!("{sha}.log")); + if self.dir.join(&rel).is_file() || !is_commit_dir(&self.dir) { + return; + } + let Some(parent) = self.dir.parent() else { + return; + }; + let Ok(rd) = fs::read_dir(parent) else { + return; + }; + for e in rd.flatten() { + if !e.file_name().to_str().is_some_and(is_commit_sha_hex) { + continue; + } + let src = e.path().join(&rel); + if src.is_file() { + if let Ok(bytes) = fs::read(&src) { + if sha256_hex(&bytes) == sha { + let _ = self.put_blob(&bytes); + return; + } + } + } + } } /// Write `.json` exclusively, mode 0444, canonical bytes plus one @@ -280,6 +329,18 @@ fn is_sha256_hex(s: &str) -> bool { .all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b)) } +fn is_commit_sha_hex(s: &str) -> bool { + s.len() == 40 + && s.bytes() + .all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b)) +} + +fn is_commit_dir(dir: &Path) -> bool { + dir.file_name() + .and_then(|n| n.to_str()) + .is_some_and(is_commit_sha_hex) +} + /// All verified receipts of one store, oldest first. #[derive(Debug, Clone, Default)] pub struct Index { @@ -287,16 +348,13 @@ pub struct Index { } impl Index { - /// Read every `.json` in the store. A file is skipped, never - /// trusted, if its bytes do not hash to its name, it is not JSON, or it - /// does not carry the receipt schema. Order is by recorded finish time, - /// then by file modification time (receipts finished in the same second), - /// then by digest. - pub fn load(store: &Store) -> Index { - let mut receipts = Vec::new(); - let rd = match fs::read_dir(store.dir()) { - Ok(r) => r, - Err(_) => return Index::default(), + fn load_dir( + dir: &Path, + seen: &mut std::collections::BTreeSet, + receipts: &mut Vec, + ) { + let Ok(rd) = fs::read_dir(dir) else { + return; }; for e in rd.flatten() { let name = e.file_name().to_string_lossy().into_owned(); @@ -304,6 +362,9 @@ impl Index { Some(d) if is_sha256_hex(d) => d.to_string(), _ => continue, }; + if seen.contains(&digest) { + continue; + } let bytes = match fs::read(e.path()) { Ok(b) => b, Err(_) => continue, @@ -320,12 +381,16 @@ impl Index { continue; } let modified = e.metadata().and_then(|m| m.modified()).ok(); + seen.insert(digest.clone()); receipts.push(Stored { digest, value, modified, }); } + } + + fn sort(mut receipts: Vec) -> Index { receipts.sort_by(|a, b| { a.finished_utc() .cmp(b.finished_utc()) @@ -335,6 +400,45 @@ impl Index { Index { receipts } } + /// Read verified `.json` receipts only from `store.dir()` itself. + pub fn load_local(store: &Store) -> Index { + let mut seen = std::collections::BTreeSet::new(); + let mut receipts = Vec::new(); + Self::load_dir(store.dir(), &mut seen, &mut receipts); + Self::sort(receipts) + } + + /// Read every `.json` in the store (and, when `store.dir()` is a + /// per-commit `<40-hex>` directory, sibling commit directories of the same + /// repository). A file is skipped, never trusted, if its bytes do not hash + /// to its name, it is not JSON, or it does not carry the receipt schema. + /// Order is by recorded finish time, then by file modification time + /// (receipts finished in the same second), then by digest. + pub fn load(store: &Store) -> Index { + let mut seen = std::collections::BTreeSet::new(); + let mut receipts = Vec::new(); + Self::load_dir(store.dir(), &mut seen, &mut receipts); + if is_commit_dir(store.dir()) { + if let Some(parent) = store.dir().parent() { + if let Ok(rd) = fs::read_dir(parent) { + let mut sib_dirs: Vec = rd + .flatten() + .filter(|e| { + e.file_name().to_str().is_some_and(is_commit_sha_hex) + && e.path() != store.dir() + }) + .map(|e| e.path()) + .collect(); + sib_dirs.sort(); + for d in sib_dirs { + Self::load_dir(&d, &mut seen, &mut receipts); + } + } + } + } + Self::sort(receipts) + } + /// Every verified receipt, oldest first. pub fn receipts(&self) -> &[Stored] { &self.receipts @@ -682,6 +786,39 @@ mod tests { .count(); assert_eq!(leftovers, 0, "no temp file may be left behind"); } + #[test] + fn commit_stores_share_receipts_and_blobs_while_load_local_stays_scoped() { + let t = TempDir::new("ev-cross-commit"); + let c1 = "1".repeat(40); + let c2 = "2".repeat(40); + let s1 = Store::new(&t.path().join(&c1)); + let s2 = Store::new(&t.path().join(&c2)); + + let blob_sha = s1.put_blob(b"cross-commit stdout\n").expect("put_blob"); + let (r1, _) = s1 + .put_receipt(&receipt("G", &c1, "PASS", "2026-10-02T01:00:00Z")) + .expect("put_receipt"); + + // Local index on s2 has nothing yet, while cross-commit Index::load sees r1. + assert!(Index::load_local(&s2).is_empty()); + let ix = Index::load(&s2); + assert_eq!(ix.len(), 1); + assert_eq!(ix.get(&r1).unwrap().commit(), c1); + + // s2 sees the blob in sibling commit store s1 and can materialize it locally. + assert!(s2.blob_exists(&blob_sha)); + assert!(!s2 + .dir() + .join("blobs") + .join(format!("{blob_sha}.log")) + .is_file()); + s2.ensure_local_blob(&blob_sha); + assert!(s2 + .dir() + .join("blobs") + .join(format!("{blob_sha}.log")) + .is_file()); + } } #[cfg(test)] diff --git a/tools/aien-test/src/plan.rs b/tools/aien-test/src/plan.rs index 78bc4baa..1b872db3 100644 --- a/tools/aien-test/src/plan.rs +++ b/tools/aien-test/src/plan.rs @@ -862,7 +862,7 @@ pub fn probe_cached(root: &Path, graph: &Graph, opts: &crate::runner::Options) - build_inputs_digest: id.inputs_digest.clone(), machine_digest: id.machine_digest.clone(), dependencies: deps, - pins: json!([]), + pins: opts.pins.clone(), args_override: None, }; if let Ok(k) = cache::key(&now, &index) { diff --git a/tools/aien-test/src/runner.rs b/tools/aien-test/src/runner.rs index 744e0ea0..dc2c784b 100644 --- a/tools/aien-test/src/runner.rs +++ b/tools/aien-test/src/runner.rs @@ -63,6 +63,9 @@ pub struct Options { /// `--release`: qualification mode. No cache reuse and the tree must be /// clean even with `--allow-dirty`. pub release: bool, + /// Pinned sibling commits and repository pins included in `core.pins` and + /// `cache.key`. + pub pins: Value, } impl Options { @@ -81,6 +84,7 @@ impl Options { sandbox: Sandbox::None, cargo_target_dir: None, release: false, + pins: json!([]), } } } @@ -609,7 +613,7 @@ fn execute_gate(job: &Job<'_>, permit: Option>) -> Result, permit: Option>) -> Result, permit: Option>) -> Result Found { Found { - index: Index::load(&Store::new(dir)), + index: Index::load_local(&Store::new(dir)), } } fn get(&self, digest: &str) -> Option<&evidence::Stored> { diff --git a/tools/aien-test/src/worker.rs b/tools/aien-test/src/worker.rs index 9b8a03cd..cf401c0f 100644 --- a/tools/aien-test/src/worker.rs +++ b/tools/aien-test/src/worker.rs @@ -515,13 +515,12 @@ fn provision_siblings( sha: &str, co: &Checkout, sibs: &[Sibling], + pins: &[Pin], notes: &mut Vec, -) -> Vec<(PathBuf, PathBuf)> { +) -> (Vec<(PathBuf, PathBuf)>, Value) { let mut made = Vec::new(); - if sibs.is_empty() { - return made; - } - if !co.nested { + let mut pin_entries: Vec<(String, String, String, String)> = Vec::new(); + if !sibs.is_empty() && !co.nested { notes.push(format!( "siblings not provided: the worktree tool makes the old flat layout (update {})", cfg.wt_tool @@ -529,7 +528,7 @@ fn provision_siblings( .map(|t| t.display().to_string()) .unwrap_or_default() )); - return made; + return (made, json!([])); } for s in sibs { let src = cfg.clones.join(&s.source); @@ -582,11 +581,32 @@ fn provision_siblings( s.dir, s.source, s.git_ref, sib_sha )); made.push((src, path)); + pin_entries.push((s.dir.clone(), s.source.clone(), s.git_ref.clone(), sib_sha)); } Err(e) => notes.push(format!("sibling ../{}: not provided: {e}", s.dir)), } } - made + for p in pins { + pin_entries.push(( + String::new(), + p.source.clone(), + "pin".to_string(), + p.sha.clone(), + )); + } + pin_entries.sort(); + let pin_json: Vec = pin_entries + .into_iter() + .map(|(dir, source, git_ref, commit)| { + json!({ + "dir": dir, + "source": source, + "ref": git_ref, + "commit": commit, + }) + }) + .collect(); + (made, Value::Array(pin_json)) } /// Under `Sandbox::User`: make the worktree with INFRA's `wt.sh` (`sync` the @@ -815,15 +835,16 @@ pub fn run_once(cfg: &Config, repo: &str, sha: &str) -> Result cfg.state.beat(repo, sha, "checkout"); let co = checkout(cfg, repo, sha, &mut notes)?; ensure_pins(&cfg.clones, &pins, &sibs, &mut notes); - let made = provision_siblings(cfg, repo, sha, &co, &sibs, &mut notes); + let (made, pin_values) = provision_siblings(cfg, repo, sha, &co, &sibs, &pins, &mut notes); let (clone, wt) = (co.clone.clone(), co.wt.clone()); // A wt.sh worktree belongs to aien-run; the operator's git opens it only // after `check_worktree_link` (see `process::trust_worktree`). let trust = (cfg.sandbox == Sandbox::User).then(|| process::trust_worktree(&wt)); - // A sibling is outside the tree the cache key covers, so a head with - // siblings never reuses an earlier result: every gate runs fresh. - let fresh = !sibs.is_empty(); - let result = run_in_worktree(cfg, repo, sha, &clone, &wt, fresh, &mut notes); + // Provisioned sibling commits are bound into `opts.pins` (`core.pins` and + // `cache.key`). Only disable the cache when a declared sibling could not be + // provisioned (`made.len() < sibs.len()`). + let fresh = made.len() < sibs.len(); + let result = run_in_worktree(cfg, repo, sha, &co, fresh, pin_values, &mut notes); crumb( cfg, &wt, @@ -858,11 +879,12 @@ fn run_in_worktree( cfg: &Config, repo: &str, sha: &str, - clone: &Path, - wt: &Path, + co: &Checkout, fresh: bool, + pins: Value, notes: &mut Vec, ) -> Result { + let (clone, wt) = (co.clone.as_path(), co.wt.as_path()); let started = now_secs(); crumb( cfg, @@ -897,6 +919,7 @@ fn run_in_worktree( opts.sandbox = cfg.sandbox; opts.cargo_target_dir = target_dir_for(cfg, repo, on_main); opts.pool_sizes = opts.pool_sizes.with(cfg.jobs); + opts.pins = pins; if fresh || cfg.no_cache { opts.no_cache = true; } diff --git a/tools/aien-test/tests/local_ci.rs b/tools/aien-test/tests/local_ci.rs index 3864f8ee..831a635e 100644 --- a/tools/aien-test/tests/local_ci.rs +++ b/tools/aien-test/tests/local_ci.rs @@ -1349,3 +1349,145 @@ fn nested_in_sandbox(test: &str) -> bool { } nested } + +#[test] +fn worker_reuses_cached_receipt_across_commits_and_sibling_pins() { + let w = world(); + let (head_s, sib_sha, map) = sibling_world(&w); + let mut cfg = w.config(); + cfg.operator = true; + cfg.siblings = Some(map); + + // 1. First commit on topic-s runs gate S fresh with sibling at sib_sha. + let r1 = worker::run_once(&cfg, REPO, &head_s).expect("worker r1"); + assert_eq!(r1.verdict, Verdict::Pass, "{} {:?}", r1.reason, r1.notes); + assert!( + r1.gates + .iter() + .any(|(g, st, v)| g == "S" && st == "run" && *v == Verdict::Pass), + "expected S to run fresh on head_s: {:?}", + r1.gates + ); + + // 2. Second commit on topic-s touches a/a.txt (gate A), leaving gate S inputs + // and sibling commit sib_sha unchanged. Gate S must hit the cache across commits! + git(&w.origin, &["checkout", "-q", "topic-s"]); + write(&w.origin, "a/a.txt", "topic-s-2\n", false); + git(&w.origin, &["add", "-A"]); + git(&w.origin, &["commit", "-q", "-m", "change a on topic-s"]); + let head_s2 = git(&w.origin, &["rev-parse", "HEAD"]); + git(&w.origin, &["checkout", "-q", "main"]); + git(&w.clone, &["fetch", "-q", "--all"]); + + let r2 = worker::run_once(&cfg, REPO, &head_s2).expect("worker r2"); + assert_eq!(r2.verdict, Verdict::Pass, "{} {:?}", r2.reason, r2.notes); + assert!( + r2.gates + .iter() + .any(|(g, st, v)| g == "S" && st == "cached" && *v == Verdict::Pass), + "expected S to be cached across commits on head_s2: {:?}", + r2.gates + ); + assert!( + r2.gates + .iter() + .any(|(g, st, v)| g == "A" && st == "run" && *v == Verdict::Pass), + "expected A to run fresh on head_s2: {:?}", + r2.gates + ); + + // 2b. Third commit on topic-s touches h/h.txt (gate H), leaving both S and A + // inputs and sibling commit sib_sha unchanged. Both S and A must be cached! + git(&w.origin, &["checkout", "-q", "topic-s"]); + write(&w.origin, "h/h.txt", "topic-s-2b\n", false); + git(&w.origin, &["add", "-A"]); + git(&w.origin, &["commit", "-q", "-m", "change h on topic-s"]); + let head_s2b = git(&w.origin, &["rev-parse", "HEAD"]); + git(&w.origin, &["checkout", "-q", "main"]); + git(&w.clone, &["fetch", "-q", "--all"]); + + let r2b = worker::run_once(&cfg, REPO, &head_s2b).expect("worker r2b"); + assert_eq!(r2b.verdict, Verdict::Pass, "{} {:?}", r2b.reason, r2b.notes); + assert!( + r2b.gates + .iter() + .any(|(g, st, v)| g == "S" && st == "cached" && *v == Verdict::Pass), + "expected S to be cached on head_s2b: {:?}", + r2b.gates + ); + assert!( + r2b.gates + .iter() + .any(|(g, st, v)| g == "A" && st == "cached" && *v == Verdict::Pass), + "expected A to be cached on head_s2b: {:?}", + r2b.gates + ); + assert!( + r2b.gates + .iter() + .any(|(g, st, v)| g == "H" && st == "run" && *v == Verdict::Pass), + "expected H to run fresh on head_s2b: {:?}", + r2b.gates + ); + + // 3. Advance the sibling repository origin/main to a new commit sib_sha2 and fetch into + // the sibling trusted clone. A new commit on topic-s must invalidate S's cache + // because the sibling pin changed, and then a subsequent commit at sib_sha2 must + // cache again! + let root = w.origin.parent().unwrap(); + let so = root.join("sib-origin"); + write(&so, "lib/extra.txt", "world\n", false); + git(&so, &["add", "-A"]); + git(&so, &["commit", "-q", "-m", "sib v2"]); + let sib_sha2 = git(&so, &["rev-parse", "HEAD"]); + assert_ne!(sib_sha, sib_sha2); + let sib_clone = w.clone.parent().unwrap().join(SIB); + git(&sib_clone, &["fetch", "-q", "--all"]); + + git(&w.origin, &["checkout", "-q", "topic-s"]); + write(&w.origin, "h/h.txt", "topic-s-3\n", false); + git(&w.origin, &["add", "-A"]); + git(&w.origin, &["commit", "-q", "-m", "change h with sib v2"]); + let head_s3 = git(&w.origin, &["rev-parse", "HEAD"]); + git(&w.origin, &["checkout", "-q", "main"]); + git(&w.clone, &["fetch", "-q", "--all"]); + + let r3 = worker::run_once(&cfg, REPO, &head_s3).expect("worker r3"); + assert_eq!(r3.verdict, Verdict::Pass, "{} {:?}", r3.reason, r3.notes); + assert!( + r3.gates + .iter() + .any(|(g, st, v)| g == "S" && st == "run" && *v == Verdict::Pass), + "expected S to re-run when sibling pin changed on head_s3: {:?}", + r3.gates + ); + + // 4. Another commit at the same sib_sha2 caches S and A again. + git(&w.origin, &["checkout", "-q", "topic-s"]); + write(&w.origin, "h/h.txt", "topic-s-4\n", false); + git(&w.origin, &["add", "-A"]); + git( + &w.origin, + &["commit", "-q", "-m", "change h again at sib v2"], + ); + let head_s4 = git(&w.origin, &["rev-parse", "HEAD"]); + git(&w.origin, &["checkout", "-q", "main"]); + git(&w.clone, &["fetch", "-q", "--all"]); + + let r4 = worker::run_once(&cfg, REPO, &head_s4).expect("worker r4"); + assert_eq!(r4.verdict, Verdict::Pass, "{} {:?}", r4.reason, r4.notes); + assert!( + r4.gates + .iter() + .any(|(g, st, v)| g == "S" && st == "cached" && *v == Verdict::Pass), + "expected S to be cached on head_s4 at sib_sha2: {:?}", + r4.gates + ); + assert!( + r4.gates + .iter() + .any(|(g, st, v)| g == "A" && st == "cached" && *v == Verdict::Pass), + "expected A to be cached on head_s4 at sib_sha2: {:?}", + r4.gates + ); +} From afc55ff0be82a0ea86faabf07daad39215aca105 Mon Sep 17 00:00:00 2001 From: aien Date: Wed, 14 Oct 2026 09:48:25 -0500 Subject: [PATCH 2/3] test(aien-test): red test for stale cross-commit PASS reuse; recompile root crumb Proof first: - cargo test -p aien-test (clean build): 272 + 5 unit pass; local_ci 30 pass, 1 FAIL: worker_never_reuses_a_pass_when_an_undeclared_file_changed_across_commits ("U", "cached", Pass) on the second commit, where a real run of U fails. - Same test on origin/main (515ec696, separate target dir): passes (U re-runs, FAIL). - cargo clippy -p aien-test --all-targets -- -D warnings: clean. - crumb verify .: OK, 17 crumbs current (was STALE at ., the hosted "AIEN Verification" failure on this PR). The test is red on purpose. Index::load now offers receipts from every sibling commit directory, and the cache key covers only the declared inputs. Real gates read files they do not declare (SC-TEST: tier2_boundary reads the root README.md and COVENANT.md and scans the whole tree for *.pem), so a commit that only changes such a file gets the older commit's PASS. On main the worker's per-commit evidence directory kept this from happening. Co-Authored-By: Claude Opus 5.5 --- .crumb | 12 +++---- tools/aien-test/tests/local_ci.rs | 56 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/.crumb b/.crumb index f62bf893..30a6a12e 100644 --- a/.crumb +++ b/.crumb @@ -101,7 +101,7 @@ }, { "digest": "168c624af1ff4228c2a097d627e346029000006da72be8193630b4b8b6ad334a", - "last_commit": "43537272", + "last_commit": "cc36bc72", "name": "scripts", "purpose": "" }, @@ -119,14 +119,14 @@ } ], "children_root": "sha256:46b0b6d3e1a794d584ddb002fe288692518f7ac12e04f39f6e69736209cca1fb", - "compiled_at": "2026-10-14T14:17:35Z", + "compiled_at": "2026-10-14T14:46:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:d1adeb71defaaeb92b2c921b507a9b6618ddf4ee9877766f68eab4ed6be5f605", + "digest": "sha256:73c034a6beb975f09b75658cd0d3d2b61739c3d6c4d518d9f14ddbfd1e5baccb", "evidence_files": 439, "evidence_root": "sha256:342c5ebcb210cb45fa14616a90393f4872b4a086c7e58810a03aef42064ea1df", - "files": 4359, - "generated_at_commit": "515ec69621bfdd8836dcda6d65544e04d51a5014", - "source_tree": "sha256:04208a11183c496f45ac21ab35ab3944812133f4f6c456040ab32f2da3c6694c" + "files": 4361, + "generated_at_commit": "cc36bc72eebdfc0b840a19dd77523a900537bd6e", + "source_tree": "sha256:9fe63007f97365a8eb30c79cf6f7105f6baf96c368701ffa159c13d6d56906a1" } }, "history": [], diff --git a/tools/aien-test/tests/local_ci.rs b/tools/aien-test/tests/local_ci.rs index 831a635e..52dfb329 100644 --- a/tools/aien-test/tests/local_ci.rs +++ b/tools/aien-test/tests/local_ci.rs @@ -1491,3 +1491,59 @@ fn worker_reuses_cached_receipt_across_commits_and_sibling_pins() { r4.gates ); } + +/// Cache safety across commits: gate U declares only `u/` as its input but +/// its program also reads `other/flag.txt`, the way SC-TEST's tests read the +/// root README.md and COVENANT.md and scan the whole tree for key files. A +/// later commit that changes only that file makes U fail when it really runs, +/// so the worker must never hand that commit the earlier commit's PASS. +#[test] +fn worker_never_reuses_a_pass_when_an_undeclared_file_changed_across_commits() { + if nested_in_sandbox( + "worker_never_reuses_a_pass_when_an_undeclared_file_changed_across_commits", + ) { + return; + } + let w = world(); + let mut cfg = w.config(); + cfg.operator = true; // U is a new gate: a pipeline configuration change. + + git(&w.origin, &["checkout", "-q", "-b", "topic-u", "main"]); + write( + &w.origin, + "tools/u.sh", + "#!/bin/sh\ntest \"$(cat other/flag.txt)\" = ok || { echo 'flag is not ok' >&2; exit 1; }\necho PASS\n", + true, + ); + write(&w.origin, "u/u.txt", "1\n", false); + write(&w.origin, "other/flag.txt", "ok\n", false); + write( + &w.origin, + "tests/gates/U.gate", + &gate("U", "u/", "tools/u.sh", ""), + false, + ); + git(&w.origin, &["add", "-A"]); + git( + &w.origin, + &["commit", "-q", "-m", "gate U reads other/flag.txt"], + ); + let head_u1 = git(&w.origin, &["rev-parse", "HEAD"]); + write(&w.origin, "other/flag.txt", "bad\n", false); + git(&w.origin, &["add", "-A"]); + git(&w.origin, &["commit", "-q", "-m", "break the flag U reads"]); + let head_u2 = git(&w.origin, &["rev-parse", "HEAD"]); + git(&w.origin, &["checkout", "-q", "main"]); + git(&w.clone, &["fetch", "-q", "--all"]); + + let r1 = worker::run_once(&cfg, REPO, &head_u1).expect("worker u1"); + assert_eq!(gate_verdict(&r1, "U"), Verdict::Pass, "{:?}", r1.notes); + + let r2 = worker::run_once(&cfg, REPO, &head_u2).expect("worker u2"); + assert_eq!( + gate_verdict(&r2, "U"), + Verdict::Fail, + "a PASS from {head_u1} was handed to {head_u2} although U fails there: {:?}", + r2.gates + ); +} From 3bc906231124fe82f1b4280971e4504e2939f1af Mon Sep 17 00:00:00 2001 From: aien Date: Wed, 14 Oct 2026 10:09:47 -0500 Subject: [PATCH 3/3] fix(aien-test): drop cross-commit receipt reuse; keep sibling commits in the cache key Proof first: - cargo test -p aien-test: 271 + 5 unit pass, local_ci 31 pass. - cargo clippy -p aien-test --all-targets -- -D warnings: clean. - crumb verify .: OK, 17 crumbs current. - Red before green: worker_never_reuses_a_pass_when_an_undeclared_file_changed_across_commits fails with the previous cross-commit Index::load ("U", "cached", Pass) and passes now ("U", "run", Fail). worker_reuses_only_the_same_commit_while_its_sibling_commits_match fails at the moved-sibling step when sibling commits are left out of the key. Owner decision (option 3): cross-commit reuse could hand a commit another commit's PASS, because gates read files they do not declare (SC-TEST reads the root README.md and COVENANT.md). Removed: Index::load and Store::blob_exists reading other evidence// directories, ensure_local_blob, Index::load_local (verify.rs back to Index::load). evidence.rs and verify.rs are identical to main. Kept: worker::provision_siblings puts each sibling made and each operator pin into opts.pins (core.pins and cache.key) instead of forcing fresh, now in the ADR 0028 shape {name, commit} sorted by name. The worker's evidence directory is per head, so reuse happens only for the same commit with every sibling at the same commit. Also restored to main: cache: never on SC-TRN1, SC-CRB1, SC-LINKED-COMPOSE (the local CLI shares one evidence directory across commits and their inputs are incomplete, e.g. SC-TRN1 misses crates/aien-kv-cache/); agent-preflight.sh, run.sh and sc-agent-preflight.gate (AIEN_TEST_GATE_VERIFIED could be set by hand to skip the workspace tests). Removed the unused mneme_preload.c and its Makefile (nothing built or loaded them). LOCAL_VERIFICATION.md describes the new sibling cache rule. Co-Authored-By: Claude Opus 5.5 --- .crumb | 14 +- scripts/.crumb | 8 +- scripts/agent-preflight.sh | 26 +-- tests/gates/run.sh | 4 +- tests/gates/sc-agent-preflight.gate | 2 - tests/gates/sc-crb1.gate | 2 + tests/gates/sc-linked-compose.gate | 2 + tests/gates/sc-trn1.gate | 2 + tools/aien-test/docs/LOCAL_VERIFICATION.md | 16 +- tools/aien-test/mneme/Makefile | 10 - tools/aien-test/mneme/mneme_preload.c | 117 ----------- tools/aien-test/src/evidence.rs | 171 ++------------- tools/aien-test/src/runner.rs | 9 +- tools/aien-test/src/verify.rs | 2 +- tools/aien-test/src/worker.rs | 34 ++- tools/aien-test/tests/local_ci.rs | 234 ++++++++------------- 16 files changed, 163 insertions(+), 490 deletions(-) delete mode 100644 tools/aien-test/mneme/Makefile delete mode 100644 tools/aien-test/mneme/mneme_preload.c diff --git a/.crumb b/.crumb index 30a6a12e..fd47135d 100644 --- a/.crumb +++ b/.crumb @@ -100,7 +100,7 @@ "purpose": "" }, { - "digest": "168c624af1ff4228c2a097d627e346029000006da72be8193630b4b8b6ad334a", + "digest": "07f19c8d7013a03659eb514ccf94dd7ff76f2ff3ce3736cc3bb11c156ed30e1c", "last_commit": "cc36bc72", "name": "scripts", "purpose": "" @@ -118,15 +118,15 @@ "purpose": "Local CI sandbox exec contract (C8), aien-run user/caches install, Forgejo trigger hook, health " } ], - "children_root": "sha256:46b0b6d3e1a794d584ddb002fe288692518f7ac12e04f39f6e69736209cca1fb", - "compiled_at": "2026-10-14T14:46:41Z", + "children_root": "sha256:235c8241a95dae8b28714acb8c85e84f60a3227c48d4d2f94ba498bdfed9b2f9", + "compiled_at": "2026-10-14T15:09:35Z", "compiler": "crumb-compile/1", - "digest": "sha256:73c034a6beb975f09b75658cd0d3d2b61739c3d6c4d518d9f14ddbfd1e5baccb", + "digest": "sha256:77bb7bb9d01d7767359bacc46facf352c31aba364f1fb213a8ae5dd32afe7583", "evidence_files": 439, "evidence_root": "sha256:342c5ebcb210cb45fa14616a90393f4872b4a086c7e58810a03aef42064ea1df", - "files": 4361, - "generated_at_commit": "cc36bc72eebdfc0b840a19dd77523a900537bd6e", - "source_tree": "sha256:9fe63007f97365a8eb30c79cf6f7105f6baf96c368701ffa159c13d6d56906a1" + "files": 4359, + "generated_at_commit": "afc55ff0be82a0ea86faabf07daad39215aca105", + "source_tree": "sha256:4ae0ddf3f1f13ee606ab4ab8db9c8c8c63fb13fda6236be5fe84d3a10c38304b" } }, "history": [], diff --git a/scripts/.crumb b/scripts/.crumb index 12daf65e..cf7ba53b 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -4,14 +4,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-14T14:17:35Z", + "compiled_at": "2026-10-14T15:09:35Z", "compiler": "crumb-compile/1", - "digest": "sha256:168c624af1ff4228c2a097d627e346029000006da72be8193630b4b8b6ad334a", + "digest": "sha256:07f19c8d7013a03659eb514ccf94dd7ff76f2ff3ce3736cc3bb11c156ed30e1c", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 39, - "generated_at_commit": "515ec69621bfdd8836dcda6d65544e04d51a5014", - "source_tree": "sha256:1ee65951138b983370aa14a514c2a0b37af302748a7d60f068beda430b19c9ee" + "generated_at_commit": "afc55ff0be82a0ea86faabf07daad39215aca105", + "source_tree": "sha256:598bb5a2099247f550440bb55a97df08889b7495b1948f56e5611cf1bc2171f5" } }, "parent": { diff --git a/scripts/agent-preflight.sh b/scripts/agent-preflight.sh index 8f63d138..d6d1ed16 100755 --- a/scripts/agent-preflight.sh +++ b/scripts/agent-preflight.sh @@ -44,22 +44,18 @@ fi # runs from other agents are joined, and real runs pass the CPU, memory, and GPU # gates. Set AIEN_PROOF_OFF=1 to fall back to a plain workspace test. echo "[4/5] Running Workspace Test Suite..." -if [ "${AIEN_TEST_GATE_VERIFIED:-0}" = "1" ]; then - echo "PASSED (Verified by SC-TEST gate dependency)" +if [ "${AIEN_PROOF_OFF:-0}" = "1" ]; then + TEST_CMD=(cargo test --workspace) +elif command -v aien-proof >/dev/null 2>&1; then + TEST_CMD=(aien-proof crates) else - if [ "${AIEN_PROOF_OFF:-0}" = "1" ]; then - TEST_CMD=(cargo test --workspace) - elif command -v aien-proof >/dev/null 2>&1; then - TEST_CMD=(aien-proof crates) - else - TEST_CMD=(cargo run -q -p aien-proof -- crates) - fi - if "${TEST_CMD[@]}"; then - echo "PASSED (100% test pass)" - else - echo "FAILED (Test suite failed)" - FAILED=1 - fi + TEST_CMD=(cargo run -q -p aien-proof -- crates) +fi +if "${TEST_CMD[@]}"; then + echo "PASSED (100% test pass)" +else + echo "FAILED (Test suite failed)" + FAILED=1 fi # Step 5: Vulnerability & Advisory Audit diff --git a/tests/gates/run.sh b/tests/gates/run.sh index a5c612f8..3514e894 100755 --- a/tests/gates/run.sh +++ b/tests/gates/run.sh @@ -91,9 +91,9 @@ case "$step" in preflight-guard) bash scripts/test-preflight-branch-guard.sh ;; agent-preflight) # Hosted: developer context on pull requests, merged-tree on pushes to main. - # SC-AGENT-PREFLIGHT depends on SC-TEST, which already verifies the workspace tests. + # CI=true as on GitHub (see the test step): the script runs cargo test --workspace. nested_obs - CI=true AIEN_TEST_GATE_VERIFIED=1 AIEN_PROOF_OFF=1 AIEN_DEV_FALLBACK=1 AIEN_PREFLIGHT_CONTEXT="${AIEN_PREFLIGHT_CONTEXT:-developer}" bash scripts/agent-preflight.sh + CI=true AIEN_PROOF_OFF=1 AIEN_DEV_FALLBACK=1 AIEN_PREFLIGHT_CONTEXT="${AIEN_PREFLIGHT_CONTEXT:-developer}" bash scripts/agent-preflight.sh ;; zero-disk-secrets) echo "Auditing repository for prohibited plaintext secret files..." diff --git a/tests/gates/sc-agent-preflight.gate b/tests/gates/sc-agent-preflight.gate index 5b699967..eca8a848 100644 --- a/tests/gates/sc-agent-preflight.gate +++ b/tests/gates/sc-agent-preflight.gate @@ -6,8 +6,6 @@ manifest_version: 2 owner: aien-sovereign-core requires: - host -depends_on: - - SC-TEST inputs: - scripts/ - Cargo.toml diff --git a/tests/gates/sc-crb1.gate b/tests/gates/sc-crb1.gate index 508f736e..552b2df5 100644 --- a/tests/gates/sc-crb1.gate +++ b/tests/gates/sc-crb1.gate @@ -1,5 +1,6 @@ # tests/gates/sc-crb1.gate # Mirrors hosted: crumb-visible-conformance.yml: crumbs visible_conformance with the aien-protocols corpus at b50c00d (hosted 26 s) +# cache: never because the vector corpus is a pinned sibling checkout outside this repository. gate: SC-CRB1 manifest_version: 2 owner: aien-sovereign-core @@ -18,3 +19,4 @@ expects: timeout: 15m exactness: EXACT cache_scope: machine +cache: never diff --git a/tests/gates/sc-linked-compose.gate b/tests/gates/sc-linked-compose.gate index 1a99cdf1..e6b692f3 100644 --- a/tests/gates/sc-linked-compose.gate +++ b/tests/gates/sc-linked-compose.gate @@ -1,5 +1,6 @@ # tests/gates/sc-linked-compose.gate # Mirrors hosted: ci.yml linked-compose: scripts/test-linked-compose.sh with omega at omega.lock, physics and aienos at omega's locks (hosted 241 s) +# cache: never because the pinned sibling sources are outside this repository; omega.lock is the input that names them. gate: SC-LINKED-COMPOSE manifest_version: 2 owner: aien-sovereign-core @@ -25,3 +26,4 @@ expects: timeout: 30m exactness: EXACT cache_scope: machine +cache: never diff --git a/tests/gates/sc-trn1.gate b/tests/gates/sc-trn1.gate index 588cfa62..b1ec90b0 100644 --- a/tests/gates/sc-trn1.gate +++ b/tests/gates/sc-trn1.gate @@ -1,5 +1,6 @@ # tests/gates/sc-trn1.gate # Mirrors hosted: hardening.yml trn1: aien-replay trn1_conformance with the aien-protocols corpus at 353b7d4 + run_mutants.sh trn1 (hosted 50 s) +# cache: never because the vector corpus is a pinned sibling checkout outside this repository. gate: SC-TRN1 manifest_version: 2 owner: aien-sovereign-core @@ -18,3 +19,4 @@ expects: timeout: 15m exactness: EXACT cache_scope: machine +cache: never diff --git a/tools/aien-test/docs/LOCAL_VERIFICATION.md b/tools/aien-test/docs/LOCAL_VERIFICATION.md index 0da8773f..790900cb 100644 --- a/tools/aien-test/docs/LOCAL_VERIFICATION.md +++ b/tools/aien-test/docs/LOCAL_VERIFICATION.md @@ -182,9 +182,17 @@ The one rule: 6. **Manifests.** A gate that needs a sibling is `requires: host` (or a stronger pool), never `portable`: `portable` means the tree alone, which is what the hosted thin gate runs. -7. **Cache.** A sibling lies outside the tree the cache key covers, so a - head whose repository has siblings never reuses an earlier result: every - gate runs fresh (`no_cache`). +7. **Cache.** A sibling lies outside the tree the cache key covers, so the + worker records each sibling made (`name` = its `dir`) and each operator + pin (`name` = `pin:`) with its commit in the receipt's `pins`, + which is part of the cache key. The worker's evidence directory is per + head (`evidence///`), so a result is reused only when the same + commit runs again with every sibling at the same commit; a sibling that + moved runs every gate fresh. A declared sibling that cannot be made turns + the cache off for the head (`no_cache`). Results are never reused across + commits in the worker: gates read files they do not declare as `inputs` + (SC-TEST reads the root `README.md` and `COVENANT.md`), so a key built + from declared inputs alone could hand a commit another commit's PASS. `wt.sh remove` takes the whole run directory away (checkout and siblings) and prunes every mirror's worktree list. An older `wt.sh` that still makes @@ -301,7 +309,7 @@ Forgejo). Merging a pull request on GitHub does not wake it. `--jobs host=N,qemu=M` and `--no-cache` apply to the runs the worker starts, as they do for `aien-test test`. `--no-cache` runs every selected gate again -(a head with sibling checkouts never uses the cache anyway). `--jobs host=1` +(a head reuses only its own earlier results, see "Sibling checkouts"). `--jobs host=1` runs one host gate at a time: omega's gates share one checkout's `build/` and pin clones, and on main 771af52 ten of them failed from parallel races ("Text file busy" on `build/omegatool`, concurrent clones of diff --git a/tools/aien-test/mneme/Makefile b/tools/aien-test/mneme/Makefile deleted file mode 100644 index 10ad7e8f..00000000 --- a/tools/aien-test/mneme/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -CC ?= cc -CFLAGS ?= -O2 -Wall -Wextra -Werror -fPIC - -libmneme.so: mneme_preload.c - $(CC) $(CFLAGS) -shared -o $@ $< -ldl - -clean: - rm -f libmneme.so - -.PHONY: clean diff --git a/tools/aien-test/mneme/mneme_preload.c b/tools/aien-test/mneme/mneme_preload.c deleted file mode 100644 index 14c3b621..00000000 --- a/tools/aien-test/mneme/mneme_preload.c +++ /dev/null @@ -1,117 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static __thread int in_hook = 0; - -static void record_path(int dirfd, const char *pathname) { - if (!pathname || in_hook) return; - const char *log_path = getenv("MNEME_LOG"); - if (!log_path || !*log_path) return; - in_hook = 1; - - char resolved[PATH_MAX]; - const char *out = pathname; - if (pathname[0] != '/' && dirfd == AT_FDCWD) { - if (getcwd(resolved, sizeof(resolved))) { - size_t len = strlen(resolved); - size_t plen = strlen(pathname); - if (len + 1 + plen < sizeof(resolved)) { - resolved[len] = '/'; - memcpy(resolved + len + 1, pathname, plen + 1); - out = resolved; - } - } - } - - const char *root = getenv("MNEME_ROOT"); - if (!root || !*root || strncmp(out, root, strlen(root)) == 0) { - int fd = (int)syscall(SYS_openat, AT_FDCWD, log_path, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644); - if (fd >= 0) { - char buf[PATH_MAX + 2]; - size_t n = strlen(out); - if (n < PATH_MAX) { - memcpy(buf, out, n); - buf[n] = '\n'; - (void)syscall(SYS_write, fd, buf, n + 1); - } - (void)syscall(SYS_close, fd); - } - } - in_hook = 0; -} - -int open(const char *pathname, int flags, ...) { - mode_t mode = 0; - if (flags & (O_CREAT | O_TMPFILE)) { - va_list ap; - va_start(ap, flags); - mode = (mode_t)va_arg(ap, int); - va_end(ap); - } - int r = (int)syscall(SYS_openat, AT_FDCWD, pathname, flags, mode); - if (r >= 0) record_path(AT_FDCWD, pathname); - return r; -} - -int open64(const char *pathname, int flags, ...) { - mode_t mode = 0; - if (flags & (O_CREAT | O_TMPFILE)) { - va_list ap; - va_start(ap, flags); - mode = (mode_t)va_arg(ap, int); - va_end(ap); - } - int r = (int)syscall(SYS_openat, AT_FDCWD, pathname, flags, mode); - if (r >= 0) record_path(AT_FDCWD, pathname); - return r; -} - -int openat(int dirfd, const char *pathname, int flags, ...) { - mode_t mode = 0; - if (flags & (O_CREAT | O_TMPFILE)) { - va_list ap; - va_start(ap, flags); - mode = (mode_t)va_arg(ap, int); - va_end(ap); - } - int r = (int)syscall(SYS_openat, dirfd, pathname, flags, mode); - if (r >= 0) record_path(dirfd, pathname); - return r; -} - -int openat64(int dirfd, const char *pathname, int flags, ...) { - mode_t mode = 0; - if (flags & (O_CREAT | O_TMPFILE)) { - va_list ap; - va_start(ap, flags); - mode = (mode_t)va_arg(ap, int); - va_end(ap); - } - int r = (int)syscall(SYS_openat, dirfd, pathname, flags, mode); - if (r >= 0) record_path(dirfd, pathname); - return r; -} - -__attribute__((constructor)) -static void mneme_init(void) { - const char *cur = getenv("ASAN_OPTIONS"); - if (!cur || !*cur) { - setenv("ASAN_OPTIONS", "verify_asan_link_order=0", 1); - } else if (!strstr(cur, "verify_asan_link_order")) { - char buf[1024]; - size_t n = strlen(cur); - if (n + 26 < sizeof(buf)) { - memcpy(buf, cur, n); - memcpy(buf + n, ":verify_asan_link_order=0", 26); - setenv("ASAN_OPTIONS", buf, 1); - } - } -} diff --git a/tools/aien-test/src/evidence.rs b/tools/aien-test/src/evidence.rs index c745fb9a..40b222b7 100644 --- a/tools/aien-test/src/evidence.rs +++ b/tools/aien-test/src/evidence.rs @@ -192,63 +192,14 @@ impl Store { Ok(sha) } - /// True if the stdout/stderr blob `sha` is present in this store or a - /// sibling commit store under the same repository evidence directory. + /// True if the stdout/stderr blob `sha` is present in this store (it is + /// not read or re-hashed here). pub fn blob_exists(&self, sha: &str) -> bool { - if !is_sha256_hex(sha) { - return false; - } - let rel = Path::new("blobs").join(format!("{sha}.log")); - if self.dir.join(&rel).is_file() { - return true; - } - if is_commit_dir(&self.dir) { - if let Some(parent) = self.dir.parent() { - if let Ok(rd) = fs::read_dir(parent) { - for e in rd.flatten() { - if e.file_name().to_str().is_some_and(is_commit_sha_hex) - && e.path().join(&rel).is_file() - { - return true; - } - } - } - } - } - false - } - - /// Ensure blob `sha` is present in `self.dir/blobs/.log`, copying and - /// verifying it from a sibling commit store if needed so each commit's - /// evidence directory stays self-contained. - pub fn ensure_local_blob(&self, sha: &str) { - if !is_sha256_hex(sha) { - return; - } - let rel = Path::new("blobs").join(format!("{sha}.log")); - if self.dir.join(&rel).is_file() || !is_commit_dir(&self.dir) { - return; - } - let Some(parent) = self.dir.parent() else { - return; - }; - let Ok(rd) = fs::read_dir(parent) else { - return; - }; - for e in rd.flatten() { - if !e.file_name().to_str().is_some_and(is_commit_sha_hex) { - continue; - } - let src = e.path().join(&rel); - if src.is_file() { - if let Ok(bytes) = fs::read(&src) { - if sha256_hex(&bytes) == sha { - let _ = self.put_blob(&bytes); - return; - } - } - } - } + sha.len() == 64 + && sha + .bytes() + .all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b)) + && self.dir.join("blobs").join(format!("{sha}.log")).is_file() } /// Write `.json` exclusively, mode 0444, canonical bytes plus one @@ -329,18 +280,6 @@ fn is_sha256_hex(s: &str) -> bool { .all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b)) } -fn is_commit_sha_hex(s: &str) -> bool { - s.len() == 40 - && s.bytes() - .all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b)) -} - -fn is_commit_dir(dir: &Path) -> bool { - dir.file_name() - .and_then(|n| n.to_str()) - .is_some_and(is_commit_sha_hex) -} - /// All verified receipts of one store, oldest first. #[derive(Debug, Clone, Default)] pub struct Index { @@ -348,13 +287,16 @@ pub struct Index { } impl Index { - fn load_dir( - dir: &Path, - seen: &mut std::collections::BTreeSet, - receipts: &mut Vec, - ) { - let Ok(rd) = fs::read_dir(dir) else { - return; + /// Read every `.json` in the store. A file is skipped, never + /// trusted, if its bytes do not hash to its name, it is not JSON, or it + /// does not carry the receipt schema. Order is by recorded finish time, + /// then by file modification time (receipts finished in the same second), + /// then by digest. + pub fn load(store: &Store) -> Index { + let mut receipts = Vec::new(); + let rd = match fs::read_dir(store.dir()) { + Ok(r) => r, + Err(_) => return Index::default(), }; for e in rd.flatten() { let name = e.file_name().to_string_lossy().into_owned(); @@ -362,9 +304,6 @@ impl Index { Some(d) if is_sha256_hex(d) => d.to_string(), _ => continue, }; - if seen.contains(&digest) { - continue; - } let bytes = match fs::read(e.path()) { Ok(b) => b, Err(_) => continue, @@ -381,16 +320,12 @@ impl Index { continue; } let modified = e.metadata().and_then(|m| m.modified()).ok(); - seen.insert(digest.clone()); receipts.push(Stored { digest, value, modified, }); } - } - - fn sort(mut receipts: Vec) -> Index { receipts.sort_by(|a, b| { a.finished_utc() .cmp(b.finished_utc()) @@ -400,45 +335,6 @@ impl Index { Index { receipts } } - /// Read verified `.json` receipts only from `store.dir()` itself. - pub fn load_local(store: &Store) -> Index { - let mut seen = std::collections::BTreeSet::new(); - let mut receipts = Vec::new(); - Self::load_dir(store.dir(), &mut seen, &mut receipts); - Self::sort(receipts) - } - - /// Read every `.json` in the store (and, when `store.dir()` is a - /// per-commit `<40-hex>` directory, sibling commit directories of the same - /// repository). A file is skipped, never trusted, if its bytes do not hash - /// to its name, it is not JSON, or it does not carry the receipt schema. - /// Order is by recorded finish time, then by file modification time - /// (receipts finished in the same second), then by digest. - pub fn load(store: &Store) -> Index { - let mut seen = std::collections::BTreeSet::new(); - let mut receipts = Vec::new(); - Self::load_dir(store.dir(), &mut seen, &mut receipts); - if is_commit_dir(store.dir()) { - if let Some(parent) = store.dir().parent() { - if let Ok(rd) = fs::read_dir(parent) { - let mut sib_dirs: Vec = rd - .flatten() - .filter(|e| { - e.file_name().to_str().is_some_and(is_commit_sha_hex) - && e.path() != store.dir() - }) - .map(|e| e.path()) - .collect(); - sib_dirs.sort(); - for d in sib_dirs { - Self::load_dir(&d, &mut seen, &mut receipts); - } - } - } - } - Self::sort(receipts) - } - /// Every verified receipt, oldest first. pub fn receipts(&self) -> &[Stored] { &self.receipts @@ -786,39 +682,6 @@ mod tests { .count(); assert_eq!(leftovers, 0, "no temp file may be left behind"); } - #[test] - fn commit_stores_share_receipts_and_blobs_while_load_local_stays_scoped() { - let t = TempDir::new("ev-cross-commit"); - let c1 = "1".repeat(40); - let c2 = "2".repeat(40); - let s1 = Store::new(&t.path().join(&c1)); - let s2 = Store::new(&t.path().join(&c2)); - - let blob_sha = s1.put_blob(b"cross-commit stdout\n").expect("put_blob"); - let (r1, _) = s1 - .put_receipt(&receipt("G", &c1, "PASS", "2026-10-02T01:00:00Z")) - .expect("put_receipt"); - - // Local index on s2 has nothing yet, while cross-commit Index::load sees r1. - assert!(Index::load_local(&s2).is_empty()); - let ix = Index::load(&s2); - assert_eq!(ix.len(), 1); - assert_eq!(ix.get(&r1).unwrap().commit(), c1); - - // s2 sees the blob in sibling commit store s1 and can materialize it locally. - assert!(s2.blob_exists(&blob_sha)); - assert!(!s2 - .dir() - .join("blobs") - .join(format!("{blob_sha}.log")) - .is_file()); - s2.ensure_local_blob(&blob_sha); - assert!(s2 - .dir() - .join("blobs") - .join(format!("{blob_sha}.log")) - .is_file()); - } } #[cfg(test)] diff --git a/tools/aien-test/src/runner.rs b/tools/aien-test/src/runner.rs index dc2c784b..1258b401 100644 --- a/tools/aien-test/src/runner.rs +++ b/tools/aien-test/src/runner.rs @@ -63,8 +63,8 @@ pub struct Options { /// `--release`: qualification mode. No cache reuse and the tree must be /// clean even with `--allow-dirty`. pub release: bool, - /// Pinned sibling commits and repository pins included in `core.pins` and - /// `cache.key`. + /// `core.pins` and part of `cache.key` (ADR 0028: `{name, commit}` sorted + /// by `name`). The worker sets the head's sibling and operator pins. pub pins: Value, } @@ -643,11 +643,6 @@ fn execute_gate(job: &Job<'_>, permit: Option>) -> Result Found { Found { - index: Index::load_local(&Store::new(dir)), + index: Index::load(&Store::new(dir)), } } fn get(&self, digest: &str) -> Option<&evidence::Stored> { diff --git a/tools/aien-test/src/worker.rs b/tools/aien-test/src/worker.rs index cf401c0f..79baffdc 100644 --- a/tools/aien-test/src/worker.rs +++ b/tools/aien-test/src/worker.rs @@ -508,7 +508,10 @@ struct Checkout { /// clone at the clone's `origin/`. A sibling that cannot be made is a /// note (its gates then fail on the missing directory, never PASS); every /// sibling made is journaled with its commit. Returns what to remove later -/// under `Sandbox::None`. +/// under `Sandbox::None`, and the receipt `pins` (ADR 0028: `{name, commit}` +/// sorted by `name`): each sibling made, named by its `dir`, and each operator +/// pin, named `pin:`. They enter `core.pins` and `cache.key`, so a +/// result is reused only while every sibling is at the same commit. fn provision_siblings( cfg: &Config, repo: &str, @@ -519,7 +522,7 @@ fn provision_siblings( notes: &mut Vec, ) -> (Vec<(PathBuf, PathBuf)>, Value) { let mut made = Vec::new(); - let mut pin_entries: Vec<(String, String, String, String)> = Vec::new(); + let mut pin_entries: Vec<(String, String)> = Vec::new(); if !sibs.is_empty() && !co.nested { notes.push(format!( "siblings not provided: the worktree tool makes the old flat layout (update {})", @@ -581,30 +584,19 @@ fn provision_siblings( s.dir, s.source, s.git_ref, sib_sha )); made.push((src, path)); - pin_entries.push((s.dir.clone(), s.source.clone(), s.git_ref.clone(), sib_sha)); + pin_entries.push((s.dir.clone(), sib_sha)); } Err(e) => notes.push(format!("sibling ../{}: not provided: {e}", s.dir)), } } for p in pins { - pin_entries.push(( - String::new(), - p.source.clone(), - "pin".to_string(), - p.sha.clone(), - )); + pin_entries.push((format!("pin:{}", p.source), p.sha.clone())); } + // ADR 0028 receipt member `pins`: `{name, commit}` sorted by `name`. pin_entries.sort(); let pin_json: Vec = pin_entries .into_iter() - .map(|(dir, source, git_ref, commit)| { - json!({ - "dir": dir, - "source": source, - "ref": git_ref, - "commit": commit, - }) - }) + .map(|(name, commit)| json!({ "name": name, "commit": commit })) .collect(); (made, Value::Array(pin_json)) } @@ -840,9 +832,11 @@ pub fn run_once(cfg: &Config, repo: &str, sha: &str) -> Result // A wt.sh worktree belongs to aien-run; the operator's git opens it only // after `check_worktree_link` (see `process::trust_worktree`). let trust = (cfg.sandbox == Sandbox::User).then(|| process::trust_worktree(&wt)); - // Provisioned sibling commits are bound into `opts.pins` (`core.pins` and - // `cache.key`). Only disable the cache when a declared sibling could not be - // provisioned (`made.len() < sibs.len()`). + // Every sibling's commit is in `opts.pins` (`core.pins` and `cache.key`), + // and the evidence directory is this head's own (`evidence//`), + // so a result is reused only for this same commit with every sibling at + // the same commit. A declared sibling that could not be made turns the + // cache off for the whole head. let fresh = made.len() < sibs.len(); let result = run_in_worktree(cfg, repo, sha, &co, fresh, pin_values, &mut notes); crumb( diff --git a/tools/aien-test/tests/local_ci.rs b/tools/aien-test/tests/local_ci.rs index 52dfb329..730a73b6 100644 --- a/tools/aien-test/tests/local_ci.rs +++ b/tools/aien-test/tests/local_ci.rs @@ -1350,153 +1350,92 @@ fn nested_in_sandbox(test: &str) -> bool { nested } +/// A new commit `name` on `branch` of the world's origin that writes `files`, +/// fetched into the trusted clone. Returns the commit. +fn commit_on(w: &World, branch: &str, files: &[(&str, &str)], name: &str) -> String { + git(&w.origin, &["checkout", "-q", branch]); + for (rel, content) in files { + write(&w.origin, rel, content, false); + } + git(&w.origin, &["add", "-A"]); + git(&w.origin, &["commit", "-q", "-m", name]); + let sha = git(&w.origin, &["rev-parse", "HEAD"]); + git(&w.origin, &["checkout", "-q", "main"]); + git(&w.clone, &["fetch", "-q", "--all"]); + sha +} + +fn gate_status(s: &worker::Summary, id: &str) -> (String, Verdict) { + s.gates + .iter() + .find(|g| g.0 == id) + .map(|g| (g.1.clone(), g.2)) + .unwrap_or_else(|| panic!("no gate {id} in {:?}", s.gates)) +} + +/// With siblings, the worker reuses a result only for the same commit of +/// the repository and only while every sibling is at the same commit: the +/// sibling commits are in the cache key, and the evidence directory is the +/// head's own. #[test] -fn worker_reuses_cached_receipt_across_commits_and_sibling_pins() { +fn worker_reuses_only_the_same_commit_while_its_sibling_commits_match() { + if nested_in_sandbox("worker_reuses_only_the_same_commit_while_its_sibling_commits_match") { + return; + } let w = world(); let (head_s, sib_sha, map) = sibling_world(&w); let mut cfg = w.config(); - cfg.operator = true; + cfg.operator = true; // S is a new gate: a pipeline configuration change. cfg.siblings = Some(map); + let pass = |st: &str| (st.to_string(), Verdict::Pass); - // 1. First commit on topic-s runs gate S fresh with sibling at sib_sha. let r1 = worker::run_once(&cfg, REPO, &head_s).expect("worker r1"); - assert_eq!(r1.verdict, Verdict::Pass, "{} {:?}", r1.reason, r1.notes); + assert_eq!(gate_status(&r1, "S"), pass("run"), "{:?}", r1.notes); assert!( - r1.gates - .iter() - .any(|(g, st, v)| g == "S" && st == "run" && *v == Verdict::Pass), - "expected S to run fresh on head_s: {:?}", - r1.gates + r1.notes.iter().any(|n| n.contains(&sib_sha)), + "{:?}", + r1.notes ); - // 2. Second commit on topic-s touches a/a.txt (gate A), leaving gate S inputs - // and sibling commit sib_sha unchanged. Gate S must hit the cache across commits! - git(&w.origin, &["checkout", "-q", "topic-s"]); - write(&w.origin, "a/a.txt", "topic-s-2\n", false); - git(&w.origin, &["add", "-A"]); - git(&w.origin, &["commit", "-q", "-m", "change a on topic-s"]); - let head_s2 = git(&w.origin, &["rev-parse", "HEAD"]); - git(&w.origin, &["checkout", "-q", "main"]); - git(&w.clone, &["fetch", "-q", "--all"]); - - let r2 = worker::run_once(&cfg, REPO, &head_s2).expect("worker r2"); - assert_eq!(r2.verdict, Verdict::Pass, "{} {:?}", r2.reason, r2.notes); - assert!( - r2.gates - .iter() - .any(|(g, st, v)| g == "S" && st == "cached" && *v == Verdict::Pass), - "expected S to be cached across commits on head_s2: {:?}", - r2.gates - ); - assert!( - r2.gates - .iter() - .any(|(g, st, v)| g == "A" && st == "run" && *v == Verdict::Pass), - "expected A to run fresh on head_s2: {:?}", - r2.gates - ); + // The same head again, sibling unchanged: reused. + let r2 = worker::run_once(&cfg, REPO, &head_s).expect("worker r2"); + assert_eq!(gate_status(&r2, "S"), pass("cached"), "{:?}", r2.gates); - // 2b. Third commit on topic-s touches h/h.txt (gate H), leaving both S and A - // inputs and sibling commit sib_sha unchanged. Both S and A must be cached! - git(&w.origin, &["checkout", "-q", "topic-s"]); - write(&w.origin, "h/h.txt", "topic-s-2b\n", false); - git(&w.origin, &["add", "-A"]); - git(&w.origin, &["commit", "-q", "-m", "change h on topic-s"]); - let head_s2b = git(&w.origin, &["rev-parse", "HEAD"]); - git(&w.origin, &["checkout", "-q", "main"]); - git(&w.clone, &["fetch", "-q", "--all"]); + // A new commit that leaves S's declared inputs (tools/) alone still runs + // S: results never cross commits. + let head_s2 = commit_on(&w, "topic-s", &[("h/h.txt", "s2\n")], "change h"); + let r3 = worker::run_once(&cfg, REPO, &head_s2).expect("worker r3"); + assert_eq!(gate_status(&r3, "S"), pass("run"), "{:?}", r3.gates); - let r2b = worker::run_once(&cfg, REPO, &head_s2b).expect("worker r2b"); - assert_eq!(r2b.verdict, Verdict::Pass, "{} {:?}", r2b.reason, r2b.notes); - assert!( - r2b.gates - .iter() - .any(|(g, st, v)| g == "S" && st == "cached" && *v == Verdict::Pass), - "expected S to be cached on head_s2b: {:?}", - r2b.gates - ); - assert!( - r2b.gates - .iter() - .any(|(g, st, v)| g == "A" && st == "cached" && *v == Verdict::Pass), - "expected A to be cached on head_s2b: {:?}", - r2b.gates - ); - assert!( - r2b.gates - .iter() - .any(|(g, st, v)| g == "H" && st == "run" && *v == Verdict::Pass), - "expected H to run fresh on head_s2b: {:?}", - r2b.gates - ); - - // 3. Advance the sibling repository origin/main to a new commit sib_sha2 and fetch into - // the sibling trusted clone. A new commit on topic-s must invalidate S's cache - // because the sibling pin changed, and then a subsequent commit at sib_sha2 must - // cache again! - let root = w.origin.parent().unwrap(); - let so = root.join("sib-origin"); + // The sibling moves to a new commit: the same head runs S again. + let so = w.origin.parent().unwrap().join("sib-origin"); write(&so, "lib/extra.txt", "world\n", false); git(&so, &["add", "-A"]); git(&so, &["commit", "-q", "-m", "sib v2"]); let sib_sha2 = git(&so, &["rev-parse", "HEAD"]); assert_ne!(sib_sha, sib_sha2); - let sib_clone = w.clone.parent().unwrap().join(SIB); - git(&sib_clone, &["fetch", "-q", "--all"]); - - git(&w.origin, &["checkout", "-q", "topic-s"]); - write(&w.origin, "h/h.txt", "topic-s-3\n", false); - git(&w.origin, &["add", "-A"]); - git(&w.origin, &["commit", "-q", "-m", "change h with sib v2"]); - let head_s3 = git(&w.origin, &["rev-parse", "HEAD"]); - git(&w.origin, &["checkout", "-q", "main"]); - git(&w.clone, &["fetch", "-q", "--all"]); - - let r3 = worker::run_once(&cfg, REPO, &head_s3).expect("worker r3"); - assert_eq!(r3.verdict, Verdict::Pass, "{} {:?}", r3.reason, r3.notes); - assert!( - r3.gates - .iter() - .any(|(g, st, v)| g == "S" && st == "run" && *v == Verdict::Pass), - "expected S to re-run when sibling pin changed on head_s3: {:?}", - r3.gates - ); - - // 4. Another commit at the same sib_sha2 caches S and A again. - git(&w.origin, &["checkout", "-q", "topic-s"]); - write(&w.origin, "h/h.txt", "topic-s-4\n", false); - git(&w.origin, &["add", "-A"]); git( - &w.origin, - &["commit", "-q", "-m", "change h again at sib v2"], + &w.clone.parent().unwrap().join(SIB), + &["fetch", "-q", "--all"], ); - let head_s4 = git(&w.origin, &["rev-parse", "HEAD"]); - git(&w.origin, &["checkout", "-q", "main"]); - git(&w.clone, &["fetch", "-q", "--all"]); - - let r4 = worker::run_once(&cfg, REPO, &head_s4).expect("worker r4"); - assert_eq!(r4.verdict, Verdict::Pass, "{} {:?}", r4.reason, r4.notes); + let r4 = worker::run_once(&cfg, REPO, &head_s).expect("worker r4"); + assert_eq!(gate_status(&r4, "S"), pass("run"), "{:?}", r4.gates); assert!( - r4.gates - .iter() - .any(|(g, st, v)| g == "S" && st == "cached" && *v == Verdict::Pass), - "expected S to be cached on head_s4 at sib_sha2: {:?}", - r4.gates - ); - assert!( - r4.gates - .iter() - .any(|(g, st, v)| g == "A" && st == "cached" && *v == Verdict::Pass), - "expected A to be cached on head_s4 at sib_sha2: {:?}", - r4.gates + r4.notes.iter().any(|n| n.contains(&sib_sha2)), + "{:?}", + r4.notes ); + + // Same head, sibling still at its new commit: reused again. + let r5 = worker::run_once(&cfg, REPO, &head_s).expect("worker r5"); + assert_eq!(gate_status(&r5, "S"), pass("cached"), "{:?}", r5.gates); } /// Cache safety across commits: gate U declares only `u/` as its input but -/// its program also reads `other/flag.txt`, the way SC-TEST's tests read the -/// root README.md and COVENANT.md and scan the whole tree for key files. A -/// later commit that changes only that file makes U fail when it really runs, -/// so the worker must never hand that commit the earlier commit's PASS. +/// its program also reads the root `README.md`, as SC-TEST's +/// `tier2_boundary` tests read the root `README.md` and `COVENANT.md`. A +/// later commit that changes only `README.md` makes U fail when it really +/// runs, so the worker must run U again, never hand it the earlier PASS. #[test] fn worker_never_reuses_a_pass_when_an_undeclared_file_changed_across_commits() { if nested_in_sandbox( @@ -1512,38 +1451,39 @@ fn worker_never_reuses_a_pass_when_an_undeclared_file_changed_across_commits() { write( &w.origin, "tools/u.sh", - "#!/bin/sh\ntest \"$(cat other/flag.txt)\" = ok || { echo 'flag is not ok' >&2; exit 1; }\necho PASS\n", + "#!/bin/sh\ngrep -q 'AGPL-3.0' README.md || { echo 'README.md lost its licence' >&2; exit 1; }\necho PASS\n", true, ); - write(&w.origin, "u/u.txt", "1\n", false); - write(&w.origin, "other/flag.txt", "ok\n", false); - write( - &w.origin, - "tests/gates/U.gate", - &gate("U", "u/", "tools/u.sh", ""), - false, + git(&w.origin, &["checkout", "-q", "main"]); + let head_u1 = commit_on( + &w, + "topic-u", + &[ + ("u/u.txt", "1\n"), + ("README.md", "Licence: AGPL-3.0\n"), + ("tests/gates/U.gate", &gate("U", "u/", "tools/u.sh", "")), + ], + "gate U reads README.md", ); - git(&w.origin, &["add", "-A"]); - git( - &w.origin, - &["commit", "-q", "-m", "gate U reads other/flag.txt"], + let head_u2 = commit_on( + &w, + "topic-u", + &[("README.md", "Licence: none\n")], + "README.md loses its licence", ); - let head_u1 = git(&w.origin, &["rev-parse", "HEAD"]); - write(&w.origin, "other/flag.txt", "bad\n", false); - git(&w.origin, &["add", "-A"]); - git(&w.origin, &["commit", "-q", "-m", "break the flag U reads"]); - let head_u2 = git(&w.origin, &["rev-parse", "HEAD"]); - git(&w.origin, &["checkout", "-q", "main"]); - git(&w.clone, &["fetch", "-q", "--all"]); let r1 = worker::run_once(&cfg, REPO, &head_u1).expect("worker u1"); - assert_eq!(gate_verdict(&r1, "U"), Verdict::Pass, "{:?}", r1.notes); - + assert_eq!( + gate_status(&r1, "U"), + ("run".to_string(), Verdict::Pass), + "{:?}", + r1.notes + ); let r2 = worker::run_once(&cfg, REPO, &head_u2).expect("worker u2"); assert_eq!( - gate_verdict(&r2, "U"), - Verdict::Fail, - "a PASS from {head_u1} was handed to {head_u2} although U fails there: {:?}", + gate_status(&r2, "U"), + ("run".to_string(), Verdict::Fail), + "a PASS from {head_u1} must not be handed to {head_u2}: {:?}", r2.gates ); }