summaryrefslogtreecommitdiffstats
path: root/tests/approve.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/approve.rs')
-rw-r--r--tests/approve.rs39
1 files changed, 0 insertions, 39 deletions
diff --git a/tests/approve.rs b/tests/approve.rs
index 86dcf46..15a205a 100644
--- a/tests/approve.rs
+++ b/tests/approve.rs
@@ -4,8 +4,6 @@ use aur_build::db::model::*;
use aur_build::review::{approve::Stale, approve::*, candidates, diff};
use common::*;
-/// Detect, open the review, and render it the way a reviewer opening the page
-/// would — returning the candidate plus the two hashes an approval must echo.
fn open_review(env: &Env, name: &str) -> (CandidateRow, String) {
aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, name).unwrap();
let c = candidates::pending_candidates(&env.db).unwrap().remove(0);
@@ -21,8 +19,6 @@ fn approve_writes_an_immutable_row_carrying_both_hashes() {
assert_eq!(a.decision, "approved");
assert_eq!(a.identity_hash, c.identity_hash);
assert_eq!(a.diff_digest, dd);
- // The row itself records them, so "the human approved *this* diff" is
- // provable later (§7.2).
let stored: (String, String, Option<String>) = env
.db
.read(|c| {
@@ -35,7 +31,6 @@ fn approve_writes_an_immutable_row_carrying_both_hashes() {
.unwrap();
assert_eq!(stored.0, c.identity_hash);
assert_eq!(stored.1, dd);
- // Approvals are append-only: the audit trigger rejects any edit (§10 I10).
let err = env
.db
.writer
@@ -45,7 +40,6 @@ fn approve_writes_an_immutable_row_carrying_both_hashes() {
})
.err();
assert!(err.is_some(), "approval rows must be immutable");
- // And the human action is in the audit log.
let actions: Vec<String> = env
.db
.read(|c| {
@@ -61,8 +55,6 @@ fn approve_writes_an_immutable_row_carrying_both_hashes() {
fn a_stale_identity_hash_is_refused() {
let (env, fx) = env_with_fixture("plain-make");
let (c, dd) = open_review(&env, "plain-make");
- // AUR moves while the reviewer is reading: the candidate collapses in place
- // and its identity changes under them.
fx.bump(&[("pkgver", "2.0")]);
aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, "plain-make").unwrap();
let now = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap();
@@ -75,8 +67,6 @@ fn a_stale_identity_hash_is_refused() {
Some(0),
"a refused approval must leave nothing behind"
);
- // Approving with the *current* identity succeeds: the reviewer just has to
- // look at what is on screen now.
let dd2 = diff::render_and_store(&env.db, &env.cfg, &now).unwrap();
approve(&env.db, "tester", c.id, &now.identity_hash, &dd2, None).unwrap();
}
@@ -103,19 +93,12 @@ fn approving_twice_is_refused_not_duplicated() {
#[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" — the one message telling 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 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, CandidateState::PendingReview, "a failed approval must not resolve the review");
@@ -123,32 +106,25 @@ fn a_broken_database_is_not_reported_as_a_stale_review() {
#[test]
fn bulk_refusals_are_their_own_reasons() {
- // Bulk used to bend `Stale::NotPending` into "high risk", "unknown decision"
- // and "the database failed" (§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));
@@ -160,7 +136,6 @@ fn a_bulk_rejection_hands_back_no_invented_approval() {
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.
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));
}
@@ -172,8 +147,6 @@ fn collapse_in_place_bumps_revision_without_a_new_row() {
let first = c.revision;
assert!(c.viewed_at.is_none(), "render_and_store must not mark it viewed");
- // Nobody has looked at it: the new upstream state collapses *into* the open
- // review instead of queueing beside it (§7.1).
fx.bump(&[("pkgver", "2.0")]);
aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, "plain-make").unwrap();
let after = candidates::pending_candidates(&env.db).unwrap();
@@ -200,8 +173,6 @@ fn once_viewed_a_new_state_freezes_the_old_one_as_superseded() {
assert_ne!(open[0].id, c.id, "a fresh review was opened");
let frozen = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap();
assert_eq!(frozen.state, CandidateState::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, ApproveError::Stale(Stale::NotPending { .. })), "{err:?}");
}
@@ -211,10 +182,8 @@ fn a_rejected_identity_is_not_re_raised() {
let (env, _fx) = env_with_fixture("plain-make");
let (c, _dd) = open_review(&env, "plain-make");
reject(&env.db, "tester", c.id, "not this").unwrap();
- // Same upstream state, polled again: nothing new to review.
aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, "plain-make").unwrap();
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, ApproveError::Stale(Stale::NotPending { .. })));
}
@@ -237,7 +206,6 @@ fn reject_requires_a_reason_and_records_it() {
.unwrap();
assert!(note.contains("license"), "{note}");
- // And the audit row says *which review* was rejected, not only why (§6 m-4).
let (actor_kind, detail): (String, String) = env
.db
.read(|c| {
@@ -257,8 +225,6 @@ fn reject_requires_a_reason_and_records_it() {
// ------------------------------------------------------------- the CLI path --
-/// Drive the real binary the way an operator would: `init`, `subscribe`,
-/// `detect`, `show`, `approve --yes`.
#[test]
fn cli_end_to_end_approves_and_queues_a_build() {
let tmp = tempfile::tempdir().unwrap();
@@ -280,8 +246,6 @@ fn cli_end_to_end_approves_and_queues_a_build() {
let out = cli(bin, &root, &["reviews"]);
assert!(out.stdout.contains("#1"), "reviews: {}", out.stdout);
- // `show` renders the panels and the hashes; `approve` without --yes refuses to
- // act.
let out = cli(bin, &root, &["show", "1"]);
assert!(out.stdout.contains("identity_hash"), "show: {}", out.stdout);
let shown = out.stdout.clone();
@@ -298,7 +262,6 @@ fn cli_end_to_end_approves_and_queues_a_build() {
assert_eq!(cli_count(&root, "build"), 1);
assert!(shown.contains("PKGBUILD") || shown.contains("pkgver"), "diff pane: {shown}");
- // Approving the same review again is refused with a non-zero status.
let out = cli(bin, &root, &["approve", "1", "--yes"]);
assert_eq!(out.code, Some(2), "stale approval should exit 2: {:?}", out);
}
@@ -342,13 +305,11 @@ fn cli(bin: &str, root: &std::path::Path, args: &[&str]) -> Out {
}
}
-/// A local git repo standing in for AUR, so the CLI test needs no network.
fn cli_fixture(root: &std::path::Path, name: &str) -> (std::path::PathBuf, Fixture) {
let fx = materialize_fixture(root, name);
(fx.aur.clone(), fx)
}
-/// Query the CLI's own database through a throwaway read connection.
fn cli_count(root: &std::path::Path, table: &str) -> i64 {
let conn = rusqlite::Connection::open_with_flags(
root.join("aur-build.db"),