diff options
Diffstat (limited to 'src/shims/mod.rs')
| -rw-r--r-- | src/shims/mod.rs | 117 |
1 files changed, 37 insertions, 80 deletions
diff --git a/src/shims/mod.rs b/src/shims/mod.rs index 7118283..818d28d 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -1,26 +1,3 @@ -//! Toolchain shims (§16a). -//! -//! The pipeline shells out to `makepkg`, `pacman`, `repo-add` and `gpg` inside -//! a sandbox, and `git` outside it. In test mode the harness prepends a -//! directory of fakes to `PATH`; each fake records its invocation, obeys a -//! scripted outcome from the fixture manifest, and emits plausible -//! `.PKGINFO`/`.BUILDINFO`/`.sig` output. The `mkarchroot` and `makechrootpkg` -//! fakes remain as stand-ins for the real devtools — the pipeline stopped -//! calling them when builds moved to the provisioning model — so the shim -//! protocol itself stays exercised end to end. -//! -//! That is what makes the full step machine, checkpointing, lease/reaper -//! recovery, publishing and index regeneration runnable in milliseconds on any -//! machine — no Arch host, no root, no network. -//! -//! Protocol, all via environment so the pipeline needs no test-only code paths: -//! -//! | var | meaning | -//! |---|---| -//! | `AUR_SHIM_DIR` | where invocations are recorded (`invocations.jsonl`) | -//! | `AUR_SHIM_MANIFEST` | fixture manifest describing the scripted outcome | -//! | `AUR_SHIM_FAIL` | optional step name that must fail, e.g. `build` | - use std::path::{Path, PathBuf}; use serde::{Deserialize, Serialize}; @@ -150,15 +127,11 @@ 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: -/// the pipeline process dies while a step is running, with no chance to clean -/// up, and the next process must pick up from the checkpoints. +/// 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 { - // Flush the invocation log first (record() already closed the file), - // then murder the parent. No cleanup, no unwinding, no atexit. unsafe { libc::kill(libc::getppid(), libc::SIGKILL); } @@ -250,20 +223,17 @@ pub fn mkarchroot(args: &[String]) -> Result<i32, String> { Ok(0) } -/// `makechrootpkg -c -r <chroot> -- ...`: the real tool's contract, kept as a -/// stand-in for direct shim tests. The pipeline no longer calls it — the build -/// step runs `makepkg` in the provisioned sandbox — so the package-emitting -/// logic lives in [`emit_packages`], shared with the `makepkg` shim. +/// `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 for it, like the real tool: signing is - // `-si<key>`/`-i`, and the pipeline stopped passing it when signing moved - // hub-side to ingest. A shim that signed anyway would hide that move from - // every test in the suite. + // 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) } @@ -283,8 +253,8 @@ 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())?; - // The real tool reads the PKGBUILD it was handed; we assert it is there so - // a broken materialize step cannot pass silently. + // 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<_>>()) @@ -309,9 +279,9 @@ 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 pointing wherever the test names, -/// 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. +/// 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, @@ -498,23 +468,19 @@ pub fn makepkg(args: &[String], m: &Manifest) -> Result<i32, String> { } } } else { - // `makepkg -c -f` style: the pipeline's build step, running in the - // provisioned sandbox. No `-s` and no `-si` reach this shim, and the - // emulation does not care: dependencies and signatures are the hub's - // business now. + // `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. +/// `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 -/// — the same trust posture as the real signature check — and records each -/// package from its `.PKGINFO`. `-Q` then reports exactly what was installed, -/// which is what makes the pipeline's fail-closed world assertion a real test -/// rather than a no-op. +/// `-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('-')) { @@ -556,24 +522,18 @@ 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; `-R` replaces an existing entry. We rebuild the whole -/// db from the packages given, which is what our publish step does anyway (it -/// passes exactly the packages that belong in the index). -/// The database filenames pacman's repo-add accepts — and therefore the ones -/// this shim must accept, and no others. -/// -/// A shim that is 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` and rename -/// it into place, real repo-add rejects that filename as a usage error, and every -/// publish test in the suite passed because the shim would write anywhere. That -/// is how the first real package anyone tried to publish died at the last step. -/// This list is the accepted set as measured against `repo-add (pacman) 7.1.0`: -/// the `.db.tar` forms with or without a compression suffix, and nothing else — -/// not `aur.db`, not `aur.db.gz`, and not the `.files.*` forms, which belong to -/// `repo-files`. +// `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", @@ -669,14 +629,11 @@ 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 (§6 M-4). The shim used to carry its own copy of the field parser, and -/// two parsers that can drift is a supply-chain-shaped foot-gun in a system -/// whose whole job is provenance: a test that passed because the shim read a -/// package one way would not have meant the pipeline read it that way. +/// 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); |
