diff options
| author | aur-build <aur-build@localhost> | 2026-11-18 15:33:32 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-18 15:33:32 +0000 |
| commit | 753e05a4f588d3e8a3ea0b88b2e03d74f9f00be8 (patch) | |
| tree | 9a9d73297e81716a398adcb6dd069735dcf91827 /tests | |
| parent | 933c637de34095f1ea1ab88b02626bbf22eec7f4 (diff) | |
| download | aur-build-753e05a4f588d3e8a3ea0b88b2e03d74f9f00be8.tar.gz aur-build-753e05a4f588d3e8a3ea0b88b2e03d74f9f00be8.zip | |
pipeline: the name we publish comes from the real .PKGINFO parser, and the shims are test-only
`publish.rs::package_name` — the function that decides which package a built
artifact is, and therefore what the index says — called into the test harness
(`shims::read_pkginfo`) to read it. Worse, the shim module carried its own
`.PKGINFO` field parser alongside the real one in `pkginfo.rs`. Two parsers
that can drift is a supply-chain-shaped foot-gun in a system whose whole job
is provenance: the bytes we sign and the bytes the tests believed in would be
interpreted by different code, and a green shim test would not have meant the
pipeline read the package the same way.
There is now one parser. `package_name` uses `pkginfo::pkginfo_text` and
`pkginfo::parse_pkginfo`; the shim's `repo-add` renders its `DESC` entry from
the same `PkgInfo` the production code parses, so the fake tool and the real
pipeline cannot disagree about what a package calls itself. The duplicate
parser and the two wrapper functions are deleted, and the harness test reads
its artifact with `pkginfo` too.
The module itself is now test-only in the way the review asked for. `pub(crate)`
was not available — the shim binaries are separate crates that link the
library — so the equivalent enforcement is used instead: `shims` is compiled
out unless the `test-support` feature is on, and every shim binary declares
`required-features = ["test-support"]`. A production `cargo build --release`
neither builds the fakes nor links their code; `cargo build --bin makepkg`
says so out loud. `tests/production_surface.rs` covers the half the compiler
cannot see: no module in `src/` outside the harness may name `shims::`, and the
binaries must keep declaring the feature.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/production_surface.rs | 74 | ||||
| -rw-r--r-- | tests/shims.rs | 7 |
2 files changed, 79 insertions, 2 deletions
diff --git a/tests/production_surface.rs b/tests/production_surface.rs new file mode 100644 index 0000000..1fa855f --- /dev/null +++ b/tests/production_surface.rs @@ -0,0 +1,74 @@ +//! The production surface cannot see the test scaffolding (§6 M-4, M-9). +//! +//! The shim harness is load-bearing: the whole step machine is tested by driving +//! the real binaries with fakes for `makepkg`, `mkarchroot`, `gpg` and friends. +//! That is fine. What is not fine is production code reaching into it — the +//! publish path once read a package's name through the shim module's copy of the +//! `.PKGINFO` parser, which meant the bytes we signed and the bytes the tests +//! believed were parsed by two pieces of code that could drift apart. +//! +//! The compile-time half of this rule is real: `shims` is compiled out unless the +//! `test-support` feature is on, and only this crate's own dev-dependency turns +//! it on. This test covers the half the compiler cannot: a module in `src/` +//! naming the scaffolding directly. + +use std::path::{Path, PathBuf}; + +fn rust_files(dir: &Path, out: &mut Vec<PathBuf>) { + for entry in std::fs::read_dir(dir).expect("read_dir") { + let path = entry.expect("entry").path(); + if path.is_dir() { + rust_files(&path, out); + } else if path.extension().is_some_and(|e| e == "rs") { + out.push(path); + } + } +} + +#[test] +fn no_production_module_references_the_shim_harness() { + let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("src"); + let mut files = Vec::new(); + rust_files(&root, &mut files); + + let mut offenders: Vec<String> = Vec::new(); + for file in files { + let rel = file.strip_prefix(&root).unwrap_or(&file).to_string_lossy().replace('\\', "/"); + // The harness itself, and the shim binaries that are its front ends, are + // allowed to know about it. + if rel.starts_with("shims") || rel.starts_with("bin/") { + continue; + } + let text = std::fs::read_to_string(&file).expect("read source"); + for (no, line) in text.lines().enumerate() { + let t = line.trim_start(); + if t.starts_with("//") { + continue; + } + if line.contains("shims::") { + offenders.push(format!("{rel}:{}: {t}", no + 1)); + } + } + } + assert!( + offenders.is_empty(), + "production code must not depend on the test harness (§6 M-4). Parse with `pkginfo`, not with the shim:\n{}", + offenders.join("\n") + ); +} + +#[test] +fn the_shim_binaries_are_test_only() { + let manifest = std::fs::read_to_string(Path::new(env!("CARGO_MANIFEST_DIR")).join("Cargo.toml")) + .expect("read Cargo.toml"); + for tool in ["mkarchroot", "makechrootpkg", "makepkg", "repo-add", "gpg", "pacman"] { + let block = manifest + .split("[[bin]]") + .find(|b| b.contains(&format!("name = \"{tool}\""))) + .unwrap_or_else(|| panic!("no [[bin]] for {tool}")); + assert!( + block.contains("required-features = [\"test-support\"]"), + "the {tool} shim is a test binary and must not be built for a production target" + ); + } +} diff --git a/tests/shims.rs b/tests/shims.rs index f5cab7d..757e456 100644 --- a/tests/shims.rs +++ b/tests/shims.rs @@ -62,11 +62,14 @@ fn makechrootpkg_emits_pkginfo_buildinfo_and_sig() { let pkg = build.join("plain-make-1.0-1-x86_64.pkg.tar.zst"); assert!(pkg.exists(), "artifact left in the build dir like the real tool does"); let bytes = std::fs::read(&pkg).unwrap(); - let pkginfo = shims::read_pkginfo(&bytes).unwrap(); + // Read the artifact with the production parser, not a shim-only one: the + // harness is only a faithful stand-in if it reads a package the way the + // pipeline will (§6 M-4). + let pkginfo = aur_build::pkginfo::pkginfo_text(&bytes).unwrap(); assert!(pkginfo.contains("pkgname = plain-make")); assert!(pkginfo.contains("pkgver = 1.0-1")); assert!(pkginfo.contains("pkgarch = x86_64")); - let buildinfo = shims::read_buildinfo(&bytes).unwrap(); + let buildinfo = aur_build::pkginfo::buildinfo_text(&bytes).unwrap(); assert!(buildinfo.contains("format = 2")); assert!(buildinfo.contains("installed ="), "BUILDINFO carries the chroot world (§10.1)"); assert!(buildinfo.contains(" glibc 2.39-1 x86_64 -")); |
