summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authordev <dev@localhost>2026-11-20 19:03:01 +0000
committerdev <dev@localhost>2026-11-20 19:03:01 +0000
commite6c3a02229994a9e007d8e6618add778e1ec021c (patch)
tree275b4a025af0738bf33b613741c7e7ecc7b708db /tests
parent6c4b4394bd8ddf28d130e87e0100349f13f6e912 (diff)
downloadaur-build-e6c3a02229994a9e007d8e6618add778e1ec021c.tar.gz
aur-build-e6c3a02229994a9e007d8e6618add778e1ec021c.zip
docs: record the census, and make the README describe the tree that exists
The census report gets its after-table, and the README's Layout gets rewritten — it had drifted into fiction, listing `db/queries.rs`'s successors as "queries" and omitting `usecase`, `error`, `hash`, `time`, `urlutil`, `git`, `fetch` and `recipe` entirely. It now states the ranks and says plainly that they are enforced by `tests/architecture.rs`, not kept in hope, and names the two commands that keep it true. This commit also carries the last of the narrowing that fell out of writing the report, because writing it meant actually reading the numbers: - `watch::upstream::resolve` looked test-only and was not — the tests contain an unrelated local function of the same name, which the census matches as a word. It is crate-internal and now says so. - `read_tree` closed with it. Its two integration tests were testing the module's own batching behaviour from outside, so they moved inside as unit tests with a throwaway git repo, which is where a test about one `ls-tree` and one `cat-file --batch` belongs. They lost nothing: the empty-blob and NUL-byte assertions came across verbatim, plus one the old test never made — binary blobs are still listed, just not read. - `Assessment::is_high`, `Tree::get`, `approve::current_accepted` and `diff::full_recipe_text` were dead once their callers closed, and are gone. - `set_risk_for_tests` is gone too. The bulk-refusal test needed a candidate marked high-risk, and the honest way to get one was for the fixture to write the row — `Env::execute` — rather than the library growing a public setter that exists only so a test can pass. That was the last budget above baseline apart from `error.pub`. `error.pub` stays at 21 against a baseline of 15, and the report says why: the six payload enums are constructed in four modules and matched in `error`, so they are interface. `error.dead` is 0. Final: 281 passed / 0 failed across 36 binaries (baseline 273), clippy -D warnings clean, release clean, census within budget.
Diffstat (limited to 'tests')
-rw-r--r--tests/approve.rs5
-rw-r--r--tests/architecture-budget.json38
-rw-r--r--tests/common/mod.rs17
-rw-r--r--tests/detect.rs45
4 files changed, 41 insertions, 64 deletions
diff --git a/tests/approve.rs b/tests/approve.rs
index 7d014f8..c5be8e0 100644
--- a/tests/approve.rs
+++ b/tests/approve.rs
@@ -108,7 +108,10 @@ fn a_broken_database_is_not_reported_as_a_stale_review() {
fn bulk_refusals_are_their_own_reasons() {
let (env, _fx) = env_with_fixture("plain-make");
let (c, dd) = open_review(&env, "plain-make");
- candidates::set_risk_for_tests(&env.db, c.id, "high", &["new source host".into()]).unwrap();
+ env.execute(
+ "UPDATE candidate SET risk_level=?1, risk_signals_json=?2 WHERE id=?3",
+ &[P::S("high".into()), P::S(r#"["new source host"]"#.into()), P::I(c.id)],
+ );
let items = [(c.id, c.identity_hash.clone(), dd.clone())];
let out = bulk(&env.db, "tester", &items, "approve", &[]).unwrap();
diff --git a/tests/architecture-budget.json b/tests/architecture-budget.json
index 422bfb5..4df78b1 100644
--- a/tests/architecture-budget.json
+++ b/tests/architecture-budget.json
@@ -232,15 +232,15 @@
"test": 0
},
"review": {
- "dead": 10,
- "deadonly": 5,
+ "dead": 5,
+ "deadonly": 1,
"glob": 0,
- "largest": 295,
+ "largest": 288,
"largest_file": "src/review/diff.rs",
- "lines": 880,
- "priv": 2,
- "pub": 29,
- "test": 5
+ "lines": 859,
+ "priv": 3,
+ "pub": 24,
+ "test": 4
},
"sandbox": {
"dead": 15,
@@ -298,27 +298,27 @@
"test": 0
},
"watch": {
- "dead": 13,
- "deadonly": 7,
+ "dead": 8,
+ "deadonly": 4,
"glob": 0,
"largest": 270,
"largest_file": "src/watch/detect.rs",
- "lines": 970,
- "priv": 2,
- "pub": 30,
- "test": 6
+ "lines": 1038,
+ "priv": 7,
+ "pub": 24,
+ "test": 4
}
},
"totals": {
- "dead": 115,
- "deadonly": 40,
+ "dead": 105,
+ "deadonly": 33,
"edges": 87,
"glob": 0,
"largest": 603,
"largest_file": "src/shims/mod.rs",
- "lines": 14244,
- "priv": 103,
- "pub": 516,
- "test": 75
+ "lines": 14291,
+ "priv": 109,
+ "pub": 505,
+ "test": 72
}
}
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index d1c07a4..5c48923 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -128,6 +128,23 @@ impl Env {
self.cfg.hooks.shim_fail = Some(tool.to_string());
}
+ /// Run a statement the library deliberately does not expose.
+ ///
+ /// Fixtures use this to put a row in a state production would take a long
+ /// way to reach — forcing a risk level, say — rather than the library
+ /// growing a public setter that exists only for tests.
+ pub fn execute(&self, sql: &str, params: &[P]) {
+ let c = rusqlite::Connection::open(self.cfg.db_path()).unwrap();
+ let refs: Vec<&dyn rusqlite::ToSql> = params
+ .iter()
+ .map(|p| match p {
+ P::I(i) => i as &dyn rusqlite::ToSql,
+ P::S(s) => s as &dyn rusqlite::ToSql,
+ })
+ .collect();
+ c.execute(sql, rusqlite::params_from_iter(refs)).unwrap();
+ }
+
pub fn query_i64(&self, sql: &str, params: &[P]) -> Option<i64> {
let sql = sql.to_string();
let params: Vec<P> = params.to_vec();
diff --git a/tests/detect.rs b/tests/detect.rs
index ef57121..86d1315 100644
--- a/tests/detect.rs
+++ b/tests/detect.rs
@@ -5,7 +5,7 @@ use common::{git_add_commit, make_git_repo, params, Env, P};
use aur_build::db::{self, model::*, ReleaseRow};
use aur_build::review::{approve, candidates};
use aur_build::watch::detect::{check_pkgbase, Outcome};
-use aur_build::watch::mirror::{read_tree, sync_mirror, Sync};
+use aur_build::watch::mirror::{sync_mirror, Sync};
fn aur(env: &Env, name: &str) -> std::path::PathBuf {
env.path(&format!("aur/{name}.git"))
@@ -403,46 +403,3 @@ fn notices_are_not_duplicated_by_repeated_polling() {
);
let _ = P::I(0);
}
-
-#[test]
-fn read_tree_returns_every_blob_from_one_batch_read() {
- let env = Env::new();
- env.subscribe("foo");
- make_git_repo(
- &aur(&env, "foo"),
- &[
- ("PKGBUILD", &common::pkgbuild("foo", "1.0", "1", "")),
- ("empty.txt", ""),
- ("blob.bin", "\u{0}not text"),
- ],
- "initial",
- );
- let url = format!("file://{}", aur(&env, "foo").display());
- sync_mirror(&env.cfg, &env.db, "foo", &url).unwrap();
- let mirror = env.cfg.mirror_path("foo");
- let head = aur_build::git::head(&mirror).unwrap();
- let tree = read_tree(&mirror, &head).unwrap();
-
- assert!(tree.files["PKGBUILD"].contains("pkgver=1.0"));
- assert_eq!(tree.files["empty.txt"], "", "an empty blob is a file, not a miss");
- assert!(
- !tree.files.contains_key("blob.bin"),
- "a NUL in the first block means it is not text: {:?}",
- tree.files.keys().collect::<Vec<_>>()
- );
-}
-
-#[test]
-fn read_tree_fails_closed_when_the_commit_is_gone_from_the_mirror() {
- let env = Env::new();
- env.subscribe("foo");
- seed(&env, "foo", "1.0", "1", "");
- let url = format!("file://{}", aur(&env, "foo").display());
- sync_mirror(&env.cfg, &env.db, "foo", &url).unwrap();
- let mirror = env.cfg.mirror_path("foo");
-
- for gone in ["0123456789012345678901234567890123456789", "deadbeef"] {
- let err = read_tree(&mirror, gone).unwrap_err().to_string();
- assert!(err.contains("missing from the local mirror"), "{gone}: {err}");
- }
-}