README Source History Refs Reviews Compare Notes Search Review guide SM-003 slice: `xtask arch` + `xtask pup` architecture gates wired into `check` (#125) 93e1c601939b1ead7510ea8c2cbdcf9f181d0c83
agent-smith-bugabinga-adc[bot] <306488075+agent-smith-bugabinga-adc[bot]@users.noreply.github.com > · 26 Jul 2026
SSH signature · not checked
Browse files Compare with HEAD
## What forced this
Architecture boundaries were specified but could still regress without
stable metadata and pinned source-level gates.
## The call
Make `check` stop at both architecture gates; use stable metadata for
dependency edges and pinned-nightly cargo-pup for source rules.
## What we deliberately didn't do
We did not widen CI workflow ownership; the downstream CI slice owns
production workflow wiring.
## Evidence
`cargo run -p xtask -- arch`, `cargo +nightly-2026-01-22 pup`, and
`cargo run -p xtask -- pup` pass on the real workspace.
## Surface touched
SPEC §§2.2–3.5 and §15; two product-slice surfaces.
## If this ages badly
Reopen #90 if Cargo metadata or cargo-pup changes invalidate an
architecture invariant.
Closes #90
---------
Co-authored-by: agent-smith-bugabinga-adc[bot] <agent-smith-bugabinga-adc[bot]@users.noreply.github.com>
Co-authored-by: Oliver Jan Krylow <oliver@bugabinga.net> Changed files (4) Diff layout Auto Unified Split
+98 / −0 text lines
8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" 14 + source = "registry+https://github.com/rust-lang/crates.io-index" 15 + checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" 20 + source = "registry+https://github.com/rust-lang/crates.io-index" 21 + checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" 29 + source = "registry+https://github.com/rust-lang/crates.io-index" 30 + checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" 38 + source = "registry+https://github.com/rust-lang/crates.io-index" 39 + checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" 47 + source = "registry+https://github.com/rust-lang/crates.io-index" 48 + checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" 56 + source = "registry+https://github.com/rust-lang/crates.io-index" 57 + checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" 67 + source = "registry+https://github.com/rust-lang/crates.io-index" 68 + checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" 5 77 [[package ]][[package ]]6 78 name = "smith" name = "smith" 7 79 version = "0.1.0" version = "0.1.0" 26 98 name = "smith-tui" name = "smith-tui" 27 99 version = "0.1.0" version = "0.1.0"
104 + source = "registry+https://github.com/rust-lang/crates.io-index" 105 + checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3" 113 + name = "unicode-ident" 115 + source = "registry+https://github.com/rust-lang/crates.io-index" 116 + checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" 29 118 [[package ]][[package ]]30 119 name = "xtask" name = "xtask" 31 120 version = "0.1.0" version = "0.1.0"
128 + source = "registry+https://github.com/rust-lang/crates.io-index" 129 + checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" new file mode 100644+42 / −0 text lines
1 + // cargo-pup's source-level counterpart to xtask's stable metadata checks.5 + name: "hygienic-mod-files",6 + matches: Module(".*"),7 + rules: [MustHaveEmptyModFile(Error)],10 + name: "no-wildcard-imports",11 + matches: Module(".*"),12 + rules: [NoWildcardImports(Error)],15 + name: "smith-core-import-boundary",16 + matches: Module("^smith_core($|::.*)"),17 + rules: [RestrictImports(19 + denied: Some(["^smith_ai($|::.*)", "^smith_tui($|::.*)", "^smith_harness($|::.*)", "^smith_cli($|::.*)"],),24 + name: "smith-ai-import-boundary",25 + matches: Module("^smith_ai($|::.*)"),26 + rules: [RestrictImports(28 + denied: Some(["^smith_core($|::.*)", "^smith_tui($|::.*)", "^smith_harness($|::.*)", "^smith_cli($|::.*)"],),33 + name: "smith-tui-import-boundary",34 + matches: Module("^smith_tui($|::.*)"),35 + rules: [RestrictImports(37 + denied: Some(["^smith_core($|::.*)", "^smith_ai($|::.*)", "^smith_harness($|::.*)", "^smith_cli($|::.*)"],),+3 / −0 text lines
12 12 workspace = true workspace = true xtask/src/main.rs Modified +440 / −37 text lines
7 7 process::{Command, ExitCode}, process::{Command, ExitCode},10 - const CHECK_GATES : [Gate; 4 ] = [10 + const CHECK_GATES : [Gate; 6 ] = [11 11 Gate::new("fmt" , & ["fmt" , "--check" ]), Gate::new("fmt" , & ["fmt" , "--check" ]),12 12 Gate::new( Gate::new(21 21 "warnings" , "warnings" ,
24 + Gate::new("arch" , & ["run" , "-p" , "xtask" , "--" , "arch" ]),25 + Gate::new("pup" , & ["run" , "-p" , "xtask" , "--" , "pup" ]),24 26 Gate::new("test" , & ["nextest" , "run" , "--workspace" ]), Gate::new("test" , & ["nextest" , "run" , "--workspace" ]),25 27 Gate::new("doc" , & ["test" , "--doc" , "--workspace" ]), Gate::new("doc" , & ["test" , "--doc" , "--workspace" ]),
30 + const ARCHITECTURE : [CrateRule; 7 ] = [31 + CrateRule::new("smith" , & []),32 + CrateRule::new("smith-core" , & ["smith" ]),33 + CrateRule::new("smith-ai" , & ["smith" ]),34 + CrateRule::new("smith-tui" , & ["smith" ]),37 + & ["smith" , "smith-core" , "smith-ai" , "smith-tui" ],39 + CrateRule::new("smith-cli" , & ["smith" , "smith-harness" ]),40 + CrateRule::new("xtask" , & []),43 + const PINNED_NIGHTLY : &str = "+nightly-2026-01-22" ;28 45 struct Gate {struct Gate {29 46 name: &'static str , name: &'static str ,30 47 arguments: &'static [&'static str ], arguments: &'static [&'static str ],
58 + allowed_internal_dependencies: &'static [&'static str ],64 + allowed_internal_dependencies: &'static [&'static str ],68 + allowed_internal_dependencies,39 73 #[derive(Debug)]#[derive(Debug)]40 74 enum GateError {enum GateError {41 75 Spawn(io::Error), Spawn(io::Error),
110 + Metadata(io::Error),111 + MetadataFailed(String ),112 + MetadataDecode(serde_json::Error),113 + InvalidMetadata(&'static str ),115 + Violations(Vec <String >),118 + impl fmt::Display for ArchError {119 + fn fmt (& self, formatter: &mut fmt::Formatter<'_ >) -> fmt::Result {121 + Self ::Metadata(error) => write! (formatter, "could not read Cargo metadata: {error}" ),122 + Self ::MetadataFailed(error) => write! (formatter, "Cargo metadata failed: {error}" ),123 + Self ::MetadataDecode(error) => {124 + write! (formatter, "could not decode Cargo metadata: {error}" )126 + Self ::InvalidMetadata(reason) => {127 + write! (formatter, "Cargo metadata was invalid: {reason}" )129 + Self ::Pup(error) => write! (formatter, "cargo-pup {error}" ),130 + Self ::Violations(violations) => write! (formatter, "{}" , violations.join ("\n" )),135 + impl Error for ArchError {136 + fn source (& self) -> Option <& (dyn Error + 'static )> {138 + Self ::Metadata(error) => Some (error),139 + Self ::MetadataDecode(error) => Some (error),140 + Self ::Pup(error) => Some (error),141 + Self ::MetadataFailed(_ ) | Self ::InvalidMetadata(_ ) | Self ::Violations(_ ) => None ,148 + dependencies: Vec <Dependency>,153 + kind: DependencyKind,156 + #[derive(Clone, Copy, Debug, PartialEq, Eq)]157 + enum DependencyKind {75 164 clippy::print_stderr, clippy::print_stderr,76 165 reason = "A failed gate needs a concise diagnostic before xtask exits non-zero." reason = "A failed gate needs a concise diagnostic before xtask exits non-zero." 79 168 let mut arguments = env::args().skip (1 ); let mut arguments = env::args().skip (1 );80 169 let command = arguments.next (); let command = arguments.next ();82 - if command.as_deref () == Some ("check" ) && arguments.next ().is_none () {83 - return match run_check (run_cargo) {171 + if arguments.next ().is_some () {175 + match command.as_deref () {176 + Some ( " check " ) => match run_check (run_cargo) {84 177 Ok (()) => ExitCode::SUCCESS , Ok (()) => ExitCode::SUCCESS ,85 178 Err (error) => { Err (error) => {86 179 eprintln! ("xtask check: {error}" ); eprintln! ("xtask check: {error}" );87 180 ExitCode::FAILURE ExitCode::FAILURE 183 + Some ("arch" ) => match run_arch () {184 + Ok (()) => ExitCode::SUCCESS ,186 + eprintln! ("xtask arch: {error}" );190 + Some ("pup" ) => match run_pup () {191 + Ok (()) => ExitCode::SUCCESS ,193 + eprintln! ("xtask pup: {error}" );197 + Some ("print-modules" ) => match run_print_modules () {198 + Ok (()) => ExitCode::SUCCESS ,200 + eprintln! ("xtask print-modules: {error}" );92 - eprintln! ("usage: cargo run -p xtask -- check" );209 + clippy::print_stderr,210 + reason = "Usage is an interactive command-line diagnostic." 212 + fn usage () -> ExitCode {213 + eprintln! ("usage: cargo run -p xtask -- < check|arch|pup|print-modules> " );93 214 ExitCode::FAILURE ExitCode::FAILURE
230 + fn run_pup () -> Result <(), GateError> {231 + run_cargo (& [PINNED_NIGHTLY , "pup" ])235 + clippy::print_stdout,236 + reason = "The command is a developer-facing module inventory." 238 + fn run_print_modules () -> Result <(), ArchError> {239 + for package in cargo_metadata ()? {240 + println! ("{}" , crate_root_name (& package.name));243 + run_cargo (& [PINNED_NIGHTLY , "pup" , "print-modules" ]).map_err (ArchError::Pup)246 + fn crate_root_name (package_name: &str ) -> String {247 + match package_name {248 + "smith-cli" => "smith" .to_owned (),249 + _ => package_name.replace ('-' , "_" ),109 253 fn run_cargo (arguments: & [&str ]) -> Result <(), GateError> {fn run_cargo (arguments: & [&str ]) -> Result <(), GateError> {110 254 let status = Command::new("cargo" ) let status = Command::new("cargo" )111 255 .args (arguments) .args (arguments)
266 + fn run_arch () -> Result <(), ArchError> {267 + let packages = cargo_metadata ()? ;268 + let violations = dependency_violations (& packages);270 + if violations.is_empty () {273 + Err (ArchError::Violations(violations))277 + fn cargo_metadata () -> Result <Vec <Package>, ArchError> {278 + let output = Command::new("cargo" )279 + .args (["metadata" , "--format-version" , "1" , "--no-deps" ])281 + .map_err (ArchError::Metadata)? ;283 + if ! output.status.success () {284 + return Err (ArchError::MetadataFailed(285 + String ::from_utf8_lossy(& output.stderr).trim ().to_owned (),289 + parse_metadata (& String ::from_utf8_lossy(& output.stdout))292 + fn parse_metadata (metadata: &str ) -> Result <Vec <Package>, ArchError> {293 + let metadata: serde_json::Value = 294 + serde_json::from_str(metadata).map_err (ArchError::MetadataDecode)? ;295 + let packages = metadata297 + .and_then (serde_json::Value::as_array)298 + .ok_or (ArchError::InvalidMetadata("packages were absent" ))? ;303 + let dependencies = package304 + .get ("dependencies" )305 + .and_then (serde_json::Value::as_array)306 + .ok_or (ArchError::InvalidMetadata(307 + "package dependencies were absent" ,312 + .and_then (serde_json::Value::as_str)313 + .ok_or (ArchError::InvalidMetadata("package name was absent" ))? 315 + dependencies: dependencies321 + .and_then (serde_json::Value::as_str)322 + .ok_or (ArchError::InvalidMetadata("dependency name was absent" ))? 324 + kind: dependency_kind (dependency)? ,327 + .collect::<Result <_ , _ >>()? ,333 + fn dependency_kind (dependency: & serde_json::Value) -> Result <DependencyKind, ArchError> {334 + match dependency.get ("kind" ) {335 + Some (serde_json::Value::Null) | None => Ok (DependencyKind::Normal),336 + Some (serde_json::Value::String(kind)) => match kind.as_str () {337 + "dev" => Ok (DependencyKind::Development),338 + "build" => Ok (DependencyKind::Build),339 + _ => Err (ArchError::InvalidMetadata("dependency kind was unknown" )),341 + Some (_ ) => Err (ArchError::InvalidMetadata("dependency kind was invalid" )),345 + fn dependency_violations (packages: & [Package]) -> Vec <String > {346 + let mut violations = Vec ::new();348 + for package in packages {349 + let Some (rule) = ARCHITECTURE .iter ().find (|rule| rule.name == package.name) else {350 + violations.push (format! (351 + "ARCH VIOLATION: {} has no dependency rule in SPEC §2.2" ,357 + for dependency in & package.dependencies {358 + if dependency.kind == DependencyKind::Normal359 + && ARCHITECTURE .iter ().any (|rule| rule.name == dependency.name)361 + .allowed_internal_dependencies362 + .contains (& dependency.name.as_str ())364 + violations.push (format! (365 + "ARCH VIOLATION: {} -> {} is forbidden by SPEC §2.2" ,366 + package.name, dependency.name375 + .filter (|rule| ! packages.iter ().any (|package| package.name == rule.name))378 + "ARCH VIOLATION: required workspace package {} is absent from Cargo metadata" ,122 386 #[cfg(test)]#[cfg(test)]
388 + clippy::unwrap_used,389 + reason = "Test fixtures use unwrap so setup failures report their exact operation." 123 391 mod tests {mod tests {124 - use super ::{GateError, run_check};393 + ARCHITECTURE , ArchError, Dependency, DependencyKind, GateError, Package, crate_root_name,394 + dependency_violations, parse_metadata, run_check,397 + fn complete_workspace () -> Vec <Package> {400 + .map (|rule| Package {401 + name: rule.name.to_owned (),402 + dependencies: Vec ::new(),127 - fn check_runs_stable_gates_in_order () {408 + fn check_runs_architecture_gates_in_order () {128 409 let mut invocations = Vec ::new(); let mut invocations = Vec ::new();130 411 let result = run_check (|arguments| { let result = run_check (|arguments| {135 416 assert! (result.is_ok ()); assert! (result.is_ok ());136 - let expected: [& [&str ]; 4 ] = [137 - & ["fmt" , "--check" ],147 - & ["nextest" , "run" , "--workspace" ],148 - & ["test" , "--doc" , "--workspace" ],150 - assert_eq! (invocations, expected);420 + ["fmt" , "--check" ].as_slice (),431 + ["run" , "-p" , "xtask" , "--" , "arch" ].as_slice (),432 + ["run" , "-p" , "xtask" , "--" , "pup" ].as_slice (),433 + ["nextest" , "run" , "--workspace" ].as_slice (),434 + ["test" , "--doc" , "--workspace" ].as_slice (),154 - fn check_stops_when_a_gate_fails () {440 + fn check_stops_when_pup_fails () {155 441 let mut invocations = Vec ::new(); let mut invocations = Vec ::new();156 442 let mut calls = 0 ; let mut calls = 0 ;158 444 let result = run_check (|arguments| { let result = run_check (|arguments| {159 445 invocations.push (arguments); invocations.push (arguments);160 446 calls += 1 ; calls += 1 ;162 448 Err (GateError::Failed) Err (GateError::Failed)168 - assert! (matches! (result, Err (error) if error.gate == "clippy" ));169 - let expected: [& [&str ]; 2 ] = [170 - & ["fmt" , "--check" ],454 + assert! (matches! (result, Err (error) if error.gate == "pup" ));455 + assert_eq! (invocations.len (), 4 );459 + fn metadata_parser_finds_direct_dependencies () {460 + let metadata = r #"{"packages":[{"name":"smith-core","dependencies":[{"name":"smith","kind":null}],"manifest_path":"C:\\smith-core\\Cargo.toml"}]}"# ;462 + let packages = parse_metadata (metadata).unwrap ();464 + assert_eq! (packages[0 ].name, "smith-core" );465 + assert_eq! (packages[0 ].dependencies[0 ].name, "smith" );466 + assert_eq! (packages[0 ].dependencies[0 ].kind, DependencyKind::Normal);470 + fn metadata_parser_reads_fields_by_json_structure () {471 + let metadata = r #"{"packages":[{"name":"smith-core","description":"\"dependencies\": []","dependencies":[{"name":"smith","kind":null}]}]}"# ;473 + let packages = parse_metadata (metadata).unwrap ();475 + assert_eq! (packages[0 ].dependencies[0 ].name, "smith" );479 + fn metadata_parser_preserves_non_normal_dependency_kinds () {480 + let metadata = r #"{"packages":[{"name":"smith-core","dependencies":[{"name":"smith-ai","kind":"dev"},{"name":"smith-ai","kind":"build"}]}]}"# ;482 + let packages = parse_metadata (metadata).unwrap ();485 + packages[0 ].dependencies[0 ].kind,486 + DependencyKind::Development488 + assert_eq! (packages[0 ].dependencies[1 ].kind, DependencyKind::Build);492 + fn module_inventory_uses_rust_crate_names () {493 + assert_eq! (crate_root_name ("smith-core" ), "smith_core" );497 + fn module_inventory_uses_the_cli_binary_crate_name () {498 + assert_eq! (crate_root_name ("smith-cli" ), "smith" );502 + fn arch_rejects_forbidden_internal_dependency () {503 + let mut packages = complete_workspace ();504 + let package = packages506 + .find (|package| package.name == "smith-core" )508 + package.dependencies = vec! [510 + name: "smith-ai" .to_owned (),511 + kind: DependencyKind::Normal,514 + name: "smith-tui" .to_owned (),515 + kind: DependencyKind::Normal,181 - assert_eq! (invocations, expected);520 + dependency_violations (& packages),522 + "ARCH VIOLATION: smith-core -> smith-ai is forbidden by SPEC §2.2" ,523 + "ARCH VIOLATION: smith-core -> smith-tui is forbidden by SPEC §2.2" ,529 + fn arch_allows_dev_and_build_dependencies () {530 + let mut packages = complete_workspace ();531 + let package = packages533 + .find (|package| package.name == "smith-core" )535 + package.dependencies = vec! [537 + name: "smith-ai" .to_owned (),538 + kind: DependencyKind::Development,541 + name: "smith-ai" .to_owned (),542 + kind: DependencyKind::Build,546 + assert! (dependency_violations (& packages).is_empty ());550 + fn arch_rejects_an_unlisted_workspace_package () {551 + let mut packages = complete_workspace ();552 + packages.push (Package {553 + name: "new-workspace-package" .to_owned (),554 + dependencies: Vec ::new(),558 + dependency_violations (& packages),559 + ["ARCH VIOLATION: new-workspace-package has no dependency rule in SPEC §2.2" ]564 + fn arch_rejects_a_missing_required_workspace_package () {565 + let mut packages = complete_workspace ();566 + packages.retain (|package| package.name != "xtask" );569 + dependency_violations (& packages),570 + ["ARCH VIOLATION: required workspace package xtask is absent from Cargo metadata" ]575 + fn malformed_metadata_is_rejected () {577 + parse_metadata ("{}" ),578 + Err (ArchError::InvalidMetadata(_ ))582 + parse_metadata ("{" ),583 + Err (ArchError::MetadataDecode(_ ))