summaryrefslogtreecommitdiffstats
path: root/tests/common
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-19 17:33:17 +0000
committeraur-build <aur-build@localhost>2026-11-19 17:33:17 +0000
commit4304b0f336ddba7b4ec6780795059ff2066d105b (patch)
tree10edea744a1c2bf3fc363b4dc7f64abac8b1a0d3 /tests/common
parente757979f1a2afdbe7146066345bb9acd19d3b151 (diff)
downloadaur-build-4304b0f336ddba7b4ec6780795059ff2066d105b.tar.gz
aur-build-4304b0f336ddba7b4ec6780795059ff2066d105b.zip
comments: keep only what the code cannot show
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.
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/mod.rs54
1 files changed, 0 insertions, 54 deletions
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<P> = 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<String> {
let sql = sql.to_string();
let params: Vec<P> = 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<String> for P {
}
}
-/// Shorthand for building a parameter slice.
pub fn params(v: Vec<impl Into<P>>) -> Vec<P> {
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<PathBuf>,
- /// A second upstream repo, for pkgbases that build from two of them.
pub upstream2: Option<PathBuf>,
}
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<String> {
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<String> {
let i = hay.find(open)? + open.len();
let rest = &hay[i..];