summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 17:25:41 +0000
committeraur-build <aur-build@localhost>2026-11-18 17:25:41 +0000
commitf3e4c1496d2ddcdae535132427fdb499181f1695 (patch)
treeca1c9cb5e66caa7b9542aebb38811725b98c6f46 /src/db
parent8bb76cb266a2fef5d5fe43c0f9643101f59112aa (diff)
downloadaur-build-f3e4c1496d2ddcdae535132427fdb499181f1695.tar.gz
aur-build-f3e4c1496d2ddcdae535132427fdb499181f1695.zip
review: one host rule, one body rule, one audit constructor
m-2. `hosts` existed twice, verbatim, in `review::diff` and `review::risk`. The duplication that matters is the other one: "did the executable part of the recipe change" also existed twice, with *different* semantics. The risk scorer compared everything from the first function definition onward; the diff panel compared only the lines that name a function, so a `build()` rewritten to `curl … | sh` under the same function names told the risk scorer "code changed, high" and told the reviewer nothing at all — the one reader who could have caught it. Both questions now have one answer: `urlutil::hosts` (which also strips the `git@` from ssh URLs, so a scheme change stops crying "new source host" wolf) and `recipe::bodies_changed`, in the module that owns the recipe. m-4. The three review decisions each hand-built an `AuditEntry` literal, and their `detail` shapes drifted: approve recorded the identity hash, reject recorded only the note, withdraw only the reason — so for two of the three the log cannot answer which candidate bytes the decision was about. `AuditEntry` is built by `::human` / `::system` now, and reject records the identity hash it rejected. m-3, the four-times-copied 21-column candidate `SELECT`, was already gone: the `CANDIDATE_COLS` constant came with moving the candidate SQL into `db/` in an earlier commit. Tests: the body rule is pinned at the unit level with the exact drift case (same function names, different body), `tests/production_surface.rs` fails if either module grows a private copy again or if an audit row is hand-built, and the reject test reads its own audit row back and requires the identity in it.
Diffstat (limited to 'src/db')
-rw-r--r--src/db/queries.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/db/queries.rs b/src/db/queries.rs
index 18f91cd..23b95ec 100644
--- a/src/db/queries.rs
+++ b/src/db/queries.rs
@@ -82,6 +82,13 @@ pub fn audit(
}
/// An audit row to append inside someone else's transaction.
+///
+/// Build one with [`AuditEntry::human`] or [`AuditEntry::system`] rather than
+/// by writing the literal: `actor_kind` is a closed set and the timestamp is
+/// not the caller's to improvise (§6 m-4). Three review sites had each
+/// hand-built this struct, and their `detail` shapes drifted until the log
+/// could not answer, for two of the three, which candidate bytes the decision
+/// was about.
#[derive(Debug)]
pub struct AuditEntry<'a> {
pub at: &'a str,
@@ -93,6 +100,31 @@ pub struct AuditEntry<'a> {
pub detail: serde_json::Value,
}
+impl<'a> AuditEntry<'a> {
+ /// A decision a named human made (§11: every approval is attributable).
+ pub fn human(
+ at: &'a str,
+ actor: &'a str,
+ action: &'a str,
+ entity: &'a str,
+ entity_id: &'a str,
+ detail: serde_json::Value,
+ ) -> Self {
+ Self { at, actor_kind: "human", actor, action, entity, entity_id, detail }
+ }
+
+ /// Something the server did by itself: a publish, a requeue, a watcher tick.
+ pub fn system(
+ at: &'a str,
+ action: &'a str,
+ entity: &'a str,
+ entity_id: &'a str,
+ detail: serde_json::Value,
+ ) -> Self {
+ Self { at, actor_kind: "system", actor: "", action, entity, entity_id, detail }
+ }
+}
+
/// Append an audit row inside a caller's transaction (I10). This is the variant
/// every multi-statement mutation uses: the record of a decision commits with
/// the decision or not at all, so there is no window where an audit row