summaryrefslogtreecommitdiffstats
path: root/src/watch
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 /src/watch
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 'src/watch')
-rw-r--r--src/watch/digests.rs2
-rw-r--r--src/watch/mirror.rs87
-rw-r--r--src/watch/mod.rs5
-rw-r--r--src/watch/upstream.rs2
4 files changed, 82 insertions, 14 deletions
diff --git a/src/watch/digests.rs b/src/watch/digests.rs
index 534b5bd..027062b 100644
--- a/src/watch/digests.rs
+++ b/src/watch/digests.rs
@@ -4,7 +4,7 @@ use crate::error::Result;
use crate::recipe::{declared_sums, is_hex_digest, SKIP};
use crate::watch::mirror::Tree;
-pub fn resolve_sources(
+pub(crate) fn resolve_sources(
cfg: &Config,
db: &Db,
mirror: &std::path::Path,
diff --git a/src/watch/mirror.rs b/src/watch/mirror.rs
index 924eb52..07a60c0 100644
--- a/src/watch/mirror.rs
+++ b/src/watch/mirror.rs
@@ -46,7 +46,7 @@ fn record(db: &Db, name: &str, head: &str, mirror: &Path) -> Result<()> {
}
#[derive(Debug, Clone)]
-pub struct Tree {
+pub(crate) struct Tree {
pub blobs: Vec<(String, String)>,
pub files: BTreeMap<String, String>,
}
@@ -55,18 +55,12 @@ impl Tree {
pub fn recipe_hash(&self) -> String {
crate::hash::recipe_hash(&self.blobs)
}
- pub fn get(&self, suffix: &str) -> Option<&String> {
- self.files
- .iter()
- .find(|(k, _)| k.ends_with(suffix))
- .map(|(_, v)| v)
- }
pub fn json_list(&self) -> String {
serde_json::to_string(&self.blobs).unwrap_or_else(|_| "[]".into())
}
}
-pub fn read_tree(mirror: &Path, commit: &str) -> Result<Tree> {
+pub(crate) fn read_tree(mirror: &Path, commit: &str) -> Result<Tree> {
// One `ls-tree` and one `cat-file --batch` for the whole tree, so the number
// of files a recipe ships does not decide how many processes a read costs.
// A commit that is gone from the mirror surfaces here, from `ls-tree`, rather
@@ -102,6 +96,81 @@ fn looks_textual(b: &[u8]) -> bool {
!b[..b.len().min(512)].contains(&0)
}
-pub fn read_file(mirror: &Path, commit: &str, path: &str) -> Result<Vec<u8>> {
+pub(crate) fn read_file(mirror: &Path, commit: &str, path: &str) -> Result<Vec<u8>> {
git::read_blob(mirror, commit, path)
}
+
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// A throwaway repo with these files committed, and its tip.
+ ///
+ /// Deliberately minimal: `read_tree` only ever needs a directory git will
+ /// answer for, so the test does not stand up a mirror, a database or a
+ /// config to ask it a question about one tree.
+ fn repo(files: &[(&str, &[u8])]) -> (std::path::PathBuf, String) {
+ let nonce = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap()
+ .as_nanos();
+ let dir = std::env::temp_dir().join(format!("aur-read-tree-{}-{}", std::process::id(), nonce));
+ std::fs::create_dir_all(&dir).unwrap();
+ let git = |args: &[&str]| {
+ let out = std::process::Command::new("git")
+ .arg("-C")
+ .arg(&dir)
+ .args(args)
+ .env("GIT_CONFIG_NOSYSTEM", "1")
+ .env("HOME", &dir)
+ .output()
+ .unwrap();
+ assert!(out.status.success(), "git {args:?}: {}", String::from_utf8_lossy(&out.stderr));
+ };
+ git(&["init", "-q", "-b", "master"]);
+ git(&["config", "user.email", "test@example.invalid"]);
+ git(&["config", "user.name", "test"]);
+ for (name, body) in files {
+ std::fs::write(dir.join(name), body).unwrap();
+ }
+ git(&["add", "-A"]);
+ git(&["commit", "-q", "-m", "initial"]);
+ let head = std::fs::read_to_string(dir.join(".git/refs/heads/master")).unwrap();
+ (dir, head.trim().to_string())
+ }
+
+ #[test]
+ fn read_tree_returns_every_blob_from_one_batch_read() {
+ let (dir, head) = repo(&[
+ ("PKGBUILD", b"pkgbase=foo
+pkgver=1.0
+pkgrel=1
+"),
+ ("empty.txt", b""),
+ ("blob.bin", b"\x00not text"),
+ ]);
+ let tree = read_tree(&dir, &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<_>>()
+ );
+ assert!(tree.blobs.iter().any(|(p, _)| p == "blob.bin"), "binary blobs are still listed");
+ std::fs::remove_dir_all(&dir).ok();
+ }
+
+ #[test]
+ fn read_tree_fails_closed_when_the_commit_is_gone_from_the_mirror() {
+ let (dir, _head) = repo(&[("PKGBUILD", b"pkgbase=foo
+")]);
+ for gone in ["0123456789012345678901234567890123456789", "deadbeef"] {
+ let err = read_tree(&dir, gone).unwrap_err().to_string();
+ assert!(err.contains("missing from the local mirror"), "{gone}: {err}");
+ }
+ std::fs::remove_dir_all(&dir).ok();
+ }
+}
diff --git a/src/watch/mod.rs b/src/watch/mod.rs
index b3c0533..839596a 100644
--- a/src/watch/mod.rs
+++ b/src/watch/mod.rs
@@ -6,7 +6,6 @@ pub mod sources;
pub mod staleness;
pub mod upstream;
-pub use detect::{check_pkgbase, CheckReport, Outcome};
-pub use digests::resolve_sources;
-pub use mirror::{read_tree, sync_mirror, Tree};
+pub use detect::{check_pkgbase, Outcome};
+pub use mirror::sync_mirror;
pub use scheduler::spawn_scheduler;
diff --git a/src/watch/upstream.rs b/src/watch/upstream.rs
index 1af1488..002d72b 100644
--- a/src/watch/upstream.rs
+++ b/src/watch/upstream.rs
@@ -141,7 +141,7 @@ impl Drop for StageBSlot {
}
}
-pub fn resolve(
+pub(crate) fn resolve(
cfg: &Config,
db: &Db,
pb: &Pkgbase,