summaryrefslogtreecommitdiffstats
path: root/tests/production_surface.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/production_surface.rs')
-rw-r--r--tests/production_surface.rs62
1 files changed, 62 insertions, 0 deletions
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<PathBuf>) {
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}");
+}