summaryrefslogtreecommitdiffstats
path: root/tests/shims.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/shims.rs')
-rw-r--r--tests/shims.rs118
1 files changed, 117 insertions, 1 deletions
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 `<db>.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::<Vec<_>>();
+ 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<String> = 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()
+ );
+}