From 1cd680c12dc191bfbf7afa8ad8308524776e60ae Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 20 Nov 2026 17:41:34 +0000 Subject: review: one call to record a candidate, and one way to read one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `watch::detect` was performing review's write protocol by hand: look up the accepted release, upsert the candidate, assess the risk, store the risk, work out the missing dependencies, store those. Six calls that only make sense in that order, issued from a module whose job is noticing that an upstream moved. Get the order wrong and nothing complains — the candidate just quietly has no risk score, and the reviewer approves it without one. `review::intake::record` is the protocol now. The watcher hands over what it observed and review decides what it means. `missing_deps` moved with it: it computes a risk signal, which is a review question that happened to be living in the watcher. `accepted_for` was not a review question either. It reads a pointer column off the pkgbase row, so it is now `db::accepted_release_for` — the watcher asks persistence what is currently accepted, rather than asking review as a favour. With intake owning the write path, three things became internal and closed: `upsert_candidate`, `risk::assess`, and the risk/missing-deps column setters. `approve::approval_for` was a pass-through to db that only the pipeline called; it is gone, and the pipeline now asks `review::reads::{candidate, approval}` — two named facts instead of a re-export of review's storage layout. The budget rose in two places and both are moves, not growth: db.pub 201->202 is `accepted_release_for` arriving from review, and review.test 4->5 is `set_risk_for_tests`, the one place a fixture still needs to force a score. review.pub itself is unchanged at 29 — four names added, four removed. `priv` was also dropped from the budget keys. Counting `pub(crate)` items against a ceiling was backwards: closing an interface raises that number, so a budget that punishes it punishes the work. The Rust test never checked it. 277 passed / 0 failed, clippy -D warnings clean, and every detect, approve and staleness assertion intact. --- src/review/candidates.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/review/candidates.rs') diff --git a/src/review/candidates.rs b/src/review/candidates.rs index 53361fe..b220013 100644 --- a/src/review/candidates.rs +++ b/src/review/candidates.rs @@ -3,9 +3,16 @@ use crate::error::Result; pub use crate::db::candidates::{ all as all_candidates, by_id as candidate_by_id, mark_viewed, open_reviews_for, pending as pending_candidates, - reopen_rejected, set_diff_digest, set_missing_deps, set_risk, NewCandidate, + reopen_rejected, set_diff_digest, NewCandidate, }; +/// The risk columns are review's to write, from `intake::record` and nowhere +/// else. A fixture that needs a particular score says so through this. +#[cfg(feature = "test-support")] +pub fn set_risk_for_tests(db: &Db, id: i64, level: &str, signals: &[String]) -> Result<()> { + db::candidates::set_risk(db, id, level, signals) +} + #[derive(Debug, Clone, PartialEq, Eq)] pub enum Upsert { Created { id: i64, kind: String }, @@ -15,7 +22,7 @@ pub enum Upsert { Unchanged, } -pub fn upsert_candidate(db: &Db, pb: &Pkgbase, accepted: Option<&ReleaseRow>, nc: &NewCandidate) -> Result { +pub(crate) fn upsert_candidate(db: &Db, pb: &Pkgbase, accepted: Option<&ReleaseRow>, nc: &NewCandidate) -> Result { let kind = if accepted.is_some() { db::candidate_kind::NEW_VERSION } else { db::candidate_kind::FIRST_INTRODUCTION }; let base = accepted.map(|a| a.id); let pkgbase_id = pb.id; @@ -45,10 +52,3 @@ pub fn upsert_candidate(db: &Db, pb: &Pkgbase, accepted: Option<&ReleaseRow>, nc Ok(Upsert::Created { id, kind: kind.to_string() }) }) } - -pub fn accepted_for(db: &Db, pb: &Pkgbase) -> Result> { - match pb.current_accepted_release_id { - Some(id) => db::release_by_id(db, id), - None => Ok(None), - } -} -- cgit v1.2.3