From e757979f1a2afdbe7146066345bb9acd19d3b151 Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 17:09:59 +0000 Subject: comments: say why, not what MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every module-level `//!` header is gone, and the comments that remained either re-explained the line below them or had grown into paragraphs. Density went from one comment line per 6.7 lines of code to one per 10. 827 insertions against 2194 deletions across 86 files. What survived: the invariants (I1-I12), the design cross-references into DESIGN.md, and the notes recording a bug that was found and fixed — those are the comments that carry weight, because they answer a question the code cannot answer about itself. What did not: restating a function signature in prose, and narration of the statement underneath. --- src/shims/mod.rs | 117 ++++++++++++++++++------------------------------------- 1 file changed, 37 insertions(+), 80 deletions(-) (limited to 'src/shims/mod.rs') 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 { Ok(0) } -/// `makechrootpkg -c -r -- ...`: 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 -- ...`: 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 { // 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 ".into()); } - // Sign only when the caller asked for it, like the real tool: signing is - // `-si`/`-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>()) @@ -309,9 +279,9 @@ pub fn emit_packages(m: &Manifest, tool: &str, wants_sig: bool) -> Result t, @@ -498,23 +468,19 @@ pub fn makepkg(args: &[String], m: &Manifest) -> Result { } } } 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 ` / `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 ` / `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 { 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::env::var("AUR_SHIM_DIR").ok().map(|d| std::path::Path::new(&d).join("installed.txt")) } -/// `repo-add [-s -p key -R] `: 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 `.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] `: 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 `.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 { 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); -- cgit v1.2.3