From c712124f214fc53a57b23c10ed98e8e869cbf7c2 Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 18:02:43 +0000 Subject: =?UTF-8?q?watch,=20review,=20config:=20the=20clarity=20minors=20?= =?UTF-8?q?=E2=80=94=20no-ops,=20dead=20params,=20one=20error=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit m-5. `mark_approved_but_unbuilt` was a function that did nothing, called from the failure path with a comment explaining that it did nothing. The mechanism is real — a failed build leaves the accepted pointer alone, and "approved, build failed, index still serving the old version" is what the derived query reads back — but a no-op in the failure path is a trap for whoever traces a build failure at 3am. Deleted; the explanation moved to the call site that needs it. m-6. The step loop extended the lease by a hardcoded 90 seconds while `Config` carried `lease_secs`, so an operator who raised the lease got leases that were silently reset to 90s after the first step. m-8. Dead parameters and `let _ =` debris: `upstream::run` took a `Db` it never used (and a `let _ = local;` after the value's only use), `risk::assess` took a `Pkgbase` it never used, `accepted_pins` took a `Db`, `detect::schedule_next` took a `Pkgbase` it discarded, `diff::version_delta` computed a `vercmp` and threw the answer away, and two HTTP handlers took arguments they ignored. All gone, with the callers following. m-11. `schedule_next` re-queried the subscription for `poll_interval_secs` that its caller had read moments earlier to decide whether the pkgbase was paused — two queries, and two chances to get different answers. The interval is now an argument, and the scheduler's own tick (which already holds the row) was already doing it the right way. m-15. `Config::load`/`save`/`ensure_dirs` returned `anyhow::Result` while the rest of the crate returns `error::Error`, which put two vocabularies on either side of one boundary and turned "there is no config yet, run init" — the one thing a caller can branch on — into an opaque string. They return the crate's error now; `main` keeps `anyhow` at the CLI edge, where it belongs. m-19. `skip_declared` was hardcoded `true` for VCS entries, so the field that means "the recipe gave us no checksum to trust" also meant "this is a git source", and a new `-git` source was rendered to a reviewer as `sha256sums=SKIP` — a warning about a recipe that had done nothing wrong. The field now means one thing everywhere, `SourceDigest::is_vcs()` says which integrity mechanism protects an entry, and the diff panel prints "pinned commit" for those. n-6. `recipe_at` was `pub` for no reason; it is `pub(crate)`. --- src/config.rs | 17 +++++++++++++---- src/db/model.rs | 17 ++++++++++++++++- src/http/routes.rs | 29 ++++++++++++++--------------- src/pipeline/mod.rs | 22 ++++++---------------- src/pipeline/steps.rs | 2 +- src/review/diff.rs | 4 +--- src/review/risk.rs | 13 +++++-------- src/watch/detect.rs | 27 ++++++++++++++++----------- src/watch/digests.rs | 10 +++++++++- src/watch/upstream.rs | 5 +---- 10 files changed, 82 insertions(+), 64 deletions(-) diff --git a/src/config.rs b/src/config.rs index 3708639..8e303d4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -152,10 +152,19 @@ impl Default for Config { } impl Config { - pub fn load(root: &Path) -> anyhow::Result { + /// Read `/config.json`. + /// + /// The crate's own error type, like everything else that can fail (m-15): + /// `anyhow::Result` here meant two error vocabularies in one crate, and the + /// one thing a caller can actually branch on — "there is no config yet, run + /// init" — arrived as an opaque string. + pub fn load(root: &Path) -> crate::error::Result { let p = root.join("config.json"); if !p.exists() { - anyhow::bail!("no config at {}; run `aur-build init`", p.display()); + return Err(crate::error::Error::not_found(format!( + "no config at {}; run `aur-build init`", + p.display() + ))); } let s = std::fs::read_to_string(&p)?; let mut cfg: Config = serde_json::from_str(&s)?; @@ -167,7 +176,7 @@ impl Config { Ok(cfg) } - pub fn save(&self) -> anyhow::Result<()> { + pub fn save(&self) -> crate::error::Result<()> { std::fs::create_dir_all(&self.root)?; std::fs::write( self.root.join("config.json"), @@ -209,7 +218,7 @@ impl Config { } /// Create the directory tree the server needs. Idempotent. - pub fn ensure_dirs(&self) -> anyhow::Result<()> { + pub fn ensure_dirs(&self) -> crate::error::Result<()> { for d in [ self.root.clone(), self.mirrors_dir(), diff --git a/src/db/model.rs b/src/db/model.rs index 263db4e..3fa2840 100644 --- a/src/db/model.rs +++ b/src/db/model.rs @@ -55,10 +55,25 @@ pub struct SourceDigest { /// sha256, or the resolved VCS commit for vcs sources. pub digest: String, pub size: u64, - /// True when the PKGBUILD declared `SKIP` (or nothing) for this source. + /// True when the PKGBUILD gave us no checksum to trust for this source — + /// `SKIP`, a malformed digest, or nothing at all. + /// + /// It means that and nothing else (m-19). It used to be hardcoded `true` for + /// VCS entries, where it reads as a warning the recipe never earned: a + /// `-git` source has no checksum by design because the *pin* is the + /// integrity. Ask [`SourceDigest::is_vcs`] when you need to know which of + /// the two mechanisms protects an entry. pub skip_declared: bool, } +impl SourceDigest { + /// True when this entry's integrity comes from a resolved commit rather than + /// a content hash. + pub fn is_vcs(&self) -> bool { + matches!(self.kind.as_str(), "vcs" | "git" | "svn" | "hg" | "bzr") + } +} + /// A member of a world snapshot: one of *our* packages the build ran against. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] pub struct WorldMember { diff --git a/src/http/routes.rs b/src/http/routes.rs index f475d3a..4a988b2 100644 --- a/src/http/routes.rs +++ b/src/http/routes.rs @@ -195,8 +195,7 @@ fn dashboard(state: &State, req: &Req) -> Res { // ---------------------------------------------------------------- inbox -- -fn review_rows(state: &State) -> Vec { - let db = &state.db; +fn review_rows(db: &Db) -> Vec { let mut rows: Vec = candidates::pending_candidates(db) .unwrap_or_default() .into_iter() @@ -218,13 +217,12 @@ fn review_rows(state: &State) -> Vec { _ => 2, }; rows.sort_by_key(|r| (rank(&r.risk), r.age.clone(), r.id)); - let _ = state; rows } fn reviews(state: &State, req: &Req) -> Res { let page = chrome(state, req, "Reviews", "nav_reviews"); - page_to_res(ReviewsPage { page, rows: review_rows(state) }, 200) + page_to_res(ReviewsPage { page, rows: review_rows(&state.db) }, 200) } fn full_version(c: &CandidateRow) -> String { @@ -363,7 +361,7 @@ fn review_approve(state: &State, req: &Req, id: &str) -> Res { page.flash_err = true; } } - page_to_res(ReviewsPage { page, rows: review_rows(state) }, 200) + page_to_res(ReviewsPage { page, rows: review_rows(&state.db) }, 200) } Err(ap::ApproveError::System(e)) => { // The database refused. Telling the reviewer their review went stale @@ -372,7 +370,7 @@ fn review_approve(state: &State, req: &Req, id: &str) -> Res { page.flash = format!("the approval could not be recorded: {e}"); page.has_flash = true; page.flash_err = true; - page_to_res(ReviewsPage { page, rows: review_rows(state) }, 500) + page_to_res(ReviewsPage { page, rows: review_rows(&state.db) }, 500) } Err(ap::ApproveError::Stale(stale)) => { // §7.1a: refuse, re-render what it is now, and say why. Never @@ -419,21 +417,21 @@ fn review_reject(state: &State, req: &Req, id: &str) -> Res { page.flash = "a rejection needs a reason: it is the only record of why".into(); page.has_flash = true; page.flash_err = true; - return page_to_res(ReviewsPage { page, rows: review_rows(state) }, 400); + return page_to_res(ReviewsPage { page, rows: review_rows(&state.db) }, 400); }; match ap::reject(db, actor(state, req), id, ¬e) { Ok(()) => { let mut page = chrome(state, req, "Reviews", "nav_reviews"); page.flash = format!("rejected #{id}; it can be re-opened from the package page"); page.has_flash = true; - page_to_res(ReviewsPage { page, rows: review_rows(state) }, 200) + page_to_res(ReviewsPage { page, rows: review_rows(&state.db) }, 200) } Err(e) => { let mut page = chrome(state, req, "Reviews", "nav_reviews"); page.flash = format!("could not reject: {e}"); page.has_flash = true; page.flash_err = true; - page_to_res(ReviewsPage { page, rows: review_rows(state) }, 409) + page_to_res(ReviewsPage { page, rows: review_rows(&state.db) }, 409) } } } @@ -463,7 +461,7 @@ fn reviews_bulk(state: &State, req: &Req) -> Res { page.flash = "nothing selected".into(); page.has_flash = true; page.flash_err = true; - return page_to_res(ReviewsPage { page, rows: review_rows(state) }, 400); + return page_to_res(ReviewsPage { page, rows: review_rows(&state.db) }, 400); } // The rule itself lives in `review::approve::bulk`, so the page and the // library cannot disagree about what a bulk decision means (§7.4). @@ -480,7 +478,7 @@ fn reviews_bulk(state: &State, req: &Req) -> Res { page.flash = format!("the decisions could not be recorded: {e}"); page.has_flash = true; page.flash_err = true; - return page_to_res(ReviewsPage { page, rows: review_rows(state) }, 500); + return page_to_res(ReviewsPage { page, rows: review_rows(&state.db) }, 500); } }; let mut done = Vec::new(); @@ -506,7 +504,7 @@ fn reviews_bulk(state: &State, req: &Req) -> Res { ); page.has_flash = true; page.flash_err = !refused.is_empty(); - page_to_res(ReviewsPage { page, rows: review_rows(state) }, 200) + page_to_res(ReviewsPage { page, rows: review_rows(&state.db) }, 200) } /// Who the audit trail says made a decision. With no password configured the @@ -674,7 +672,6 @@ fn notice_ack(state: &State, req: &Req) -> Res { let _ = db::acknowledge_notice(&state.db.writer, id); // POST-redirect-GET: the notice vanishing from the list is its own // confirmation, and a refresh can no longer re-POST. - let _ = req; Res::redirect("/attention") } @@ -789,9 +786,11 @@ fn package_detail(state: &State, req: &Req, name: &str) -> Res { fn package_rebuild(state: &State, req: &Req, name: &str) -> Res { match pipeline::enqueue_manual_rebuild(&state.cfg, &state.db, name) { Ok(id) => { - let _ = id; let mut page = chrome(state, req, "Builds", "nav_builds"); - page.flash = format!("queued a rebuild of the approved version of {name} (no new approval needed)"); + page.flash = format!( + "queued a rebuild of the approved version of {name} (build {}, no new approval needed)", + &id[..8.min(id.len())] + ); page.has_flash = true; builds_with(state, req, page) } diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index 9ddfc65..c3a2cb3 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -212,7 +212,7 @@ pub fn run_with(ctx: &Ctx) -> Result { match steps::run_step(ctx, step) { Ok(StepResult::Done(digest)) => { builds::finish_step(&ctx.db, &ctx.build.id, step, StepState::Succeeded, digest.as_deref(), None)?; - builds::extend_lease(&ctx.db, &ctx.build.id, 90)?; + builds::extend_lease(&ctx.db, &ctx.build.id, ctx.cfg.lease_secs)?; } Ok(StepResult::Skipped(why)) => { ctx.log_line(&format!(" skipped: {why}")); @@ -234,13 +234,11 @@ pub fn run_with(ctx: &Ctx) -> Result { Some(&format!("{step}: {e}")), )?; ctx.log_line(&format!("!! {step} failed: {e}")); - // A failed build must not leave the old version looking healthy: - // the release stays approved_but_unbuilt and the UI says so. - if let Some(cid) = ctx.build.candidate_id { - if ctx.build.release_id.is_none() { - mark_approved_but_unbuilt(&ctx.db, cid)?; - } - } + // A failed build must not leave the old version looking healthy. + // Nothing has to *do* that: the accepted pointer was never moved, + // so "approved, build failed, index still serving the old + // version" is what the derived query reads back (§8.4). There is + // deliberately no state to set here — see `approved_but_unbuilt`. return Ok(Outcome::Failed { step: step.to_string(), error: e.to_string(), transient }); } } @@ -265,14 +263,6 @@ impl Ctx { } } -/// A failed build must not make the old version look healthy (§8.4). The -/// candidate stays `approved`; what the UI renders is the *absence* of a -/// published release behind it: "v2 approved, build failed, index still -/// serving v1". Nothing here mutates the accepted pointer. -fn mark_approved_but_unbuilt(_db: &Db, _candidate_id: i64) -> Result<()> { - Ok(()) -} - /// Enqueue the build an approval implies. Deterministic id, so calling this /// twice is a no-op (§8.2). pub fn enqueue_for_candidate(cfg: &Config, db: &Db, c: &CandidateRow) -> Result { diff --git a/src/pipeline/steps.rs b/src/pipeline/steps.rs index 033093b..7187e13 100644 --- a/src/pipeline/steps.rs +++ b/src/pipeline/steps.rs @@ -438,7 +438,7 @@ fn publish(ctx: &Ctx) -> Result { use std::path::PathBuf; /// Read the recipe from a materialized tree, preferring `.SRCINFO`. -pub fn recipe_at(dir: &Path) -> Result { +pub(crate) fn recipe_at(dir: &Path) -> Result { let mut files = std::collections::BTreeMap::new(); for entry in walkdir::WalkDir::new(dir).max_depth(2).into_iter().filter_map(|e| e.ok()) { let p = entry.path(); diff --git a/src/review/diff.rs b/src/review/diff.rs index 629258c..3eecc4e 100644 --- a/src/review/diff.rs +++ b/src/review/diff.rs @@ -205,7 +205,6 @@ fn version_delta(base: Option<&ReleaseRow>, c: &CandidateRow) -> Panel { Some(b) => { let (bv, cv) = (b.version(), c.version()); body.push_str(&format!("{bv} -> {cv}\n")); - let ord = crate::pkgver::vercmp(&bv, &cv); if b.epoch != c.epoch { body.push_str(&format!("epoch bump: {} -> {}\n", b.epoch, c.epoch)); } @@ -215,7 +214,6 @@ fn version_delta(base: Option<&ReleaseRow>, c: &CandidateRow) -> Panel { if crate::pkgver::is_downgrade(&bv, &cv) { body.push_str("DOWNGRADE: AUR now offers a lower version than we serve\n"); } - let _ = ord; } None => body.push_str(&format!("first introduction: {}\n", c.version())), } @@ -240,7 +238,7 @@ fn digest_delta(base: &ReleaseRow, c: &CandidateRow) -> Panel { n.index, n.url, n.kind, - if n.skip_declared { ", sha256sums=SKIP" } else { "" } + if n.skip_declared && !n.is_vcs() { ", sha256sums=SKIP" } else if n.is_vcs() { ", pinned commit" } else { "" } )), } } diff --git a/src/review/risk.rs b/src/review/risk.rs index 73f9be7..cf7069d 100644 --- a/src/review/risk.rs +++ b/src/review/risk.rs @@ -10,7 +10,7 @@ //! what the candidate records now — the same "never last seen" rule that makes //! I2 true for the diff panels. -use crate::db::{self, model::*, Db, Pkgbase}; +use crate::db::{self, model::*, Db}; use crate::error::Result; use crate::pkgver; @@ -48,7 +48,6 @@ impl Assessment { pub fn assess( db: &Db, cfg: &crate::config::Config, - pb: &Pkgbase, new: &Recipe, new_digests: &[SourceDigest], accepted: Option<&ReleaseRow>, @@ -93,12 +92,12 @@ pub fn assess( // Upstream movement that touches the build system (§6): the diff is in a // language ecosystem we cannot inspect, so say so. if let Some(a) = accepted { - for pin in accepted_pins(db, accepted) { + for pin in accepted_pins(accepted) { if let Some(old_pin) = a.pins().into_iter().find(|p| p.index == pin.index) { if !old_pin.commit.is_empty() && !pin.commit.is_empty() && old_pin.commit != pin.commit - && upstream_touches_build_system(cfg, pb, &old_pin.commit, &pin.commit) + && upstream_touches_build_system(cfg, &old_pin.commit, &pin.commit) { s.add("upstream-build-system", level::MEDIUM); } @@ -109,8 +108,7 @@ pub fn assess( Ok(Assessment { level: s.level(), signals: s.signals }) } -fn accepted_pins(db: &Db, accepted: Option<&ReleaseRow>) -> Vec { - let _ = db; +fn accepted_pins(accepted: Option<&ReleaseRow>) -> Vec { accepted.map(|a| a.pins()).unwrap_or_default() } @@ -193,7 +191,7 @@ fn compare_digests( } -fn upstream_touches_build_system(cfg: &crate::config::Config, pb: &Pkgbase, from: &str, to: &str) -> bool { +fn upstream_touches_build_system(cfg: &crate::config::Config, from: &str, to: &str) -> bool { // Best-effort: if we have the upstream clone cached we can ask it directly. let cache = cfg.vcs_cache_dir(); if !cache.exists() { @@ -204,7 +202,6 @@ fn upstream_touches_build_system(cfg: &crate::config::Config, pb: &Pkgbase, from let path = dir.path(); if let Ok(files) = crate::git::git(Some(&path), &["diff", "--name-only", &range]) { if files.lines().any(|f| BUILD_SYSTEM_FILES.iter().any(|b| f.ends_with(b))) { - let _ = pb; return true; } } diff --git a/src/watch/detect.rs b/src/watch/detect.rs index 37bdc8a..d2ffd4e 100644 --- a/src/watch/detect.rs +++ b/src/watch/detect.rs @@ -53,9 +53,8 @@ pub fn check_pkgbase(cfg: &Config, db: &Db, name: &str) -> Result { // broken must not keep opening reviews nobody is going to act on, and it // must not keep polling AUR either. The pause lives on the subscription, so // that is what we consult. - let paused = db::get_subscription(db, name)? - .map(|s| s.state == SubscriptionState::Paused) - .unwrap_or(false); + let sub = db::get_subscription(db, name)?; + let paused = sub.as_ref().map(|s| s.state == SubscriptionState::Paused).unwrap_or(false); if paused { return Ok(CheckReport { pkgbase: name.into(), head: String::new(), outcome: Outcome::Paused }); } @@ -79,18 +78,24 @@ pub fn check_pkgbase(cfg: &Config, db: &Db, name: &str) -> Result { Sync::Fetched { head, .. } | Sync::Cloned { head } => head.clone(), }; let r = analyse(cfg, db, &pb, &head); - schedule_next(db, name, &pb); + schedule_next(db, name, sub.as_ref().and_then(|s| s.poll_interval_secs)); r } -fn schedule_next(db: &Db, name: &str, pb: &Pkgbase) { - let interval = db::subscription_poll_interval(db, name) - .ok() - .flatten() - .unwrap_or(crate::db::setting_i64(db, "poll_interval", 86400)); +/// When to look at this pkgbase again: its own interval if the subscription +/// carries one, otherwise the global default. +/// +/// The interval arrives as an argument because the caller read the subscription +/// row a moment ago to decide whether this pkgbase is paused (m-11); going back +/// to the database for a number the caller was holding was both a second query +/// and a second, possibly different, answer. +fn schedule_next(db: &Db, name: &str, poll_interval: Option) { + let interval = poll_interval.unwrap_or_else(|| crate::db::setting_i64(db, "poll_interval", 86400)); let next = time::secs_ahead(interval); + // Best-effort: a missed "next check" stamp means the scheduler looks again + // a tick early, not that a change goes unnoticed — the tick re-selects by + // `next_check_at` and a NULL is due immediately. let _ = db::note_check(&db.writer, name, &next, None); - let _ = pb; } /// Everything after the mirror is up to date. @@ -245,7 +250,7 @@ fn score( candidate_id: Option, ) { let Some(id) = candidate_id else { return }; - if let Ok(a) = crate::review::risk::assess(db, cfg, pb, recipe, digests, accepted) { + if let Ok(a) = crate::review::risk::assess(db, cfg, recipe, digests, accepted) { let _ = crate::review::candidates::set_risk(db, id, &a.level, &a.signals); } // Record now what would block the build later, using the same rule the plan diff --git a/src/watch/digests.rs b/src/watch/digests.rs index c67d60e..8136850 100644 --- a/src/watch/digests.rs +++ b/src/watch/digests.rs @@ -48,7 +48,15 @@ pub fn resolve_sources( kind: entry.vcs.clone().unwrap_or_else(|| "vcs".into()), digest, size: 0, - skip_declared: true, + // Computed from the recipe like every other entry (m-19), not + // hardcoded: the field answers "did the recipe give us a + // checksum?", and for a VCS source the answer is usually yes-by- + // absence — which is why renderers must ask `is_vcs` before + // calling it a missing checksum. + skip_declared: match declared_sums(recipe, entry.index) { + Some(d) => d == SKIP || !is_hex_digest(&d), + None => true, + }, }); continue; } diff --git a/src/watch/upstream.rs b/src/watch/upstream.rs index 8d7fa4f..c2772a2 100644 --- a/src/watch/upstream.rs +++ b/src/watch/upstream.rs @@ -214,7 +214,7 @@ pub fn resolve( } let _slot = StageBSlot::acquire(db::setting_i64(db, "stage_b_concurrency", 1) as usize); - let resolved = run(cfg, db, pb, recipe, recipe_hash, &tip_hash, stage_a)?; + let resolved = run(cfg, pb, recipe, recipe_hash, &tip_hash, stage_a)?; db::stage_b_cache_put(db, pb.id, recipe_hash, &tip_hash, &resolved.as_row())?; Ok(Some(resolved)) } @@ -222,7 +222,6 @@ pub fn resolve( /// The actual work: warm the clone cache, then ask `makepkg` what it computes. fn run( cfg: &Config, - db: &Db, pb: &Pkgbase, recipe: &Recipe, recipe_hash: &str, @@ -248,7 +247,6 @@ fn run( if let Ok(local) = git::head(&cache) { if !local.is_empty() && git::has_commit(&cache, &pin.commit) { pin.branch = pin.branch.clone().or_else(|| default_branch(&cache)); - let _ = local; } } } @@ -281,7 +279,6 @@ fn run( if pkgver.is_empty() { return Err(Error::other(format!("makepkg --vercheck produced {text:?}"))); } - let _ = db; Ok(StageB { epoch: recipe.epoch.clone(), pkgver, -- cgit v1.2.3