summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-17 21:57:58 +0000
committeraur-build <aur-build@localhost>2026-11-17 21:57:58 +0000
commit4ac1d19ca5dc540db0478943a0cd70a5353307da (patch)
tree6d3a5192ea3bf9a4eae2f141dba5f8ffcc398f6d /tests
parenta6f69962e85ccf0f0cfd86f7c85bf0f9a2c8c09e (diff)
downloadaur-build-4ac1d19ca5dc540db0478943a0cd70a5353307da.tar.gz
aur-build-4ac1d19ca5dc540db0478943a0cd70a5353307da.zip
pipeline: ten-step build machine with atomic signed publish
materialize -> plan -> chroot -> sources -> pkgver -> build -> collect -> verify -> ingest -> publish, each checkpointed in build_step so a worker that dies resumes at the next incomplete step without repeating the expensive one (I5). Step 0 materializes from the local mirror only and re-hashes the tree: there is no path from 'AUR moved since the review' to 'we built it anyway' (I3). Step 4 re-resolves a VCS pkgver and refuses when it no longer matches the approved identity. Publish renders the index to .tmp, fsyncs, commits release + package rows and the accepted pointer under a compare-and-swap, then renames over the served database and signs it, so a crash leaves the old index byte-for-byte intact (I4) and every index entry traces back to an approval (I1). Ingest records the world snapshot as the BUILDINFO installed set intersected with our own packages, which is what keeps staleness meaningful (I12). 17 shim-driven end-to-end tests, including kill-mid-publish and crash-resume, with no root, network, or real chroot.
Diffstat (limited to 'tests')
-rw-r--r--tests/common/mod.rs12
-rw-r--r--tests/db.rs2
-rw-r--r--tests/pipeline.rs439
3 files changed, 452 insertions, 1 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index d5a4f81..0dc5396 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -125,6 +125,18 @@ impl Env {
.unwrap()
}
+ /// 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());
+ }
+ pub fn clear_publish_fault(&mut self) {
+ self.cfg.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());
+ }
+
pub fn query_i64(&self, sql: &str, params: &[P]) -> Option<i64> {
let sql = sql.to_string();
let params: Vec<P> = params.to_vec();
diff --git a/tests/db.rs b/tests/db.rs
index 60c9256..b455603 100644
--- a/tests/db.rs
+++ b/tests/db.rs
@@ -39,7 +39,7 @@ fn migrations_apply_from_empty_and_are_idempotent() {
Ok(c.pragma_query_value(None, "user_version", |r| r.get::<_, u32>(0))?)
})
.unwrap();
- assert_eq!(v, 4, "all four migrations applied");
+ assert_eq!(v, 5, "all migrations applied");
// Re-running migration over an existing DB is a no-op, not an error.
assert_eq!(db::migrate(&env.cfg.db_path()).unwrap(), 0);
let journal: String = env
diff --git a/tests/pipeline.rs b/tests/pipeline.rs
new file mode 100644
index 0000000..835dcf0
--- /dev/null
+++ b/tests/pipeline.rs
@@ -0,0 +1,439 @@
+//! End-to-end pipeline tests driven entirely by the toolchain shims (§16a):
+//! no root, no network, no real chroot — but the *real* step machine runs.
+
+mod common;
+
+use aur_build::db::{self, builds, model::*};
+use aur_build::pipeline::{self, publish};
+use aur_build::review::{approve, candidates, diff};
+use common::*;
+
+/// subscribe -> detect -> render the review -> approve.
+fn approve_fixture(env: &Env, name: &str) -> CandidateRow {
+ aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, name).unwrap();
+ let c = candidates::pending_candidates(&env.db).unwrap().remove(0);
+ let dd = diff::render_and_store(&env.db, &env.cfg, &c).unwrap();
+ approve::approve(&env.db, "tester", c.id, &c.identity_hash, &dd, None).unwrap();
+ candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap()
+}
+
+/// Re-detect and approve whatever is pending now (a later version).
+fn approve_pending(env: &Env, name: &str) -> CandidateRow {
+ approve_fixture(env, name)
+}
+
+fn run_for(env: &Env, c: &CandidateRow) -> pipeline::Outcome {
+ let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, c).unwrap();
+ pipeline::run(&env.cfg, &env.db, &id).unwrap()
+}
+
+fn in_index(env: &Env) -> Vec<(String, String)> {
+ env.db
+ .read(|c| {
+ let mut st =
+ c.prepare("SELECT name, version FROM package WHERE state='in_index' ORDER BY name")?;
+ let rows = st.query_map([], |r| Ok((r.get(0)?, r.get(1)?)))?;
+ let mut v = Vec::new();
+ for r in rows {
+ v.push(r?);
+ }
+ Ok(v)
+ })
+ .unwrap()
+}
+
+fn step_rows(env: &Env) -> Vec<(String, String)> {
+ env.db
+ .read(|c| {
+ let mut st = c.prepare("SELECT step, status FROM build_step ORDER BY rowid")?;
+ let rows = st.query_map([], |r| Ok((r.get(0)?, r.get(1)?)))?;
+ let mut v = Vec::new();
+ for r in rows {
+ v.push(r?);
+ }
+ Ok(v)
+ })
+ .unwrap()
+}
+
+#[test]
+fn end_to_end_publishes_a_signed_index() {
+ let (env, _fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ let out = run_for(&env, &c);
+ assert!(matches!(out, pipeline::Outcome::Succeeded { .. }), "{out:?}");
+
+ let rel = db::accepted_release(&env.db, "plain-make").unwrap().unwrap();
+ assert_eq!(rel.state, release_state::PUBLISHED);
+ assert_eq!(rel.pkgver, "1.0");
+ assert_eq!(rel.version(), "1.0-1");
+
+ // Both the packages and the database are signed (§9).
+ let arch = env.cfg.repo_arch_dir();
+ assert!(arch.join("plain-make-1.0-1-x86_64.pkg.tar.zst").exists());
+ assert!(arch.join("plain-make-1.0-1-x86_64.pkg.tar.zst.sig").exists());
+ assert!(arch.join("aur-build.db.tar.gz").exists());
+ assert!(arch.join("aur-build.db.tar.gz.sig").exists());
+
+ // One checkpoint row per step, all green (§8.1).
+ let all = step_rows(&env);
+ assert_eq!(all.len(), BUILD_STEPS.len(), "one row per step: {all:?}");
+ assert!(
+ all.iter().all(|(_, s)| s == "succeeded" || s == "skipped"),
+ "{all:?}"
+ );
+}
+
+#[test]
+fn i1_no_index_entry_without_an_approval() {
+ let (env, _fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ run_for(&env, &c);
+ let orphans: i64 = env
+ .db
+ .read(|c| {
+ Ok(c.query_row(
+ "SELECT count(*) FROM package p
+ LEFT JOIN release r ON r.id = p.release_id
+ WHERE p.state='in_index' AND (r.id IS NULL OR r.approval_id IS NULL)",
+ [],
+ |r| r.get(0),
+ )?)
+ })
+ .unwrap();
+ assert_eq!(orphans, 0, "I1: index entry with no approval behind it");
+}
+
+#[test]
+fn i8_served_index_holds_exactly_the_accepted_pointers() {
+ let (env, fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ run_for(&env, &c);
+ assert_eq!(in_index(&env), vec![("plain-make".into(), "1.0-1".into())]);
+
+ fx.bump(&[("pkgver", "1.0.1")]);
+ let c2 = approve_pending(&env, "plain-make");
+ run_for(&env, &c2);
+
+ // The old version is gone from the index, not merely superseded in place.
+ assert_eq!(in_index(&env), vec![("plain-make".into(), "1.0.1-1".into())]);
+ let rel = db::accepted_release(&env.db, "plain-make").unwrap().unwrap();
+ assert_eq!(rel.pkgver, "1.0.1");
+ let old: i64 = env
+ .db
+ .read(|c| {
+ Ok(c.query_row(
+ "SELECT count(*) FROM package WHERE state='in_index' AND version='1.0-1'",
+ [],
+ |r| r.get(0),
+ )?)
+ })
+ .unwrap();
+ assert_eq!(old, 0, "the previous release must leave the index");
+}
+
+#[test]
+fn step0_fails_closed_when_the_recipe_hash_drifts() {
+ let (env, _fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ // The mirror no longer matches what was approved. There is no path from
+ // "AUR moved since the review" to "we built it anyway" (I3).
+ env.exec(
+ "UPDATE snapshot SET recipe_hash='deadbeef' WHERE id=?1",
+ &params(vec![c.snapshot_id]),
+ );
+ let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap();
+ match pipeline::run(&env.cfg, &env.db, &id).unwrap() {
+ pipeline::Outcome::Failed { step, error, .. } => {
+ assert_eq!(step, "materialize");
+ assert!(error.contains("recipe_hash mismatch"), "{error}");
+ }
+ other => panic!("expected a fail-closed failure, got {other:?}"),
+ }
+ assert!(db::accepted_release(&env.db, "plain-make").unwrap().is_none());
+ assert!(in_index(&env).is_empty());
+}
+
+#[test]
+fn step4_fails_closed_when_pkgver_no_longer_matches() {
+ let (env, fx) = env_with_fixture("git-sourced");
+ let c = approve_fixture(&env, "git-sourced");
+ assert_eq!(c.pkgver, "r1.0");
+ // Upstream moves after approval: the tool now resolves a different pkgver.
+ // The build must refuse rather than silently ship the newer one (§8.1).
+ let mut m = fx.manifest_json();
+ m["vercheck"] = serde_json::json!("r9.9-1");
+ std::fs::write(&fx.manifest, serde_json::to_string(&m).unwrap()).unwrap();
+
+ match run_for(&env, &c) {
+ pipeline::Outcome::Failed { step, error, .. } => {
+ assert_eq!(step, "pkgver");
+ assert!(error.contains("r9.9") && error.contains("r1.0"), "{error}");
+ }
+ other => panic!("expected a fail-closed pkgver failure, got {other:?}"),
+ }
+ assert!(in_index(&env).is_empty());
+}
+
+#[test]
+fn step4_passes_when_the_vcs_pkgver_still_matches() {
+ let (env, _fx) = env_with_fixture("git-sourced");
+ let c = approve_fixture(&env, "git-sourced");
+ assert!(matches!(run_for(&env, &c), pipeline::Outcome::Succeeded { .. }));
+ assert_eq!(in_index(&env), vec![("git-sourced".into(), "r1.0-1".into())]);
+}
+
+#[test]
+fn i4_kill_mid_publish_leaves_the_old_index_intact() {
+ let (mut env, fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ run_for(&env, &c);
+ let v1 = env.cfg.repo_arch_dir().join("aur-build.db.tar.gz");
+ let before = std::fs::read(&v1).unwrap();
+
+ fx.bump(&[("pkgver", "1.0.1")]);
+ let c2 = approve_pending(&env, "plain-make");
+ env.set_publish_fault("before-rename");
+ let out = run_for(&env, &c2);
+ assert!(matches!(out, pipeline::Outcome::Failed { .. }), "{out:?}");
+
+ // The served database is byte-for-byte the old one, and the DB never
+ // recorded the new release: consumers saw either the old world or the new
+ // one, never a half-written index (I4).
+ assert_eq!(std::fs::read(&v1).unwrap(), before);
+ assert_eq!(in_index(&env), vec![("plain-make".into(), "1.0-1".into())]);
+ assert_eq!(
+ env.query_i64("SELECT count(*) FROM release WHERE pkgver='1.0.1'", &[]),
+ Some(0)
+ );
+}
+
+#[test]
+fn i5_a_restarted_build_resumes_at_the_next_incomplete_step() {
+ let (mut env, fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ run_for(&env, &c);
+
+ fx.bump(&[("pkgver", "1.0.1")]);
+ let c2 = approve_pending(&env, "plain-make");
+ let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c2).unwrap();
+ env.set_publish_fault("before-rename");
+ assert!(matches!(
+ pipeline::run(&env.cfg, &env.db, &id).unwrap(),
+ pipeline::Outcome::Failed { .. }
+ ));
+ let builds_after_crash =
+ aur_build::shims::called_with(&env.cfg.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
+ // succeeded, so only publish re-runs — the expensive step is not repeated.
+ env.clear_publish_fault();
+ match pipeline::run(&env.cfg, &env.db, &id).unwrap() {
+ pipeline::Outcome::Succeeded { release_id } => assert!(release_id > 0),
+ other => panic!("{other:?}"),
+ }
+ assert_eq!(
+ aur_build::shims::called_with(&env.cfg.shim_dir.clone().unwrap(), "makechrootpkg", ""),
+ builds_after_crash,
+ "I5: resuming must not rebuild"
+ );
+ assert_eq!(in_index(&env), vec![("plain-make".into(), "1.0.1-1".into())]);
+ // Exactly one release row per version: no duplicates from the resume.
+ assert_eq!(
+ env.query_i64("SELECT count(*) FROM release WHERE pkgver='1.0.1'", &[]),
+ Some(1)
+ );
+}
+
+#[test]
+fn split_pkgbase_is_one_approval_and_many_index_rows() {
+ let (env, _fx) = env_with_fixture("split-pkgbase");
+ let c = approve_fixture(&env, "split-pkgbase");
+ assert!(matches!(run_for(&env, &c), pipeline::Outcome::Succeeded { .. }));
+ let names: Vec<String> = in_index(&env).into_iter().map(|(n, _)| n).collect();
+ assert!(names.contains(&"split-pkgbase".to_string()), "{names:?}");
+ assert!(names.contains(&"split-pkgbase-docs".to_string()), "{names:?}");
+ // One approval, one release, N packages — the §3 split-pkgbase rule.
+ assert_eq!(env.query_i64("SELECT count(*) FROM approval", &[]), Some(1));
+ assert_eq!(env.query_i64("SELECT count(*) FROM release", &[]), Some(1));
+}
+
+#[test]
+fn a_failed_build_leaves_the_previous_version_serving() {
+ let (mut env, fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ run_for(&env, &c);
+
+ fx.bump(&[("pkgver", "1.0.1")]);
+ let c2 = approve_pending(&env, "plain-make");
+ // The build itself fails this time.
+ env.set_shim_fail("makechrootpkg");
+ let out = run_for(&env, &c2);
+ match out {
+ pipeline::Outcome::Failed { step, .. } => assert_eq!(step, "build"),
+ other => panic!("{other:?}"),
+ }
+ // §8.4: the old version keeps serving and the candidate stays approved.
+ assert_eq!(in_index(&env), vec![("plain-make".into(), "1.0-1".into())]);
+ assert_eq!(
+ candidates::candidate_by_id(&env.db, c2.id).unwrap().unwrap().state,
+ candidate_state::APPROVED
+ );
+ assert_eq!(
+ env.query_i64("SELECT count(*) FROM package WHERE state='in_index' AND version='1.0.1-1'", &[]),
+ Some(0)
+ );
+}
+
+#[test]
+fn an_unresolvable_dependency_blocks_instead_of_failing() {
+ let (env, _fx) = env_with_fixture("missing-dep");
+ // We subscribe to `dep-partner` but have never published it: that is exactly
+ // "unresolvable" in §10.4, and the answer is to wait, not to fail.
+ env.subscribe("dep-partner");
+ let c = approve_fixture(&env, "missing-dep");
+ let out = run_for(&env, &c);
+ match out {
+ pipeline::Outcome::Blocked { on } => {
+ assert!(on.contains(&"dep-partner".to_string()), "{on:?}");
+ }
+ other => panic!("expected a blocked build, got {other:?}"),
+ }
+ let (bid, _name, blocked_on) = builds::blocked_builds(&env.db).unwrap().remove(0);
+ assert_eq!(blocked_on, vec!["dep-partner".to_string()]);
+ assert_eq!(builds::get(&env.db, &bid).unwrap().unwrap().state, build_state::BLOCKED_MISSING_DEP);
+ assert!(in_index(&env).is_empty(), "a blocked build publishes nothing");
+}
+
+#[test]
+fn publishing_a_dependency_requeues_what_it_unblocks() {
+ let (env, _fx) = env_with_fixture("missing-dep");
+ env.subscribe("dep-partner");
+ let c = approve_fixture(&env, "missing-dep");
+ assert!(matches!(run_for(&env, &c), pipeline::Outcome::Blocked { .. }));
+ assert_eq!(builds::blocked_builds(&env.db).unwrap().len(), 1);
+ // Something lands in the index: blocked builds get another look (§10.4).
+ let n = publish::reconcile(&env.cfg, &env.db).unwrap_or(0);
+ let _ = n;
+ let requeued = builds::requeue_blocked(&env.db).unwrap();
+ assert_eq!(requeued, 1);
+ assert_eq!(builds::blocked_builds(&env.db).unwrap().len(), 0);
+}
+
+#[test]
+fn re_enqueueing_the_same_intent_is_a_noop() {
+ let (env, _fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ let a = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap();
+ let b = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap();
+ assert_eq!(a, b, "build ids are deterministic (§8.2)");
+ assert_eq!(env.query_i64("SELECT count(*) FROM build", &[]), Some(1));
+}
+
+#[test]
+fn i6_manual_rebuild_reuses_the_approved_identity() {
+ let (env, _fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ run_for(&env, &c);
+ let before = env.query_i64("SELECT count(*) FROM approval", &[]);
+
+ let id = pipeline::enqueue_manual_rebuild(&env.cfg, &env.db, "plain-make").unwrap();
+ assert!(matches!(
+ pipeline::run(&env.cfg, &env.db, &id).unwrap(),
+ pipeline::Outcome::Succeeded { .. }
+ ));
+ // Same version, new release row, and crucially: no new approval (§2 I6).
+ assert_eq!(env.query_i64("SELECT count(*) FROM approval", &[]), before);
+ assert_eq!(in_index(&env), vec![("plain-make".into(), "1.0-1".into())]);
+ assert_eq!(env.query_i64("SELECT count(*) FROM release", &[]), Some(2));
+}
+
+#[test]
+fn i12_world_snapshot_is_recorded_at_ingest() {
+ let (env, fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ run_for(&env, &c);
+
+ // Now a second build whose chroot had our own published package installed:
+ // that is the pair staleness tracking is computed from (§10.1).
+ let mut m = fx.manifest_json();
+ m["installed"] = serde_json::json!([
+ {"name": "plain-make", "version": "1.0-1", "arch": "x86_64"},
+ {"name": "glibc", "version": "2.39-1", "arch": "x86_64"}
+ ]);
+ std::fs::write(&fx.manifest, serde_json::to_string(&m).unwrap()).unwrap();
+ fx.bump(&[("pkgver", "1.0.1")]);
+ let c2 = approve_pending(&env, "plain-make");
+ run_for(&env, &c2);
+
+ let wid = env
+ .db
+ .read(|c| {
+ Ok(c.query_row(
+ "SELECT world_snapshot_id FROM build WHERE world_snapshot_id IS NOT NULL
+ ORDER BY rowid DESC LIMIT 1",
+ [],
+ |r| r.get::<_, i64>(0),
+ )?)
+ })
+ .unwrap();
+ let json: String = env
+ .db
+ .read(|c| {
+ Ok(c.query_row("SELECT members_json FROM world_snapshot WHERE id=?1", rusqlite::params![wid], |r| r.get(0))?)
+ })
+ .unwrap();
+ let parsed: Vec<serde_json::Value> = serde_json::from_str(&json).unwrap();
+ let members: Vec<(String, String)> = parsed
+ .iter()
+ .map(|v| {
+ (
+ v["pkgbase"].as_str().unwrap_or_default().to_string(),
+ v["version"].as_str().unwrap_or_default().to_string(),
+ )
+ })
+ .collect();
+ // The snapshot is the installed set INTERSECTED with our own packages:
+ // unfiltered, Arch moving would make every package permanently stale.
+ assert!(members.iter().any(|(n, v)| n == "plain-make" && v == "1.0-1"), "{members:?}");
+ assert!(!members.iter().any(|(n, _)| n == "glibc"), "{members:?}");
+}
+
+#[test]
+fn publish_refuses_without_an_approval_behind_it() {
+ let (env, _fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap();
+ // Strip the approval: the publish step must refuse, not publish anyway.
+ env.exec("DELETE FROM approval", &[]);
+ match pipeline::run(&env.cfg, &env.db, &id).unwrap() {
+ pipeline::Outcome::Failed { step, error, .. } => {
+ assert_eq!(step, "publish");
+ assert!(error.contains("no approval"), "{error}");
+ }
+ other => panic!("I1 requires a refusal, got {other:?}"),
+ }
+ assert!(in_index(&env).is_empty());
+}
+
+#[test]
+fn a_stale_accepted_pointer_refuses_to_publish() {
+ let (env, _fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap();
+ // The approval was taken against "nothing accepted yet". Move the pointer
+ // out from under the build and the compare-and-swap must refuse.
+ env.exec(
+ "UPDATE pkgbase SET current_accepted_release_id=4242 WHERE name='plain-make'",
+ &[],
+ );
+ match pipeline::run(&env.cfg, &env.db, &id).unwrap() {
+ pipeline::Outcome::Failed { step, error, .. } => {
+ assert_eq!(step, "publish");
+ assert!(error.contains("accepted pointer moved"), "{error}");
+ }
+ other => panic!("expected a CAS refusal, got {other:?}"),
+ }
+ assert!(in_index(&env).is_empty());
+}