summaryrefslogtreecommitdiffstats
path: root/src/review
diff options
context:
space:
mode:
authordev <dev@localhost>2026-11-20 17:41:34 +0000
committerdev <dev@localhost>2026-11-20 17:41:34 +0000
commit1cd680c12dc191bfbf7afa8ad8308524776e60ae (patch)
tree492da08774525f32e7f25642af46f22160154e1b /src/review
parent154f6f6dd284c11da82cf1188ff8549db6459228 (diff)
downloadaur-build-1cd680c12dc191bfbf7afa8ad8308524776e60ae.tar.gz
aur-build-1cd680c12dc191bfbf7afa8ad8308524776e60ae.zip
review: one call to record a candidate, and one way to read one
`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.
Diffstat (limited to 'src/review')
-rw-r--r--src/review/approve.rs4
-rw-r--r--src/review/candidates.rs18
-rw-r--r--src/review/intake.rs69
-rw-r--r--src/review/mod.rs4
-rw-r--r--src/review/reads.rs19
-rw-r--r--src/review/risk.rs2
6 files changed, 101 insertions, 15 deletions
diff --git a/src/review/approve.rs b/src/review/approve.rs
index 23afee3..79726ca 100644
--- a/src/review/approve.rs
+++ b/src/review/approve.rs
@@ -200,10 +200,6 @@ pub fn bulk(
Ok(out)
}
-pub fn approval_for(db: &Db, candidate_id: i64) -> Result<Option<(i64, String)>> {
- approvals::for_candidate(db, candidate_id)
-}
-
pub fn withdraw(db: &Db, actor: &str, release_id: i64, reason: &str) -> Result<()> {
let actor = actor.to_string();
let reason = reason.to_string();
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<Upsert> {
+pub(crate) fn upsert_candidate(db: &Db, pb: &Pkgbase, accepted: Option<&ReleaseRow>, nc: &NewCandidate) -> Result<Upsert> {
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<Option<ReleaseRow>> {
- match pb.current_accepted_release_id {
- Some(id) => db::release_by_id(db, id),
- None => Ok(None),
- }
-}
diff --git a/src/review/intake.rs b/src/review/intake.rs
new file mode 100644
index 0000000..7d84544
--- /dev/null
+++ b/src/review/intake.rs
@@ -0,0 +1,69 @@
+//! Turning a detected change into a scored candidate is one operation.
+//!
+//! The watcher used to perform review's write protocol itself: 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 by a module that has no business knowing the
+//! order — and if it got the order wrong, or skipped the scoring because it was
+//! in a hurry, nothing would have complained.
+//!
+//! `record` is the protocol. The watcher calls it once with what it observed,
+//! and review decides what a candidate means.
+
+use crate::config::Config;
+use crate::db::{self, model::*, Db, Pkgbase};
+use crate::error::Result;
+use crate::review::candidates::{self, NewCandidate, Upsert};
+use crate::review::risk;
+
+/// Record a detected change as a candidate, scored. Returns what the upsert
+/// decided so the caller can report it; a change that collapsed or was already
+/// rejected is recorded as such and scored only when a candidate row exists.
+pub fn record(
+ db: &Db,
+ cfg: &Config,
+ pb: &Pkgbase,
+ recipe: &Recipe,
+ digests: &[SourceDigest],
+ accepted: Option<&ReleaseRow>,
+ nc: &NewCandidate,
+) -> Result<Upsert> {
+ let up = candidates::upsert_candidate(db, pb, accepted, nc)?;
+ let id = match &up {
+ Upsert::Created { id, .. } | Upsert::Collapsed { id, .. } | Upsert::Superseded { new: id, .. } => *id,
+ // Nothing was written, so there is nothing to score.
+ Upsert::PreviouslyRejected | Upsert::Unchanged => return Ok(up),
+ };
+ // Scoring is advisory: a candidate that cannot be scored is still a
+ // candidate, and a reviewer sees the diff either way.
+ if let Ok(a) = risk::assess(db, cfg, recipe, digests, accepted) {
+ let _ = db::candidates::set_risk(db, id, &a.level, &a.signals);
+ }
+ let _ = db::candidates::set_missing_deps(db, id, &missing_deps(db, pb, recipe));
+ Ok(up)
+}
+
+/// Dependencies this recipe needs that we build ourselves but have not
+/// published yet — the reason a build would fail on a missing dep, said before
+/// it runs.
+fn missing_deps(db: &Db, pb: &Pkgbase, recipe: &Recipe) -> Vec<String> {
+ let ours = match db::our_package_names(db) {
+ Ok(o) => o,
+ Err(_) => return Vec::new(),
+ };
+ let mut out = Vec::new();
+ for dep in crate::pkgver::dep_names(&recipe.depends) {
+ if ours.contains(&dep) || dep == pb.name || recipe.pkgnames.contains(&dep) {
+ continue;
+ }
+ let ours_to_publish = db::get_subscription(db, &dep)
+ .map(|s| s.is_some())
+ .unwrap_or(false)
+ || db::get_pkgbase(db, &dep).map(|p| p.is_some()).unwrap_or(false);
+ if ours_to_publish {
+ out.push(dep);
+ }
+ }
+ out.sort();
+ out
+}
diff --git a/src/review/mod.rs b/src/review/mod.rs
index eb78b3a..78a6961 100644
--- a/src/review/mod.rs
+++ b/src/review/mod.rs
@@ -1,6 +1,8 @@
pub mod approve;
pub mod candidates;
pub mod diff;
+pub mod intake;
+pub mod reads;
pub mod risk;
-pub use candidates::{upsert_candidate, NewCandidate, Upsert};
+pub use candidates::{NewCandidate, Upsert};
diff --git a/src/review/reads.rs b/src/review/reads.rs
new file mode 100644
index 0000000..0f91f74
--- /dev/null
+++ b/src/review/reads.rs
@@ -0,0 +1,19 @@
+//! Reading review's state without reaching into its tables.
+//!
+//! The pipeline needs two facts about a candidate: the row itself, and whether
+//! a human approved it. It used to fetch them by calling through review's
+//! re-exports of db's query functions, which meant the step machine knew the
+//! shape of review's storage. These two calls are the whole of what it needs.
+
+use crate::db::{self, approvals, model::CandidateRow, Db};
+use crate::error::Result;
+
+pub fn candidate(db: &Db, id: i64) -> Result<Option<CandidateRow>> {
+ db::candidates::by_id(db, id)
+}
+
+/// The approval behind a candidate, as `(approval id, decision)`. `None` means
+/// no human has decided, which is what publish refuses on.
+pub fn approval(db: &Db, candidate_id: i64) -> Result<Option<(i64, String)>> {
+ approvals::for_candidate(db, candidate_id)
+}
diff --git a/src/review/risk.rs b/src/review/risk.rs
index f33f9e0..9c59bfa 100644
--- a/src/review/risk.rs
+++ b/src/review/risk.rs
@@ -27,7 +27,7 @@ impl Assessment {
}
}
-pub fn assess(
+pub(crate) fn assess(
db: &Db,
cfg: &crate::config::Config,
new: &Recipe,