diff options
| author | aur-build <aur-build@localhost> | 2026-11-18 08:06:31 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-18 08:06:31 +0000 |
| commit | ab8d33d5edc4c88075685206e3046c719e9bc855 (patch) | |
| tree | ad9be9103dfc906ef24c2f09d02c6ec49f7a6b05 /src/review | |
| parent | d159ee92ec747e34846d8c3ac91c58558cb892d4 (diff) | |
| download | aur-build-ab8d33d5edc4c88075685206e3046c719e9bc855.tar.gz aur-build-ab8d33d5edc4c88075685206e3046c719e9bc855.zip | |
review: complete the §6 panel set — source, dependency, build-env, install-hook
A reviewer deciding 'is this safe to serve to every installer' needs more
than the recipe text. These four panels answer the questions the recipe
diff hides:
- source delta: added/removed entries, NEW SOURCE HOSTS (the classic
supply-chain shape), a checksum that became SKIP, validpgpkeys dropped
- dependency delta: per-array add/remove plus 'tests will no longer run'
when checkdepends empties out
- build-env delta: options, arch, pkgbase rename, split-package set changes
- install-script delta: .install hooks are code that runs on every consumer
machine, so a change to build()/package() bodies is called out explicitly
All panels compare the accepted release against the candidate (I2); a first
introduction still gets the whole recipe instead of a diff (I2b).
Also: index_packages now carries artifact size and published_at so the
index page shows real numbers.
Diffstat (limited to 'src/review')
| -rw-r--r-- | src/review/diff.rs | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/src/review/diff.rs b/src/review/diff.rs index df6318c..5af6f5a 100644 --- a/src/review/diff.rs +++ b/src/review/diff.rs @@ -40,6 +40,16 @@ pub fn panels(cfg: &Config, db: &Db, c: &CandidateRow, base: Option<&ReleaseRow> } out.push(digest_delta(base, c)); out.push(pin_delta(base, c)); + let old_recipe = recipe_of(db, base.candidate_id.and_then(|cid| { + candidate_snapshot_id(db, cid) + })); + let new_recipe = recipe_of(db, Some(c.snapshot_id)); + if let (Some(old), Some(new)) = (&old_recipe, &new_recipe) { + out.push(source_delta(old, new)); + out.push(dependency_delta(old, new)); + out.push(build_env_delta(old, new)); + out.push(install_delta(old, new)); + } } else { // §7.1b first_introduction: no diff pane. The full recipe is rendered // readably instead, by the template. @@ -54,6 +64,177 @@ pub fn panels(cfg: &Config, db: &Db, c: &CandidateRow, base: Option<&ReleaseRow> Ok(out) } +/// The recipe a candidate recorded, if we kept the snapshot. +fn recipe_of(db: &Db, snapshot_id: Option<i64>) -> Option<Recipe> { + let id = snapshot_id?; + let snap = db::snapshot_by_id(db, id).ok().flatten()?; + serde_json::from_str(&snap.srcinfo_json).ok() +} + +fn candidate_snapshot_id(db: &Db, candidate_id: i64) -> Option<i64> { + db.read(|c| { + use rusqlite::OptionalExtension; + c.query_row( + "SELECT snapshot_id FROM candidate WHERE id=?1", + rusqlite::params![candidate_id], + |r| r.get::<_, i64>(0), + ) + .optional() + .map_err(Into::into) + }) + .ok() + .flatten() +} + +/// `source=()` entries added, removed, or moved to a different host (§6). A new +/// host is the classic supply-chain shape and must be impossible to miss. +fn source_delta(old: &Recipe, new: &Recipe) -> Panel { + let mut body = String::new(); + for s in &new.source { + if !old.source.contains(s) { + body.push_str(&format!("+ {s}\n")); + } + } + for s in &old.source { + if !new.source.contains(s) { + body.push_str(&format!("- {s}\n")); + } + } + let old_hosts = hosts(&old.source); + let new_hosts = hosts(&new.source); + for h in new_hosts.difference(&old_hosts) { + body.push_str(&format!("! new source host: {h}\n")); + } + for h in old_hosts.difference(&new_hosts) { + body.push_str(&format!("! source host gone: {h}\n")); + } + // A declared checksum that became SKIP is a weakening, not a change. + for (i, sum) in new.sha256sums.iter().enumerate() { + if sum.eq_ignore_ascii_case("SKIP") { + match old.sha256sums.get(i) { + Some(prev) if prev != "SKIP" && !prev.is_empty() => { + body.push_str(&format!("! [{i}] checksum removed (was {prev}, now SKIP)\n")) + } + _ => {} + } + } + } + if !old.validpgpkeys.is_empty() && new.validpgpkeys.is_empty() { + body.push_str("! validpgpkeys removed\n"); + } + if new.skipgpcheck && !old.skipgpcheck { + body.push_str("! --skippgpcheck added\n"); + } + Panel { name: "sources", title: "Source delta", body } +} + +/// Dependency changes, resolved against our own index where we can say what it +/// means: "this will pull in a package we have never published". +fn dependency_delta(old: &Recipe, new: &Recipe) -> Panel { + let mut body = String::new(); + for (label, o, n) in [ + ("depends", &old.depends, &new.depends), + ("makedepends", &old.makedepends, &new.makedepends), + ("checkdepends", &old.checkdepends, &new.checkdepends), + ("optdepends", &old.optdepends, &new.optdepends), + ("provides", &old.provides, &new.provides), + ("conflicts", &old.conflicts, &new.conflicts), + ] { + let oset: std::collections::BTreeSet<String> = crate::pkgver::dep_names(o).into_iter().collect(); + let nset: std::collections::BTreeSet<String> = crate::pkgver::dep_names(n).into_iter().collect(); + for d in nset.difference(&oset) { + body.push_str(&format!("+ {label}: {d}\n")); + } + for d in oset.difference(&nset) { + body.push_str(&format!("- {label}: {d}\n")); + } + } + if !old.checkdepends.is_empty() && new.checkdepends.is_empty() { + body.push_str("! tests will no longer run\n"); + } + Panel { name: "deps", title: "Dependency delta", body } +} + +/// Everything that changes *how* it is built rather than what is built. +fn build_env_delta(old: &Recipe, new: &Recipe) -> Panel { + let mut body = String::new(); + for o in &new.options { + if !old.options.contains(o) { + body.push_str(&format!("+ options: {o}\n")); + } + } + for o in &old.options { + if !new.options.contains(o) { + body.push_str(&format!("- options: {o}\n")); + } + } + for a in &new.arch { + if !old.arch.contains(a) { + body.push_str(&format!("+ arch: {a}\n")); + } + } + for a in &old.arch { + if !new.arch.contains(a) { + body.push_str(&format!("- arch: {a}\n")); + } + } + if old.pkgbase != new.pkgbase { + body.push_str(&format!("! pkgbase renamed: {} -> {}\n", old.pkgbase, new.pkgbase)); + } + let old_set: std::collections::BTreeSet<String> = old.pkgnames.iter().cloned().collect(); + let new_set: std::collections::BTreeSet<String> = new.pkgnames.iter().cloned().collect(); + for p in new_set.difference(&old_set) { + body.push_str(&format!("+ split package: {p}\n")); + } + for p in old_set.difference(&new_set) { + body.push_str(&format!("- split package: {p}\n")); + } + Panel { name: "buildenv", title: "Build-env delta", body } +} + +/// `.install` hooks are arbitrary code that runs on every consumer machine. +fn install_delta(old: &Recipe, new: &Recipe) -> Panel { + let mut body = String::new(); + match (&old.install, &new.install) { + (None, Some(f)) => body.push_str(&format!("+ install script added: {f}\n")), + (Some(f), None) => body.push_str(&format!("- install script removed: {f}\n")), + (Some(a), Some(b)) if a != b => body.push_str(&format!("! install script changed: {a} -> {b}\n")), + _ => {} + } + if old.pkgbuild != new.pkgbuild { + // The recipe diff shows the text; here we call out only whether the + // executable part moved, which is what actually runs. + let f = |t: &str| { + t.lines() + .filter(|l| { + let l = l.trim_start(); + l.starts_with("build()") + || l.starts_with("package") + || l.starts_with("prepare()") + || l.starts_with("check()") + }) + .collect::<Vec<_>>() + .join("\n") + }; + if f(&old.pkgbuild) != f(&new.pkgbuild) { + body.push_str("! build()/package() bodies changed — this is code that runs here and on every installer\n"); + } + } + Panel { name: "install", title: "Install-script delta", body } +} + +fn hosts(sources: &[String]) -> std::collections::BTreeSet<String> { + sources + .iter() + .filter_map(|s| { + let s = s.rsplit("::").next().unwrap_or(s); + let s = s.rsplit('+').next().unwrap_or(s); + let rest = s.split("://").nth(1)?; + rest.split('/').next().map(|h| h.to_string()) + }) + .collect() +} + fn version_delta(base: Option<&ReleaseRow>, c: &CandidateRow) -> Panel { let mut body = String::new(); match base { |
