summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 17:16:23 +0000
committeraur-build <aur-build@localhost>2026-11-18 17:16:23 +0000
commit8bb76cb266a2fef5d5fe43c0f9643101f59112aa (patch)
treeef421aa194b3cac2ab9e2662fcf41ce551260138 /tests
parente7922f3dd1d985dcb993b624146b2492183f3a11 (diff)
downloadaur-build-8bb76cb266a2fef5d5fe43c0f9643101f59112aa.tar.gz
aur-build-8bb76cb266a2fef5d5fe43c0f9643101f59112aa.zip
config: the test hooks are a gated submodule, not the production surface
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/common/mod.rs30
-rw-r--r--tests/crash.rs8
-rw-r--r--tests/dispatch.rs4
-rw-r--r--tests/invariants.rs6
-rw-r--r--tests/pipeline.rs4
-rw-r--r--tests/production_surface.rs62
-rw-r--r--tests/shims.rs6
-rw-r--r--tests/vcs.rs2
8 files changed, 95 insertions, 27 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 58c6dae..426f44d 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -5,7 +5,7 @@
use std::path::{Path, PathBuf};
-use aur_build::config::Config;
+use aur_build::config::{Config, TestHooks};
use aur_build::db::{self, Db};
pub struct Env {
@@ -127,14 +127,14 @@ impl Env {
/// Make the next publish abort at a named point (I4 / I5 tests).
pub fn set_publish_fault(&mut self, at: &str) {
- self.cfg.publish_fault = Some(at.to_string());
+ self.cfg.hooks.publish_fault = Some(at.to_string());
}
pub fn clear_publish_fault(&mut self) {
- self.cfg.publish_fault = None;
+ self.cfg.hooks.publish_fault = None;
}
/// Make the named shim fail (the "build failed" path, §8.4).
pub fn set_shim_fail(&mut self, tool: &str) {
- self.cfg.shim_fail = Some(tool.to_string());
+ self.cfg.hooks.shim_fail = Some(tool.to_string());
}
pub fn query_i64(&self, sql: &str, params: &[P]) -> Option<i64> {
@@ -236,12 +236,15 @@ pub fn env_with_fixture(name: &str) -> (Env, Fixture) {
let cfg = Config {
root: tmp.path().to_path_buf(),
signing_key_id: "TESTKEY".into(),
- path_prepend: Some(shim_dir()),
- shim_manifest: Some(fx.manifest.clone()),
- shim_dir: Some(tmp.path().join("shimlog")),
+ hooks: TestHooks {
+ path_prepend: Some(shim_dir()),
+ shim_manifest: Some(fx.manifest.clone()),
+ shim_dir: Some(tmp.path().join("shimlog")),
+ ..TestHooks::default()
+ },
..Config::default()
};
- std::fs::create_dir_all(cfg.shim_dir.as_ref().unwrap()).unwrap();
+ std::fs::create_dir_all(cfg.hooks.shim_dir.as_ref().unwrap()).unwrap();
cfg.ensure_dirs().unwrap();
let env = Env::with_cfg(tmp, cfg);
env.subscribe(name);
@@ -258,12 +261,15 @@ pub fn env_with_two_fixtures(a: &str, b: &str) -> (Env, Fixture, Fixture) {
let cfg = Config {
root: tmp.path().to_path_buf(),
signing_key_id: "TESTKEY".into(),
- path_prepend: Some(shim_dir()),
- shim_manifest: Some(fb.manifest.clone()),
- shim_dir: Some(tmp.path().join("shimlog")),
+ hooks: TestHooks {
+ path_prepend: Some(shim_dir()),
+ shim_manifest: Some(fb.manifest.clone()),
+ shim_dir: Some(tmp.path().join("shimlog")),
+ ..TestHooks::default()
+ },
..Config::default()
};
- std::fs::create_dir_all(cfg.shim_dir.as_ref().unwrap()).unwrap();
+ std::fs::create_dir_all(cfg.hooks.shim_dir.as_ref().unwrap()).unwrap();
cfg.ensure_dirs().unwrap();
let env = Env::with_cfg(tmp, cfg);
env.subscribe(a);
diff --git a/tests/crash.rs b/tests/crash.rs
index 66e6043..ca58a04 100644
--- a/tests/crash.rs
+++ b/tests/crash.rs
@@ -46,7 +46,7 @@ fn a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work
let (mut env, _fx) = env_with_fixture("plain-make");
let id = queued(&env, "plain-make");
// The child will be murdered the moment it invokes makechrootpkg.
- env.cfg.shim_kill_parent = Some("makechrootpkg".into());
+ env.cfg.hooks.shim_kill_parent = Some("makechrootpkg".into());
env.cfg.save().unwrap();
let out = run_cli(&env, &["run", &id]);
@@ -89,12 +89,12 @@ fn a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work
// Resume. The completed steps are not repeated; only the interrupted one and
// what follows run.
- env.cfg.shim_kill_parent = None;
+ env.cfg.hooks.shim_kill_parent = None;
env.cfg.save().unwrap();
let out = run_cli(&env, &["run", &id]);
assert!(out.status.success(), "resume failed: {}", String::from_utf8_lossy(&out.stderr));
- let shim = env.cfg.shim_dir.clone().unwrap();
+ let shim = env.cfg.hooks.shim_dir.clone().unwrap();
assert_eq!(
aur_build::shims::called_with(&shim, "mkarchroot", ""),
1,
@@ -126,7 +126,7 @@ fn a_cancelled_build_stops_at_a_step_boundary_and_publishes_nothing() {
assert!(matches!(out, pipeline::Outcome::Cancelled), "{out:?}");
assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, BuildState::Cancelled);
// Nothing ran, so nothing to undo.
- let shim = env.cfg.shim_dir.clone().unwrap();
+ let shim = env.cfg.hooks.shim_dir.clone().unwrap();
assert_eq!(aur_build::shims::called_with(&shim, "repo-add", ""), 0);
assert!(db::accepted_release(&env.db, "plain-make").unwrap().is_none());
// A cancelled build is not a failure and is not retried.
diff --git a/tests/dispatch.rs b/tests/dispatch.rs
index d0d4bd7..e62b351 100644
--- a/tests/dispatch.rs
+++ b/tests/dispatch.rs
@@ -202,7 +202,7 @@ fn a_reaped_build_resumes_at_the_next_incomplete_step_with_no_duplicate_work() {
pipeline::run(&env.cfg, &env.db, &id).unwrap(),
pipeline::Outcome::Failed { .. }
));
- let builds_before = aur_build::shims::called_with(&env.cfg.shim_dir.clone().unwrap(), "makechrootpkg", "");
+ let builds_before = aur_build::shims::called_with(&env.cfg.hooks.shim_dir.clone().unwrap(), "makechrootpkg", "");
// The worker "died" at publish: the row is leased with a lease nobody will
// extend. A fresh dispatcher reaps it and a worker finishes from the
@@ -223,7 +223,7 @@ fn a_reaped_build_resumes_at_the_next_incomplete_step_with_no_duplicate_work() {
assert_eq!(state, BuildState::Succeeded, "the resumed build did not finish");
assert_eq!(
- aur_build::shims::called_with(&env.cfg.shim_dir.clone().unwrap(), "makechrootpkg", ""),
+ aur_build::shims::called_with(&env.cfg.hooks.shim_dir.clone().unwrap(), "makechrootpkg", ""),
builds_before,
"I5: resuming must not rebuild"
);
diff --git a/tests/invariants.rs b/tests/invariants.rs
index b7bfc0d..8026a79 100644
--- a/tests/invariants.rs
+++ b/tests/invariants.rs
@@ -158,7 +158,7 @@ fn i5_resume_after_a_crash_repeats_no_completed_step() {
pipeline::run(&env.cfg, &env.db, &id).unwrap(),
pipeline::Outcome::Failed { .. }
));
- let shim = env.cfg.shim_dir.clone().unwrap();
+ let shim = env.cfg.hooks.shim_dir.clone().unwrap();
let builds_before = aur_build::shims::called_with(&shim, "makechrootpkg", "");
assert_eq!(builds_before, 2, "one build per attempted publish");
@@ -422,10 +422,10 @@ fn i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir() {
// Something a build must never get to publish: our own database file.
let secret = env.cfg.db_path();
let store_before = dir_listing(&env.cfg.store_dir());
- env.cfg.shim_plant_link = Some(secret.display().to_string());
+ env.cfg.hooks.shim_plant_link = Some(secret.display().to_string());
let out = pipeline::run(&env.cfg, &env.db, &id);
- env.cfg.shim_plant_link = None;
+ env.cfg.hooks.shim_plant_link = None;
let (step, err) = match out {
Ok(pipeline::Outcome::Failed { step, error, .. }) => (step, error),
other => panic!("a build that smuggled in a symlink must fail closed, got {other:?}"),
diff --git a/tests/pipeline.rs b/tests/pipeline.rs
index a8eb1d9..0da1612 100644
--- a/tests/pipeline.rs
+++ b/tests/pipeline.rs
@@ -223,7 +223,7 @@ fn i5_a_restarted_build_resumes_at_the_next_incomplete_step() {
pipeline::Outcome::Failed { .. }
));
let builds_after_crash =
- aur_build::shims::called_with(&env.cfg.shim_dir.clone().unwrap(), "makechrootpkg", "");
+ aur_build::shims::called_with(&env.cfg.hooks.shim_dir.clone().unwrap(), "makechrootpkg", "");
assert_eq!(builds_after_crash, 2, "one real build before the crash");
// "Restart": same build row, no fault. Steps 0-8 are checkpointed as
@@ -234,7 +234,7 @@ fn i5_a_restarted_build_resumes_at_the_next_incomplete_step() {
other => panic!("{other:?}"),
}
assert_eq!(
- aur_build::shims::called_with(&env.cfg.shim_dir.clone().unwrap(), "makechrootpkg", ""),
+ aur_build::shims::called_with(&env.cfg.hooks.shim_dir.clone().unwrap(), "makechrootpkg", ""),
builds_after_crash,
"I5: resuming must not rebuild"
);
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}");
+}
diff --git a/tests/shims.rs b/tests/shims.rs
index 757e456..3422500 100644
--- a/tests/shims.rs
+++ b/tests/shims.rs
@@ -297,9 +297,9 @@ fn fixtures_are_detected_through_the_watcher() {
fn shim_environment_reaches_child_processes_through_the_config() {
let env = Env::new();
let mut cfg = env.cfg.clone();
- cfg.path_prepend = Some(shim_dir());
- cfg.shim_manifest = Some(fixture_manifest("plain-make"));
- cfg.shim_dir = Some(env.path("shimlog"));
+ cfg.hooks.path_prepend = Some(shim_dir());
+ cfg.hooks.shim_manifest = Some(fixture_manifest("plain-make"));
+ cfg.hooks.shim_dir = Some(env.path("shimlog"));
std::fs::create_dir_all(env.path("shimlog")).unwrap();
// Prove the config is what puts the shims on PATH, not the test process env.
diff --git a/tests/vcs.rs b/tests/vcs.rs
index df0d756..b1edd51 100644
--- a/tests/vcs.rs
+++ b/tests/vcs.rs
@@ -24,7 +24,7 @@ fn stage_b_rows(env: &Env) -> i64 {
}
fn makepkg_calls(env: &Env) -> usize {
- aur_build::shims::called_with(&env.cfg.shim_dir.clone().unwrap(), "makepkg", "--vercheck")
+ aur_build::shims::called_with(&env.cfg.hooks.shim_dir.clone().unwrap(), "makepkg", "--vercheck")
}
#[test]