test(arch): every test file cites its spec; gate in cargo x arch
fbc47ab4710a623c4baaa5901fc9db627868ca22
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: b0e908b74927
There are many coding harnesses - but this one is fast
fbc47ab4710a623c4baaa5901fc9db627868ca22
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+154 / −25 text lines
+1 / −1 text lines
+2 / −1 text lines
//! Credential resolution without context exposure.+1 / −1 text lines
+2 / −1 text lines
//! Offline model catalog, capabilities, and deterministic resolution.+2 / −1 text lines
//! Endpoint routing with bounded retry and failover.+2 / −1 text lines
//! OpenAI-compatible chat-completions stream adapter.+2 / −1 text lines
//! Cancellable catalog refresh with generation-checked publication.+2 / −1 text lines
//! Vendor HTTP transport: request bodies, posting, and SSE decoding.+1 / −1 text lines
+3 / −1 text lines
//! Workspace architecture law, expressed as source-level tests.+2 / −1 text lines
+2 / −1 text lines
+2 / −1 text lines
//! The provider-independent agent loop.+2 / −1 text lines
//! Bounded, cancellable shell execution with owned-process-tree termination.+2 / −1 text lines
+1 / −1 text lines
+2 / −1 text lines
//! one contiguous payload arena, plus restoration from durable frames.+1 / −1 text lines
+2 / −0 text lines
+2 / −1 text lines
//! Replay evidence derived from durable session state.+2 / −1 text lines
+2 / −1 text lines
+2 / −1 text lines
+2 / −1 text lines
//! LF-delimited JSON-RPC over standard input and output.+2 / −1 text lines
+108 / −1 text lines
//! Cargo-only Smith project automation./// The first `.rs` file under any workspace crate that carries test code/// (`#[test]` or a `tests/` directory) but cites no `SMH-SPEC-…` id in its/// first 20 lines or its `//!` header block.fn missing_spec_reference() -> Option<PathBuf> { for crate_name in CRATES { let mut files = Vec::new(); collect_rs_files(Path::new(crate_name), &mut files); for path in files { let Ok(source) = fs::read_to_string(&path) else { continue; }; if is_test_bearing(&path, &source) && !cites_a_spec(&source) { return Some(path); } } } None}/// `.rs` files under `dir`, deterministically ordered, skipping `target`.fn collect_rs_files(dir: &Path, out: &mut Vec<PathBuf>) { let Ok(entries) = fs::read_dir(dir) else { return; }; let mut entries: Vec<PathBuf> = entries.flatten().map(|entry| entry.path()).collect(); entries.sort(); for path in entries { if path.is_dir() { if path.file_name().is_some_and(|name| name == "target") { continue; } collect_rs_files(&path, out); } else if path.extension().is_some_and(|ext| ext == "rs") { out.push(path); } }}/// A file carries test code when it literally declares `#[test]` or lives/// under a `tests/` directory (integration test crates have no attribute).fn is_test_bearing(path: &Path, source: &str) -> bool { source.contains("#[test]") || path.components().any(|part| part.as_os_str() == "tests")}/// Whether `SMH-SPEC-` appears in the first 20 lines or the leading `//!`/// doc-comment block, whichever the file has.fn cites_a_spec(source: &str) -> bool { let first_twenty: Vec<&str> = source.lines().take(20).collect(); first_twenty.iter().any(|line| line.contains("SMH-SPEC-")) || leading_doc_block(source).contains("SMH-SPEC-")}/// The contiguous run of `//!` lines starting the file, attributes and/// blank lines before it skipped, concatenated.fn leading_doc_block(source: &str) -> String { let mut block = String::new(); for line in source.lines() { let trimmed = line.trim_start(); if trimmed.starts_with("//!") { block.push_str(trimmed); block.push('\n'); } else if !block.is_empty() { break; } } block} use super::{cites_a_spec, is_test_bearing}; use std::path::Path; #[test] fn test_bearing_by_attribute_or_by_directory() { assert!(is_test_bearing( Path::new("smith-core/src/agent.rs"), "mod tests {\n#[test]\nfn it_works() {}\n}" )); assert!(is_test_bearing( Path::new("smith-cli/tests/e2e_eval.rs"), "fn helper() {}" )); assert!(!is_test_bearing( Path::new("smith-core/src/lib.rs"), "fn helper() {}" )); } #[test] fn spec_citation_in_first_twenty_lines_or_doc_block() { assert!(cites_a_spec("//! docs (`SMH-SPEC-SPEC0001`, Tools).\n")); let padded = format!("{}fn f() {{}}\n", "//! line\n".repeat(19)); assert!(!cites_a_spec(&padded)); let past_twenty = format!( "{}//! cites `SMH-SPEC-SPEC0001` here\nfn f() {{}}\n", "//! line\n".repeat(25) ); assert!(cites_a_spec(&past_twenty)); assert!(!cites_a_spec("// no doc block\nfn f() {}\n")); }