//! The ยง13 surfaces driven by live state, not fixtures of HTML: Attention must //! name outdated dependencies, downgrades and blocked builds; the package page //! must answer "what does this depend on and what depends on it"; and a manual //! rebuild must reuse the approved source identity without asking again (I6). mod common; use aur_build::db::{self, builds, model::*}; use aur_build::pipeline; use aur_build::review::candidates; use common::*; #[test] fn attention_lists_a_downgrade_when_aur_moves_below_what_we_serve() { let web = Web::new("plain-make"); web.publish("plain-make"); assert!(!web.get("/attention").body.contains("Downgrades"), "nothing is stale yet"); // The maintainer reverts their version bump. We still serve the higher one. web.fx.bump(&[("pkgver", "0.9")]); aur_build::watch::detect::check_pkgbase(&web.env.cfg, &web.env.db, "plain-make").unwrap(); let page = web.get("/attention"); assert_eq!(page.status, 200); assert!(page.body.contains("Downgrade"), "no downgrade section: {}", &page.body[..400.min(page.body.len())]); assert!(page.body.contains("0.9"), "the offered version is not shown"); assert!(page.body.contains("1.0"), "the served version is not shown"); } #[test] fn attention_lists_outdated_dependencies_from_the_recorded_world() { let (env, plain, client) = env_with_two_fixtures("plain-make", "dep-client"); let web = Web::attach(env, client); web.publish("plain-make"); web.publish("dep-client"); assert!( !web.get("/attention").body.contains("Outdated:"), "dep-client is fresh right after both were published" ); // plain-make moves; dep-client was built against the old one. plain.bump(&[("pkgver", "2.0")]); web.publish("plain-make"); let page = web.get("/attention"); assert!(page.body.contains("Outdated:"), "no outdated section: {}", &page.body[..600.min(page.body.len())]); assert!(page.body.contains("dep-client"), "the stale package is not named"); assert!(page.body.contains("plain-make"), "the dependency is not named"); assert!(page.body.contains("1.0") && page.body.contains("2.0"), "the built-against/now pair is missing"); } #[test] fn the_package_page_answers_dependencies_and_staleness() { let (env, plain, client) = env_with_two_fixtures("plain-make", "dep-client"); let web = Web::attach(env, client); web.publish("plain-make"); web.publish("dep-client"); plain.bump(&[("pkgver", "2.0")]); web.publish("plain-make"); let page = web.get("/packages/dep-client"); assert_eq!(page.status, 200); assert!(page.body.contains("Depends on"), "no depends block"); assert!(page.body.contains("plain-make"), "the dependency is not listed"); assert!(page.body.contains("Stale"), "staleness is not shown on the package page"); // And from the other side: what would a change to plain-make disturb? let other = web.get("/packages/plain-make"); assert!(other.body.contains("Needed by"), "no needed-by block"); assert!(other.body.contains("dep-client"), "the dependent is not listed"); // The timeline is the aur_commit history: one row per release, each linking // into AUR's cgit at that exact commit. assert!(other.body.contains("aur.archlinux.org/cgit/aur.git/tree/?h=plain-make&id="), "no per-release cgit link"); assert!(other.body.contains("serving 2.0"), "the summary does not say what is served"); } #[test] fn a_manual_rebuild_reuses_the_approved_identity_without_a_new_approval() { // I6: rebuilding what is already approved is not a new decision. It must // not create an approval, and it must not need one. let web = Web::new("plain-make"); web.publish("plain-make"); let approvals_before = web.env.query_i64("SELECT count(*) FROM approval", &[]).unwrap(); assert_eq!(approvals_before, 1); let res = web.post("/packages/plain-make/rebuild", &[("csrf", &web.csrf)]); assert_eq!(res.status, 200, "rebuild should be accepted: {}", &res.body[..200.min(res.body.len())]); assert!(res.body.contains("no new approval"), "the confirmation does not say why no approval is needed"); assert_eq!( web.env.query_i64("SELECT count(*) FROM approval", &[]).unwrap(), approvals_before, "a manual rebuild must not mint an approval" ); let queued = web .env .query_i64("SELECT count(*) FROM build WHERE kind='manual_rebuild'", &[]) .unwrap(); assert_eq!(queued, 1, "the rebuild was not queued"); // Run it: it publishes the same version, still on the one approval. let id: String = web .env .db .read(|c| { use rusqlite::OptionalExtension; c.query_row( "SELECT id FROM build WHERE kind='manual_rebuild'", [], |r| r.get::<_, String>(0), ) .optional() .map_err(Into::into) }) .unwrap() .unwrap(); pipeline::run(&web.env.cfg, &web.env.db, &id).unwrap(); let b = builds::get(&web.env.db, &id).unwrap().unwrap(); assert_eq!(b.state, BuildState::Succeeded, "rebuild failed: {:?}", b.error); assert_eq!( web.env.query_i64("SELECT count(*) FROM approval", &[]).unwrap(), approvals_before, "running a rebuild must not mint an approval either" ); assert_eq!(db::index_version(&web.env.db, "plain-make").unwrap().as_deref(), Some("1.0-1")); } #[test] fn the_builds_page_names_the_version_and_the_audit_page_records_the_decision() { let web = Web::new("plain-make"); web.publish("plain-make"); let page = web.get("/builds"); assert_eq!(page.status, 200); assert!(page.body.contains("plain-make"), "the build row has no pkgbase"); assert!(page.body.contains("1.0-1"), "the build row has no version: {}", &page.body[..600.min(page.body.len())]); assert!(page.body.contains("succeeded") || page.body.contains("Succeeded"), "the finished build is not shown"); let audit = web.get("/audit"); assert!(audit.body.contains("approve"), "the approval is not in the audit log"); assert!(audit.body.contains("test") || audit.body.contains("cli"), "no actor recorded"); } #[test] fn the_subscriptions_page_shows_state_and_last_check() { let web = Web::new("plain-make"); web.publish("plain-make"); let page = web.get("/subscriptions"); assert_eq!(page.status, 200); assert!(page.body.contains("plain-make"), "the subscription is not listed"); assert!(page.body.contains("active"), "no state shown"); // Pause and remove are per-subscription POSTs, not links that mutate. assert!(page.body.contains("action=\"/subscriptions/pause\""), "no pause form"); assert!(page.body.contains("action=\"/subscriptions/remove\""), "no remove form"); } #[test] fn pausing_a_subscription_stops_detection_and_resuming_starts_it_again() { let web = Web::new("plain-make"); web.post("/subscriptions/pause", &[("csrf", &web.csrf), ("pkgbase", "plain-make")]); assert_eq!( web.env.query_i64("SELECT count(*) FROM subscription WHERE state='paused'", &[]), Some(1), "pause did not take" ); // A paused pkgbase is not re-detected even when upstream moves. web.fx.bump(&[("pkgver", "3.0")]); let report = aur_build::watch::detect::check_pkgbase(&web.env.cfg, &web.env.db, "plain-make").unwrap(); assert!(matches!(report.outcome, aur_build::watch::detect::Outcome::Paused), "a paused subscription was still inspected"); assert_eq!( candidates::pending_candidates(&web.env.db).unwrap().len(), 0, "a paused subscription produced a candidate" ); web.post("/subscriptions/pause", &[("csrf", &web.csrf), ("pkgbase", "plain-make")]); aur_build::watch::detect::check_pkgbase(&web.env.cfg, &web.env.db, "plain-make").unwrap(); assert_eq!(candidates::pending_candidates(&web.env.db).unwrap().len(), 1, "resuming did not restore detection"); }