summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 16:13:30 +0000
committeraur-build <aur-build@localhost>2026-11-18 16:13:30 +0000
commitf8370b48f3e4464a1454d0ff7af1819b5448c619 (patch)
treeb6180118a83fb38780472381243f95ef66429d31 /tests
parente04152da00f97c5ecc9a3f6dc5217d61274c7907 (diff)
downloadaur-build-f8370b48f3e4464a1454d0ff7af1819b5448c619.tar.gz
aur-build-f8370b48f3e4464a1454d0ff7af1819b5448c619.zip
db, watch: two upward edges removed, and the layering is now a test
M-6. `db::stage_b_cache_get` and `db::stage_b_recent` returned `watch::upstream::StageB`, so the persistence layer could not be read without the VCS watcher, and the table's row shape was defined by whatever the watcher happened to find convenient. The row is `db::model::StageBCacheRow` now — epoch, pkgver, pkgrel, pins — and `watch::upstream` converts at its own boundary. The two types are deliberately not the same one: `StageB` carries `cached`, and "was this answer a cache hit?" is a fact about the resolution that just happened, not a column. M-7. `review::risk` called `watch::digests::skip_on_non_vcs` while `watch::detect` called into `review::candidates`, a cycle between two sibling domains. Whether a recipe declines to verify its own sources is a question about the recipe, so `skip_on_non_vcs` — with `SKIP`, `declared_sums` and `is_hex_digest`, which it needed and which the watcher had no business owning — moved to `recipe.rs`, a leaf both sides may look down at. `watch::digests` keeps its use of them for digest resolution; the re-export is gone. `tests/layers.rs` enforces the direction from now on: `src/db` names no module above itself, `src/review` does not name `watch`, `src/watch` does not name `pipeline` or `http`, and `recipe.rs` names nothing at all. Each rule failed before this commit and each failure message prints the exact file and line of the offending edge, so the next reasonable-looking commit cannot reintroduce one quietly.
Diffstat (limited to 'tests')
-rw-r--r--tests/layers.rs94
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/layers.rs b/tests/layers.rs
new file mode 100644
index 0000000..548f475
--- /dev/null
+++ b/tests/layers.rs
@@ -0,0 +1,94 @@
+//! The dependency direction between modules (§6 M-6, M-7).
+//!
+//! These are not style rules. The review found the persistence layer naming a
+//! type from the VCS watcher, and the reviewer's risk scorer calling back into
+//! the watcher for a recipe question — two edges pointing up the stack, which
+//! makes `db` and `watch` mutually dependent and means any change to one is a
+//! change to the other. A layering rule that is only written down gets violated
+//! by the next reasonable-looking commit, so it is a test here.
+
+use std::path::{Path, PathBuf};
+
+fn src_root() -> PathBuf {
+ Path::new(env!("CARGO_MANIFEST_DIR")).join("src")
+}
+
+fn rust_files(dir: &Path) -> Vec<PathBuf> {
+ let mut out = Vec::new();
+ let mut stack = vec![dir.to_path_buf()];
+ while let Some(d) = stack.pop() {
+ for entry in std::fs::read_dir(&d).expect("read dir") {
+ let path = entry.expect("entry").path();
+ if path.is_dir() {
+ stack.push(path);
+ } else if path.extension().is_some_and(|e| e == "rs") {
+ out.push(path);
+ }
+ }
+ }
+ out.sort();
+ out
+}
+
+/// Every `crate::X` reference from `dir` into any of `forbidden`, as
+/// "file:line: text" so a failure names the exact edge.
+fn edges(dir: &str, forbidden: &[&str]) -> Vec<String> {
+ let mut hits = Vec::new();
+ for file in rust_files(&src_root().join(dir)) {
+ let text = std::fs::read_to_string(&file).expect("read file");
+ for (n, line) in text.lines().enumerate() {
+ let line = line.trim();
+ if line.starts_with("//") {
+ continue;
+ }
+ for m in forbidden {
+ if line.contains(&format!("crate::{m}")) {
+ hits.push(format!(
+ "{}:{}: {line}",
+ file.strip_prefix(src_root()).unwrap().display(),
+ n + 1
+ ));
+ }
+ }
+ }
+ }
+ hits
+}
+
+#[test]
+fn persistence_names_nothing_above_itself() {
+ // M-6: `db::stage_b_cache_get` used to return `watch::upstream::StageB`, so
+ // the storage layer could not be understood without the watcher. The row
+ // type is `db::model::StageBCacheRow` now and the watcher converts.
+ let hits = edges("db", &["watch", "review", "pipeline", "http", "ops", "shims"]);
+ assert!(hits.is_empty(), "src/db depends upward on the modules above it:\n{hits:#?}");
+}
+
+#[test]
+fn review_does_not_call_back_into_the_watcher() {
+ // M-7: `review::risk` called `watch::digests::skip_on_non_vcs` while
+ // `watch::detect` called `review::candidates` — a cycle. Whether a recipe
+ // skips verification is a recipe question, so `recipe::skip_on_non_vcs` is
+ // where it lives and both sides look down, not sideways.
+ let hits = edges("review", &["watch", "pipeline", "http"]);
+ assert!(hits.is_empty(), "src/review depends on modules beside or above it:\n{hits:#?}");
+}
+
+#[test]
+fn the_watcher_does_not_reach_into_the_pipeline_or_the_ui() {
+ let hits = edges("watch", &["pipeline", "http", "shims"]);
+ assert!(hits.is_empty(), "src/watch depends on modules above it:\n{hits:#?}");
+}
+
+#[test]
+fn the_recipe_leaf_depends_on_nothing_above_it() {
+ // `recipe` is a leaf: parsing and recipe-shaped questions. Everything else
+ // is allowed to ask it; it may ask nothing.
+ let text = std::fs::read_to_string(src_root().join("recipe.rs")).expect("read recipe.rs");
+ for m in ["watch", "review", "pipeline", "http", "ops", "shims"] {
+ assert!(
+ !text.contains(&format!("crate::{m}")),
+ "src/recipe.rs must not name crate::{m}"
+ );
+ }
+}