diff options
Diffstat (limited to 'src/review')
| -rw-r--r-- | src/review/approve.rs | 62 | ||||
| -rw-r--r-- | src/review/candidates.rs | 21 | ||||
| -rw-r--r-- | src/review/diff.rs | 7 | ||||
| -rw-r--r-- | src/review/mod.rs | 3 | ||||
| -rw-r--r-- | src/review/risk.rs | 12 |
5 files changed, 20 insertions, 85 deletions
diff --git a/src/review/approve.rs b/src/review/approve.rs index e5f446f..c8cd99d 100644 --- a/src/review/approve.rs +++ b/src/review/approve.rs @@ -1,10 +1,3 @@ -//! Approval semantics (§7.1, §7.1a, §7.2, §7.4). -//! -//! Rule of the system: **we build exactly what was displayed, or nothing.** -//! The approve POST carries the `identity_hash` and `diff_digest` that were -//! rendered; if either has moved under the reviewer, the approval is refused -//! with a conflict (HTTP 409) and a re-render, never silently retargeted. - use crate::db::{self, approvals, candidates, CandidateState, *}; use crate::error::{Error, Result}; use crate::time; @@ -36,20 +29,16 @@ pub struct Approval { /// Why a decision did not happen (§7.1a, §6 M-3). /// -/// Two families, and the difference is the whole point. `Stale` means the -/// reviewer's screen no longer matches the database: the answer is to look -/// again, and the UI says so with a 409 and a fresh diff. `System` means the -/// database itself refused: looking again changes nothing, and the operator has -/// a broken thing to fix. They used to be the same variant — every failure, -/// SQLite included, arrived as "review is no longer pending (state: sqlite: -/// …)", which told a reviewer their eyes were wrong when the truth was that -/// the write failed. +/// Two families, and the difference is the whole point: `Stale` means the +/// reviewer's screen no longer matches the database, so the answer is to look +/// again; `System` means the database itself refused, and looking again changes +/// nothing. #[derive(Debug, thiserror::Error)] pub enum ApproveError { /// What is stored is not what was displayed. #[error(transparent)] Stale(#[from] Stale), - /// The write itself failed. Nothing about the review is at fault. + /// The write itself failed; nothing about the review is at fault. #[error("the decision could not be recorded: {0}")] System(#[from] Error), } @@ -77,19 +66,16 @@ pub fn approve( let base = subject.base_release_id; let current_base = subject.current_base_release_id; - // 1. still open if !subject.state.is_open() { return Ok(Err(ApproveError::Stale(Stale::NotPending { state: subject.state.to_string() }))); } - // 2. same candidate bytes if subject.identity_hash != ih { return Ok(Err(ApproveError::Stale(Stale::Identity { expected: ih.clone(), actual: subject.identity_hash }))); } - // 3. same rendered diff if subject.diff_digest != dd { return Ok(Err(ApproveError::Stale(Stale::Diff { expected: dd.clone(), actual: subject.diff_digest }))); } - // 4. base is still the accepted release (I2, end to end) + // Base is still the accepted release (I2, end to end). if base != current_base { return Ok(Err(ApproveError::Stale(Stale::Base { expected: base, actual: current_base }))); } @@ -128,7 +114,7 @@ pub fn approve( identity_hash: ih, })) }) - // A failure of the transaction is a system failure, never a stale review. + // A failed transaction is a system failure, never a stale review. .map_err(ApproveError::System)? } @@ -156,9 +142,6 @@ pub fn reject(db: &Db, actor: &str, candidate_id: i64, note: &str) -> Result<()> "reject", "candidate", &candidate_id.to_string(), - // The identity hash, not only the note: "why was this rejected" - // is unanswerable if the row does not say which bytes were on - // screen (§11). serde_json::json!({"identity": identity, "note": note}), ), )?; @@ -169,15 +152,13 @@ pub fn reject(db: &Db, actor: &str, candidate_id: i64, note: &str) -> Result<()> /// One item of a bulk decision, and what happened to it (§7.4). #[derive(Debug)] pub struct BulkItem { - /// The review this outcome is about; `None` when the id matched nothing — - /// which is exactly the case a caller must be able to report, so the row - /// cannot be the key. + /// `None` when the id matched nothing — which a caller must be able to + /// report, so the row cannot be the key. pub candidate: Option<CandidateRow>, pub outcome: BulkOutcome, } impl BulkItem { - /// The pkgbase to name in a summary line. pub fn pkgbase(&self) -> &str { self.candidate.as_ref().map(|c| c.pkgbase.as_str()).unwrap_or("(gone)") } @@ -188,21 +169,14 @@ impl BulkItem { pub enum BulkOutcome { /// Approved; the approval row is here so the caller can queue the build. Approved(Approval), - /// Rejected. A rejection records no approval, so there is no row to hand - /// back — the old code fabricated `Approval { id: 0 }`, which a caller - /// could not tell from a real one (§6 M-3). + /// A rejection records no approval, so there is no row to hand back. Rejected, /// Not decided, and why. Refused(BulkRefusal), } -/// Why a bulk decision skipped one of its items (§7.4). -/// -/// Each reason is its own variant because they are different answers to give a -/// human: one wants a confirmation click, one is a form bug, one means the -/// review moved while the page was open, one means the database is broken. They -/// used to all be `Stale::NotPending`, which made the flash message the only -/// place the truth survived. +/// Why a bulk decision skipped one of its items (§7.4). Each reason is its own +/// variant because they are different answers to give a human. #[derive(Debug, thiserror::Error)] pub enum BulkRefusal { /// High-risk items need their own confirmation, per item (§7.4). @@ -222,11 +196,11 @@ pub enum BulkRefusal { System(Error), } -/// §7.4 bulk decision. High-risk items are refused unless confirmed individually, -/// and one refused item never rolls back the ones that were decided. -/// -/// `items` carries the identity and diff each review was displayed with, so the -/// approval-echo rule applies to bulk exactly as it does to a single approval. +/// §7.4 bulk decision. High-risk items are refused unless confirmed +/// individually, and one refused item never rolls back the ones that were +/// decided. `items` carries the identity and diff each review was displayed +/// with, so the approval-echo rule applies to bulk exactly as to a single +/// approval. pub fn bulk( db: &Db, actor: &str, @@ -262,7 +236,6 @@ pub fn bulk( Ok(out) } -/// The approval behind a candidate, if any. pub fn approval_for(db: &Db, candidate_id: i64) -> Result<Option<(i64, String)>> { approvals::for_candidate(db, candidate_id) } @@ -290,7 +263,6 @@ pub fn withdraw(db: &Db, actor: &str, release_id: i64, reason: &str) -> Result<( }) } -/// The pkgbase's accepted release pointer, exposed for callers that need it. pub fn current_accepted(db: &Db, pkgbase: &str) -> Result<Option<ReleaseRow>> { db::accepted_release(db, pkgbase) } diff --git a/src/review/candidates.rs b/src/review/candidates.rs index 7cedf4b..d4c49e8 100644 --- a/src/review/candidates.rs +++ b/src/review/candidates.rs @@ -1,15 +1,3 @@ -//! Candidate creation and the collapse-in-place rule (§7.1). -//! -//! One review object per pkgbase at a time. A newer detection **collapses into** -//! the open review rather than queueing beside it, and the review's `base` is -//! fixed at creation to the pkgbase's `current_accepted_release` — that is what -//! makes "diff against the last accepted version, never the last seen one" (I2) -//! true no matter how many detections arrive while nobody is looking. -//! -//! This module is the *rule*, not the SQL: every statement it needs lives in -//! `db::candidates` and is called through the transaction handle, so the whole -//! decision is atomic and the schema still has one owner. - use crate::db::{self, candidates as sql, Db, Pkgbase, ReleaseRow}; use crate::error::Result; @@ -49,22 +37,20 @@ pub fn upsert_candidate(db: &Db, pb: &Pkgbase, accepted: Option<&ReleaseRow>, nc return Ok(Upsert::Unchanged); } if !open.viewed() { - // Collapse in place: same base, no new row, revision bumped. let revision = sql::collapse_in(tx, &open, &nc)?; return Ok(Upsert::Collapsed { id: open.id, revision }); } - // A human saw the old diff: freeze it for the audit trail and open a - // fresh review against the same base. + // A human saw the old diff: freeze it for the audit trail and open + // a fresh review against the same base. sql::supersede_in(tx, open.id)?; let new_id = sql::insert_in(tx, pkgbase_id, base, kind, &nc)?; return Ok(Upsert::Superseded { old: open.id, new: new_id }); } - // No open review. A previously rejected identity must not be re-raised. + // A previously rejected identity must not be re-raised. if sql::rejected_before_in(tx, pkgbase_id, &nc.identity_hash)? { return Ok(Upsert::PreviouslyRejected); } - // Same identity already approved/recorded: nothing to do. if sql::recorded_before_in(tx, pkgbase_id, &nc.identity_hash)? { return Ok(Upsert::Unchanged); } @@ -73,7 +59,6 @@ pub fn upsert_candidate(db: &Db, pb: &Pkgbase, accepted: Option<&ReleaseRow>, nc }) } -/// Convenience used by the watcher: the accepted release of a pkgbase row. 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), diff --git a/src/review/diff.rs b/src/review/diff.rs index 3eecc4e..519d9ae 100644 --- a/src/review/diff.rs +++ b/src/review/diff.rs @@ -1,10 +1,3 @@ -//! Diff rendering (§6). -//! -//! A review is not one diff, it is a panel set, and **every** panel compares what -//! the accepted release recorded against what the candidate records now — never -//! "last seen". The rendered text is hashed into `diff_digest`, which is what -//! makes "we build exactly what was displayed, or nothing" (§7.1a) provable. - use crate::config::Config; use crate::db::{self, *}; use crate::error::Result; diff --git a/src/review/mod.rs b/src/review/mod.rs index c8b2f50..eb78b3a 100644 --- a/src/review/mod.rs +++ b/src/review/mod.rs @@ -1,6 +1,3 @@ -//! Review lifecycle: candidate creation and collapse-in-place (§7.1), the -//! approval record (§7.2), diffing (§6) and risk scoring (§6). - pub mod approve; pub mod candidates; pub mod diff; diff --git a/src/review/risk.rs b/src/review/risk.rs index cf7069d..3b483cf 100644 --- a/src/review/risk.rs +++ b/src/review/risk.rs @@ -1,15 +1,3 @@ -//! Advisory risk scoring (§6). -//! -//! The reviewer's attention is the scarcest resource in this system, so every -//! candidate gets a computed level that orders and colours the inbox. It is -//! **advisory only**: there is no auto-approval in v1 (§7.3), so nothing is -//! gated on a score and no heuristic can let something through. A wrong score -//! costs attention, never safety. -//! -//! Every signal is computed from what the accepted release recorded against -//! 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}; use crate::error::Result; use crate::pkgver; |
