From 0624847760b06444206d5c6d7552c83ad16f5706 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 18 Oct 2026 10:23:08 -0500 Subject: [PATCH 1/3] aien-test: inputs_top names a folder's direct files only (omega#524) A gate that lists src/ in inputs is selected by any change under src/, including subfolders it never builds and the folder's .crumb, which every crumb recompile touches. inputs_top (manifest v2) names folders whose direct, non-dot files are inputs: selection, check identity (index and tree listings) and the build inputs digest all read it the same way. Older binaries refuse the unknown key instead of misreading it, and a plain input may not spell the /* form. Co-Authored-By: Claude Opus 5.5 --- tools/aien-test/src/identity.rs | 91 +++++++++++++++++++++++++++++---- tools/aien-test/src/manifest.rs | 80 +++++++++++++++++++++++++++-- tools/aien-test/src/plan.rs | 36 ++++++++++++- tools/aien-test/src/runner.rs | 24 ++++++++- 4 files changed, 216 insertions(+), 15 deletions(-) diff --git a/tools/aien-test/src/identity.rs b/tools/aien-test/src/identity.rs index 3109689d..bf42eed6 100644 --- a/tools/aien-test/src/identity.rs +++ b/tools/aien-test/src/identity.rs @@ -17,7 +17,7 @@ use crate::evidence::{canonical, sha256_hex}; use crate::graph::Graph; -use crate::manifest::{CacheScope, Manifest}; +use crate::manifest::{self, CacheScope, Manifest}; use crate::process; use serde_json::{json, Value}; use std::collections::{BTreeMap, BTreeSet}; @@ -74,8 +74,17 @@ fn git_ls_files(root: &Path, spec: &str) -> Result, String pub fn input_blob_ids(m: &Manifest, root: &Path) -> Result, String> { let mut rows: BTreeMap> = BTreeMap::new(); for input in &m.inputs { - let spec = input.trim_end_matches('/'); - let found = git_ls_files(root, spec)?; + let (spec, found) = match manifest::shallow_dir(input) { + Some(dir) => { + let mut found = git_ls_files(root, dir)?; + found.retain(|(path, _)| manifest::directly_in(dir, path)); + (input.as_str(), found) + } + None => { + let spec = input.trim_end_matches('/'); + (spec, git_ls_files(root, spec)?) + } + }; if found.is_empty() { rows.entry(spec.to_string()).or_insert(None); } @@ -120,6 +129,24 @@ pub fn declared_dependencies(m: &Manifest) -> Vec { pub fn input_blob_ids_from_rows(m: &Manifest, tree: &BTreeMap) -> Vec { let mut rows: BTreeMap> = BTreeMap::new(); for input in &m.inputs { + if let Some(dir) = manifest::shallow_dir(input) { + // Same null-row key as `input_blob_ids`: the entry as written (`/*`). + let prefix = format!("{dir}/"); + let mut found = false; + for (path, blob) in tree.range(prefix.clone()..) { + if !path.starts_with(&prefix) { + break; + } + if manifest::directly_in(dir, path) { + rows.insert(path.clone(), Some(blob.clone())); + found = true; + } + } + if !found { + rows.entry(input.clone()).or_insert(None); + } + continue; + } let spec = input.trim_end_matches('/'); let prefix = format!("{spec}/"); let mut found = false; @@ -267,12 +294,12 @@ pub fn graph_identities( pub fn select_changed(graph: &Graph, changed: &[String]) -> BTreeSet { let touched: Vec = (0..graph.len()) .filter(|&i| { - graph.node(i).manifest.inputs.iter().any(|input| { - let dir = input.trim_end_matches('/'); - changed - .iter() - .any(|c| c == dir || c.starts_with(&format!("{dir}/"))) - }) + graph + .node(i) + .manifest + .inputs + .iter() + .any(|input| changed.iter().any(|c| manifest::input_covers(input, c))) }) .collect(); let mut seeds = touched; @@ -624,3 +651,49 @@ mod rows_tests { assert_eq!(a, r); } } + +#[cfg(test)] +mod inputs_top_tests { + use super::*; + use crate::testutil::init_repo; + use std::process::Command; + + /// omega#524: an `inputs_top` folder contributes only its direct, non-dot files, and the + /// index listing and the tree listing agree (including the null row for an empty folder). + #[test] + fn inputs_top_rows_are_direct_files_only_in_both_listings() { + let g = "gate: A\nmanifest_version: 2\nowner: t\nrequires:\n - host\ninputs_top:\n - src\n - empty\nrun:\n exec: run.sh\nexpects:\n exit: 0\n verdict: PASS\ntimeout: 5s\n"; + let t = init_repo( + "ident-top", + &[ + ("a.gate", g, false), + ("run.sh", "#!/bin/sh\n", true), + ("src/a.c", "a\n", false), + ("src/.crumb", "{}\n", false), + ("src/lane/l.c", "l\n", false), + ("src-x/b.c", "b\n", false), + ("empty/sub/x.c", "x\n", false), + ], + ); + let m = manifest::parse(g.as_bytes()).unwrap(); + let from_index = input_blob_ids(&m, t.path()).unwrap(); + let mut cmd = Command::new("git"); + cmd.arg("-C").arg(t.path()).args(["ls-tree", "-r", "HEAD"]); + let out = process::output_gated(&mut cmd).unwrap(); + let mut tree = BTreeMap::new(); + for line in String::from_utf8_lossy(&out.stdout).lines() { + let (meta, path) = line.split_once('\t').unwrap(); + tree.insert( + path.to_string(), + meta.split(' ').nth(2).unwrap().to_string(), + ); + } + assert_eq!(from_index, input_blob_ids_from_rows(&m, &tree)); + let paths: Vec<&str> = from_index + .iter() + .map(|r| r["path"].as_str().unwrap()) + .collect(); + assert_eq!(paths, ["empty/*", "src/a.c"]); + assert!(from_index[0]["blob_id"].is_null()); + } +} diff --git a/tools/aien-test/src/manifest.rs b/tools/aien-test/src/manifest.rs index a7deafc7..e211925f 100644 --- a/tools/aien-test/src/manifest.rs +++ b/tools/aien-test/src/manifest.rs @@ -220,6 +220,28 @@ pub fn valid_obs_name(s: &str) -> bool { chars.all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_' || c == '.' || c == '-') } +/// The folder of an `inputs_top` entry (`/*` in `inputs`), or None for a plain input. +pub fn shallow_dir(input: &str) -> Option<&str> { + input.strip_suffix("/*") +} + +/// `path` is a file directly inside `dir` whose name does not start with a dot. +pub fn directly_in(dir: &str, path: &str) -> bool { + path.strip_prefix(dir) + .and_then(|r| r.strip_prefix('/')) + .is_some_and(|n| !n.is_empty() && !n.contains('/') && !n.starts_with('.')) +} + +/// A changed `path` falls under one entry of `inputs`: the input itself or anything below +/// it, or, for an `inputs_top` entry, a file directly inside its folder. +pub fn input_covers(input: &str, path: &str) -> bool { + if let Some(dir) = shallow_dir(input) { + return directly_in(dir, path); + } + let dir = input.trim_end_matches('/'); + path == dir || path.starts_with(&format!("{dir}/")) +} + fn valid_rel_path(s: &str) -> bool { !s.is_empty() && !s.starts_with('/') && !s.contains('\0') && !s.split('/').any(|c| c == "..") } @@ -465,13 +487,14 @@ pub const REQUIRES_V2: [&str; 9] = [ "operator", ]; -const V2_KEYS: [&str; 6] = [ +const V2_KEYS: [&str; 7] = [ "exactness", "tolerance", "backends", "fallback", "cache_scope", "oracle", + "inputs_top", ]; fn bad(msg: String) -> Result { @@ -702,13 +725,14 @@ pub fn parse(bytes: &[u8]) -> Result { } let entries = parse_entries(text)?; - const KNOWN: [&str; 19] = [ + const KNOWN: [&str; 20] = [ "gate", "manifest_version", "owner", "requires", "depends_on", "inputs", + "inputs_top", "build", "run", "expects", @@ -793,17 +817,32 @@ pub fn parse(bytes: &[u8]) -> Result { return Err(ManifestError(format!("invalid depends_on id {d:?}"))); } } - let inputs = match get("inputs") { + let mut inputs = match get("inputs") { Some(e) => list(e)?, None => Vec::new(), }; for i in &inputs { - if !valid_rel_path(i) { + if !valid_rel_path(i) || shallow_dir(i).is_some() { return Err(ManifestError(format!( "inputs path must be repo-relative: {i:?}" ))); } } + // `inputs_top` (v2, omega#524): only the tracked files directly inside each folder, not + // its subfolders and not its dotfiles (`.crumb`). Kept in `inputs` as `/*`, which + // `shallow_dir` and `input_covers` read. A plain input may not end in `/*`, and a binary + // older than this key refuses the manifest (unknown key) instead of misreading it. + if let Some(e) = get("inputs_top") { + for d in list(e)? { + let d = d.trim_end_matches('/'); + if !valid_rel_path(d) || d.contains('*') { + return Err(ManifestError(format!( + "inputs_top folder must be repo-relative: {d:?}" + ))); + } + inputs.push(format!("{d}/*")); + } + } let build = match get("build") { None => None, @@ -1234,6 +1273,39 @@ mod tests { assert_eq!(m.oracle.compare.as_deref(), Some("G-0")); } + #[test] + fn inputs_top_parses_into_shallow_entries() { + let m = + parse(v2("inputs:\n - mk/\ninputs_top:\n - src\n - tools/\n").as_bytes()).unwrap(); + assert_eq!(m.inputs, ["mk/", "src/*", "tools/*"]); + assert_eq!(shallow_dir("src/*"), Some("src")); + assert_eq!(shallow_dir("src/"), None); + // v1 does not know the key; plain inputs may not spell the shallow form. + let e = parse(with("inputs_top:\n - src\n").as_bytes()) + .unwrap_err() + .0; + assert!(e.contains("requires manifest_version 2"), "{e}"); + assert!(v2_err("inputs:\n - src/*\n").contains("repo-relative")); + for bad in ["/abs", "a/../b", "src/*/x", "*"] { + let e = v2_err(&format!("inputs_top:\n - {bad}\n")); + assert!(e.contains("inputs_top folder"), "{bad}: {e}"); + } + } + + #[test] + fn input_covers_reads_both_forms() { + assert!(input_covers("src/", "src/visor/a.c")); + assert!(input_covers("src", "src")); + assert!(!input_covers("src", "srcx/a.c")); + assert!(input_covers("src/*", "src/a.c")); + assert!(!input_covers("src/*", "src/visor/a.c")); + assert!(!input_covers("src/*", "src/.crumb")); + assert!(!input_covers("src/*", "src")); + assert!(!input_covers("src/*", "src-x/a.c")); + assert!(directly_in("a/b", "a/b/c.h")); + assert!(!directly_in("a/b", "a/bc.h")); + } + #[test] fn v2_refusals() { let tol = "tolerance:\n metric: m\n abs: 1\n rel_ppm: 1\n"; diff --git a/tools/aien-test/src/plan.rs b/tools/aien-test/src/plan.rs index e24aa846..c924277e 100644 --- a/tools/aien-test/src/plan.rs +++ b/tools/aien-test/src/plan.rs @@ -466,8 +466,12 @@ pub fn watched(m: &Manifest, rel: &str, rows: &BTreeMap) -> Vec< v } -/// `input` is `path` or a directory above it. +/// `input` is `path` or a directory above it; an `inputs_top` entry (`/*`) +/// covers only the files directly inside its folder. pub fn covers(input: &str, path: &str) -> bool { + if let Some(dir) = manifest::shallow_dir(input) { + return manifest::directly_in(dir, path); + } let input = input.trim_end_matches('/'); input.is_empty() || path == input || path.starts_with(&format!("{input}/")) } @@ -1494,6 +1498,36 @@ mod tests { assert_eq!(p.unmapped, ["src/kern/other.rs"]); } + /// omega#524: a gate that names `src` in `inputs_top` is selected by a file directly in + /// `src/`, not by one in a subfolder and not by the folder's `.crumb`. + #[test] + fn inputs_top_selects_only_files_directly_in_the_folder() { + let top = gate("TOP", &["mk/"], "inputs_top:\n - src\n"); + let lane = gate("LANE", &["src/lane/"], ""); + let t = init_repo( + "plan-top", + &[ + ("gates/top.gate", top.as_str(), false), + ("gates/lane.gate", lane.as_str(), false), + ("run.sh", "#!/bin/sh\n", true), + ("mk/a.mk", "x\n", false), + ("src/core.c", "int a;\n", false), + ("src/.crumb", "{}\n", false), + ("src/lane/l.c", "int l;\n", false), + ], + ); + commit(&t, &[("src/lane/l.c", "int l2;\n")]); + assert_eq!(all_gates(&plan_of(&t)), ["LANE"]); + commit(&t, &[("src/.crumb", "{\"v\":2}\n")]); + assert!(plan_of(&t).entries.is_empty()); + commit(&t, &[("src/core.c", "int b;\n")]); + let p = plan_of(&t); + assert_eq!(all_gates(&p), ["TOP"]); + assert!(p.unmapped.is_empty()); + commit(&t, &[("src/new.h", "x\n")]); + assert_eq!(all_gates(&plan_of(&t)), ["TOP"]); + } + #[test] fn a_manifest_edit_selects_its_own_gate() { let t = repo(); diff --git a/tools/aien-test/src/runner.rs b/tools/aien-test/src/runner.rs index 04f57e51..05e32917 100644 --- a/tools/aien-test/src/runner.rs +++ b/tools/aien-test/src/runner.rs @@ -341,6 +341,25 @@ fn collect_files(root: &Path, rel: &str, out: &mut BTreeSet) { } } +/// The files directly inside `dir` (an `inputs_top` entry), no dotfiles; none at all +/// is recorded as the entry itself with a null digest, like a missing plain input. +fn collect_top_files(root: &Path, dir: &str, entry: &str, out: &mut BTreeSet) { + let mut any = false; + if let Ok(rd) = fs::read_dir(root.join(dir)) { + for e in rd.flatten() { + let rel = format!("{dir}/{}", e.file_name().to_string_lossy()); + let is_file = fs::symlink_metadata(e.path()).is_ok_and(|m| m.is_file()); + if is_file && manifest::directly_in(dir, &rel) { + out.insert(rel); + any = true; + } + } + } + if !any { + out.insert(entry.to_string()); + } +} + /// Where `run.exec` is, for a run without the sandbox (the runner's PATH). /// See [`exec_path_for`]. pub fn exec_path(root: &Path, exec: &str) -> Option { @@ -388,7 +407,10 @@ fn exec_path_in(root: &Path, exec: &str, path: Option) -> Op pub fn build_inputs_digest(root: &Path, manifest_rel: Option<&Path>, m: &Manifest) -> String { let mut paths: BTreeSet = BTreeSet::new(); for i in &m.inputs { - collect_files(root, i, &mut paths); + match manifest::shallow_dir(i) { + Some(dir) => collect_top_files(root, dir, i, &mut paths), + None => collect_files(root, i, &mut paths), + } } if let Some(rel) = manifest_rel { let dir = rel.parent().unwrap_or(Path::new("")); From 371e0e887ba923af19e29348b11bcaf9e30d1097 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 18 Oct 2026 10:24:48 -0500 Subject: [PATCH 2/3] aien-test docs: explain inputs_top Co-Authored-By: Claude Opus 5.5 --- tools/aien-test/docs/LOCAL_VERIFICATION.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/aien-test/docs/LOCAL_VERIFICATION.md b/tools/aien-test/docs/LOCAL_VERIFICATION.md index d8f9951c..35aa0659 100644 --- a/tools/aien-test/docs/LOCAL_VERIFICATION.md +++ b/tools/aien-test/docs/LOCAL_VERIFICATION.md @@ -23,6 +23,11 @@ gate whose `cache_scope` is `hardware` cannot count. ## The plan +An `inputs` entry is a path prefix: `src/` covers everything under `src/`. +An `inputs_top: [src]` entry covers only the files directly in `src/`, not +its subfolders and not dot files such as `src/.crumb`. Use it when a gate +builds from the top of a folder whose subfolders belong to other gates. + Selection is the set of gates whose watched paths (declared `inputs`, the D3 implied inputs, the manifest file, the golden file) cover a changed path, plus the always set, closed over dependents and then dependencies. Sections: From 5285ae5ac95f816c526ab3a6015576a6cde86e60 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 18 Oct 2026 10:25:01 -0500 Subject: [PATCH 3/3] crumb: recompile with the pinned tool (94fffbcf) Co-Authored-By: Claude Opus 5.5 --- .crumb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.crumb b/.crumb index e03ecb9a..cd597812 100644 --- a/.crumb +++ b/.crumb @@ -119,14 +119,14 @@ } ], "children_root": "sha256:111edf8bf001ed434f7dacbc6d8ab9d75f6bda2cd909d01264fb42bbe38b1d74", - "compiled_at": "2026-10-18T14:31:44Z", + "compiled_at": "2026-10-18T15:24:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:0fa2f5ddee789ea7b983efefd1e4cb12ab60354412716000662dd0535d7376f5", + "digest": "sha256:1f01471551e5816afb431c113f9e14af5186bcbfcdbfda64d1811b44421be349", "evidence_files": 1578, "evidence_root": "sha256:135e27a1a0704c4a8371cd2c1eb555f2b5beec61c212949b029a5457418a7160", "files": 5891, - "generated_at_commit": "ecf36a2429f57b9764215d9e615cd018f83dd5bc", - "source_tree": "sha256:449e870b9a0cbc1768dd48686893b0730ae30260103df0973a3d4e4652dcc753" + "generated_at_commit": "371e0e887ba923af19e29348b11bcaf9e30d1097", + "source_tree": "sha256:cdc9d9091539832173a31167c590bc6f7e4f7d1e89fa13571d54ff500451ad8d" } }, "history": [],