diff options
| author | aur-build <aur-build@localhost> | 2026-11-18 16:49:40 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-18 16:49:40 +0000 |
| commit | 41fa1684de8eb13c5b76c3a3e174fece04ac5afa (patch) | |
| tree | 491a2faf2dd2314f537300ccaf1e0150b54d1123 /src/http | |
| parent | 101f077200e80c7869e4549db645ed94b01acb1b (diff) | |
| download | aur-build-41fa1684de8eb13c5b76c3a3e174fece04ac5afa.tar.gz aur-build-41fa1684de8eb13c5b76c3a3e174fece04ac5afa.zip | |
db: the review, step, release and subscription states are enums too
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.
Diffstat (limited to 'src/http')
| -rw-r--r-- | src/http/routes.rs | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/http/routes.rs b/src/http/routes.rs index 926d2a8..288f002 100644 --- a/src/http/routes.rs +++ b/src/http/routes.rs @@ -170,7 +170,7 @@ fn dashboard(state: &State, req: &Req) -> Res { Some(PublishRow { name: pb.name, version: r.version(), - published_at: r.published_at.unwrap_or_else(|| r.state.clone()), + published_at: r.published_at.unwrap_or_else(|| r.state.to_string()), aur_commit: r.aur_commit.clone(), aur_commit_short: short(&r.aur_commit), }) @@ -530,13 +530,13 @@ fn subscriptions(state: &State, req: &Req) -> Res { .map(|s| SubRow { pending: pending.iter().filter(|c| c.pkgbase == s.pkgbase).count() as i64, name: s.pkgbase.clone(), - state: s.state.clone(), + state: s.state.to_string(), maintainer: s.maintainer.unwrap_or_else(|| "unknown".into()), last_checked: s.last_checked_at.unwrap_or_else(|| "never".into()), next_check: s.next_check_at.unwrap_or_else(|| "soon".into()), last_error: s.last_error.clone().unwrap_or_default(), has_error: s.last_error.is_some(), - pause_label: if s.state == subscription_state::PAUSED { "resume" } else { "pause" }, + pause_label: if s.state == SubscriptionState::Paused { "resume" } else { "pause" }, }) .collect(); page_to_res(Subscriptions { page, rows }, 200) @@ -561,8 +561,16 @@ fn sub_add(state: &State, req: &Req) -> Res { fn sub_pause(state: &State, req: &Req) -> Res { let db = &state.db; let name = req.form_get("pkgbase").unwrap_or_default(); - let cur = db::get_subscription(db, &name).ok().flatten().map(|s| s.state).unwrap_or_default(); - let next = if cur == subscription_state::PAUSED { subscription_state::ACTIVE } else { subscription_state::PAUSED }; + let cur = db::get_subscription(db, &name).ok().flatten().map(|s| s.state); + // Pause and resume are the only moves this page makes. A subscription that + // is orphaned or removed is not the reviewer's to pause, and saying so beats + // quietly rewriting its state. + let next = match cur { + Some(SubscriptionState::Active) => SubscriptionState::Paused, + Some(SubscriptionState::Paused) => SubscriptionState::Active, + Some(other) => return flash_sub(state, req, &format!("{name} is {other}: nothing to pause"), true), + None => return flash_sub(state, req, &format!("no subscription for {name}"), true), + }; let _ = db::set_subscription_state(&db.writer, &name, next); flash_sub(state, req, &format!("{name}: {next}"), false) } @@ -570,7 +578,7 @@ fn sub_pause(state: &State, req: &Req) -> Res { fn sub_remove(state: &State, req: &Req) -> Res { let db = &state.db; let name = req.form_get("pkgbase").unwrap_or_default(); - let _ = db::set_subscription_state(&db.writer, &name, subscription_state::REMOVED); + let _ = db::set_subscription_state(&db.writer, &name, SubscriptionState::Removed); flash_sub(state, req, &format!("{name}: removed"), false) } @@ -583,13 +591,13 @@ fn flash_sub(state: &State, req: &Req, msg: &str, err: bool) -> Res { .map(|s| SubRow { pending: pending.iter().filter(|c| c.pkgbase == s.pkgbase).count() as i64, name: s.pkgbase.clone(), - state: s.state.clone(), + state: s.state.to_string(), maintainer: s.maintainer.unwrap_or_else(|| "unknown".into()), last_checked: s.last_checked_at.unwrap_or_else(|| "never".into()), next_check: s.next_check_at.unwrap_or_else(|| "soon".into()), last_error: s.last_error.clone().unwrap_or_default(), has_error: s.last_error.is_some(), - pause_label: if s.state == subscription_state::PAUSED { "resume" } else { "pause" }, + pause_label: if s.state == SubscriptionState::Paused { "resume" } else { "pause" }, }) .collect(); page_to_res(Subscriptions { page, rows }, 200) @@ -702,7 +710,7 @@ fn package_detail(state: &State, req: &Req, name: &str) -> Res { .into_iter() .map(|r| TimelineRow { version: r.version(), - state: r.state.clone(), + state: r.state.to_string(), aur_commit: r.aur_commit.clone(), aur_commit_short: short(&r.aur_commit), published_at: r.published_at.unwrap_or_else(|| "—".into()), @@ -906,10 +914,10 @@ fn build_detail(state: &State, req: &Req, id: &str) -> Res { .unwrap_or_default() .into_iter() .map(|s| { - let cls = if s.status == "failed" { "risk-high" } else { "mut" }.to_string(); + let cls = if s.status == StepState::Failed { "risk-high" } else { "mut" }.to_string(); StepRow { step: s.step, - status: s.status, + status: s.status.to_string(), attempt: s.attempt, digest: String::new(), cls, |
