From 153e72cc797c1e45a60f4896d00163fb4bdf3056 Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 14:15:16 +0000 Subject: publish: repo-add decides the database filename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Publishing renders the index before the DB commits and renames it into place after, so a crash between the two leaves the old index serving (I4). The way that was written did it at `.tar.gz.tmp` beside the live file — a filename real repo-add refuses, because its database argument has to be a name pacman would accept. Every publish test passed; the first real package anyone tried to publish died at the last step with the release already committed. `render_db` now renders into a scratch directory under the served directory, under the name a consumer will download. Same filesystem, so the rename is still the atomic swap, and the live database is never the file repo-add is writing into. `publish`, `reconcile` and `withdraw_package` all had the bug and all share the helper now; `reconcile` sweeps scratch directories a crash left behind. `run_repo_add` drops `-s` too: repo-add would sign into scratch space that is about to be deleted, and `publish::sign` already signs the renamed file. The reason 238 tests missed this is that the shim would write the database anywhere it was told. It now enforces the accepted set — measured against `repo-add (pacman) 7.1.0`, not read out of its docs — with the real tool's wording and exit status, and a gated test re-derives the set against the installed tool, in the shape of the vercmp oracle. A shim that is more permissive than its tool is not a test of the tool. --- tests/shims.rs | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/shims.rs b/tests/shims.rs index b21efab..d512bd7 100644 --- a/tests/shims.rs +++ b/tests/shims.rs @@ -7,7 +7,7 @@ mod common; use std::path::{Path, PathBuf}; use std::process::Command; -use common::{corpus_root, env_with_fixture, shim_dir, Env}; +use common::{corpus_root, env_with_fixture, shim_dir, Env, Web}; use aur_build::shims; @@ -358,3 +358,119 @@ fn shim_environment_reaches_child_processes_through_the_config() { assert!(s.contains("makechrootpkg"), "{s}"); assert!(s.contains("manifest.json"), "{s}"); } + +// --------------------------------------------------------------------------- +// repo-add's database filename. +// +// The shim used to write the database wherever it was told to, and the pipeline +// took that literally: it rendered the index to `.tar.gz.tmp` and renamed it +// into place. Real repo-add rejects that filename as a usage error, so every +// publish test in this suite passed while the first real package anyone tried to +// publish died at the last step. A shim must be as strict as the tool it stands +// in for, or it is not a test of the tool. +// --------------------------------------------------------------------------- + +/// Names pacman's repo-add accepts as its database argument, measured against +/// `repo-add (pacman) 7.1.0` rather than guessed from its docs. +const REAL_ACCEPTED: [&str; 5] = [ + "aur.db.tar", + "aur.db.tar.gz", + "aur.db.tar.zst", + "aur.db.tar.bz2", + "aur.db.tar.xz", +]; + +/// Names it refuses — including the render target the pipeline used to use, and +/// the `.files.*` forms, which are `repo-files`' business and not repo-add's. +const REAL_REJECTED: [&str; 5] = + ["aur.db", "aur.db.gz", "aur.db.tar.gz.tmp", "aur.files.tar.gz", "aur"]; + +#[test] +fn repo_add_shim_refuses_a_database_name_repo_add_refuses() { + let tmp = tempfile::tempdir().unwrap(); + for name in REAL_REJECTED { + let bad = tmp.path().join(name); + let (code, _, err) = shim("repo-add", tmp.path(), &[], &["-R", &bad.display().to_string()]); + assert_eq!(code, 1, "repo-add must fail on {name}, like the real tool"); + assert!( + err.contains("does not have a valid database archive extension"), + "{name}: {err}" + ); + assert!(!bad.exists(), "{name}: nothing may be written for a rejected name"); + } + for name in REAL_ACCEPTED { + let good = tmp.path().join(name); + let (code, _, err) = shim("repo-add", tmp.path(), &[], &["-R", &good.display().to_string()]); + assert_eq!(code, 0, "{name}: {err}"); + assert!(good.exists(), "{name}: a valid database name must be written"); + } +} + +/// The oracle, when the host has one: the shim's verdict must be the real tool's +/// verdict, name for name. Gated and noted rather than skipped silently, in the +/// shape of `versions::vercmp_matches_the_system_oracle`. +#[test] +fn repo_add_db_names_match_the_real_repo_add() { + if Command::new("repo-add").arg("--version").output().is_err() { + eprintln!("note: no real repo-add on PATH; the differential check is not running"); + return; + } + let tmp = tempfile::tempdir().unwrap(); + for name in REAL_ACCEPTED.into_iter().chain(REAL_REJECTED) { + let p = tmp.path().join(name); + let real = Command::new("repo-add") + .args(["-R", &p.display().to_string()]) + .output() + .unwrap(); + assert_eq!( + shims::valid_db_arg(&p), + real.status.success(), + "the shim and the real repo-add disagree about {name}" + ); + } +} + +/// The regression itself, asserted on the pipeline rather than on the shim: what +/// filename does publish actually hand repo-add, and does it clean up after +/// itself while doing it? +#[test] +fn publish_hands_repo_add_a_database_name_the_real_tool_accepts() { + let web = Web::new("plain-make"); + web.publish("plain-make"); + + let shim = web.env.cfg.hooks.shim_dir.clone().unwrap(); + let args = shims::invocations(&shim) + .into_iter() + .find(|e| e["tool"] == "repo-add") + .expect("publish must invoke repo-add") + .get("args") + .and_then(|a| a.as_array().cloned()) + .expect("the invocation log records args") + .iter() + .filter_map(|v| v.as_str().map(|s| s.to_string())) + .collect::>(); + let db = args + .iter() + .find(|a| !a.starts_with('-')) + .expect("repo-add's first positional is the database"); + assert!( + shims::valid_db_arg(Path::new(db)), + "publish passed {db}, which repo-add would refuse" + ); + + // The render happens in a scratch directory beside the live database, under + // the name a consumer will download, and is gone once the rename lands. A + // leftover would mean a publish that died on a path that never cleaned up. + let arch = web.env.cfg.repo_arch_dir(); + let leftovers: Vec = std::fs::read_dir(&arch) + .unwrap() + .flatten() + .map(|e| e.file_name().to_string_lossy().into_owned()) + .filter(|n| n.starts_with(".render-")) + .collect(); + assert!( + leftovers.is_empty(), + "scratch directories left behind in {}: {leftovers:?}", + arch.display() + ); +} -- cgit v1.2.3