1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
mod common;
use aur_build::db::{builds, model::*};
use aur_build::pipeline;
use aur_build::review::{candidates, diff};
use aur_build::watch::staleness;
use common::*;
fn approved(env: &Env, name: &str) -> CandidateRow {
aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, name).unwrap();
let c = candidates::pending_candidates(&env.db).unwrap().remove(0);
let dd = diff::render_and_store(&env.db, &env.cfg, &c).unwrap();
let c = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap();
aur_build::review::approve::approve(&env.db, "t", c.id, &c.identity_hash, &dd, None).unwrap();
candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap()
}
fn publish(env: &Env, name: &str) {
let c = approved(env, name);
let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap();
pipeline::run(&env.cfg, &env.db, &id).unwrap();
}
#[test]
fn staleness_is_derived_on_read_and_nothing_stores_it() {
let (env, plain, client) = env_with_two_fixtures("plain-make", "dep-client");
publish(&env, "plain-make");
publish(&env, "dep-client");
assert!(staleness::stale_rows(&env.db).unwrap().is_empty(), "both were just published");
plain.bump(&[("pkgver", "2.0")]);
publish(&env, "plain-make");
let stale = staleness::stale_rows(&env.db).unwrap();
assert_eq!(stale.len(), 1, "dep-client should be stale: {stale:?}");
assert_eq!(stale[0].pkgbase, "dep-client");
assert_eq!(stale[0].dependency, "plain-make");
assert_eq!(stale[0].built_with, "1.0-1");
assert_eq!(stale[0].now, "2.0-1");
// "Derived purely on read" means there is nowhere for a stale answer to hide.
let cols: Vec<String> = env
.db
.read(|c| {
let mut st = c.prepare(
"SELECT m.name || '.' || p.name FROM sqlite_master m, pragma_table_info(m.name) p
WHERE m.type='table' AND p.name LIKE '%stale%'",
)?;
let out = st.query_map([], |r| r.get::<_, String>(0))?.filter_map(|x| x.ok()).collect();
Ok(out)
})
.unwrap();
assert!(cols.is_empty(), "staleness must not be persisted anywhere: {cols:?}");
// The answer tracks the index, not any stored flag: withdrawing plain-make
// changes what is true about dep-client without touching it.
pipeline::publish::withdraw_package(&env.cfg, &env.db, "plain-make").unwrap();
let after = staleness::stale_rows(&env.db).unwrap();
assert!(
after.iter().any(|s| s.pkgbase == "dep-client" && s.kind == staleness::Kind::Missing),
"withdrawing the dependency should flip the answer to missing: {after:?}"
);
// And nothing about dep-client was written to make that happen.
assert_eq!(
env.query_i64("SELECT count(*) FROM release WHERE pkgbase_id=(SELECT id FROM pkgbase WHERE name='dep-client')", &[]),
Some(1),
"the dependent was untouched by its dependency moving"
);
let _ = client;
}
#[test]
fn a_missing_dependency_blocks_the_build_and_names_the_blocker_everywhere() {
let (env, fx, _partner) = env_with_two_fixtures("missing-dep", "dep-partner");
// dep-partner is a package we intend to publish but have not yet: the build
// cannot run, and that is a fact to report (§10.4).
let c = approved(&env, "missing-dep");
assert_eq!(c.missing_deps(), vec!["dep-partner".to_string()], "the review must warn before approving");
let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap();
let out = pipeline::run(&env.cfg, &env.db, &id).unwrap();
assert!(matches!(out, pipeline::Outcome::Blocked { .. }), "{out:?}");
let b = builds::get(&env.db, &id).unwrap().unwrap();
assert_eq!(b.state, BuildState::BlockedMissingDep);
let blocked_on: Vec<String> = serde_json::from_str(&b.blocked_on_json).unwrap();
assert_eq!(blocked_on, vec!["dep-partner".to_string()]);
// Blocked is not failed: nothing went wrong with the build itself.
assert_eq!(env.query_i64("SELECT count(*) FROM build WHERE state='failed'", &[]), Some(0));
// It shows on Attention with the blocker named, not just "something is wrong".
let web = Web::attach(env, fx);
let page = web.get("/attention");
assert!(page.body.contains("Blocked builds"), "no blocked section: {}", &page.body[..600.min(page.body.len())]);
assert!(page.body.contains("dep-partner"), "the blocking pkgbase is not named");
assert!(page.body.contains("missing-dep"), "the blocked package is not named");
}
#[test]
fn a_blocked_build_waits_and_is_requeued_only_when_the_blocker_arrives() {
let (env, fx, _partner) = env_with_two_fixtures("missing-dep", "dep-partner");
let c = approved(&env, "missing-dep");
let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap();
let _ = fx;
pipeline::run(&env.cfg, &env.db, &id).unwrap();
assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, BuildState::BlockedMissingDep);
// The dispatcher sweeps blocked builds every pass. Requeueing one that will
// immediately block again is a busy loop, so it must stay put.
assert_eq!(builds::requeue_blocked(&env.db).unwrap(), 0, "requeued while still blocked");
assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, BuildState::BlockedMissingDep);
// Publishing dep-partner is what unblocks it: a human already approved it.
publish(&env, "dep-partner");
assert!(
aur_build::db::our_package_names(&env.db).unwrap().contains("dep-partner"),
"dep-partner should be in the index now: {:?}",
aur_build::db::our_package_names(&env.db)
);
// Publishing the blocker requeues what was waiting on it.
assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, BuildState::Queued, "the blocker arrived and the build stayed blocked");
assert_eq!(builds::requeue_blocked(&env.db).unwrap(), 0, "nothing left to requeue");
// And it now runs to completion.
pipeline::run(&env.cfg, &env.db, &id).unwrap();
assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, BuildState::Succeeded);
assert!(aur_build::db::index_version(&env.db, "missing-dep").unwrap().is_some());
}
#[test]
fn the_review_page_warns_about_missing_deps_before_approval() {
let (env, fx, _partner) = env_with_two_fixtures("missing-dep", "dep-partner");
aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, "missing-dep").unwrap();
let c = candidates::pending_candidates(&env.db).unwrap().remove(0);
diff::render_and_store(&env.db, &env.cfg, &c).unwrap();
let web = Web::attach(env, fx);
let page = web.get(&format!("/reviews/{}", c.id));
assert!(page.body.contains("Missing dependencies"), "no warning: {}", &page.body[..600.min(page.body.len())]);
assert!(page.body.contains("dep-partner"), "the missing dep is not named");
}
#[test]
fn the_review_page_answers_what_approving_this_would_disturb() {
// §10.3: "approving this marks N packages stale".
let (env, plain, _client) = env_with_two_fixtures("plain-make", "dep-client");
publish(&env, "plain-make");
publish(&env, "dep-client");
plain.bump(&[("pkgver", "2.0")]);
aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, "plain-make").unwrap();
let c = candidates::pending_candidates(&env.db).unwrap().remove(0);
diff::render_and_store(&env.db, &env.cfg, &c).unwrap();
let web = Web::attach(env, plain);
let page = web.get(&format!("/reviews/{}", c.id));
assert!(
page.body.contains("will mark 1 package(s) stale"),
"the dependents question is not answered: {}",
&page.body[..800.min(page.body.len())]
);
assert!(page.body.contains("dep-client"), "the dependent is not named");
// And the same answer is available without the UI.
assert_eq!(staleness::dependents_of(&web.env.db, "plain-make").unwrap(), vec!["dep-client".to_string()]);
// Approving it does not rebuild anything by itself (§10: no rebuild engine).
assert_eq!(web.env.query_i64("SELECT count(*) FROM build", &[]), Some(2), "one build per published package");
}
#[test]
fn a_dependency_we_stopped_publishing_shows_as_missing_not_outdated() {
let (env, _plain, client) = env_with_two_fixtures("plain-make", "dep-client");
publish(&env, "plain-make");
publish(&env, "dep-client");
// Withdraw plain-make from the index: dep-client now depends on something we
// no longer serve.
pipeline::publish::withdraw_package(&env.cfg, &env.db, "plain-make").unwrap();
let stale = staleness::stale_rows(&env.db).unwrap();
let missing: Vec<_> = stale
.iter()
.filter(|s| s.kind == staleness::Kind::Missing)
.cloned()
.collect();
assert_eq!(missing.len(), 1, "withdrawal should read as missing: {stale:?}");
assert_eq!(missing[0].pkgbase, "dep-client");
assert_eq!(missing[0].dependency, "plain-make");
let web = Web::attach(env, client);
let page = web.get("/attention");
assert!(page.body.contains("Missing:"), "no missing section: {}", &page.body[..600.min(page.body.len())]);
assert!(page.body.contains("dep-client"));
}
|