From f8370b48f3e4464a1454d0ff7af1819b5448c619 Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 16:13:30 +0000 Subject: db, watch: two upward edges removed, and the layering is now a test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/watch/digests.rs | 31 +------------------------------ src/watch/mod.rs | 2 +- src/watch/upstream.rs | 28 +++++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 34 deletions(-) (limited to 'src/watch') diff --git a/src/watch/digests.rs b/src/watch/digests.rs index cb7bdbc..c67d60e 100644 --- a/src/watch/digests.rs +++ b/src/watch/digests.rs @@ -13,23 +13,9 @@ use crate::config::Config; use crate::db::{self, *}; use crate::error::Result; +use crate::recipe::{declared_sums, is_hex_digest, SKIP}; use crate::watch::mirror::Tree; -const SKIP: &str = "SKIP"; - -fn declared_sums(recipe: &Recipe, index: usize) -> Option { - recipe - .sha256sums - .get(index) - .or_else(|| recipe.b2sums.get(index)) - .map(|s| s.trim().to_string()) - .filter(|s| !s.is_empty()) -} - -fn is_hex_digest(s: &str) -> bool { - (s.len() == 64 || s.len() == 128) && s.chars().all(|c| c.is_ascii_hexdigit()) -} - /// Resolve the digest of every `source=()` entry. pub fn resolve_sources( cfg: &Config, @@ -157,18 +143,3 @@ pub fn cached_path(db: &Db, url: &str, digest: &str) -> Option Vec { - recipe - .source_entries - .iter() - .filter(|e| !e.is_vcs()) - .filter(|e| match declared_sums(recipe, e.index) { - Some(d) => d == SKIP || !is_hex_digest(&d), - None => true, - }) - .map(|e| e.index) - .collect() -} diff --git a/src/watch/mod.rs b/src/watch/mod.rs index f469f86..87df3f3 100644 --- a/src/watch/mod.rs +++ b/src/watch/mod.rs @@ -9,6 +9,6 @@ pub mod staleness; pub mod upstream; pub use detect::{check_pkgbase, CheckReport, Outcome}; -pub use digests::{cached_path, download_and_cache, resolve_sources, skip_on_non_vcs}; +pub use digests::{cached_path, download_and_cache, resolve_sources}; pub use mirror::{read_tree, sync_mirror, Tree}; pub use scheduler::spawn_scheduler; diff --git a/src/watch/upstream.rs b/src/watch/upstream.rs index 442647c..8d7fa4f 100644 --- a/src/watch/upstream.rs +++ b/src/watch/upstream.rs @@ -124,6 +124,28 @@ impl StageB { pub fn version(&self) -> String { crate::pkgver::full_version(&self.epoch, &self.pkgver, &self.pkgrel) } + + /// Rebuild an answer from its cache row. The `cached` flag is ours to set: + /// the row says nothing about how this call got its answer (§6 M-6). + fn from_cache(row: StageBCacheRow) -> Self { + StageB { + epoch: row.epoch, + pkgver: row.pkgver, + pkgrel: row.pkgrel, + pins: row.pins, + cached: true, + } + } + + /// The row this answer occupies in `stage_b_cache`. + fn as_row(&self) -> StageBCacheRow { + StageBCacheRow { + epoch: self.epoch.clone(), + pkgver: self.pkgver.clone(), + pkgrel: self.pkgrel.clone(), + pins: self.pins.clone(), + } + } } /// A process-wide cap on concurrent Stage B resolutions (§5.2 "a global @@ -180,7 +202,7 @@ pub fn resolve( // Cache hit: same recipe, same upstream tips. Keyed on // (pkgbase, recipe_hash, upstream_tip) exactly as §5.2 asks. if let Some(hit) = db::stage_b_cache_get(db, pb.id, recipe_hash, &tip_hash)? { - return Ok(Some(hit)); + return Ok(Some(StageB::from_cache(hit))); } // Per-pkgbase cooldown: even if the tips moved again, we do not re-resolve @@ -188,12 +210,12 @@ pub fn resolve( // is reused, so a chatty upstream cannot turn detection into a build loop. let cooldown = db::setting_i64(db, "stage_b_cooldown", 86400); if let Some(recent) = db::stage_b_recent(db, pb.id, cooldown)? { - return Ok(Some(recent)); + return Ok(Some(StageB::from_cache(recent))); } let _slot = StageBSlot::acquire(db::setting_i64(db, "stage_b_concurrency", 1) as usize); let resolved = run(cfg, db, pb, recipe, recipe_hash, &tip_hash, stage_a)?; - db::stage_b_cache_put(db, pb.id, recipe_hash, &tip_hash, &resolved)?; + db::stage_b_cache_put(db, pb.id, recipe_hash, &tip_hash, &resolved.as_row())?; Ok(Some(resolved)) } -- cgit v1.2.3