From 41fa1684de8eb13c5b76c3a3e174fece04ac5afa Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 16:49:40 +0000 Subject: db: the review, step, release and subscription states are enums too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit M-8 named four more machines after `build_state`, and each had the same defect in miniature: `&str` constants, a writer that took any `&str`, and a rule that lived only in the caller's discipline. They are `CandidateState`, `StepState`, `ReleaseState` and `SubscriptionState` now, all parsed through one `db::state_col` at the row boundary — a column value the code cannot name fails the read rather than becoming a state it did not ask for. The one that mattered is the review machine. `resolve_in(tx, id, &str)` would move a candidate to any state from any state, so an approval racing a rejection, or a stale worker resolving a review that had already been superseded, silently overwrote what a human had decided — the direct route to breaking I2 and I3 with no symptom anywhere. It is a compare-and-swap on `CandidateState` now: a decided review is only ever frozen, never re-decided, and a refusal names both states. `supersede_in` goes through it, so the freeze cannot resurrect a superseded review either. `StepState` gives I5 teeth. `begin_step` upserted over any existing checkpoint, including one recorded `succeeded`, so a resume that asked to re-run a finished step could rewrite the very row that told it to skip; the upsert now refuses to touch a done checkpoint and `finish_step` is a CAS. The blocked path (`running → pending`) and the reaper's `running → interrupted` are unchanged, and both are in the table. Two behaviour changes, both for the better and both tested: the UI's pause button now says "orphaned: nothing to pause" instead of rewriting an orphaned subscription back to a pausable state, and a step checkpoint that is already done makes `begin_step` an error rather than a quiet overwrite. Five tests in `tests/state_machine.rs` cover the review CAS in both directions, the frozen checkpoint, the interrupted/blocked transitions, and the unknown value in a candidate and a step row. --- src/review/approve.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/review/approve.rs') diff --git a/src/review/approve.rs b/src/review/approve.rs index a76eeac..208e8e2 100644 --- a/src/review/approve.rs +++ b/src/review/approve.rs @@ -5,7 +5,7 @@ //! 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, candidate_state, candidates, *}; +use crate::db::{self, approvals, candidates, CandidateState, *}; use crate::error::{Error, Result}; use crate::time; @@ -78,8 +78,8 @@ pub fn approve( let current_base = subject.current_base_release_id; // 1. still open - if subject.state != candidate_state::PENDING { - return Ok(Err(ApproveError::Stale(Stale::NotPending { state: subject.state }))); + 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 { @@ -107,7 +107,7 @@ pub fn approve( note: note.as_deref(), }, )?; - candidates::resolve_in(tx, id, candidate_state::APPROVED, &at)?; + candidates::resolve_in(tx, id, CandidateState::Approved, &at)?; db::audit_in( tx, &db::AuditEntry { @@ -142,13 +142,13 @@ pub fn reject(db: &Db, actor: &str, candidate_id: i64, note: &str) -> Result<()> db.writer.tx(move |tx| { let state = candidates::state_in(tx, candidate_id)? .ok_or_else(|| Error::not_found(format!("candidate {candidate_id}")))?; - if state != candidate_state::PENDING { + if !state.is_open() { return Err(Error::conflict(format!("candidate is {state}, not pending"))); } let identity = candidates::identity_in(tx, candidate_id)? .ok_or_else(|| Error::not_found(format!("candidate {candidate_id}")))?; approvals::record_rejection_in(tx, candidate_id, &at, &identity, ¬e)?; - candidates::resolve_in(tx, candidate_id, candidate_state::REJECTED, &at)?; + candidates::resolve_in(tx, candidate_id, CandidateState::Rejected, &at)?; db::audit_in( tx, &db::AuditEntry { -- cgit v1.2.3