From 4304b0f336ddba7b4ec6780795059ff2066d105b Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 17:33:17 +0000 Subject: comments: keep only what the code cannot show MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stripped every comment that described what an item does, documented its arguments or fields, or cited the design docs (§n, I-n, m-n, decision n). 2247 comments down to 83. What survives: the section dividers that segment the large modules, the secret-handling warnings, the agent wire-frame directions, and the few notes without which the code they attach to reads as redundant, reorderable, or unsound. --- tests/approve.rs | 39 -------------------------------- tests/common/mod.rs | 54 --------------------------------------------- tests/config.rs | 48 ---------------------------------------- tests/crash.rs | 21 ------------------ tests/db.rs | 14 ------------ tests/detect.rs | 22 ------------------ tests/dispatch.rs | 37 ------------------------------- tests/failure_modes.rs | 14 ------------ tests/hash.rs | 8 ------- tests/http.rs | 24 -------------------- tests/invariants.rs | 51 ------------------------------------------ tests/kata.rs | 24 -------------------- tests/layers.rs | 8 ------- tests/live.rs | 22 ------------------ tests/notices.rs | 12 ---------- tests/ops.rs | 30 ------------------------- tests/pipeline.rs | 44 ------------------------------------ tests/production_surface.rs | 16 -------------- tests/remote_agent.rs | 20 ----------------- tests/schema_ownership.rs | 12 ---------- tests/shims.rs | 30 ------------------------- tests/staleness.rs | 18 --------------- tests/state_machine.rs | 30 ------------------------- tests/surfaces.rs | 10 --------- tests/time.rs | 5 ----- tests/vcs.rs | 26 ---------------------- tests/versions.rs | 33 --------------------------- tests/world.rs | 15 ------------- 28 files changed, 687 deletions(-) (limited to 'tests') diff --git a/tests/approve.rs b/tests/approve.rs index 86dcf46..15a205a 100644 --- a/tests/approve.rs +++ b/tests/approve.rs @@ -4,8 +4,6 @@ use aur_build::db::model::*; use aur_build::review::{approve::Stale, approve::*, candidates, diff}; use common::*; -/// Detect, open the review, and render it the way a reviewer opening the page -/// would — returning the candidate plus the two hashes an approval must echo. fn open_review(env: &Env, name: &str) -> (CandidateRow, String) { aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, name).unwrap(); let c = candidates::pending_candidates(&env.db).unwrap().remove(0); @@ -21,8 +19,6 @@ fn approve_writes_an_immutable_row_carrying_both_hashes() { assert_eq!(a.decision, "approved"); assert_eq!(a.identity_hash, c.identity_hash); assert_eq!(a.diff_digest, dd); - // The row itself records them, so "the human approved *this* diff" is - // provable later (§7.2). let stored: (String, String, Option) = env .db .read(|c| { @@ -35,7 +31,6 @@ fn approve_writes_an_immutable_row_carrying_both_hashes() { .unwrap(); assert_eq!(stored.0, c.identity_hash); assert_eq!(stored.1, dd); - // Approvals are append-only: the audit trigger rejects any edit (§10 I10). let err = env .db .writer @@ -45,7 +40,6 @@ fn approve_writes_an_immutable_row_carrying_both_hashes() { }) .err(); assert!(err.is_some(), "approval rows must be immutable"); - // And the human action is in the audit log. let actions: Vec = env .db .read(|c| { @@ -61,8 +55,6 @@ fn approve_writes_an_immutable_row_carrying_both_hashes() { fn a_stale_identity_hash_is_refused() { let (env, fx) = env_with_fixture("plain-make"); let (c, dd) = open_review(&env, "plain-make"); - // AUR moves while the reviewer is reading: the candidate collapses in place - // and its identity changes under them. fx.bump(&[("pkgver", "2.0")]); aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, "plain-make").unwrap(); let now = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap(); @@ -75,8 +67,6 @@ fn a_stale_identity_hash_is_refused() { Some(0), "a refused approval must leave nothing behind" ); - // Approving with the *current* identity succeeds: the reviewer just has to - // look at what is on screen now. let dd2 = diff::render_and_store(&env.db, &env.cfg, &now).unwrap(); approve(&env.db, "tester", c.id, &now.identity_hash, &dd2, None).unwrap(); } @@ -103,19 +93,12 @@ fn approving_twice_is_refused_not_duplicated() { #[test] fn a_broken_database_is_not_reported_as_a_stale_review() { - // What this pins: every failure inside the approval transaction used to be - // mapped into `Stale::NotPending`, so a SQLite error reached the reviewer as - // "review is no longer pending" — the one message telling them to look again - // when the truth is that the write failed (§6 M-3). let (env, _fx) = env_with_fixture("plain-make"); let (c, dd) = open_review(&env, "plain-make"); - // Make the write impossible halfway through: the approval row and the - // candidate update succeed, then the audit append has nowhere to go. env.exec("DROP TABLE audit", &[]); let err = approve(&env.db, "tester", c.id, &c.identity_hash, &dd, None).unwrap_err(); assert!(matches!(err, ApproveError::System(_)), "a broken database was reported as a stale review: {err:?}"); assert!(err.to_string().contains("could not be recorded"), "the message hides the cause: {err}"); - // And the refusal is atomic: the half-written approval rolled back with it. assert_eq!(env.query_i64("SELECT count(*) FROM approval", &[]), Some(0)); let after = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap(); assert_eq!(after.state, CandidateState::PendingReview, "a failed approval must not resolve the review"); @@ -123,32 +106,25 @@ fn a_broken_database_is_not_reported_as_a_stale_review() { #[test] fn bulk_refusals_are_their_own_reasons() { - // Bulk used to bend `Stale::NotPending` into "high risk", "unknown decision" - // and "the database failed" (§6 M-3). let (env, _fx) = env_with_fixture("plain-make"); let (c, dd) = open_review(&env, "plain-make"); candidates::set_risk(&env.db, c.id, "high", &["new source host".into()]).unwrap(); let items = [(c.id, c.identity_hash.clone(), dd.clone())]; - // High risk without the individual confirmation: the reason is the risk. let out = bulk(&env.db, "tester", &items, "approve", &[]).unwrap(); assert!( matches!(out[0].outcome, BulkOutcome::Refused(BulkRefusal::HighRiskUnconfirmed)), "{:?}", out[0].outcome ); - // A decision the form should never have sent is its own reason. let out = bulk(&env.db, "tester", &items, "ship-it", &[]).unwrap(); assert!( matches!(out[0].outcome, BulkOutcome::Refused(BulkRefusal::UnknownDecision(_))), "{:?}", out[0].outcome ); - // Confirming it individually is the answer to the first refusal. let out = bulk(&env.db, "tester", &items, "approve", &[c.id]).unwrap(); assert!(matches!(out[0].outcome, BulkOutcome::Approved(_)), "{:?}", out[0].outcome); - // Now it is no longer pending, and *that* is a staleness — the two reasons - // stay distinguishable in both directions. let out = bulk(&env.db, "tester", &items, "approve", &[c.id]).unwrap(); assert!(matches!(out[0].outcome, BulkOutcome::Refused(BulkRefusal::Stale(_))), "{:?}", out[0].outcome); assert_eq!(env.query_i64("SELECT count(*) FROM approval", &[]), Some(1)); @@ -160,7 +136,6 @@ fn a_bulk_rejection_hands_back_no_invented_approval() { let (c, dd) = open_review(&env, "plain-make"); let out = bulk(&env.db, "tester", &[(c.id, c.identity_hash.clone(), dd)], "reject", &[]).unwrap(); assert!(matches!(out[0].outcome, BulkOutcome::Rejected), "{:?}", out[0].outcome); - // A rejection records a `rejected` row; there is no approval to return. assert_eq!(env.query_i64("SELECT count(*) FROM approval WHERE decision='rejected'", &[]), Some(1)); assert_eq!(env.query_i64("SELECT count(*) FROM approval WHERE decision='approved'", &[]), Some(0)); } @@ -172,8 +147,6 @@ fn collapse_in_place_bumps_revision_without_a_new_row() { let first = c.revision; assert!(c.viewed_at.is_none(), "render_and_store must not mark it viewed"); - // Nobody has looked at it: the new upstream state collapses *into* the open - // review instead of queueing beside it (§7.1). fx.bump(&[("pkgver", "2.0")]); aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, "plain-make").unwrap(); let after = candidates::pending_candidates(&env.db).unwrap(); @@ -200,8 +173,6 @@ fn once_viewed_a_new_state_freezes_the_old_one_as_superseded() { assert_ne!(open[0].id, c.id, "a fresh review was opened"); let frozen = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap(); assert_eq!(frozen.state, CandidateState::Superseded); - // The frozen one can no longer be approved: approving it would build a version - // nobody is looking at. let err = approve(&env.db, "tester", c.id, &frozen.identity_hash, &frozen.diff_digest, None).unwrap_err(); assert!(matches!(err, ApproveError::Stale(Stale::NotPending { .. })), "{err:?}"); } @@ -211,10 +182,8 @@ fn a_rejected_identity_is_not_re_raised() { let (env, _fx) = env_with_fixture("plain-make"); let (c, _dd) = open_review(&env, "plain-make"); reject(&env.db, "tester", c.id, "not this").unwrap(); - // Same upstream state, polled again: nothing new to review. aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, "plain-make").unwrap(); assert!(candidates::pending_candidates(&env.db).unwrap().is_empty()); - // A different identity is a different question, and gets its own review. let err = approve(&env.db, "tester", c.id, &c.identity_hash, &c.diff_digest, None).unwrap_err(); assert!(matches!(err, ApproveError::Stale(Stale::NotPending { .. }))); } @@ -237,7 +206,6 @@ fn reject_requires_a_reason_and_records_it() { .unwrap(); assert!(note.contains("license"), "{note}"); - // And the audit row says *which review* was rejected, not only why (§6 m-4). let (actor_kind, detail): (String, String) = env .db .read(|c| { @@ -257,8 +225,6 @@ fn reject_requires_a_reason_and_records_it() { // ------------------------------------------------------------- the CLI path -- -/// Drive the real binary the way an operator would: `init`, `subscribe`, -/// `detect`, `show`, `approve --yes`. #[test] fn cli_end_to_end_approves_and_queues_a_build() { let tmp = tempfile::tempdir().unwrap(); @@ -280,8 +246,6 @@ fn cli_end_to_end_approves_and_queues_a_build() { let out = cli(bin, &root, &["reviews"]); assert!(out.stdout.contains("#1"), "reviews: {}", out.stdout); - // `show` renders the panels and the hashes; `approve` without --yes refuses to - // act. let out = cli(bin, &root, &["show", "1"]); assert!(out.stdout.contains("identity_hash"), "show: {}", out.stdout); let shown = out.stdout.clone(); @@ -298,7 +262,6 @@ fn cli_end_to_end_approves_and_queues_a_build() { assert_eq!(cli_count(&root, "build"), 1); assert!(shown.contains("PKGBUILD") || shown.contains("pkgver"), "diff pane: {shown}"); - // Approving the same review again is refused with a non-zero status. let out = cli(bin, &root, &["approve", "1", "--yes"]); assert_eq!(out.code, Some(2), "stale approval should exit 2: {:?}", out); } @@ -342,13 +305,11 @@ fn cli(bin: &str, root: &std::path::Path, args: &[&str]) -> Out { } } -/// A local git repo standing in for AUR, so the CLI test needs no network. fn cli_fixture(root: &std::path::Path, name: &str) -> (std::path::PathBuf, Fixture) { let fx = materialize_fixture(root, name); (fx.aur.clone(), fx) } -/// Query the CLI's own database through a throwaway read connection. fn cli_count(root: &std::path::Path, table: &str) -> i64 { let conn = rusqlite::Connection::open_with_flags( root.join("aur-build.db"), diff --git a/tests/common/mod.rs b/tests/common/mod.rs index b1a50ac..b4f40dd 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -46,7 +46,6 @@ impl Env { self.tmp.path().join(p) } - /// Insert a pkgbase + active subscription and return the pkgbase id. pub fn subscribe(&self, name: &str) -> i64 { let rid = db::repo_id(&self.db).unwrap(); let url = format!("file://{}/aur/{}.git", self.root().display(), name); @@ -54,8 +53,6 @@ impl Env { db::get_pkgbase(&self.db, name).unwrap().unwrap().id } - /// Drop a row back in via raw SQL (tests need to construct states the API - /// only reaches through several steps). pub fn exec(&self, sql: &str, params: &[P]) -> usize { let sql = sql.to_string(); let params: Vec

= params.to_vec(); @@ -74,8 +71,6 @@ impl Env { .unwrap() } - /// Stand in for the build+publish path: turn an approved candidate into a - /// published release and move the accepted pointer. pub fn accept_as_release(&self, candidate_id: i64) -> i64 { let at = "2026-01-01T00:00:00Z"; self.db @@ -121,14 +116,12 @@ 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.hooks.publish_fault = Some(at.to_string()); } pub fn clear_publish_fault(&mut self) { 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.hooks.shim_fail = Some(tool.to_string()); } @@ -152,7 +145,6 @@ impl Env { .unwrap() } - /// The same for a text column, so a test can read a timestamp back. pub fn query_str(&self, sql: &str, params: &[P]) -> Option { let sql = sql.to_string(); let params: Vec

= params.to_vec(); @@ -173,7 +165,6 @@ impl Env { } } -/// A test parameter. Owned so it can cross the writer-actor channel. #[derive(Debug, Clone)] pub enum P { I(i64), @@ -196,7 +187,6 @@ impl From for P { } } -/// Shorthand for building a parameter slice. pub fn params(v: Vec>) -> Vec

{ v.into_iter().map(Into::into).collect() } @@ -209,13 +199,10 @@ impl Drop for Env { // ------------------------------------------------------------- fixtures ---- -/// Root of the checked-in fake-package corpus (§16a). pub fn corpus_root() -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("testcorpus") } -/// Directory holding the shim executables cargo just built. Prepending this to -/// PATH is the whole test harness: the pipeline runs unmodified. pub fn shim_dir() -> PathBuf { Path::new(&env!("CARGO_BIN_EXE_makechrootpkg")) .parent() @@ -223,9 +210,6 @@ pub fn shim_dir() -> PathBuf { .to_path_buf() } -/// An environment wired to one corpus fixture: the fixture is committed into a real -/// git repo standing in for AUR, an optional local upstream git repo exists for VCS -/// sources, and the shims obey the fixture manifest. pub fn env_with_fixture(name: &str) -> (Env, Fixture) { let tmp = tempfile::tempdir().expect("tempdir"); let fx = materialize_fixture(tmp.path(), name); @@ -247,8 +231,6 @@ pub fn env_with_fixture(name: &str) -> (Env, Fixture) { (env, fx) } -/// Two fixtures sharing one server root, so a test can talk about packages that -/// depend on each other. pub fn env_with_two_fixtures(a: &str, b: &str) -> (Env, Fixture, Fixture) { let tmp = tempfile::tempdir().expect("tempdir"); let fa = materialize_fixture(tmp.path(), a); @@ -272,17 +254,12 @@ pub fn env_with_two_fixtures(a: &str, b: &str) -> (Env, Fixture, Fixture) { (env, fa, fb) } -/// Copy a corpus fixture into a server root: recipe files into a git repo standing -/// in for AUR, payload files beside it so their bytes can be swapped, and a local -/// upstream repo when the recipe references one. pub fn materialize_fixture(root: &Path, name: &str) -> Fixture { let src = corpus_root().join(name); assert!(src.exists(), "no fixture {name} in {}", corpus_root().display()); let manifest = root.join("manifest.json"); std::fs::copy(src.join("manifest.json"), &manifest).expect("copy manifest"); - // Data files a source URL points at live outside the recipe so a test can swap - // their bytes (the digest-drift case) without touching git. let data = root.join(format!("fixture/{name}")); std::fs::create_dir_all(&data).unwrap(); let aur = root.join(format!("aur/{name}.git")); @@ -321,7 +298,6 @@ pub fn materialize_fixture(root: &Path, name: &str) -> Fixture { if has_upstream2 { make_git_repo(&upstream2, &[("README", "second upstream\n")], "upstream: initial"); } - // A `#tag=v1` source needs the tag to exist. if std::fs::read_to_string(src.join("PKGBUILD")) .unwrap_or_default() .contains("#tag=") @@ -351,12 +327,10 @@ pub struct Fixture { pub data: PathBuf, pub manifest: PathBuf, pub upstream: Option, - /// A second upstream repo, for pkgbases that build from two of them. pub upstream2: Option, } impl Fixture { - /// Commit a new recipe revision, rewriting `pkgver`/`pkgrel`/`epoch`. pub fn bump(&self, changes: &[(&str, &str)]) -> String { let path = self.aur.join("PKGBUILD"); let text = std::fs::read_to_string(&path).unwrap(); @@ -375,7 +349,6 @@ impl Fixture { git(&self.aur, &["rev-parse", "HEAD"]) } - /// Swap the bytes behind a `SKIP` source without touching the recipe. pub fn swap_payload(&self, body: &str) { for f in ["payload.bin", "data.bin"] { let p = self.data.join(f); @@ -387,21 +360,18 @@ impl Fixture { panic!("fixture {} has no payload file", self.name); } - /// Add a commit to the local upstream repo (pin drift, §5.2). pub fn upstream_commit(&self, body: &str) -> String { let up = self.upstream.clone().expect("fixture has no upstream repo"); git_add_commit(&up, &[("README", body)], body); git(&up, &["rev-parse", "HEAD"]) } - /// Add a commit to the second upstream repo. pub fn upstream2_commit(&self, body: &str) -> String { let up = self.upstream2.clone().expect("fixture has no second upstream repo"); git_add_commit(&up, &[(("README"), body)], body); git(&up, &["rev-parse", "HEAD"]) } - /// HEAD of the (first) upstream repo. pub fn upstream_head(&self) -> String { let up = self.upstream.clone().expect("fixture has no upstream repo"); git(&up, &["rev-parse", "HEAD"]) @@ -417,14 +387,12 @@ impl Fixture { } } -/// A minimal PKGBUILD for tests that need recipe bytes without a fixture dir. pub fn pkgbuild(pkgbase: &str, pkgver: &str, pkgrel: &str, extra: &str) -> String { format!( "pkgbase={pkgbase}\npkgver={pkgver}\npkgrel={pkgrel}\npkgdesc=test\narch=(x86_64)\nurl=https://example.invalid\nlicense=(MIT)\n{extra}\nbuild() {{ :\n}}\npackage_{pkgbase}() {{ :\n}}\n" ) } -/// Build a throwaway git repo with the given files and return its path. pub fn make_git_repo(dir: &Path, files: &[(&str, &str)], msg: &str) -> String { std::fs::create_dir_all(dir).unwrap(); git(dir, &["init", "-q", "-b", "master"]); @@ -468,8 +436,6 @@ pub fn git(dir: &Path, args: &[&str]) -> String { // ------------------------------------------------------------- web driver -- -/// A tiny HTTP client for the surface tests: keeps the session cookie and the CSRF -/// token, and hands back status + body. pub struct Web { pub env: Env, pub fx: Fixture, @@ -495,8 +461,6 @@ impl Web { Self::attach(env, fx) } - /// Start a server on an env the test already built (two fixtures, odd - /// configs) and pick up the session it hands out. pub fn attach(mut env: Env, fx: Fixture) -> Self { env.cfg.bind = "127.0.0.1:0".into(); let server = aur_build::http::spawn(env.cfg.clone(), env.db.clone()).unwrap(); @@ -513,7 +477,6 @@ impl Web { web } - /// Subscribe, detect and render a review so an approval can be attempted. pub fn open_review(&self, name: &str) -> aur_build::db::model::CandidateRow { aur_build::watch::detect::check_pkgbase(&self.env.cfg, &self.env.db, name).unwrap(); let c = aur_build::review::candidates::pending_candidates(&self.env.db).unwrap().remove(0); @@ -521,8 +484,6 @@ impl Web { aur_build::review::candidates::candidate_by_id(&self.env.db, c.id).unwrap().unwrap() } - /// Approve through the library and run the build to publication, so a test can - /// talk about "what the index serves". pub fn publish(&self, name: &str) { let c = self.open_review(name); aur_build::review::approve::approve(&self.env.db, "test", c.id, &c.identity_hash, &c.diff_digest, None) @@ -545,8 +506,6 @@ impl Web { }; let cookie = r.header("set-cookie").map(|s| s.to_string()).unwrap_or_default(); let mut headers = vec![("set-cookie".to_string(), cookie)]; - // ureq 2 will not hand out the whole header map, but it answers for a named - // one, which is all the assertions below need. for name in ["content-type", "content-encoding", "location"] { if let Some(v) = r.header(name) { headers.push((name.to_string(), v.to_string())); @@ -565,16 +524,11 @@ impl Web { self.finish(resp, path) } - /// POST with exactly the fields given and nothing added — used to prove the - /// CSRF gate refuses a form that omitted the token. pub fn post_bare(&self, path: &str, form: &[(&str, &str)]) -> Page { let resp = ureq::post(&self.url(path)).set("Cookie", &self.cookie).send_form(form); self.finish(resp, path) } - /// Send a request over a bare socket: no cookie jar, no redirect following, so - /// the test sees the 303 a browser would have swallowed. The session gate is - /// only meaningful at this level. pub fn raw_request(&self, method: &str, path: &str, headers: &[(&str, String)], body: Option<&str>) -> Raw { use std::io::{Read, Write}; let addr = self.server.addr.clone(); @@ -598,8 +552,6 @@ impl Web { Raw::parse(&raw) } - /// Log in and adopt the session cookie the server issued, refreshing the CSRF - /// token with it — the token is derived from the sid. pub fn login(&mut self, password: &str) -> Raw { let raw = self.raw_request("POST", "/login", &[], Some(&format!("password={}", url_encode(password)))); if let Some(cookie) = raw.cookie() { @@ -619,7 +571,6 @@ impl Web { } } -/// A response read straight off the wire, before any client undoes it. pub struct Raw { pub status: u16, pub headers: Vec<(String, String)>, @@ -646,8 +597,6 @@ impl Raw { self.headers.iter().find(|(k, _)| k == name).map(|(_, v)| v.as_str()) } - /// The `name=value` a browser would keep from this response, i.e. the first - /// Set-Cookie with its attributes stripped. pub fn cookie(&self) -> Option { self.header("set-cookie") .map(|v| v.split(';').next().unwrap_or("").to_string()) @@ -655,7 +604,6 @@ impl Raw { } } -/// Percent-encode enough for a form body built by hand. fn url_encode(s: &str) -> String { s.bytes() .map(|b| match b { @@ -666,8 +614,6 @@ fn url_encode(s: &str) -> String { .collect() } -/// Pull an attribute or meta value out of rendered HTML and undo the escaping the -/// templates applied — a page is the contract here, so we read it as one. pub fn extract(hay: &str, open: &str, close: &str) -> Option { let i = hay.find(open)? + open.len(); let rest = &hay[i..]; diff --git a/tests/config.rs b/tests/config.rs index 3737045..080bbc7 100644 --- a/tests/config.rs +++ b/tests/config.rs @@ -3,8 +3,6 @@ use std::process::Command; use aur_build::config::Config; -/// The exact shape of the bug: a relative `--root`, saved verbatim, read back by -/// the next command. #[test] fn a_relative_root_is_absolutized_once_and_never_doubled() { let rel = PathBuf::from("target").join("config-root-test").join("runtime"); @@ -28,16 +26,12 @@ fn a_relative_root_is_absolutized_once_and_never_doubled() { "the root must never be joined onto itself: {}", rel.join("runtime").display() ); - // Everything derived hangs off the one root, so the database cannot end up in - // a second tree while the config sits in the first. assert!(reloaded.db_path().starts_with(&reloaded.root)); assert!(reloaded.repo_arch_dir().starts_with(&reloaded.root)); std::fs::remove_dir_all(&rel).unwrap(); } -/// The legacy shape on disk: a config written by an `init` that saved `--root -/// runtime` verbatim. Loading it must not resurrect the doubled tree. #[test] fn a_stale_relative_root_in_the_file_is_ignored() { let tmp = tempfile::tempdir().unwrap(); @@ -61,8 +55,6 @@ fn a_root_with_no_config_is_an_error_not_a_fresh_server() { ); } -/// The CLI half of the same rule: the old fallback invented a default config for -/// *any* command, so a typo'd `--root` quietly produced an empty server. #[test] fn the_cli_refuses_a_root_that_was_never_initialized() { let tmp = tempfile::tempdir().unwrap(); @@ -83,7 +75,6 @@ fn the_cli_refuses_a_root_that_was_never_initialized() { assert!(err.contains("init"), "{err}"); } -/// …and `init` is still allowed to run where there is no config yet. #[test] fn init_still_runs_where_there_is_no_config_yet() { let tmp = tempfile::tempdir().unwrap(); @@ -100,14 +91,11 @@ fn init_still_runs_where_there_is_no_config_yet() { assert!(root.join("config.json").exists()); assert!(root.join("aur-build.db").exists()); - // And the command after it agrees about where the tree is. let cfg = Config::load(&root).unwrap(); assert_eq!(cfg.root, std::path::absolute(&root).unwrap()); assert!(!root.join("runtime").exists(), "no doubled tree"); } -/// A root that exists but holds nothing but a config still resolves to itself, -/// whichever way it was spelled. #[test] fn an_absolute_root_is_used_verbatim() { let tmp = tempfile::tempdir().unwrap(); @@ -120,11 +108,6 @@ fn an_absolute_root_is_used_verbatim() { assert_eq!(Config::load(dir).unwrap().root, dir); } -// The sandbox configuration: three kinds, and only three. The kinds are an enum -// now, so a configuration that would silently mean "run the untrusted PKGBUILD as -// the hub's own user" does not parse. - -/// Write a config carrying exactly this `sandbox` value and load it. fn load_sandbox(sandbox: &str) -> Result { let tmp = tempfile::tempdir().unwrap(); std::fs::write( @@ -135,7 +118,6 @@ fn load_sandbox(sandbox: &str) -> Result { Config::load(tmp.path()).map_err(|e| e.to_string()) } -/// Load a config written as an older `aur-build init` would have written it. fn load_raw(body: &str) -> Result { let tmp = tempfile::tempdir().unwrap(); std::fs::write(tmp.path().join("config.json"), body).unwrap(); @@ -206,15 +188,12 @@ fn a_missing_required_field_names_the_field() { #[test] fn a_misspelled_field_is_refused_not_ignored() { - // deny_unknown_fields: `listn` must not parse as "no listen address given". let err = load_sandbox(r#"{"kind":"remote","listn":"127.0.0.1:1","token":"t"}"#).unwrap_err(); assert!(err.contains("listn"), "a typo'd field name must be named: {err}"); } #[test] fn an_unknown_kind_names_the_value_and_the_valid_set() { - // The exact mistake this enum exists to catch: `kata` was a real intent, - // and the old match sent it quietly to loopback. let err = load_sandbox(r#"{"kind":"kata"}"#).unwrap_err(); assert!(err.contains("kata"), "must name the bad value: {err}"); for kind in aur_build::config::Sandbox::KINDS { @@ -224,8 +203,6 @@ fn an_unknown_kind_names_the_value_and_the_valid_set() { #[test] fn a_config_with_no_sandbox_object_is_the_local_backend() { - // The contract with every config.json already on disk: saying nothing means - // loopback. let cfg = load_raw("{\n \"repo_name\": \"aur\"\n}\n").unwrap(); assert!(matches!(cfg.sandbox, aur_build::config::Sandbox::Loopback)); assert_eq!(cfg.repo_name, "aur", "the rest of the config is untouched"); @@ -233,8 +210,6 @@ fn a_config_with_no_sandbox_object_is_the_local_backend() { assert!(cfg.sandbox.shared_workspace(), "loopback shares the filesystem by construction"); } -/// The file an older `aur-build init` wrote, verbatim. It carries the retired keys, -/// but they say what the default already means, so it must still load. #[test] fn a_config_init_wrote_before_the_enum_still_loads() { let cfg = load_raw( @@ -269,8 +244,6 @@ fn a_config_init_wrote_before_the_enum_still_loads() { assert_eq!(cfg.lease_secs, 90); } -/// …but retired keys that *would* have changed behaviour are refused, not quietly -/// reinterpreted. #[test] fn retired_sandbox_keys_that_mean_something_are_refused() { let err = load_raw(r#"{ "sandbox_backend": "remote", "agent_listen": "0.0.0.0:1", "agent_token": "t" }"#) @@ -278,18 +251,14 @@ fn retired_sandbox_keys_that_mean_something_are_refused() { assert!(err.contains("sandbox_backend"), "must name the retired key: {err}"); assert!(err.contains("sandbox"), "must point at the replacement: {err}"); - // Even one retired key with content is enough to refuse. let err = load_raw(r#"{ "sandbox_backend": "kata" }"#).unwrap_err(); assert!(err.contains("sandbox_backend"), "{err}"); - // An empty retired key is noise, not intent, and stays tolerated. assert!(load_raw(r#"{ "sandbox_backend": "loopback", "agent_token": "" }"#).is_ok()); } #[test] fn the_rendezvous_secrets_never_reach_debug() { - // A config that ends up in a log line, a panic, or an audit payload must - // not carry the token or the cluster bearer. let cfg = load_sandbox( r#"{"kind":"agent-sandbox","api":"https://k8s:6443","namespace":"builds", "bearer":"kube-token","image":"img","listen":"0.0.0.0:1","token":"s3cr3t"}"#, @@ -301,12 +270,6 @@ fn the_rendezvous_secrets_never_reach_debug() { assert!(shown.contains("builds"), "the non-secret fields are still visible: {shown}"); } -// The startup guard: the enum makes the impossible unrepresentable, this refuses -// what a type cannot see — a field present but empty, and a remote backend that -// was never told the workspace is shared. - -/// A config that parses but cannot work must be refused by `validate`, not -/// discovered at the step that needed the thing it is missing. #[test] fn a_field_that_is_present_but_empty_is_refused() { let cfg = load_sandbox(r#"{"kind":"remote","listen":"","token":"t","shared_workspace":true}"#) @@ -319,7 +282,6 @@ fn a_field_that_is_present_but_empty_is_refused() { let err = cfg.validate().unwrap_err().to_string(); assert!(err.contains("token"), "whitespace is not a token: {err}"); - // Every agent-sandbox field, one at a time. for blank in ["api", "namespace", "bearer", "image", "listen", "token"] { let mut fields = std::collections::BTreeMap::from([ ("api", "https://k8s:6443"), @@ -338,8 +300,6 @@ fn a_field_that_is_present_but_empty_is_refused() { } } -/// The workspace gap: the build workspace is not shipped to a remote sandbox, so -/// "remote" without this assertion would silently build on the hub. #[test] fn a_remote_backend_must_assert_the_shared_workspace() { let cfg = load_sandbox(r#"{"kind":"remote","listen":"127.0.0.1:1","token":"t"}"#).unwrap(); @@ -357,7 +317,6 @@ fn a_remote_backend_must_assert_the_shared_workspace() { assert!(err.contains("shared_workspace"), "{err}"); assert!(err.contains("agent-sandbox"), "{err}"); - // Asserting it is enough — the guard refuses the silence, not the kind. assert!(load_sandbox( r#"{"kind":"remote","listen":"127.0.0.1:1","token":"t","shared_workspace":true}"# ) @@ -368,15 +327,10 @@ fn a_remote_backend_must_assert_the_shared_workspace() { #[test] fn the_local_backend_needs_no_assertion_at_all() { - // The whole point of keeping loopback the default: it shares the filesystem - // by construction, so there is nothing to promise. assert!(load_sandbox(r#"{"kind":"loopback"}"#).unwrap().validate().is_ok()); assert!(load_raw("{}\n").unwrap().validate().is_ok()); } -/// The guard is wired to the process, not just available as a library call: -/// `aur-build serve` with a remote config that never asserted the shared -/// workspace must refuse rather than come up healthy and build on the hub. #[test] fn serve_refuses_a_remote_config_that_never_asserted_the_workspace() { let tmp = tempfile::tempdir().unwrap(); @@ -394,8 +348,6 @@ fn serve_refuses_a_remote_config_that_never_asserted_the_workspace() { assert!(err.contains("shared_workspace"), "{err}"); } -/// …and the same for the CLI build path, which is where the build would -/// actually have run. #[test] fn the_cli_build_path_refuses_an_unusable_sandbox_config() { let tmp = tempfile::tempdir().unwrap(); diff --git a/tests/crash.rs b/tests/crash.rs index 68cac5c..ca7d90a 100644 --- a/tests/crash.rs +++ b/tests/crash.rs @@ -8,7 +8,6 @@ use aur_build::pipeline; use aur_build::review::{candidates, diff}; use common::*; -/// Approve a fixture's candidate and hand back the approved row. fn approved(env: &Env, name: &str) -> aur_build::db::model::CandidateRow { aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, name).unwrap(); let c = candidates::pending_candidates(&env.db).unwrap().remove(0); @@ -18,7 +17,6 @@ fn approved(env: &Env, name: &str) -> aur_build::db::model::CandidateRow { candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap() } -/// Approve and enqueue the build without running it. fn queued(env: &Env, name: &str) -> String { let c = approved(env, name); pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap() @@ -37,7 +35,6 @@ fn run_cli(env: &Env, args: &[&str]) -> std::process::Output { 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 makepkg. env.cfg.hooks.shim_kill_parent = Some("makepkg".into()); env.cfg.save().unwrap(); @@ -51,7 +48,6 @@ fn a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work String::from_utf8_lossy(&out.stderr) ); - // The database survived, because no transaction ever spans a build step. let b = builds::get(&env.db, &id).unwrap().expect("build row survived the kill"); assert!( b.state == BuildState::Leased || b.state == BuildState::Running, @@ -70,8 +66,6 @@ fn a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work ); assert!(db::accepted_release(&env.db, "plain-make").unwrap().is_none(), "nothing was published"); - // Time passes; the lease expires. A fresh process's dispatcher reaps it — the - // same code path as any other expired lease. env.exec("UPDATE build SET lease_expires_at='2000-01-01T00:00:00Z' WHERE id=?1", ¶ms(vec![id.as_str()])); assert_eq!(builds::reap_expired(&env.db).unwrap(), 1); assert_eq!( @@ -79,7 +73,6 @@ fn a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work Some(StepState::Interrupted) ); - // Resume: the completed steps are not repeated. env.cfg.hooks.shim_kill_parent = None; env.cfg.save().unwrap(); let out = run_cli(&env, &["run", &id]); @@ -108,35 +101,26 @@ fn a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work #[test] fn a_cancelled_build_stops_at_a_step_boundary_and_publishes_nothing() { - // §8.2: cancellation is cooperative at a step boundary. A worker never kills a - // step halfway through, because that is the state a crash leaves. let (env, _fx) = env_with_fixture("plain-make"); let id = queued(&env, "plain-make"); builds::request_cancel(&env.db, &id).unwrap(); let out = pipeline::run(&env.cfg, &env.db, &id).unwrap(); 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.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. assert_eq!(env.query_i64("SELECT count(*) FROM build WHERE state='failed'", &[]), Some(0)); } #[test] fn a_failed_build_leaves_the_index_serving_the_old_version_and_says_so() { - // §8.4: "v2 approved, build failed, index still serving v1". The dangerous - // failure mode is a package that looks healthy while the new version never - // arrived. let (mut env, fx) = env_with_fixture("plain-make"); - // Publish v1 for real. let c = approved(&env, "plain-make"); let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap(); pipeline::run(&env.cfg, &env.db, &id).unwrap(); assert_eq!(db::index_version(&env.db, "plain-make").unwrap().as_deref(), Some("1.0-1")); - // v2 is approved and its build fails deterministically. fx.bump(&[("pkgver", "2.0")]); env.set_shim_fail("makepkg"); let c2 = approved(&env, "plain-make"); @@ -144,7 +128,6 @@ fn a_failed_build_leaves_the_index_serving_the_old_version_and_says_so() { let out = pipeline::run(&env.cfg, &env.db, &id2).unwrap(); assert!(matches!(out, pipeline::Outcome::Failed { .. }), "{out:?}"); - // The index still serves v1 — correct — and the system knows v2 never landed. assert_eq!(db::index_version(&env.db, "plain-make").unwrap().as_deref(), Some("1.0-1")); let unbuilt = db::approved_but_unbuilt(&env.db).unwrap(); assert_eq!(unbuilt.len(), 1, "the failed approval must be surfaced: {unbuilt:?}"); @@ -152,7 +135,6 @@ fn a_failed_build_leaves_the_index_serving_the_old_version_and_says_so() { assert_eq!(unbuilt[0].approved, "2.0-1"); assert_eq!(unbuilt[0].serving, "1.0-1"); - // And it is on the surfaces a human actually looks at. let web = Web::attach(env, fx); let attention = web.get("/attention"); assert!(attention.body.contains("Approved but unbuilt"), "no Attention section: {}", &attention.body[..600.min(attention.body.len())]); @@ -164,8 +146,6 @@ fn a_failed_build_leaves_the_index_serving_the_old_version_and_says_so() { #[test] fn a_transient_failure_retries_but_a_deterministic_one_never_does() { - // The retry policy is asserted at the state machine level here; the dispatch - // tests cover it through the pool. let (mut env, _fx) = env_with_fixture("build-fails"); let id = queued(&env, "build-fails"); let pool = aur_build::pipeline::dispatch::Pool::spawn(std::sync::Arc::new(env.cfg.clone()), env.db.clone()); @@ -182,7 +162,6 @@ fn a_transient_failure_retries_but_a_deterministic_one_never_does() { pool.shutdown(); assert_eq!(state, BuildState::Failed); assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().attempt, 1, "a deterministic failure must not retry"); - // The release stays approved_but_unbuilt rather than vanishing. assert_eq!(db::approved_but_unbuilt(&env.db).unwrap().len(), 1); let _ = &mut env; } diff --git a/tests/db.rs b/tests/db.rs index 31f4326..ea8c4de 100644 --- a/tests/db.rs +++ b/tests/db.rs @@ -35,7 +35,6 @@ fn migrations_apply_from_empty_and_are_idempotent() { }) .unwrap(); assert_eq!(v as usize, db::MIGRATIONS.len(), "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 .db @@ -54,7 +53,6 @@ fn default_settings_are_seeded() { assert_eq!(db::setting_i64(&env.db, "retention_versions", 0), 5); } -/// I7: a pkgbase has at most one open review, enforced by a partial unique index. #[test] fn i7_second_open_review_is_rejected_by_the_database() { let env = Env::new(); @@ -67,7 +65,6 @@ fn i7_second_open_review_is_rejected_by_the_database() { }); assert!(err.is_err(), "second pending_review must fail"); - // A terminal state frees the slot again. insert_candidate(&env, pb, snap2, "id-2", "rejected"); let n: Option = env.query_i64( "SELECT count(*) FROM candidate WHERE pkgbase_id=?1", @@ -76,7 +73,6 @@ fn i7_second_open_review_is_rejected_by_the_database() { assert_eq!(n, Some(2)); } -/// Same identity for the same pkgbase must never create a second candidate (I3). #[test] fn candidate_identity_is_unique_per_pkgbase() { let env = Env::new(); @@ -88,7 +84,6 @@ fn candidate_identity_is_unique_per_pkgbase() { assert!(res.is_err(), "UNIQUE(pkgbase_id, identity_hash) must hold"); } -/// I10: every state transition is recorded, and the log cannot be rewritten. #[test] fn audit_log_is_append_only() { let env = Env::new(); @@ -106,11 +101,9 @@ fn audit_log_is_append_only() { std::panic::catch_unwind(|| env.exec("DELETE FROM audit WHERE id=?1", ¶ms(vec![id]))).is_err(), "audit DELETE must be refused by trigger" ); - // Inserts keep working. db::audit_system(&env.db.writer, "test2", "pkgbase", "1", serde_json::json!({})).unwrap(); } -/// §16: concurrent approvals on the same pkgbase are a guarded compare-and-swap. #[test] fn accepted_release_pointer_is_compared_and_swapped() { let env = Env::new(); @@ -129,7 +122,6 @@ fn accepted_release_pointer_is_compared_and_swapped() { Ok(tx.last_insert_rowid()) }) .unwrap(); - // First swap from NULL wins, second loses. assert!(db::cas_accepted_release(&env.db.writer, pb, None, rel).unwrap()); assert!(!db::cas_accepted_release(&env.db.writer, pb, None, rel).unwrap()); assert_eq!( @@ -138,7 +130,6 @@ fn accepted_release_pointer_is_compared_and_swapped() { ); } -/// §11a: WAL lets readers proceed concurrently with the writer. #[test] fn many_readers_do_not_block_the_writer() { let env = std::sync::Arc::new(Env::new()); @@ -166,7 +157,6 @@ fn many_readers_do_not_block_the_writer() { .unwrap(), ); } - // Write while they read: none of these may fail with SQLITE_BUSY. for i in 0..200 { db::set_setting(&env.db.writer, &format!("k{i}"), "1").unwrap(); } @@ -180,7 +170,6 @@ fn world_snapshot_dedupes_by_hash() { let env = Env::new(); let m = |b: &str, v: &str| db::WorldMember { pkgbase: b.into(), version: v.into() }; let a = db::put_world_snapshot(&env.db.writer, &[m("foo", "1-1"), m("bar", "2-1")]).unwrap(); - // Order-insensitive: same set, same snapshot. let b = db::put_world_snapshot(&env.db.writer, &[m("bar", "2-1"), m("foo", "1-1")]).unwrap(); assert_eq!(a, b); let members = db::world_members(&env.db, a).unwrap(); @@ -199,7 +188,6 @@ fn duplicate_open_notices_are_suppressed() { assert!(db::put_notice_once(&env.db.writer, pb, "pin_drift", "info", detail.clone()) .unwrap() .is_none()); - // Acknowledging lets a fresh one through. let id = env .query_i64("SELECT id FROM notice ORDER BY id DESC LIMIT 1", &[]) .unwrap(); @@ -213,7 +201,6 @@ fn duplicate_open_notices_are_suppressed() { fn i1_query_flags_index_entries_without_approval() { let env = Env::new(); let pb = env.subscribe("foo"); - // A published release with no approval row: exactly the thing I1 forbids. let rel = env .db .writer @@ -235,7 +222,6 @@ fn i1_query_flags_index_entries_without_approval() { #[test] fn a_setting_that_is_absent_is_the_default_and_one_that_is_nonsense_falls_back() { - // m-9: absent means default, nonsense means default *and a complaint*. let env = Env::new(); assert_eq!(db::setting_i64(&env.db, "stage_b_cooldown", 86400), 86400); db::set_setting(&env.db.writer, "stage_b_cooldown", "86400x").unwrap(); diff --git a/tests/detect.rs b/tests/detect.rs index 6284b31..a7641b1 100644 --- a/tests/detect.rs +++ b/tests/detect.rs @@ -7,7 +7,6 @@ use aur_build::review::{approve, candidates}; use aur_build::watch::detect::{check_pkgbase, Outcome}; use aur_build::watch::mirror::{sync_mirror, Sync}; -/// Path of the fake AUR repo for `name`, matching `Env::subscribe`'s URL. fn aur(env: &Env, name: &str) -> std::path::PathBuf { env.path(&format!("aur/{name}.git")) } @@ -40,7 +39,6 @@ fn first_detection_opens_a_first_introduction_with_no_base() { assert_eq!(c.kind, candidate_kind::FIRST_INTRODUCTION); assert_eq!(c.base_release_id, None, "I2 has no referent for a first introduction"); assert_eq!(c.version(), "1.0-1"); - // The pin is recorded on the snapshot and it is the commit we cloned. let snap = db::snapshot_by_id(&env.db, c.snapshot_id).unwrap().unwrap(); assert_eq!(snap.aur_commit, commit); assert_eq!(snap.recipe_hash.len(), 64); @@ -59,7 +57,6 @@ fn cheap_poll_does_not_fetch_when_the_tip_is_unchanged() { Sync::Unchanged { head } => assert_eq!(head, git_head(&aur(&env, "foo"))), other => panic!("expected Unchanged, got {other:?}"), } - // A new commit makes it fetch. git_add_commit(&aur(&env, "foo"), &[("PKGBUILD", &common::pkgbuild("foo", "1.1", "1", ""))], "bump"); let moved = sync_mirror(&env.cfg, &env.db, "foo", &url).unwrap(); assert!(matches!(moved, Sync::Fetched { .. }), "SHA moved -> fetch"); @@ -69,8 +66,6 @@ fn git_head(p: &std::path::Path) -> String { aur_build::git::head(p).unwrap() } -/// §3: `recipe_hash` covers the *entire* tree, because a shipped patch is part of -/// the recipe and is a classic silent-change vector. #[test] fn recipe_hash_covers_shipped_patches() { let env = Env::new(); @@ -83,7 +78,6 @@ fn recipe_hash_covers_shipped_patches() { let h1 = db::snapshot_by_id(&env.db, c1.snapshot_id).unwrap().unwrap().recipe_hash; env.accept_as_release(c1.id); - // Same PKGBUILD, different patch bytes. git_add_commit(&aur(&env, "foo"), &[("fix.patch", "--- a\n+++ b\n@@\n-old\n+EVIL\n")], "patch2"); let rep = check_pkgbase(&env.cfg, &env.db, "foo").unwrap(); assert!( @@ -117,7 +111,6 @@ fn skip_sources_are_stream_hashed_into_the_cache() { assert_eq!(digests[0].digest, expected, "we hash SKIP sources ourselves (§5.3)"); assert!(digests[0].skip_declared); assert_eq!(digests[0].kind, "static"); - // The bytes landed in the content-addressed cache and are recorded. let cached = env.query_i64( "SELECT count(*) FROM source_cache WHERE url LIKE '%payload.txt' AND digest=?1", ¶ms(vec![expected.clone()]), @@ -125,7 +118,6 @@ fn skip_sources_are_stream_hashed_into_the_cache() { assert_eq!(cached, Some(1)); let path = env.cfg.source_cache_path(&expected); assert!(path.exists(), "cached file is reused by the build"); - // A declared checksum costs no bandwidth: nothing was downloaded for it. } #[test] @@ -153,7 +145,6 @@ fn declared_checksums_are_trusted_without_downloading() { ); } -/// I2, the headline rule: diffs are always against the last *accepted* version. #[test] fn i2_diff_base_is_the_last_accepted_version_however_many_detections_arrive() { let env = Env::new(); @@ -164,15 +155,12 @@ fn i2_diff_base_is_the_last_accepted_version_however_many_detections_arrive() { let rel1 = env.accept_as_release(c1.id); assert_eq!(accepted(&env, "foo").unwrap().id, rel1); - // v2 arrives and is detected but nobody looks at it. git_add_commit(&aur(&env, "foo"), &[("PKGBUILD", &common::pkgbuild("foo", "2.0", "1", ""))], "v2"); check_pkgbase(&env.cfg, &env.db, "foo").unwrap(); let c2 = pending(&env, "foo").unwrap(); assert_eq!(c2.base_release_id, Some(rel1), "base is the accepted release"); assert_eq!(c2.version(), "2.0-1"); - // v3 and v4 arrive while nobody is looking: they collapse into the same review, - // and the base is *still* v1. for v in ["3.0", "4.0"] { git_add_commit(&aur(&env, "foo"), &[("PKGBUILD", &common::pkgbuild("foo", v, "1", ""))], v); check_pkgbase(&env.cfg, &env.db, "foo").unwrap(); @@ -188,7 +176,6 @@ fn i2_diff_base_is_the_last_accepted_version_however_many_detections_arrive() { ); } -/// §7.1: `superseded` exists only when a human actually saw the old diff. #[test] fn a_viewed_review_is_frozen_and_a_fresh_one_opened() { let env = Env::new(); @@ -240,7 +227,6 @@ fn a_rejected_identity_is_not_re_raised() { check_pkgbase(&env.cfg, &env.db, "foo").unwrap(); let c = pending(&env, "foo").unwrap(); approve::reject(&env.db, "tester", c.id, "not this one").unwrap(); - // Re-running detection must not nag (§7.1). let rep = check_pkgbase(&env.cfg, &env.db, "foo").unwrap(); assert!( matches!(rep.outcome, Outcome::PreviouslyRejected | Outcome::NoChange), @@ -248,13 +234,11 @@ fn a_rejected_identity_is_not_re_raised() { rep.outcome ); assert!(pending(&env, "foo").is_none()); - // A *newer* version is still detected: rejection does not block (§7.1). git_add_commit(&aur(&env, "foo"), &[("PKGBUILD", &common::pkgbuild("foo", "2.0", "1", ""))], "v2"); check_pkgbase(&env.cfg, &env.db, "foo").unwrap(); assert!(pending(&env, "foo").is_some()); } -/// I11: a change that is not publishable never silently disappears. #[test] fn recipe_drift_under_a_static_version_is_a_notice_not_a_candidate() { let env = Env::new(); @@ -264,7 +248,6 @@ fn recipe_drift_under_a_static_version_is_a_notice_not_a_candidate() { let c = pending(&env, "foo").unwrap(); env.accept_as_release(c.id); - // Maintainer edits the PKGBUILD but forgets to bump pkgrel. git_add_commit( &aur(&env, "foo"), &[("PKGBUILD", &common::pkgbuild("foo", "1.0", "1", "# a comment only"))], @@ -282,7 +265,6 @@ fn recipe_drift_under_a_static_version_is_a_notice_not_a_candidate() { assert_eq!(notices[0].severity, "warning"); } -/// §5.3: the single most valuable detection — same version, swapped bytes. #[test] fn digest_drift_with_an_unchanged_version_is_an_integrity_alert() { let env = Env::new(); @@ -300,7 +282,6 @@ fn digest_drift_with_an_unchanged_version_is_an_integrity_alert() { let c = pending(&env, "foo").unwrap(); env.accept_as_release(c.id); - // The CDN now serves something else and the version did not move. std::fs::write(&payload, b"EVIL swapped artifact").unwrap(); let rep = check_pkgbase(&env.cfg, &env.db, "foo").unwrap(); match rep.outcome { @@ -311,7 +292,6 @@ fn digest_drift_with_an_unchanged_version_is_an_integrity_alert() { let notices = db::list_notices(&env.db, false).unwrap(); assert_eq!(notices[0].severity, "high"); assert!(notices[0].detail_json.contains("no longer serves")); - // The index keeps serving the artifact built from the old bytes (I1). assert_eq!(db::unapproved_index_entries(&env.db).unwrap(), Vec::::new()); } @@ -354,7 +334,6 @@ fn detection_is_idempotent_and_records_no_duplicate_candidate() { fn srcinfo_is_preferred_over_the_pkgbuild_when_present() { let env = Env::new(); env.subscribe("foo"); - // .SRCINFO disagrees with the PKGBUILD, which is what makepkg reports. make_git_repo( &aur(&env, "foo"), &[ @@ -398,7 +377,6 @@ fn epoch_and_pkgrel_are_part_of_the_identity() { check_pkgbase(&env.cfg, &env.db, "foo").unwrap(); let c = pending(&env, "foo").unwrap(); env.accept_as_release(c.id); - // pkgrel reset: a major signal, and a new identity. git_add_commit(&aur(&env, "foo"), &[("PKGBUILD", &common::pkgbuild("foo", "1.0", "7", ""))], "rel"); check_pkgbase(&env.cfg, &env.db, "foo").unwrap(); let c2 = pending(&env, "foo").expect("pkgrel bump is publishable, so it is a candidate"); diff --git a/tests/dispatch.rs b/tests/dispatch.rs index 197d226..f702151 100644 --- a/tests/dispatch.rs +++ b/tests/dispatch.rs @@ -9,7 +9,6 @@ use aur_build::pipeline::{self, dispatch}; use aur_build::review::{candidates, diff}; use common::*; -/// Approve a fixture's candidate and enqueue its build without running it. fn queued_build(env: &Env, name: &str) -> String { aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, name).unwrap(); let c = candidates::pending_candidates(&env.db).unwrap().remove(0); @@ -27,7 +26,6 @@ fn pass(env: &Env) -> Vec { #[test] fn the_deterministic_build_id_makes_re_enqueue_a_noop() { - // §8.2: re-submitting the same intent is an INSERT OR IGNORE no-op. let (env, _fx) = env_with_fixture("plain-make"); aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, "plain-make").unwrap(); let c = candidates::pending_candidates(&env.db).unwrap().remove(0); @@ -51,13 +49,10 @@ fn backpressure_admits_no_more_than_max_concurrent_builds() { let claimed = pass(&env); assert_eq!(claimed.len(), 1, "one slot must admit exactly one build"); - // The dispatcher will not run ahead into the second slot while the first is - // still in flight. assert_eq!(pass(&env).len(), 0, "admitted a second build while one is in flight"); assert_eq!(env.query_i64("SELECT count(*) FROM build WHERE state='leased'", &[]), Some(1)); assert_eq!(env.query_i64("SELECT count(*) FROM build WHERE state='queued'", &[]), Some(1)); - // Widen the pool and the second one goes. env.cfg.max_concurrent_builds = 2; assert_eq!(pass(&env).len(), 1); } @@ -66,12 +61,10 @@ fn backpressure_admits_no_more_than_max_concurrent_builds() { fn disk_headroom_is_part_of_backpressure() { let (mut env, _fx) = env_with_fixture("plain-make"); queued_build(&env, "plain-make"); - // Ask for more free space than any machine has: nothing is admitted (§8.2). env.cfg.min_free_disk_mb = u64::MAX / 2; assert_eq!(dispatch::admissible(&env.cfg, &env.db), 0); assert!(pass(&env).is_empty(), "claimed a build with no disk headroom"); assert_eq!(env.query_i64("SELECT count(*) FROM build WHERE state='queued'", &[]), Some(1)); - // And the measurement itself is real, not a stub returning zero. env.cfg.min_free_disk_mb = 1; assert!(dispatch::free_disk_mb(&env.cfg.root) > 0, "free_disk_mb never measures anything"); assert_eq!(dispatch::admissible(&env.cfg, &env.db), 1); @@ -79,19 +72,14 @@ fn disk_headroom_is_part_of_backpressure() { #[test] fn an_expired_lease_is_requeued_and_its_running_step_marked_interrupted() { - // The reaper pass is the whole crash-recovery story: a worker that died - // mid-step leaves a leased row and a running step, and the next pass turns - // that back into queued + interrupted (I5). let (env, _fx) = env_with_fixture("plain-make"); let id = queued_build(&env, "plain-make"); assert_eq!(pass(&env), vec![id.clone()]); builds::begin_step(&env.db, &id, "build", 1).unwrap(); assert_eq!(builds::step_status(&env.db, &id, "build").unwrap(), Some(StepState::Running)); - // Time passes — the lease expires, as it would if the process were killed. env.exec("UPDATE build SET lease_expires_at='2000-01-01T00:00:00Z'", &[]); - // A fresh dispatcher (as after a restart) reaps it before claiming anything. let reaped = builds::reap_expired(&env.db).unwrap(); assert_eq!(reaped, 1, "the expired lease was not requeued"); assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, BuildState::Queued); @@ -100,15 +88,12 @@ fn an_expired_lease_is_requeued_and_its_running_step_marked_interrupted() { Some(StepState::Interrupted), "the in-flight step was not marked interrupted" ); - // And it is claimable again. assert_eq!(pass(&env), vec![id.clone()]); assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().attempt, 2, "the retry was not counted"); } #[test] fn a_newer_approval_cancels_an_in_flight_build_at_the_step_boundary() { - // §8.2 cancellation: a superseded candidate marks the running build - // cancel_requested; the worker stops at the next boundary. let (env, _fx) = env_with_fixture("plain-make"); let id = queued_build(&env, "plain-make"); pass(&env); @@ -116,7 +101,6 @@ fn a_newer_approval_cancels_an_in_flight_build_at_the_step_boundary() { env.exec("UPDATE candidate SET state='superseded' WHERE id=(SELECT candidate_id FROM build WHERE id=?1)", ¶ms(vec![id.as_str()])); assert_eq!(builds::cancel_superseded(&env.db).unwrap(), 1); assert!(builds::cancel_requested(&env.db, &id).unwrap()); - // run() honours it at the step boundary rather than mid-step. let out = pipeline::run(&env.cfg, &env.db, &id).unwrap(); assert!(matches!(out, pipeline::Outcome::Cancelled), "run ignored the cancellation"); assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, BuildState::Cancelled); @@ -124,8 +108,6 @@ fn a_newer_approval_cancels_an_in_flight_build_at_the_step_boundary() { #[test] fn a_deterministic_build_failure_is_not_retried() { - // §8.4: a build that fails for a deterministic reason stays failed at attempt - // 1; burning another chroot to reproduce the same failure helps nobody. let (env, _fx) = env_with_fixture("build-fails"); let id = queued_build(&env, "build-fails"); let pool = dispatch::Pool::spawn(Arc::new(env.cfg.clone()), env.db.clone()); @@ -135,15 +117,11 @@ fn a_deterministic_build_failure_is_not_retried() { let b = builds::get(&env.db, &id).unwrap().unwrap(); assert_eq!(b.attempt, 1, "a deterministic failure must not be retried"); assert!(b.error.unwrap_or_default().contains("build"), "no step named in the error"); - // And the old version keeps looking served: nothing was published. assert_eq!(db::index_version(&env.db, "build-fails").unwrap(), None); } #[test] fn a_transient_failure_is_retried_up_to_the_cap() { - // §8.4: a failure the outside world caused is retried, up to a bound. This - // drives the real path: the build's `sources` step has to fetch and gets an - // `Http` failure — the class a flaky mirror produces. let (mut env, fx) = env_with_fixture("skip-checksum"); let id = queued_build(&env, "skip-checksum"); std::fs::remove_file(fx.data.join("payload.bin")).expect("payload exists"); @@ -151,8 +129,6 @@ fn a_transient_failure_is_retried_up_to_the_cap() { env.cfg.max_transient_attempts = 3; env.cfg.dispatch_tick_secs = 0; let pool = dispatch::Pool::spawn(Arc::new(env.cfg.clone()), env.db.clone()); - // The state flickers to 'failed' between retries; what settles is the - // attempt count reaching the cap with the build left failed. let b = wait_attempt(&env, &id, 3); pool.shutdown(); assert_eq!(b.state, BuildState::Failed); @@ -165,9 +141,6 @@ fn a_transient_failure_is_retried_up_to_the_cap() { #[test] fn a_missing_toolchain_is_not_retried() { - // m-14: this used to be the transient test. A missing `makepkg` surfaces as - // an `Io` error, and `Io` used to mean "retry". It is deterministic: the tool - // is not going to appear. let (mut env, _fx) = env_with_fixture("plain-make"); let id = queued_build(&env, "plain-make"); env.cfg.makepkg_bin = "/nonexistent/makepkg-for-test".into(); @@ -186,8 +159,6 @@ fn a_missing_toolchain_is_not_retried() { #[test] fn the_pool_takes_a_queued_build_all_the_way_to_publication() { - // The threads, not a test calling run() directly: dispatcher claims, worker - // runs the ten steps, publish lands the release. let (env, _fx) = env_with_fixture("plain-make"); let id = queued_build(&env, "plain-make"); let cfg = Arc::new(env.cfg.clone()); @@ -201,8 +172,6 @@ fn the_pool_takes_a_queued_build_all_the_way_to_publication() { #[test] fn a_reaped_build_resumes_at_the_next_incomplete_step_with_no_duplicate_work() { - // I5 through the dispatcher rather than a direct run(): a build that dies late - // is requeued, re-claimed, and finishes from its checkpoints. let (mut env, fx) = env_with_fixture("plain-make"); let c = queued_candidate(&env, "plain-make"); let first = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap(); @@ -218,9 +187,6 @@ fn a_reaped_build_resumes_at_the_next_incomplete_step_with_no_duplicate_work() { )); let builds_before = aur_build::shims::called_with(&env.cfg.hooks.shim_dir.clone().unwrap(), "makepkg", ""); - // The worker "died" at publish: the row is leased to a worker that is no - // longer running, with a lease nobody will extend. A fresh dispatcher reaps it - // and a worker finishes from the checkpoints. env.clear_publish_fault(); env.exec( "UPDATE build SET state='leased', lease_owner='dead-worker', @@ -252,7 +218,6 @@ fn a_reaped_build_resumes_at_the_next_incomplete_step_with_no_duplicate_work() { assert_eq!(db::index_version(&env.db, "plain-make").unwrap().as_deref(), Some("1.0.1-1")); } -/// Approve a fixture's candidate and hand back the approved row. fn queued_candidate(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); @@ -262,7 +227,6 @@ fn queued_candidate(env: &Env, name: &str) -> CandidateRow { candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap() } -/// Poll until the build has been attempted `n` times and settled. fn wait_attempt(env: &Env, id: &str, n: i64) -> builds::BuildRow { for _ in 0..600 { if let Some(b) = builds::get(&env.db, id).unwrap() { @@ -275,7 +239,6 @@ fn wait_attempt(env: &Env, id: &str, n: i64) -> builds::BuildRow { panic!("build {id} never reached {n} attempts in state failed"); } -/// Poll until the build reaches one of `want` (or the test gives up). fn wait_for(env: &Env, id: &str, want: &[BuildState]) -> BuildState { for _ in 0..600 { if let Some(b) = builds::get(&env.db, id).unwrap() { diff --git a/tests/failure_modes.rs b/tests/failure_modes.rs index 74794b4..e9083a2 100644 --- a/tests/failure_modes.rs +++ b/tests/failure_modes.rs @@ -11,15 +11,9 @@ use common::*; #[derive(Clone, Copy, PartialEq, Eq)] enum Fault { - /// The sandbox vanishes while the build command is running — the shape of - /// a VM pulled out from under a worker. DieMidRun, - /// The sandbox's own TTL bites mid-build. TtlMidBuild, - /// The pool is at quota: no lease exists to hand out. NoCapacity, - /// The sandbox installs the lease but its `pacman -Q` comes back empty — - /// an incomplete closure, or a world that lied. EmptyWorld, } @@ -101,8 +95,6 @@ fn run_with_fault(env: &Env, id: &str, fault: Fault) -> pipeline::Outcome { #[test] fn a_sandbox_that_dies_mid_run_expires_its_lease_and_the_requeue_finishes_the_build() { - // I5 across the sandbox boundary: the box vanishes mid-build, the lease - // expires, and a fresh worker resumes from the checkpoints. let (env, _fx) = env_with_fixture("plain-make"); let id = approve_and_enqueue(&env, "plain-make"); @@ -114,7 +106,6 @@ fn a_sandbox_that_dies_mid_run_expires_its_lease_and_the_requeue_finishes_the_bu other => panic!("{other:?}"), } - // The crash shape the dispatcher reaper knows: leased to a worker that is gone. env.exec( "UPDATE build SET state='leased', lease_owner='dead-worker', lease_expires_at='2000-01-01T00:00:00Z' WHERE id=?1", @@ -122,7 +113,6 @@ fn a_sandbox_that_dies_mid_run_expires_its_lease_and_the_requeue_finishes_the_bu ); assert_eq!(builds::reap_expired(&env.db).unwrap(), 1); - // Requeue and resume on a healthy pool: the completed steps do not re-run. assert!(matches!( pipeline::run(&env.cfg, &env.db, &id).unwrap(), pipeline::Outcome::Succeeded { .. } @@ -142,7 +132,6 @@ fn a_ttl_that_bites_mid_build_is_a_failed_step_not_a_lost_build() { } other => panic!("{other:?}"), } - // Nothing was published, and the approval is still there to resume from. assert!(db::accepted_release(&env.db, "plain-make").unwrap().is_none()); } @@ -171,9 +160,6 @@ fn a_full_pool_blocks_the_build_instead_of_breaking_it() { #[test] fn an_incomplete_closure_fails_closed_as_a_world_mismatch() { - // dep-client's lease pins plain-make; the fake sandbox installs it but its - // `pacman -Q` comes back empty — the world lied. Provisioning must refuse with - // its own error class. let (env, _plain, _client) = env_with_two_fixtures("plain-make", "dep-client"); let id = approve_and_enqueue(&env, "plain-make"); assert!(matches!(pipeline::run(&env.cfg, &env.db, &id).unwrap(), pipeline::Outcome::Succeeded { .. })); diff --git a/tests/hash.rs b/tests/hash.rs index 46ecdb4..32995ff 100644 --- a/tests/hash.rs +++ b/tests/hash.rs @@ -3,8 +3,6 @@ use std::collections::HashMap; use aur_build::db::model::Identity; use aur_build::hash; -/// A value that refuses to be serialized — the input the old implementation -/// answered with `"{}"`, a digest every failed value shared. struct Unserializable; impl serde::Serialize for Unserializable { @@ -17,15 +15,11 @@ impl serde::Serialize for Unserializable { fn a_value_that_cannot_be_serialized_is_an_error_not_an_empty_object() { let err = hash::canonical_json(&Unserializable).unwrap_err(); assert!(err.to_string().contains("cannot be serialized"), "the failure was swallowed: {err}"); - // Two different unserializable values now fail loudly instead of hashing to - // the same digest. assert!(hash::canonical_json(&Unserializable).is_err()); } #[test] fn the_rendering_is_canonical_in_fact_not_in_name() { - // Same fields, different declaration order: routed through `Value`, both come - // out with the keys sorted. #[derive(serde::Serialize)] struct Ab { alpha: String, @@ -41,7 +35,6 @@ fn the_rendering_is_canonical_in_fact_not_in_name() { assert_eq!(ab, ba, "field declaration order leaked into the rendering: {ab} vs {ba}"); assert_eq!(ab, r#"{"alpha":"1","beta":"2"}"#, "not the compact sorted rendering"); - // Same for a map assembled in an arbitrary order. let mut one = HashMap::new(); one.insert("z", 1); one.insert("m", 2); @@ -66,7 +59,6 @@ fn the_identity_digest_is_a_function_of_the_identity_alone() { let hash_of = |i: &Identity| i.hash().unwrap(); assert!(hash_of(&base).starts_with("sha256:")); assert_eq!(hash_of(&base), hash_of(&base.clone()), "the same identity hashed twice, twice differently"); - // Every element of the tuple is part of the key (§5.1a). assert_ne!(hash_of(&base), hash_of(&Identity { pkgrel: "2".into(), ..base.clone() })); assert_ne!(hash_of(&base), hash_of(&Identity { epoch: "1".into(), ..base.clone() })); assert_ne!(hash_of(&base), hash_of(&Identity { aur_commit: "cafe124".into(), ..base.clone() })); diff --git a/tests/http.rs b/tests/http.rs index 068f999..9bb199e 100644 --- a/tests/http.rs +++ b/tests/http.rs @@ -29,7 +29,6 @@ fn every_surface_renders() { #[test] fn the_review_detail_shows_the_panels_and_the_hashes() { let web = Web::new("plain-make"); - // Publish a first version so the review has something to diff against. let first = web.open_review("plain-make"); let page = web.get(&format!("/reviews/{}", first.id)); let dd = extract(&page.body, "name=\"diff_digest\" value=\"", "\"").unwrap(); @@ -43,17 +42,14 @@ fn the_review_detail_shows_the_panels_and_the_hashes() { let c = web.open_review("plain-make"); let page = web.get(&format!("/reviews/{}", c.id)); assert_eq!(page.status, 200); - // The panel set (§6), all comparing accepted → candidate. for want in ["Recipe diff", "Version delta", "Source digest delta", "Dependency delta", "Build-env delta"] { assert!(page.body.contains(want), "missing panel {want}"); } assert!(page.body.contains("previous accepted release"), "no base shown"); - // The approve form carries both hashes (§7.1a) and works with JavaScript off. assert!(page.body.contains("name=\"identity_hash\"")); assert!(page.body.contains("name=\"diff_digest\"")); assert!(page.body.contains("

CandidateRow { aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, name).unwrap(); let c = candidates::pending_candidates(&env.db).unwrap().remove(0); @@ -35,14 +34,11 @@ fn count(env: &Env, sql: &str) -> i64 { .unwrap() } -/// **I1 — no artifact without an approval.** After a real publish, every entry -/// in the served index traces back through a release to an approval row. #[test] fn i1_every_index_entry_traces_back_to_an_approval() { let (env, _fx) = env_with_fixture("plain-make"); full_run(&env, "plain-make"); - // The §2 query, verbatim in spirit: index entry → release → approval. assert_eq!( count( &env, @@ -53,7 +49,6 @@ fn i1_every_index_entry_traces_back_to_an_approval() { 0, "I1: an index entry exists that no human approved" ); - // And the reverse direction: nothing was approved and then quietly dropped. assert_eq!( count(&env, "SELECT count(*) FROM approval WHERE decision='approved'"), 1 @@ -61,9 +56,6 @@ fn i1_every_index_entry_traces_back_to_an_approval() { assert_eq!(count(&env, "SELECT count(*) FROM release WHERE approval_id IS NULL"), 0); } -/// **I2 — the diff base is the last accepted version, never the last seen one.** -/// Many detections arrive while nobody is looking; the review still compares against -/// the accepted release. #[test] fn i2_base_is_the_last_accepted_version_after_many_detections() { let (env, fx) = env_with_fixture("plain-make"); @@ -71,7 +63,6 @@ fn i2_base_is_the_last_accepted_version_after_many_detections() { let accepted = db::accepted_release(&env.db, "plain-make").unwrap().unwrap(); assert_eq!(accepted.pkgver, "1.0"); - // Five upstream moves with nobody reviewing. for v in ["1.1", "1.2", "1.3", "1.4", "1.5"] { fx.bump(&[("pkgver", v)]); aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, "plain-make").unwrap(); @@ -85,7 +76,6 @@ fn i2_base_is_the_last_accepted_version_after_many_detections() { "I2: the diff base must be the accepted release ({}), not the last seen commit", accepted.id ); - // And the rendered diff really compares against it. let panels = diff::panels(&env.cfg, &env.db, &open[0], Some(&accepted)).unwrap(); let text = diff::render_text(&panels); assert!(text.contains("1.0"), "diff should show the accepted version: {text}"); @@ -93,8 +83,6 @@ fn i2_base_is_the_last_accepted_version_after_many_detections() { let _ = c; } -/// **I4 — publishing is atomic.** Kill the process mid-publish: the consumer- -/// visible index is either entirely the old one or entirely the new one. #[test] fn i4_kill_mid_publish_leaves_the_old_index_byte_identical() { let (mut env, fx) = env_with_fixture("plain-make"); @@ -108,7 +96,6 @@ fn i4_kill_mid_publish_leaves_the_old_index_byte_identical() { let dd = diff::render_and_store(&env.db, &env.cfg, &c).unwrap(); do_approve(&env.db, "tester", c.id, &c.identity_hash, &dd, None).unwrap(); let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap(); - // Die after the new database is rendered to .tmp but before the rename. env.set_publish_fault("before-rename"); assert!(matches!( pipeline::run(&env.cfg, &env.db, &id).unwrap(), @@ -124,13 +111,10 @@ fn i4_kill_mid_publish_leaves_the_old_index_byte_identical() { query_pairs(&env, "SELECT name, version FROM package WHERE state='in_index'"), vec![("plain-make".to_string(), "1.0-1".to_string())] ); - // Recovery re-materializes the index from the DB; it invents nothing. assert!(publish::reconcile(&env.cfg, &env.db).unwrap() >= 1); assert_eq!(std::fs::read(&db_file).unwrap(), old_bytes); } -/// **I5 — a build resumes at the next incomplete step.** A worker that dies -/// mid-pipeline does not repeat the expensive work or double-publish. #[test] fn i5_resume_after_a_crash_repeats_no_completed_step() { let (mut env, fx) = env_with_fixture("plain-make"); @@ -152,7 +136,6 @@ fn i5_resume_after_a_crash_repeats_no_completed_step() { let builds_before = aur_build::shims::called_with(&shim, "makepkg", ""); assert_eq!(builds_before, 2, "one build per attempted publish"); - // "Restart" the worker on the same build row. env.clear_publish_fault(); match pipeline::run(&env.cfg, &env.db, &id).unwrap() { pipeline::Outcome::Succeeded { release_id } => assert!(release_id > 0), @@ -163,16 +146,12 @@ fn i5_resume_after_a_crash_repeats_no_completed_step() { builds_before, "I5: resuming re-ran the build step" ); - // No duplicate side effects: one release row for the version, one artifact. assert_eq!(count(&env, "SELECT count(*) FROM release WHERE pkgver='2.0'"), 1); - // Artifacts are content-addressed; what must not happen is the same bytes - // recorded twice. assert_eq!( count(&env, "SELECT count(*) FROM artifact"), count(&env, "SELECT count(DISTINCT digest) FROM artifact"), "I5: the resume recorded a duplicate artifact" ); - // Every step is checkpointed as succeeded or explicitly skipped. let bad = env .db .read(|c| { @@ -186,8 +165,6 @@ fn i5_resume_after_a_crash_repeats_no_completed_step() { assert_eq!(bad, 0, "every step reached a terminal state"); } -/// **I7 — at most one open review per pkgbase.** Enforced by the partial unique -/// index, not by application politeness. #[test] fn i7_the_schema_refuses_a_second_open_review() { let (env, _fx) = env_with_fixture("plain-make"); @@ -213,8 +190,6 @@ fn i7_the_schema_refuses_a_second_open_review() { assert_eq!(candidates::pending_candidates(&env.db).unwrap().len(), 1); } -/// **I8 — the served index is exactly the set of accepted pointers.** Not a -/// superset and not a subset. Checked against the files on disk as well as the rows. #[test] fn i8_index_equals_the_accepted_pointers() { let (env, fx) = env_with_fixture("plain-make"); @@ -237,19 +212,15 @@ fn i8_index_equals_the_accepted_pointers() { assert!(!pointers.is_empty()); assert_eq!(index, pointers, "I8: index and accepted pointers diverge"); - // The superseded version is really gone, not merely hidden. assert_eq!( count(&env, "SELECT count(*) FROM package WHERE state='in_index' AND version='1.0-1'"), 0 ); - // And the database file on disk lists the same set. let db_file = env.cfg.repo_arch_dir().join("aur-build.db.tar.gz"); let names = index_db_names(&db_file); assert_eq!(names, vec!["plain-make".to_string()]); } -/// **I3 — the recipe is pinned to a commit.** Materializing anything other than -/// the approved tree fails closed before a build runs. #[test] fn i3_materialization_fails_closed_on_the_recipe_pin() { let (env, _fx) = env_with_fixture("plain-make"); @@ -272,7 +243,6 @@ fn i3_materialization_fails_closed_on_the_recipe_pin() { assert_eq!(count(&env, "SELECT count(*) FROM release"), 0); } -/// **I6 — a rebuild never needs a new approval.** #[test] fn i6_manual_rebuild_publishes_the_same_version_without_a_new_approval() { let (env, _fx) = env_with_fixture("plain-make"); @@ -290,10 +260,6 @@ fn i6_manual_rebuild_publishes_the_same_version_without_a_new_approval() { ); } -/// n-5: a manual rebuild's identity used to be a hand-rolled -/// `format!("{commit}|{hash}|manual}")` — a second, incompatible format for the -/// same concept, with a delimiter that can occur inside the values. It is now -/// derived through the same canonical-JSON hash as every other identity. #[test] fn a_manual_rebuild_is_deterministic_and_its_own_build() { let (env, _fx) = env_with_fixture("plain-make"); @@ -312,7 +278,6 @@ fn a_manual_rebuild_is_deterministic_and_its_own_build() { ); } -/// **I10 — the audit log is append-only**, and every consequential action is in it. #[test] fn i10_audit_is_append_only_and_records_the_decisions() { let (env, _fx) = env_with_fixture("plain-make"); @@ -348,7 +313,6 @@ fn i10_audit_is_append_only_and_records_the_decisions() { } } -/// **I12 — every build records the world it was built against.** #[test] fn i12_every_build_records_a_world_snapshot() { let (env, fx) = env_with_fixture("plain-make"); @@ -383,12 +347,6 @@ fn i12_every_build_records_a_world_snapshot() { assert!(!members.contains("glibc"), "foreign packages must be filtered out (§10.1)"); } -// I9 (build isolation) is exercised by the chroot step and the real-chroot tier; -// I11 (non-publishable change becomes a notice, never a silent drop) is covered -// by `recipe_drift_under_a_static_version_is_a_notice_not_a_candidate` in -// tests/detect.rs and gets its full treatment with P1's upstream probes. - -/// Read the package names out of a pacman-style database file (gzipped tar). fn index_db_names(path: &std::path::Path) -> Vec { let file = std::fs::File::open(path).unwrap(); let mut ar = tar::Archive::new(flate2::read::GzDecoder::new(file)); @@ -406,12 +364,6 @@ fn index_db_names(path: &std::path::Path) -> Vec { names } -/// I9: build hosts are treated as untrusted — a malicious PKGBUILD must not reach -/// the control plane's data or smuggle foreign bytes into what we publish. -/// -/// `collect` scans the srcdir for `*.pkg.tar.zst` and `ingest` copies whatever those -/// paths point at into the store, from where the bytes are served and signed. So the -/// pipeline refuses symlinks and anything outside the build's own staging directory. #[test] fn i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir() { let (mut env, _fx) = env_with_fixture("plain-make"); @@ -423,7 +375,6 @@ fn i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir() { let c = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap(); let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap(); - // 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.hooks.shim_plant_link = Some(secret.display().to_string()); @@ -440,7 +391,6 @@ fn i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir() { "the failure should say why it refused: {err}" ); - // The refused bytes never reached the store, and nothing was published. assert_eq!( dir_listing(&env.cfg.store_dir()), store_before, @@ -448,7 +398,6 @@ fn i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir() { ); assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, BuildState::Failed); assert!(db::index_version(&env.db, "plain-make").unwrap().is_none(), "nothing publishes from a failed build"); - // And the database itself is intact — the build read it, it did not become it. assert!(secret.exists()); } diff --git a/tests/kata.rs b/tests/kata.rs index 79bf9d6..f923ea2 100644 --- a/tests/kata.rs +++ b/tests/kata.rs @@ -12,8 +12,6 @@ use common::{env_with_fixture, shim_dir}; #[test] fn a_provisioned_sandbox_rendezvous_and_runs_a_command() { - // Real sandbox-agent process, real frames, real nonce-matched dial-in — - // everything about the kata lease path except the VM. let cfg = Config::default(); let prov = Arc::new(LocalAgentProvisioner::new(shim_dir().join("sandbox-agent"))); let backend = KataBackend::bind(&cfg, "127.0.0.1:0", "kata-token", prov.clone()).unwrap(); @@ -55,8 +53,6 @@ fn a_sandbox_that_never_dials_in_is_a_ttl_expiry_not_a_hang() { #[test] fn the_live_kata_tier_is_recorded_not_silently_absent() { - // The §16a convention: a tier that needs hardware or infrastructure - // announces its own skip rather than pretending to have run. if !Path::new("/dev/kvm").exists() { println!("note: no /dev/kvm on this host; the live kata tier is skipped, not passed"); return; @@ -65,8 +61,6 @@ fn the_live_kata_tier_is_recorded_not_silently_absent() { println!("note: /dev/kvm present but AUR_KATA_API unset; live kata tier still skipped"); return; }; - // Recorded as reached: a real cluster lease. Kept minimal on purpose — - // acquire, one command, reclaim. let cfg = Config::default(); let prov = Arc::new(aur_build::sandbox::kata::K8sSandboxProvisioner { api, @@ -82,10 +76,6 @@ fn the_live_kata_tier_is_recorded_not_silently_absent() { sbx.destroy().unwrap(); } -// agent-sandbox as a configuration, not a wish: the path from a config file to -// the CR that would boot a VM, asserted end to end from parsed JSON. - -/// A config file as an operator would write it, parsed by the real loader. fn agent_sandbox_config() -> Config { let tmp = tempfile::tempdir().unwrap(); std::fs::write( @@ -135,7 +125,6 @@ fn an_agent_sandbox_config_provisions_a_kata_vm_per_lease() { assert!(args.windows(2).any(|w| w[0] == "--agent-id" && w[1] == "sbx-nonce-9")); assert!(args.windows(2).any(|w| w[0] == "--ttl" && w[1] == "77")); - // The cluster coordinates come from the same config, not from a default. let prov = aur_build::sandbox::kata::K8sSandboxProvisioner::for_config(&cfg).unwrap(); assert_eq!(prov.api, "https://k8s.test:6443"); assert_eq!(prov.namespace, "builds"); @@ -149,24 +138,18 @@ fn agent_sandbox_is_a_backend_not_a_fallthrough_to_loopback() { let id = backend.status().unwrap()[0].id.clone(); assert!(id.contains("kata@"), "expected a kata backend, got {id}"); - // One backend per process, for the same reason the listener is: a second - // concurrent build must not race the first for the dial-ins it routes. let again = aur_build::sandbox::backend_for(&cfg).unwrap(); assert_eq!(again.status().unwrap()[0].id, id, "two builds must share one kata backend"); } #[test] fn a_loopback_config_never_becomes_agent_sandbox_or_vice_versa() { - // The fallthrough in both directions, closed. let local = Config::default(); let id = aur_build::sandbox::backend_for(&local).unwrap().status().unwrap()[0].id.clone(); assert!(!id.contains("kata@"), "loopback must not report kata: {id}"); assert!(!id.contains("remote@"), "loopback must not report remote: {id}"); } -/// The seam's whole claim, tested as one thing: a real package built and published -/// through the kata lease path, with a VM being the only thing this host cannot -/// provide. #[test] fn a_fixture_builds_and_publishes_through_the_kata_lease_path() { let (env, _fx) = env_with_fixture("plain-make"); @@ -189,22 +172,15 @@ fn a_fixture_builds_and_publishes_through_the_kata_lease_path() { }; assert!(release > 0); - // Published, not merely built: the served index now names the package. let world = aur_build::pipeline::publish::index_world(&env.db).unwrap(); assert!( world.iter().any(|w| w.pkgbase == "plain-make" && w.version == "1.0-1"), "the index must serve what the kata build produced: {world:?}" ); - // And it ran inside the leased sandbox: the agent streamed the build output over - // the wire into the same log file the SSE tail reads. let log = std::fs::read_to_string(env.cfg.build_log_path(&id)).unwrap(); assert!(log.contains("Making package"), "agent output must reach the log:\n{log}"); let shimlog = env.cfg.hooks.shim_dir.clone().unwrap(); assert_eq!(aur_build::shims::called_with(&shimlog, "makepkg", ""), 1); - - // Deliberately no assertion that the sandbox is gone: the design says the TTL is - // the guarantee and destroy is courtesy (wire.rs). A busy hub holds up to - // `steps x builds` sandboxes until their TTL bites. } diff --git a/tests/layers.rs b/tests/layers.rs index 8566584..1856462 100644 --- a/tests/layers.rs +++ b/tests/layers.rs @@ -21,8 +21,6 @@ fn rust_files(dir: &Path) -> Vec { out } -/// Every `crate::X` reference from `dir` into any of `forbidden`, as -/// "file:line: text" so a failure names the exact edge. fn edges(dir: &str, forbidden: &[&str]) -> Vec { let mut hits = Vec::new(); for file in rust_files(&src_root().join(dir)) { @@ -48,17 +46,12 @@ fn edges(dir: &str, forbidden: &[&str]) -> Vec { #[test] fn persistence_names_nothing_above_itself() { - // M-6: `db::stage_b_cache_get` used to return `watch::upstream::StageB`, so the - // storage layer could not be understood without the watcher. let hits = edges("db", &["watch", "review", "pipeline", "http", "ops", "shims"]); assert!(hits.is_empty(), "src/db depends upward on the modules above it:\n{hits:#?}"); } #[test] fn review_does_not_call_back_into_the_watcher() { - // M-7: `review::risk` called `watch::digests::skip_on_non_vcs` while - // `watch::detect` called `review::candidates` — a cycle. It now lives in - // `recipe`, and both sides look down, not sideways. let hits = edges("review", &["watch", "pipeline", "http"]); assert!(hits.is_empty(), "src/review depends on modules beside or above it:\n{hits:#?}"); } @@ -71,7 +64,6 @@ fn the_watcher_does_not_reach_into_the_pipeline_or_the_ui() { #[test] fn the_recipe_leaf_depends_on_nothing_above_it() { - // `recipe` is a leaf: everything else may ask it; it may ask nothing. let text = std::fs::read_to_string(src_root().join("recipe.rs")).expect("read recipe.rs"); for m in ["watch", "review", "pipeline", "http", "ops", "shims"] { assert!( diff --git a/tests/live.rs b/tests/live.rs index da0f7ec..e572638 100644 --- a/tests/live.rs +++ b/tests/live.rs @@ -9,7 +9,6 @@ use aur_build::pipeline; use aur_build::review::{candidates, diff}; use common::*; -/// Approve a fixture's candidate and enqueue its build without running it. fn queued(env: &Env, name: &str) -> String { aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, name).unwrap(); let c = candidates::pending_candidates(&env.db).unwrap().remove(0); @@ -20,7 +19,6 @@ fn queued(env: &Env, name: &str) -> String { pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap() } -/// Read a streaming response until EOF or the deadline, whichever comes first. fn drain(mut r: impl Read, deadline: Duration) -> String { let mut buf = [0u8; 4096]; let mut out = Vec::new(); @@ -47,8 +45,6 @@ fn the_log_stream_delivers_bytes_as_they_are_appended_and_then_ends() { std::fs::create_dir_all(log.parent().unwrap()).unwrap(); std::fs::write(&log, "==> step materialize\n").unwrap(); - // A producer appends while the stream is open, then finishes the build. If the - // endpoint buffered its response the "live" claim would be false. let db = web.env.db.clone(); let id2 = id.clone(); let log2 = log.clone(); @@ -58,8 +54,6 @@ fn the_log_stream_delivers_bytes_as_they_are_appended_and_then_ends() { std::thread::sleep(Duration::from_millis(400)); append(&log2, "==> step publish\n"); std::thread::sleep(Duration::from_millis(200)); - // Walk the machine the way a real build does: a queued build runs - // before it succeeds. builds::set_state(&db, &id2, BuildState::Running, None).unwrap(); builds::set_state(&db, &id2, BuildState::Succeeded, None).unwrap(); }); @@ -73,9 +67,7 @@ fn the_log_stream_delivers_bytes_as_they_are_appended_and_then_ends() { assert!(body.contains("data: ==> step materialize"), "the first line is missing: {body}"); assert!(body.contains("data: ==> step build"), "appended bytes never arrived: {body}"); assert!(body.contains("data: ==> step publish"), "the tail stopped early: {body}"); - // It ends when the build does, rather than holding the connection forever. assert!(body.contains("event: end"), "the stream never ended: {body}"); - // SSE framing: each log line is its own event, so a client can append. assert!(body.contains("\n\n"), "not event-framed: {body}"); } @@ -96,17 +88,13 @@ fn the_builds_table_refreshes_via_htmx_and_still_works_without_js() { let web = Web::attach(env, fx); let base = web.url("/builds"); - // One queued build so the table has a row. queued(&web.env, "plain-make"); let page = ureq::get(&base).call().unwrap().into_string().unwrap(); - // The refresh is an attribute on the table, not a script we wrote. assert!(page.contains("hx-trigger=\"every 3s\""), "no htmx refresh: {}", &page[..400.min(page.len())]); assert!(page.contains("hx-get=\"/builds?fragment=1\""), "the refresh has no target"); assert!(page.contains("