From 0b3cb443e70b46ec61455255c3ddfc2a26997613 Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 07:16:36 +0000 Subject: =?UTF-8?q?watch:=20two-stage=20VCS=20watcher=20=E2=80=94=20ls-rem?= =?UTF-8?q?ote=20probe,=20pkgver()=20resolution,=20pin=20capture=20(=C2=A7?= =?UTF-8?q?5.2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stage A probes every VCS source in source=() with git ls-remote, respecting #commit/#tag/#branch fragments, and returns one UpstreamPin per source. If the tip set equals the accepted release's pins, nothing can have changed and Stage B never runs — the common case costs one round trip per source and no clone. svn/hg have no cheap universal probe, so they are reported as unprobed and force Stage B rather than being silently treated as unchanged. Stage B runs only on movement: it fetches into a persistent vcs_cache (rather than re-cloning a multi-gigabyte upstream daily), runs makepkg --vercheck, and captures the pins from the clone it already has. Results are cached on (pkgbase, recipe_hash, upstream_tip) with a per-pkgbase cooldown, and a process-wide slot cap bounds concurrent resolutions. The resolved epoch:pkgver-pkgrel plus the pins go into identity_hash, so a different commit is a different thing to approve. Also fixes a misclassification the new path exposed: a VCS source's digest is its pin, so upstream movement showed up as an integrity_alert. Integrity events are now restricted to fixed downloads; VCS movement under a frozen pkgver is pin_drift, as §5.2 specifies. New fixtures git-multi (two upstreams) and git-tagged (#tag pin). 10 tests in tests/vcs.rs. --- src/db/migrations.rs | 22 ++++++++++++++ src/db/queries.rs | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) (limited to 'src/db') diff --git a/src/db/migrations.rs b/src/db/migrations.rs index 8ba925c..bb8974f 100644 --- a/src/db/migrations.rs +++ b/src/db/migrations.rs @@ -299,6 +299,26 @@ BEGIN END; "#; +/// Stage B results, keyed on `(pkgbase, recipe_hash, upstream_tip)` (§5.2). +/// Re-resolving means cloning an upstream repo and running makepkg, so the +/// answer is worth keeping; the same key also implements the per-pkgbase +/// cooldown, because a fresh tip inside the window reuses the old answer. +const M_0007_STAGE_B_CACHE: &str = r#" +CREATE TABLE stage_b_cache ( + pkgbase_id INTEGER NOT NULL REFERENCES pkgbase(id), + recipe_hash TEXT NOT NULL, + tip_hash TEXT NOT NULL, + epoch TEXT NOT NULL, + pkgver TEXT NOT NULL, + pkgrel TEXT NOT NULL, + pins_json TEXT NOT NULL, + resolved_at TEXT NOT NULL, + PRIMARY KEY (pkgbase_id, recipe_hash, tip_hash) +); + +CREATE INDEX stage_b_cache_by_pkgbase ON stage_b_cache (pkgbase_id, resolved_at); +"#; + pub static MIGRATIONS: &[Migration] = &[ Migration { version: 1, name: "core", sql: M_0001_CORE }, Migration { version: 2, name: "build", sql: M_0002_BUILD }, @@ -306,6 +326,7 @@ pub static MIGRATIONS: &[Migration] = &[ Migration { version: 4, name: "audit-triggers", sql: M_0004_TRIGGERS }, Migration { version: 5, name: "artifact-build", sql: M_0005_ARTIFACT_BUILD }, Migration { version: 6, name: "approval-immutable", sql: M_0006_APPROVAL_IMMUTABLE }, + Migration { version: 7, name: "stage-b-cache", sql: M_0007_STAGE_B_CACHE }, ]; /// Default settings seeded into `settings` (DESIGN.md §11). @@ -314,6 +335,7 @@ pub const DEFAULT_SETTINGS: &[(&str, &str)] = &[ ("build_timeout", "5400"), ("poll_interval", "86400"), ("stage_b_cooldown", "86400"), + ("stage_b_concurrency", "1"), ("retention_versions", "3"), ("dry_run", "0"), ("review_budget_days", "14"), diff --git a/src/db/queries.rs b/src/db/queries.rs index b1f7e4d..fe3109a 100644 --- a/src/db/queries.rs +++ b/src/db/queries.rs @@ -575,6 +575,91 @@ pub fn our_package_names(db: &Db) -> Result> }) } +// --------------------------------------------------------- stage B cache -- + +/// Exact cache hit: same recipe, same upstream tips (§5.2). +pub fn stage_b_cache_get(db: &Db, pkgbase_id: i64, recipe_hash: &str, tip_hash: &str) -> Result> { + let (rh, th) = (recipe_hash.to_string(), tip_hash.to_string()); + db.read(move |c| { + use rusqlite::OptionalExtension; + Ok(c.query_row( + "SELECT epoch, pkgver, pkgrel, pins_json FROM stage_b_cache + WHERE pkgbase_id=?1 AND recipe_hash=?2 AND tip_hash=?3", + params![pkgbase_id, rh, th], + |r| { + Ok(( + r.get::<_, String>(0)?, + r.get::<_, String>(1)?, + r.get::<_, String>(2)?, + r.get::<_, String>(3)?, + )) + }, + ) + .optional()? + .map(|(epoch, pkgver, pkgrel, pins_json)| crate::watch::upstream::StageB { + epoch, + pkgver, + pkgrel, + pins: serde_json::from_str(&pins_json).unwrap_or_default(), + cached: true, + })) + }) +} + +/// The most recent answer for this pkgbase, if it is inside the cooldown window. +pub fn stage_b_recent(db: &Db, pkgbase_id: i64, cooldown_secs: i64) -> Result> { + let cutoff = crate::time::secs_ago(cooldown_secs); + db.read(move |c| { + use rusqlite::OptionalExtension; + Ok(c.query_row( + "SELECT epoch, pkgver, pkgrel, pins_json FROM stage_b_cache + WHERE pkgbase_id=?1 AND resolved_at > ?2 + ORDER BY resolved_at DESC LIMIT 1", + params![pkgbase_id, cutoff], + |r| { + Ok(( + r.get::<_, String>(0)?, + r.get::<_, String>(1)?, + r.get::<_, String>(2)?, + r.get::<_, String>(3)?, + )) + }, + ) + .optional()? + .map(|(epoch, pkgver, pkgrel, pins_json)| crate::watch::upstream::StageB { + epoch, + pkgver, + pkgrel, + pins: serde_json::from_str(&pins_json).unwrap_or_default(), + cached: true, + })) + }) +} + +pub fn stage_b_cache_put( + db: &Db, + pkgbase_id: i64, + recipe_hash: &str, + tip_hash: &str, + r: &crate::watch::upstream::StageB, +) -> Result<()> { + let (rh, th) = (recipe_hash.to_string(), tip_hash.to_string()); + let (epoch, pkgver, pkgrel) = (r.epoch.clone(), r.pkgver.clone(), r.pkgrel.clone()); + let pins = serde_json::to_string(&r.pins)?; + let at = crate::time::now(); + db.writer.tx(move |tx| { + tx.execute( + "INSERT INTO stage_b_cache (pkgbase_id, recipe_hash, tip_hash, epoch, pkgver, pkgrel, pins_json, resolved_at) + VALUES (?1,?2,?3,?4,?5,?6,?7,?8) + ON CONFLICT(pkgbase_id, recipe_hash, tip_hash) DO UPDATE SET + epoch=excluded.epoch, pkgver=excluded.pkgver, pkgrel=excluded.pkgrel, + pins_json=excluded.pins_json, resolved_at=excluded.resolved_at", + params![pkgbase_id, rh, th, epoch, pkgver, pkgrel, pins, at], + )?; + Ok(()) + }) +} + // ----------------------------------------------------------------- notice -- pub fn put_notice( -- cgit v1.2.3