summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 15:48:02 +0000
committeraur-build <aur-build@localhost>2026-11-18 15:48:02 +0000
commit062efa6583b7fea292a4f485659661d266461611 (patch)
treea9a54bba0dad9fbd07115f5bfad8db948ab6b30e /tests
parent753e05a4f588d3e8a3ea0b88b2e03d74f9f00be8 (diff)
downloadaur-build-062efa6583b7fea292a4f485659661d266461611.tar.gz
aur-build-062efa6583b7fea292a4f485659661d266461611.zip
review: a database failure is never reported to a reviewer as a stale review
`approve()` returned `Result<Approval, Stale>` and then collapsed every inner failure into `Stale::NotPending { state: e.to_string() }`, so a SQLite error reached the human as "review is no longer pending (state: sqlite: …)". That is the one message that tells a reviewer to look again when the truth is that the write failed — and the transaction had already rolled back, so their review was still pending and nothing on screen explained why. `bulk()` bent the same variant to mean "high risk", "unknown decision" and "the database failed", and handed back a fabricated `Approval { id: 0 }` for a rejection that recorded no approval at all. `approve()` now returns `Result<Approval, ApproveError>` with two families: `Stale(Stale)` — what is stored is not what was displayed, look again — and `System(Error)` — the write failed, nothing about the review is at fault. The UI answers the first with the 409 and fresh diff it already gave, and the second with a 500 that names the cause; the CLI exits 2 for the first and propagates the second as an error. `bulk()` got its own vocabulary — `BulkOutcome::{Approved, Rejected, Refused(BulkRefusal)}` with `HighRiskUnconfirmed`, `UnknownDecision`, `NotFound`, `Stale` and `System` — and returns no approval row for a rejection, because there is none. The invented `id: 0` is gone. The web handler had its own copy of the bulk loop; it now calls `approve::bulk`, so the page and the library cannot disagree about what §7.4 says. Three tests: a dropped `audit` table mid-transaction must surface as `System` and must leave the review pending and the approval table empty; bulk refusals must name the risk, the unknown decision, and (after a real approval) the genuine staleness as three different things; a bulk rejection must record a `rejected` row and hand back nothing.
Diffstat (limited to 'tests')
-rw-r--r--tests/approve.rs77
1 files changed, 72 insertions, 5 deletions
diff --git a/tests/approve.rs b/tests/approve.rs
index 5a515eb..61e42c2 100644
--- a/tests/approve.rs
+++ b/tests/approve.rs
@@ -75,7 +75,7 @@ fn a_stale_identity_hash_is_refused() {
assert_ne!(now.identity_hash, c.identity_hash, "identity should have moved");
let err = approve(&env.db, "tester", c.id, &c.identity_hash, &dd, None).unwrap_err();
- assert!(matches!(err, Stale::Identity { .. }), "{err:?}");
+ assert!(matches!(err, ApproveError::Stale(Stale::Identity { .. })), "{err:?}");
assert_eq!(
env.query_i64("SELECT count(*) FROM approval", &[]),
Some(0),
@@ -92,7 +92,7 @@ fn a_stale_diff_digest_is_refused() {
let (env, _fx) = env_with_fixture("plain-make");
let (c, dd) = open_review(&env, "plain-make");
let err = approve(&env.db, "tester", c.id, &c.identity_hash, "sha256:whatever", None).unwrap_err();
- assert!(matches!(err, Stale::Diff { .. }), "{err:?}");
+ assert!(matches!(err, ApproveError::Stale(Stale::Diff { .. })), "{err:?}");
assert_eq!(env.query_i64("SELECT count(*) FROM approval", &[]), Some(0));
let _ = dd;
}
@@ -103,11 +103,78 @@ fn approving_twice_is_refused_not_duplicated() {
let (c, dd) = open_review(&env, "plain-make");
approve(&env.db, "tester", c.id, &c.identity_hash, &dd, None).unwrap();
let err = approve(&env.db, "tester", c.id, &c.identity_hash, &dd, None).unwrap_err();
- assert!(matches!(err, Stale::NotPending { .. }), "{err:?}");
+ assert!(matches!(err, ApproveError::Stale(Stale::NotPending { .. })), "{err:?}");
assert_eq!(env.query_i64("SELECT count(*) FROM approval", &[]), Some(1));
}
#[test]
+fn a_broken_database_is_not_reported_as_a_stale_review() {
+ // What this pins: every failure inside the approval transaction used to be
+ // mapped into `Stale::NotPending`, so a SQLite error reached the reviewer as
+ // "review is no longer pending (state: sqlite: …)" — the one message that
+ // tells them to look again when the truth is that the write failed (§6 M-3).
+ let (env, _fx) = env_with_fixture("plain-make");
+ let (c, dd) = open_review(&env, "plain-make");
+ // Make the write impossible halfway through the transaction: the approval
+ // row and the candidate update succeed, then the audit append has nowhere
+ // to go.
+ env.exec("DROP TABLE audit", &[]);
+ let err = approve(&env.db, "tester", c.id, &c.identity_hash, &dd, None).unwrap_err();
+ assert!(matches!(err, ApproveError::System(_)), "a broken database was reported as a stale review: {err:?}");
+ assert!(err.to_string().contains("could not be recorded"), "the message hides the cause: {err}");
+ // And the refusal is atomic: the half-written approval rolled back with it.
+ assert_eq!(env.query_i64("SELECT count(*) FROM approval", &[]), Some(0));
+ let after = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap();
+ assert_eq!(after.state, "pending_review", "a failed approval must not resolve the review");
+}
+
+#[test]
+fn bulk_refusals_are_their_own_reasons() {
+ // Bulk used to bend `Stale::NotPending` into "high risk", "unknown decision"
+ // and "the database failed", and to hand back a fabricated `Approval { id: 0 }`
+ // for a rejection that recorded no approval at all (§6 M-3).
+ let (env, _fx) = env_with_fixture("plain-make");
+ let (c, dd) = open_review(&env, "plain-make");
+ candidates::set_risk(&env.db, c.id, "high", &["new source host".into()]).unwrap();
+ let items = [(c.id, c.identity_hash.clone(), dd.clone())];
+
+ // High risk without the individual confirmation: the reason is the risk.
+ let out = bulk(&env.db, "tester", &items, "approve", &[]).unwrap();
+ assert!(
+ matches!(out[0].outcome, BulkOutcome::Refused(BulkRefusal::HighRiskUnconfirmed)),
+ "{:?}",
+ out[0].outcome
+ );
+ // A decision the form should never have sent is its own reason.
+ let out = bulk(&env.db, "tester", &items, "ship-it", &[]).unwrap();
+ assert!(
+ matches!(out[0].outcome, BulkOutcome::Refused(BulkRefusal::UnknownDecision(_))),
+ "{:?}",
+ out[0].outcome
+ );
+ // Confirming it individually is the answer to the first refusal.
+ let out = bulk(&env.db, "tester", &items, "approve", &[c.id]).unwrap();
+ assert!(matches!(out[0].outcome, BulkOutcome::Approved(_)), "{:?}", out[0].outcome);
+ // Now it is no longer pending, and *that* is a staleness — the two reasons
+ // stay distinguishable in both directions.
+ let out = bulk(&env.db, "tester", &items, "approve", &[c.id]).unwrap();
+ assert!(matches!(out[0].outcome, BulkOutcome::Refused(BulkRefusal::Stale(_))), "{:?}", out[0].outcome);
+ assert_eq!(env.query_i64("SELECT count(*) FROM approval", &[]), Some(1));
+}
+
+#[test]
+fn a_bulk_rejection_hands_back_no_invented_approval() {
+ let (env, _fx) = env_with_fixture("plain-make");
+ let (c, dd) = open_review(&env, "plain-make");
+ let out = bulk(&env.db, "tester", &[(c.id, c.identity_hash.clone(), dd)], "reject", &[]).unwrap();
+ assert!(matches!(out[0].outcome, BulkOutcome::Rejected), "{:?}", out[0].outcome);
+ // A rejection records a `rejected` row; there is no approval to return, and
+ // the old `Approval { id: 0 }` sentinel is gone.
+ assert_eq!(env.query_i64("SELECT count(*) FROM approval WHERE decision='rejected'", &[]), Some(1));
+ assert_eq!(env.query_i64("SELECT count(*) FROM approval WHERE decision='approved'", &[]), Some(0));
+}
+
+#[test]
fn collapse_in_place_bumps_revision_without_a_new_row() {
let (env, fx) = env_with_fixture("plain-make");
let (c, _dd) = open_review(&env, "plain-make");
@@ -145,7 +212,7 @@ fn once_viewed_a_new_state_freezes_the_old_one_as_superseded() {
// The frozen one can no longer be approved: approving it would build a
// version nobody is looking at.
let err = approve(&env.db, "tester", c.id, &frozen.identity_hash, &frozen.diff_digest, None).unwrap_err();
- assert!(matches!(err, Stale::NotPending { .. }), "{err:?}");
+ assert!(matches!(err, ApproveError::Stale(Stale::NotPending { .. })), "{err:?}");
}
#[test]
@@ -158,7 +225,7 @@ fn a_rejected_identity_is_not_re_raised() {
assert!(candidates::pending_candidates(&env.db).unwrap().is_empty());
// A different identity is a different question, and gets its own review.
let err = approve(&env.db, "tester", c.id, &c.identity_hash, &c.diff_digest, None).unwrap_err();
- assert!(matches!(err, Stale::NotPending { .. }));
+ assert!(matches!(err, ApproveError::Stale(Stale::NotPending { .. })));
}
#[test]