From 8bb76cb266a2fef5d5fe43c0f9643101f59112aa Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 17:16:23 +0000 Subject: config: the test hooks are a gated submodule, not the production surface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Seven fields sat on `Config` next to `signing_key_id` and `bind`: a PATH override, three shim protocol variables, a fault-injection point in the middle of `publish()`, and two more shims could obey. m-9's complaint was not that they exist — the shims are how I4, I5 and I9 are tested for real, and a mock would have asserted the mock's own behaviour — but that nothing said which of these was production and which was scaffolding, and the publish path carried a test branch on every real publish. They are one `TestHooks` submodule now, documented as what it is, and the whole submodule is `#[cfg(feature = "test-support")]` — the same feature that already gates the shims and the raw SQL escape hatch, and which only this crate's own dev-dependency turns on. A production build has no `hooks` field, no shim protocol in `child_env`, and no fault-injection branch in `publish()`; the serialized config skips the section entirely when nothing is hooked, so a real `config.json` never mentions any of it. `TestHooks::is_empty()` names the state a real process runs in, and three tests hold the line: the hook fields may be declared exactly once and only inside `TestHooks`, every `publish_fault` read in `publish.rs` must sit behind the feature gate, and a default config serializes without a trace of hooks. --- tests/production_surface.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'tests/production_surface.rs') diff --git a/tests/production_surface.rs b/tests/production_surface.rs index 5ade95b..26f50ea 100644 --- a/tests/production_surface.rs +++ b/tests/production_surface.rs @@ -14,6 +14,10 @@ use std::path::{Path, PathBuf}; +fn read(rel: &str) -> String { + std::fs::read_to_string(Path::new(env!("CARGO_MANIFEST_DIR")).join(rel)).expect("read source") +} + fn rust_files(dir: &Path, out: &mut Vec) { for entry in std::fs::read_dir(dir).expect("read_dir") { let path = entry.expect("entry").path(); @@ -97,3 +101,61 @@ fn the_shim_binaries_are_test_only() { ); } } + +#[test] +fn the_test_hooks_are_a_gated_submodule_not_config_fields() { + // §6 M-9: fault injection in the publish hot path, shim environment + // variables and clock pinning were part of the production API surface — + // `Config` advertised `publish_fault` next to `signing_key_id`, and the + // branch that reads it sat in the middle of every real publish. + let cfg_src = read("src/config.rs"); + for field in [ + "pub path_prepend", + "pub shim_manifest", + "pub shim_dir", + "pub publish_fault", + "pub shim_fail", + "pub shim_kill_parent", + "pub shim_plant_link", + ] { + // Each appears exactly once, inside `TestHooks`, never on `Config`. + let hits = cfg_src.matches(field).count(); + assert_eq!(hits, 1, "{field} must be declared once, on TestHooks — not on Config"); + } + assert!(cfg_src.contains("pub struct TestHooks"), "the hooks must live in one named submodule"); + assert!( + cfg_src.contains("#[cfg(feature = \"test-support\")]"), + "the hooks must be compiled out without the test-support feature" + ); +} + +#[test] +fn the_publish_hot_path_has_no_ungated_test_branch() { + // The two fault-injection points in `publish()` are the ones that ran on + // every real publish. Each must sit behind the feature gate. + let src = read("src/pipeline/publish.rs"); + let lines: Vec<&str> = src.lines().collect(); + let mut gated = 0; + for (i, line) in lines.iter().enumerate() { + if line.contains("hooks.publish_fault") { + let window = lines[i.saturating_sub(3)..i].join("\n"); + assert!( + window.contains("#[cfg(feature = \"test-support\")]"), + "fault injection at publish.rs:{} is compiled into production builds", + i + 1 + ); + gated += 1; + } + } + assert_eq!(gated, 2, "expected the two known fault points, found {gated}"); +} + +#[test] +fn a_default_config_has_no_hooks_attached() { + // The state every real process runs in: nothing hooked, and nothing written + // to config.json about hooks. + let cfg = aur_build::config::Config::default(); + assert!(cfg.hooks.is_empty()); + let json = serde_json::to_string(&cfg).unwrap(); + assert!(!json.contains("publish_fault"), "hooks leaked into the serialized config: {json}"); +} -- cgit v1.2.3