diff options
| author | aur-build <aur-build@localhost> | 2026-11-19 17:33:17 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-19 17:33:17 +0000 |
| commit | 4304b0f336ddba7b4ec6780795059ff2066d105b (patch) | |
| tree | 10edea744a1c2bf3fc363b4dc7f64abac8b1a0d3 /src/shims | |
| parent | e757979f1a2afdbe7146066345bb9acd19d3b151 (diff) | |
| download | aur-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 'src/shims')
| -rw-r--r-- | src/shims/mod.rs | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/src/shims/mod.rs b/src/shims/mod.rs index 818d28d..debcd19 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -4,7 +4,6 @@ use serde::{Deserialize, Serialize}; use crate::hash; -/// One package the fake toolchain emits. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(default)] pub struct FakePackage { @@ -42,7 +41,6 @@ impl Default for FakePackage { } impl FakePackage { - /// `1.0-1` split into the `(pkgver, pkgrel)` pacman expects in `.PKGINFO`. pub fn split_version(&self) -> (String, String) { match self.version.rsplit_once('-') { Some((v, r)) => (v.to_string(), r.to_string()), @@ -51,7 +49,6 @@ impl FakePackage { } } -/// A member of the fake chroot world, for `.BUILDINFO` (§10.1). #[derive(Debug, Clone, Default, Serialize, Deserialize)] #[serde(default)] pub struct FakeInstalled { @@ -60,22 +57,16 @@ pub struct FakeInstalled { pub arch: String, } -/// The scripted outcome of a fixture. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(default)] pub struct Manifest { pub name: String, - /// `succeed` | `fail` | `check-fail` | `no-pkgver` pub build: String, - /// Text the fake build writes to its log, for log-tail tests. pub log_lines: Vec<String>, pub packages: Vec<FakePackage>, pub installed: Vec<FakeInstalled>, - /// Emit `.sig` files (default true). pub sig: bool, - /// `pkgver` the fake `makepkg --vercheck` computes (VCS fixtures, §5.2). pub vercheck: Option<String>, - /// Extra files to drop into the package tarball. pub files: Vec<String>, } @@ -104,8 +95,6 @@ pub fn manifest() -> Manifest { } } -/// Record that a shim ran, so tests can assert on what the pipeline actually -/// invoked rather than what it intended to invoke. pub fn record(tool: &str, args: &[String]) { let dir = match std::env::var("AUR_SHIM_DIR") { Ok(d) => d, @@ -127,26 +116,20 @@ pub fn record(tool: &str, args: &[String]) { } } -/// Test hook: kill the process that invoked us, mid-step, with a signal it cannot -/// catch. This is how the crash-resume invariant (I5) is tested for real. fn kill_parent_if_asked(tool: &str) { let want = std::env::var("AUR_SHIM_KILL_PARENT").unwrap_or_default(); if want == tool { unsafe { libc::kill(libc::getppid(), libc::SIGKILL); } - // If the kill somehow did not land, do not let the step complete — that - // would make the test silently test nothing. std::process::exit(137); } } -/// True when the harness asked this tool to fail. fn forced_fail(tool: &str) -> bool { std::env::var("AUR_SHIM_FAIL").map(|v| v == tool).unwrap_or(false) } -/// Read the invocation log back (test side). pub fn invocations(dir: &Path) -> Vec<serde_json::Value> { let path = dir.join("invocations.jsonl"); match std::fs::read_to_string(path) { @@ -158,7 +141,6 @@ pub fn invocations(dir: &Path) -> Vec<serde_json::Value> { } } -/// Entries whose `args` mention `needle`. pub fn called_with(dir: &Path, tool: &str, needle: &str) -> usize { invocations(dir) .iter() @@ -172,7 +154,6 @@ pub fn called_with(dir: &Path, tool: &str, needle: &str) -> usize { .count() } -/// Dispatch table used by every `src/bin/*.rs`. pub fn run(tool: &str) -> i32 { let args: Vec<String> = std::env::args().skip(1).collect(); record(tool, &args); @@ -196,10 +177,7 @@ pub fn run(tool: &str) -> i32 { } } -/// `mkarchroot <path>`: create a directory that stands in for a warm root. pub fn mkarchroot(args: &[String]) -> Result<i32, String> { - // `mkarchroot [-C pacman.conf] [-M makepkg.conf] <root>`: the config options - // take a value, so they cannot be skipped blindly. let mut target = None; let mut skip = false; for a in args { @@ -218,28 +196,18 @@ pub fn mkarchroot(args: &[String]) -> Result<i32, String> { } let target = target.ok_or("mkarchroot: no target")?; std::fs::create_dir_all(&target).map_err(|e| e.to_string())?; - // A marker so the pipeline can tell a real root from a fake one. let _ = std::fs::write(Path::new(&target).join("SHIM-ROOT"), "fake chroot\n"); Ok(0) } -/// `makechrootpkg -c -r <chroot> -- ...`: kept as a stand-in for direct shim -/// tests. The pipeline no longer calls it; the package-emitting logic lives in -/// [`emit_packages`], shared with the `makepkg` shim. pub fn makechrootpkg(args: &[String], m: &Manifest) -> Result<i32, String> { - // The real tool reads a chroot root; asserting it keeps the fake honest - // about the real tool's contract. if !args.iter().any(|a| a == "-r") { return Err("makechrootpkg: expected -r <chroot>".into()); } - // Sign only when the caller asked, like the real tool. A shim that signed - // anyway would hide the move of signing hub-side from every test. let wants_sig = args.iter().any(|a| a.starts_with("-si") || a == "-i" || a == "--sign"); emit_packages(m, "makechrootpkg", wants_sig) } -/// The shared build emulation: emit one `.pkg.tar.zst` per manifest package -/// into the current directory, exactly where the real tools leave them. pub fn emit_packages(m: &Manifest, tool: &str, wants_sig: bool) -> Result<i32, String> { for l in &m.log_lines { println!("{l}"); @@ -253,8 +221,6 @@ pub fn emit_packages(m: &Manifest, tool: &str, wants_sig: bool) -> Result<i32, S return Ok(1); } let startdir = std::env::current_dir().map_err(|e| e.to_string())?; - // Assert the PKGBUILD is there so a broken materialize step cannot pass - // silently. if !startdir.join("PKGBUILD").exists() { let found = std::fs::read_dir(&startdir) .map(|rd| rd.filter_map(|e| e.ok()).map(|e| e.file_name().to_string_lossy().into_owned()).collect::<Vec<_>>()) @@ -279,9 +245,6 @@ pub fn emit_packages(m: &Manifest, tool: &str, wants_sig: bool) -> Result<i32, S Ok(0) } -/// I9 test hook: drop a symlink into the srcdir standing in for a PKGBUILD that -/// tries to smuggle outside bytes into the artifact store. The pipeline must -/// refuse it; see `collect` in steps.rs. fn plant_link_if_asked(startdir: &Path) { let target = match std::env::var("AUR_SHIM_PLANT_LINK") { Ok(t) if !t.is_empty() => t, @@ -301,7 +264,6 @@ fn packages_to_emit(m: &Manifest, startdir: &Path) -> Vec<FakePackage> { if !m.packages.is_empty() { return m.packages.clone(); } - // No explicit manifest: derive one package from the PKGBUILD we were given. let text = std::fs::read_to_string(startdir.join("PKGBUILD")).unwrap_or_default(); let recipe = crate::recipe::parse_pkgbuild(&text).ok(); match recipe { @@ -326,8 +288,6 @@ fn packages_to_emit(m: &Manifest, startdir: &Path) -> Vec<FakePackage> { } } -/// Write a `.pkg.tar.zst` containing `.PKGINFO`, `.BUILDINFO` and any scripted -/// payload files. pub fn write_package(dir: &Path, p: &FakePackage, m: &Manifest) -> Result<PathBuf, String> { let (pkgver, pkgrel) = p.split_version(); let filename = format!("{}-{}-{}.pkg.tar.zst", p.name, p.version, p.arch); @@ -347,7 +307,6 @@ pub fn write_package(dir: &Path, p: &FakePackage, m: &Manifest) -> Result<PathBu for f in &m.files { write_entry(&mut ar, &format!("usr/share/{}/{f}", p.name), f.as_bytes())?; } - // A payload file so the artifact has non-metadata bytes and a real size. write_entry(&mut ar, &format!("usr/bin/{}", p.name), b"#!/bin/sh\necho hi\n")?; let enc = ar.into_inner().map_err(|e| e.to_string())?; enc.finish().map_err(|e| e.to_string())?; @@ -398,9 +357,6 @@ fn pkginfo(p: &FakePackage, pkgver: &str, pkgrel: &str) -> String { s } -/// `.BUILDINFO`: the full installed set at build time. Left unfiltered this is -/// the whole chroot, which is exactly why §10.1 intersects it with our own -/// packages before storing a world snapshot. fn buildinfo(p: &FakePackage, pkgver: &str, pkgrel: &str, m: &Manifest) -> String { let mut s = String::new(); s.push_str("format = 2\n"); @@ -422,7 +378,6 @@ fn fake_sig(bytes: &[u8]) -> Vec<u8> { format!("-----BEGIN FAKE PGP SIGNATURE-----\n{}\n-----END FAKE PGP SIGNATURE-----\n", hash::hex(bytes)).into_bytes() } -/// `makepkg --printsrcinfo` / `--vercheck` (§5.2 Stage B). pub fn makepkg(args: &[String], m: &Manifest) -> Result<i32, String> { if args.iter().any(|a| a == "--vercheck" || a == "-V-check") { let v = m.vercheck.clone().unwrap_or_else(|| "1.0-1".into()); @@ -468,19 +423,10 @@ pub fn makepkg(args: &[String], m: &Manifest) -> Result<i32, String> { } } } else { - // `makepkg -c -f`: the pipeline's build step in the provisioned sandbox. - // No `-s` and no `-si` reach this shim. emit_packages(m, "makepkg", false) } } -/// `pacman -U <blobs...>` / `pacman -Q`: a fake installed database living in the -/// shim dir, so the provisioning step's world check runs against something that -/// behaves. -/// -/// `-U` refuses any file that does not hash to the digest its filename claims and -/// records each package from its `.PKGINFO`; `-Q` reports exactly what was -/// installed, which makes the pipeline's fail-closed world assertion a real test. pub fn pacman(args: &[String]) -> Result<i32, String> { if args.iter().any(|a| a == "-U") { for path in args.iter().filter(|a| !a.starts_with('-')) { @@ -522,18 +468,6 @@ fn installed_db() -> Option<std::path::PathBuf> { std::env::var("AUR_SHIM_DIR").ok().map(|d| std::path::Path::new(&d).join("installed.txt")) } -// `repo-add [-s -p key -R] <db.tar.{gz,zst}> <pkg...>`: rebuild the database -// from the packages handed to it. The real tool appends and `-R` replaces an -// existing entry; we rebuild the whole db, which is what our publish step does -// anyway. - -/// The database filenames pacman's repo-add accepts — and therefore the ones this -/// shim must accept, and no others. A shim more permissive than the tool it -/// stands in for is worse than no shim: the pipeline used to render its database -/// to `<db>.tar.gz.tmp`, real repo-add rejects that as a usage error, and every -/// publish test passed because the shim would write anywhere. Measured against -/// `repo-add (pacman) 7.1.0`: the `.db.tar` forms with or without a compression -/// suffix, and nothing else. pub const DB_SUFFIXES: [&str; 5] = [ ".db.tar", ".db.tar.gz", @@ -542,7 +476,6 @@ pub const DB_SUFFIXES: [&str; 5] = [ ".db.tar.xz", ]; -/// Whether repo-add would accept this path as its database argument. pub fn valid_db_arg(p: &Path) -> bool { let name = p .file_name() @@ -555,8 +488,6 @@ pub fn valid_db_arg(p: &Path) -> bool { } pub fn repo_add(args: &[String], _m: &Manifest) -> Result<i32, String> { - // `-p <key>` and friends take a value; a naive filter would treat the key id - // as a package path. let mut positional: Vec<&String> = Vec::new(); let mut skip = false; for a in args { @@ -577,8 +508,6 @@ pub fn repo_add(args: &[String], _m: &Manifest) -> Result<i32, String> { None => return Err("repo-add: no database given".into()), }; if !valid_db_arg(&db_path) { - // Same wording and same exit status as the real tool, so a caller that - // learns to branch on one learns to branch on the other. eprintln!( "==> ERROR: '{}' does not have a valid database archive extension.", db_path.display() @@ -617,7 +546,6 @@ pub fn repo_add(args: &[String], _m: &Manifest) -> Result<i32, String> { .map_err(|e| e.to_string())?; } let tar = ar.into_inner().map_err(|e| e.to_string())?; - // pacman databases are gzip'd tarballs. let mut enc = flate2::write::GzEncoder::new( std::fs::File::create(&db_path).map_err(|e| e.to_string())?, flate2::Compression::default(), @@ -629,11 +557,6 @@ pub fn repo_add(args: &[String], _m: &Manifest) -> Result<i32, String> { Ok(0) } -/// Pull `.PKGINFO` out of a `.pkg.tar.zst` and render the `DESC` fields a pacman -/// database carries beyond the fixed ones. Both halves come from -/// `crate::pkginfo`, the parser the production pipeline uses — two parsers that -/// can drift is a supply-chain-shaped foot-gun in a system whose whole job is -/// provenance (§6 M-4). fn pkginfo_fields(pkg_bytes: &[u8]) -> Result<(String, String, String, String), String> { let text = crate::pkginfo::pkginfo_text(pkg_bytes)?; let info = crate::pkginfo::parse_pkginfo(&text); @@ -658,8 +581,6 @@ fn pkginfo_fields(pkg_bytes: &[u8]) -> Result<(String, String, String, String), Ok((info.name, info.version, info.arch, extra)) } -/// `gpg --detach-sign --output <sig> <file>`: write a deterministic stand-in -/// signature so the signing path is exercised end to end. pub fn gpg(args: &[String]) -> Result<i32, String> { let out = args .iter() |
