diff options
Diffstat (limited to 'ARCH_REVIEW.md')
| -rw-r--r-- | ARCH_REVIEW.md | 438 |
1 files changed, 0 insertions, 438 deletions
diff --git a/ARCH_REVIEW.md b/ARCH_REVIEW.md deleted file mode 100644 index 438e45f..0000000 --- a/ARCH_REVIEW.md +++ /dev/null @@ -1,438 +0,0 @@ -# Architecture Review — `aur-build` - -**Scope.** A review of the code as it stands, judged on its own merits: module -boundaries, encapsulation, coupling, API surfaces, state modeling, naming, and -clarity. No conformance check against `DESIGN.md` / `INVARIANTS.md` was -attempted; where those documents are cited it is only because the code cites -them back at the reader. - -**Method.** Full read of `src/` (~12.0k lines, 40 modules), plus the module -dependency graph, public-surface census, and inline-SQL census. Every finding -cites `file:line`. Severity definitions at the top of §6. - ---- - -## 1. Executive summary - -This is an unusually thoughtful codebase. The core safety story — *nothing is -published that a human did not approve, and what is published is byte-identical -to what was reviewed* — is expressed in mechanisms (identity hashes, diff -digests echoed by the approve request, compare-and-swap on the accepted-release -pointer, checkpointed build steps, lease-based crash recovery) rather than in -prose, and the module doc comments explain *why* far more often than they -explain *what*. The single-writer database actor, the deterministic build id, -and the read-derived staleness/metrics design are all genuinely good -architectural decisions, and they are implemented consistently. - -The review found **one critical defect**, which is also the sharpest encapsulation -failure in the codebase: the web session is a static cookie value (`auth=1`), -so the login gate is trivially bypassed by any client that sets the cookie -itself (§6, C-1). Everything else is structural: - -- **Encapsulation is by convention, not by the compiler.** There are zero - `pub(crate)`/`pub(super)` items in the crate; 513 items are fully `pub`. The - DB writer actor hands raw `&mut Connection` closures to any module that asks, - and 12 modules outside `db/` contain hand-rolled SQL (22 statements in - `ops.rs` alone). The schema is the system's most protected asset and nothing - stands guard over it. -- **The persistence layer depends on a domain layer** (`db/queries.rs` returns - `watch::upstream::StageB`), and `watch` ↔ `review` are mutually dependent — - the dependency graph has cycles at the module-group level. -- **State machines are stringly typed.** Candidate, build, step, release, and - subscription states are `&str` constants; transitions are validated - per-call-site at runtime, and `builds::set_state` will happily write any - string. The compile-time guarantees the writer-actor comment promises - ("*who can write* is a compile-time fact") stop at the connection and never - reach the data. -- **Test scaffolding is load-bearing in production surfaces.** The production - publish path calls into the test-shim module to read `.PKGINFO`; fault- - injection and clock-pinning hooks live in the production `Config` and the - hot path; the clock helper's `secs_ahead`/`secs_ago` silently ignore the - pinned clock that `now()` honors. -- **Error-type discipline slips exactly where the stakes are highest**: the - approve path maps *all* internal failures (including SQLite errors) into - `Stale::NotPending`, and `bulk()` stuffs unrelated refusals into the same - variant. - -None of these are hard to fix, and most have obvious fixes that the existing -style invites. §7 is a prioritized punch list. - ---- - -## 2. Architecture at a glance - -One binary (`src/main.rs`), one library crate (`src/lib.rs`), no async runtime. -Threads: a DB writer actor, a watcher tick, an HTTP accept loop (thread per -connection), a dispatcher + worker pool, and a reaper folded into the -dispatcher loop. - -``` - main.rs (CLI) http/ (UI) - | | - v v - review/ (approve, candidates, diff, risk) - | | - watch/ (scheduler, detect, upstream, | - digests, staleness, mirror) <------+----> risk.rs -> watch::digests - | | - v v - pipeline/ (steps, dispatch, publish) ---> shims/ (prod path!) - | - v - db/ (writer actor, readers, queries, builds, model) - config.rs error.rs time.rs hash.rs git.rs fetch.rs - pkgver/ pkginfo.rs recipe.rs ops.rs -``` - -**Inline-SQL census** (statements outside `src/db/`): `ops.rs` 22, -`review/approve.rs` 17, `review/candidates.rs` 15, `pipeline/publish.rs` 11, -`watch/staleness.rs` 4, `watch/digests.rs` 3, one or two each in -`watch/detect.rs`, `review/diff.rs`, `pipeline/{steps,mod,dispatch}.rs`, -`http/routes.rs`. - -**Visibility census:** 513 `pub` items, **0** `pub(crate)` / `pub(super)`. -`db/mod.rs:17-18` glob-re-exports `model::*` and `queries::*`, so the entire -row/query surface is flattened into `db::` and reachable from everywhere. - ---- - -## 3. Encapsulation assessment - -**The good.** The writer actor (`db/mod.rs:89-190`) is a clean idea well -executed: one thread owns the write connection, mutations arrive as closures, -`tx()` wraps everything in `BEGIN IMMEDIATE`, readers are thread-local -read-only connections, and the `Readers::with` re-entrancy hazard is called out -and reasoned about in a comment (`db/mod.rs:220-223`). The compare-and-swap on -`current_accepted_release_id` *inside* the publish transaction -(`pipeline/publish.rs:213, 258`) is exactly the right way to make I4 -crash-safe. `review::candidates::upsert_candidate` (`review/candidates.rs:45`) -is the model the rest of the codebase should follow: one transaction, a rich -return enum (`Upsert`), no leaked SQL semantics to callers. - -**The bad.** The actor's *distribution* is unguarded. `Writer::call` / -`Writer::tx` / `Writer::send` (`db/mod.rs:144,159,177`) are `pub` and hand any -caller a `&mut Connection`. There are ~50 write sites outside `db/`, and 12 -modules contain raw SQL. This is not merely stylistic: - -- `review/approve.rs` hand-writes its `INSERT INTO audit` rows - (`approve.rs:134, 187, 256`) instead of calling `db::audit` - (`db/queries.rs:53`), so the audit trail's shape is defined in four places - with three subtly different detail payloads. -- `pipeline/publish.rs:42-52, 369-373` queries `artifact.path` directly in two - duplicated blocks; `pipeline/mod.rs:316-323` re-implements - `builds::set_release` inline. -- `watch/detect.rs:86-104` (`schedule_next`) re-queries `poll_interval_secs` - with raw SQL even though `db::get_subscription` already returns that column — - and the scheduler already has it in hand (`watch/scheduler.rs:47-51`). - -When the schema changes, the blast radius is "any module," which means the -`db/` module is not a boundary, it is a directory. - -**Layer inversions and cycles.** - -- `db/queries.rs:641, 670, 699` — the persistence layer constructs and returns - `crate::watch::upstream::StageB`. The cache row type belongs in `db/model.rs` - (or its own module) with a conversion at the `watch` boundary. -- `watch` ↔ `review` is a cycle: `watch/detect.rs` calls - `review::candidates::{accepted_for, upsert_candidate, set_risk}` and - `review::risk::assess` (`detect.rs:14, 113, 258-266`), while - `review/risk.rs:74` calls `watch::digests::skip_on_non_vcs` and - `review/risk.rs` imports from `watch`. The cycle is survivable today only - because nobody mutates across it, which is exactly the kind of fact - encapsulation should make mechanical. -- `pipeline/publish.rs:353` — production publish calls `crate::shims::read_pkginfo` - to parse a package name out of a tarball. The shims module is the fake - toolchain (§16a); the real parser already exists in `pkginfo.rs:61-71`. Worse, - `shims/mod.rs:568-576` contains a *second* `.PKGINFO` parser - (`shims::parse_pkginfo`) that duplicates `pkginfo::parse_pkginfo` - (`pkginfo.rs:73`). Two parsers that can drift is a supply-chain-shaped - foot-gun in a system whose whole job is provenance. - -**Test hooks in production surfaces.** `Config` carries `publish_fault`, -`shim_fail`, `shim_kill_parent`, `shim_plant_link` (`config.rs:62-83`); the -publish hot path branches on `publish_fault` twice (`publish.rs:115, 146`); -`time::pin` (`time.rs:32`) thread-locally fakes the clock. The *existence* of -these hooks is defensible — the test suite drives the real binary and real -crashes, which is admirable — but they are unmarked, un-gated, and part of the -public `Config` API a production operator reads and edits. A `cfg(test)`/feature -gate, or a separate `TestHooks` struct that production `Config` cannot -deserialize, would keep the power and drop the exposure. - ---- - -## 4. Clarity-of-design assessment - -**Naming and docs are a strength.** Module headers read like design notes -("Clone, don't scrape", "A stored staleness flag goes wrong the moment anything -else is published"), and functions that fail closed say what they refuse and -why. `pipeline/dispatch.rs:1-17` is the best module comment in the repo: it -states the loop shape, the recovery story, and *why there is no startup -recovery routine*. - -**Where clarity breaks down:** - -1. **Stringly-typed state.** `db/model.rs:70-135` defines six state modules of - `&str` constants. `builds::set_state(db, id, state: &str, ...)` - (`db/builds.rs:195`) accepts any string; legality of a transition is checked - (when it is checked) at individual call sites, e.g. `approve.rs` checks - `state != candidate_state::PENDING` itself. The build state machine — - queued → leased → running → {succeeded, failed, cancelled, - blocked_missing_dep} — is the most consequential state machine in the system - and exists only as a comment plus scattered `WHERE state IN (...)` clauses. - Rust enums (with `str` mapping at the SQL boundary) would move a whole class - of "impossible state" bugs to compile time. -2. **Error types that lie.** `approve()` returns `Result<Result<Approval, Stale>>` - and then collapses every inner error into `Stale::NotPending { state: - e.to_string() }` (`approve.rs:153`), so a SQLite failure is reported to the - reviewer as "review is no longer pending (state: sqlite: …)". `bulk()` - reuses `Stale::NotPending` for "high-risk: needs individual confirmation" - (`approve.rs:216`) and "unknown decision" (`approve.rs:224`), and fabricates - an `Approval { id: 0, … }` sentinel for rejects (`approve.rs:222`). When one - enum is bent to carry four unrelated meanings, callers cannot branch on - anything. -3. **A no-op that reads like a safety mechanism.** `mark_approved_but_unbuilt` - (`pipeline/mod.rs:272-274`) has a five-line doc comment and an empty body — - the real mechanism is the derived query `db::queries::approved_but_unbuilt`. - A reader tracing the failure path is invited to believe state is written - here. Delete the function, keep the comment on the query. -4. **Two locks, one promise.** `publish.rs` holds `REPO_LOCK` (line 25) *and* - `PUBLISH_LOCK` (line 64), each documented as *the* "one publish per repo" - guarantee, both acquired in `publish()` (lines 67, 99); `withdraw_package` - takes only `REPO_LOCK` (line 397). Either the second lock is redundant (then - delete it) or the guarantee is incomplete (then fix it); today a reader - cannot tell which, which is worse than either. -5. **Dead parameters and `let _ =` debris.** `let _ = db;` - (`watch/upstream.rs:262`, `review/risk.rs:113`), `let _ = pb;` - (`watch/detect.rs:103`, `review/risk.rs:243`), `let _ = ord;` - (`review/diff.rs:254`), `compare_digests(_old, _new, …)` - (`risk.rs:178`), `finish(_state, _req, …, _sid, _new)` - (`http/mod.rs:263`). Each one is a parameter the design once wanted or no - longer wants; leaving them signals a contract that doesn't exist. -6. **Duplicated logic that can drift.** `hosts()` is byte-identical in - `review/diff.rs:226` and `review/risk.rs:220`. The "did the executable part - of the PKGBUILD change" heuristic exists twice with *different semantics*: - `diff.rs:196-214` keeps only lines that start a function, while - `risk.rs:197-215` keeps everything from the first match to EOF. The same - change could be flagged by one panel and not the other. The 21-column - candidate `SELECT` is copy-pasted four times (`review/candidates.rs:149, - 181, 201, 243`) even though `db/queries.rs` establishes the `*_COLS` - constant pattern two files over. -7. **Silent error swallowing in durability-critical spots.** `fsync_file` / - `fsync_dir` (`publish.rs:316-329`) ignore every error — in a module whose - entire claim is "fsync, then rename". `db::setting_i64` - (`queries.rs:29-35`) turns any DB error into a default. `hash::canonical_json` - (`hash.rs:76-78`) — which is not actually canonical, despite the name and - the comment conceding it isn't — returns `"{}"` on serialization failure, - meaning two unserializable identities would hash identically into the - approval echo. `auth::random_hex` (`http/auth.rs:22-33`) ignores a failed - `/dev/urandom` read and proceeds with a zero buffer. - ---- - -## 5. Per-area notes - -### 5.1 `db/` — foundation -The actor design is sound (§3). The row-mapping discipline (`*_COLS` constants, -`row_to_*` fns) is good, but `builds_for_pkgbase` (`queries.rs:617`) and -`all_settings` (`queries.rs:13`) use `filter_map(|r| r.ok())`, silently -dropping unreadable rows while most queries propagate — pick one policy. -`builds.rs` is a field-by-field setter buffet (`set_release`, `set_world`, -`set_candidate`, `set_pkgbase`, `set_profile`, `set_kind`, `set_blocked_on`, -lines 398-450): anemic rows plus transitions smeared into callers. -`current_state` returns `""` for a missing build (`builds.rs:455-458`) — -"no such build" and "build in state (empty)" are different facts. -`requeue_blocked` (`builds.rs:230-260`) runs one `SELECT count(*)` per waiting -name per blocked build inside a write transaction (N+1); fine at this scale, -worth a comment. `approved_but_unbuilt` (`queries.rs:970+`) re-implements -`pkgver::full_version`'s epoch logic in SQL `CASE` — the version format now -lives in two languages. - -### 5.2 `watch/` — detection -`detect.rs::analyse` is the longest function in the crate (~150 lines, `detect.rs:107`) and -carries the most subtle logic in the system (two-stage VCS funnel, identity -construction, notice-vs-candidate routing). It is readable, but it would -benefit from extracting the stage-A/stage-B resolution into a named function -with the `Option<StageA>`/`Option<StageB>` dance inside it rather than four -parallel `Option`s in scope. `Outcome` (`detect.rs:20-38`) mirrors -`review::candidates::Upsert` field-for-field with an `outcome_of` converter -(`detect.rs:292`) — one enum would do. `mirror.rs` is the cleanest module -in the repo: `Sync` and `Tree` are exactly the right abstractions, and the -divergence fail-closed (`mirror.rs:91-98`) is well placed. -`staleness::dependents_of` (`staleness.rs:134-167`) is N+1 (one recipe query -per index package) and matches on `p.name == name` for the self-exclusion but -pushes `p.name` — it excludes *the package itself* by name equality on the -wrong field (`staleness.rs:137-139` compares `p.name == name`, then queries -`pk.name = ?1` with `p.name`; correct but only by accident of the filter). -`digests.rs` overloads `skip_declared: true` for all VCS entries -(`digests.rs:66, 122`) — "declared SKIP" and "digest is a pin, not a checksum" -are different statements crammed into one boolean. - -### 5.3 `review/` — approval -The heart of the system and mostly its best-written part. -`upsert_candidate`'s collapse/supersede/reject-memory rules are expressed as -one transaction with an exhaustive result enum — textbook. `diff.rs`'s -panel-set design and `render_and_store` (`diff.rs:342`) make the -displayed-bytes-hash invariant concrete. The problems are the error-type -abuses in `approve.rs` (§4.2), the hand-rolled audit inserts (§3), -`withdraw` not checking the release's current state (`approve.rs:245-264` — -withdrawing an already-withdrawn release silently "succeeds"), and the -duplications noted in §4.6. - -### 5.4 `pipeline/` + `shims/` — build & publish -The ten-step machine with checkpoint/resume (`pipeline/mod.rs:196-260`) is -clear and honest; `StepResult::{Done,Skipped,Blocked}` maps cleanly onto the -step-state column. `steps.rs::collect`'s I9 symlink/containment defense -(`steps.rs:265-290`) is the kind of paranoid check a reviewer wants to see, -with the threat model spelled out. Issues: the two-lock confusion (§4.4), -`extend_lease(..., 90)` hardcoding what `cfg.lease_secs` should own -(`pipeline/mod.rs:215`), staged artifacts left in the served tree when -`commit_release` rejects with a conflict (`publish.rs:84-96` — harmless to -consumers, garbage forever otherwise), `SourceIdentity`'s two-phase -initialization (`from_candidate` leaves fields empty for `Ctx::new` to fill, -`pipeline/mod.rs:36-52, 130-140`), and the shims dependency (§3). The -`shims/` module itself is well-built for its purpose; the problem is only that -production code can see it at all. - -### 5.5 `http/` + CLI + `ops.rs` -The read/write split (handlers read via thread-local readers, mutations go -through the writer) is real and consistently applied. The flat route table -(`http/mod.rs:200-247`) is fine at this size. But `routes.rs` is 1,040 lines -mixing page rendering, mutations, CSV-ish helpers, and metrics; the auth gate -is broken (C-1); `Req::form_get` re-parses the whole body per call -(`http/mod.rs:46-48`); and `metrics` is unauthenticated by design -(`http/mod.rs:207-212`) — documented and loopback-default, acceptable, but it -should say so in the response's own docs page (`http/mod.rs:226-230`). The CLI (`main.rs`) genuinely -drives the same `review::approve` / `pipeline::run` entry points as the UI, -which is the claim this architecture should make and most such projects fail -to make. `ops.rs` is cohesive; metrics-on-read (like staleness) is the right -call and is done twice consistently. - -### 5.6 Leaf utilities -`pkgver/`, `pkginfo.rs`, `recipe.rs`, `git.rs`, `fetch.rs`, `hash.rs`, -`time.rs` are well-scoped leaf modules with no upward dependencies — except -that `hash.rs`'s `canonical_json` misnames what it does (§6, M-2) and -`time.rs`'s pinning is half-honored (§6, m-1). - ---- - -## 6. Findings (severity-ranked) - -Severity: **Critical** = exploitable/incorrect behavior in the default -configuration. **Major** = structural defect that will cause bugs or block -change. **Minor** = real defect or drift risk with limited blast radius. -**Nit** = style/clutter. - -### Critical - -| # | Finding | Evidence | -|---|---------|----------| -| C-1 | **Login gate is bypassed by forging a static cookie.** `gate()` treats `Cookie: auth=1` as proof of authentication, and login merely sets that literal value. Any client can read every page (reviews, audit, settings, build logs) by sending `auth=1` without ever supplying the password. The random `sid` session machinery exists (`http/mod.rs:236-239`, `auth.rs:42-59`) but is never bound to the authenticated flag; CSRF then *re-issues* a valid session to the attacker, so even POSTs are reachable once any page is read. | `src/http/routes.rs:20` (`req.cookie("auth").as_deref() == Some("1")`), `src/http/routes.rs:50` (`Set-Cookie: auth=1`), `src/http/mod.rs:236-239` | - -*Fix direction:* make the session id the credential — set `sid` at login, mark -that sid authenticated inside `auth.rs`'s session set, and gate on -`is_valid_session(sid) && session.is_authenticated`. Delete the `auth` cookie. - -### Major - -| # | Finding | Evidence | -|---|---------|----------| -| M-1 | Writer actor hands raw `&mut Connection` to every module; 12 modules outside `db/` contain hand-rolled SQL (~50 write sites). The schema has no owner. | `src/db/mod.rs:144,159,177`; `src/ops.rs` (22 stmts), `src/review/approve.rs:134,187,256`, `src/pipeline/publish.rs:42-52,369-373`, `src/pipeline/mod.rs:316-323`, `src/watch/detect.rs:86-104` | -| M-2 | `canonical_json` is not canonical (comment admits it) and returns `"{}"` on serialization failure — every failed identity hashes to the same digest, silently. This is the function behind `Identity::hash`, the value approvals must echo. | `src/hash.rs:76-78`, `src/db/model.rs:64-66` | -| M-3 | `approve()` converts *all* internal errors (incl. SQLite) into `Stale::NotPending`; `bulk()` reuses the same variant for high-risk refusal and unknown decision, and fabricates `Approval { id: 0 }` for rejects. Callers cannot distinguish "stale review" from "database broken". | `src/review/approve.rs:153, 216, 222-224` | -| M-4 | Production publish path depends on the test-shim module and its duplicate `.PKGINFO` parser (second parser can drift from `pkginfo.rs`). | `src/pipeline/publish.rs:353`, `src/shims/mod.rs:568-576`, `src/pkginfo.rs:61-71` | -| M-5 | Two static locks (`REPO_LOCK`, `PUBLISH_LOCK`) each documented as *the* publish serialization guarantee; `withdraw_package` takes only one of the two. | `src/pipeline/publish.rs:25,64,67,99,397` | -| M-6 | Layer inversion: `db/queries.rs` returns `watch::upstream::StageB`, making persistence depend on a domain module. | `src/db/queries.rs:641,670,699` | -| M-7 | Module-group cycle: `watch` → `review` (candidates, risk) and `review` → `watch` (digests). | `src/watch/detect.rs:14,113,258-266`; `src/review/risk.rs:74` | -| M-8 | State machines are `&str` constants with no transition validation; `builds::set_state` writes any string. The build state machine exists only as scattered `WHERE state IN (...)` clauses. | `src/db/model.rs:70-135`, `src/db/builds.rs:195-207` | -| M-9 | Test hooks are part of the production API surface: fault injection branches in the publish hot path, shim env vars in `Config`, thread-local clock pinning — none gated or marked. | `src/config.rs:62-83`, `src/pipeline/publish.rs:115,146`, `src/time.rs:26-38` | - -### Minor - -| # | Finding | Evidence | -|---|---------|----------| -| m-1 | `secs_ago`/`secs_ahead` ignore the pinned clock that `now()` honors — a pinned-clock test computes real-clock lease expiries. | `src/time.rs:62-70` vs `src/time.rs:14-19` | -| m-2 | `hosts()` duplicated verbatim; "PKGBUILD body changed" heuristic duplicated with *different* semantics between the diff panel and risk scoring. | `src/review/diff.rs:226` / `src/review/risk.rs:220`; `src/review/diff.rs:196-214` / `src/review/risk.rs:197-215` | -| m-3 | 21-column candidate `SELECT` copy-pasted 4× despite the `*_COLS` convention used everywhere else in `db/`. | `src/review/candidates.rs:149,181,201,243` | -| m-4 | Audit rows hand-inserted in three places with three different detail shapes, bypassing `db::audit`. | `src/review/approve.rs:134,187,256` vs `src/db/queries.rs:53` | -| m-5 | `mark_approved_but_unbuilt` is a documented no-op; the real mechanism is a derived query. Misleading during failure-path tracing. | `src/pipeline/mod.rs:236-241,272-274` | -| m-6 | `extend_lease` hardcodes 90s instead of `cfg.lease_secs`. | `src/pipeline/mod.rs:215` | -| m-7 | `fsync_file`/`fsync_dir` swallow all errors in the module whose guarantee is "fsync then rename". | `src/pipeline/publish.rs:316-329` | -| m-8 | Dead parameters / `let _ =` debris across six modules. | `src/watch/upstream.rs:262`, `src/review/risk.rs:113,178,243`, `src/watch/detect.rs:103`, `src/review/diff.rs:254`, `src/http/mod.rs:263` | -| m-9 | `setting_i64` maps DB errors to defaults; `filter_map(\|r\| r.ok())` silently drops unreadable rows in some queries but not others. | `src/db/queries.rs:29-35,13-20,617-635` | -| m-10 | `withdraw` does not check the release's current state; re-withdrawing silently succeeds. | `src/review/approve.rs:245-264` | -| m-11 | `schedule_next` re-queries with raw SQL a value the caller already had (`sub.poll_interval_secs`). | `src/watch/detect.rs:86-104`, `src/watch/scheduler.rs:47-51` | -| m-12 | `current_state` returns `""` for a nonexistent build. | `src/db/builds.rs:455-458` | -| m-13 | `random_hex` proceeds with a zero buffer if `/dev/urandom` read fails. | `src/http/auth.rs:22-33` | -| m-14 | `is_transient` classifies every `Io` error (incl. ENOSPC/EACCES) as retryable. | `src/error.rs:73-77` | -| m-15 | `Config::load/save` use `anyhow::Result` while the rest of the crate uses `error::Error`. | `src/config.rs:125,140` | -| m-16 | Publish leaves staged artifacts in the served tree when `commit_release` rejects (conflict path). | `src/pipeline/publish.rs:84-96` | -| m-17 | N+1 query patterns: `dependents_of`, `requeue_blocked`. | `src/watch/staleness.rs:134-167`, `src/db/builds.rs:230-260` | -| m-18 | Version formatting duplicated between Rust (`pkgver::full_version`) and SQL `CASE` in `approved_but_unbuilt`. | `src/db/queries.rs:970+` | -| m-19 | `digests.rs` overloads `skip_declared: true` for VCS entries (means "digest is a pin", not "declared SKIP"). | `src/watch/digests.rs:66,122` | - -### Nit - -| # | Finding | Evidence | -|---|---------|----------| -| n-1 | `SourceIdentity::from_candidate` returns a half-initialized value completed by `Ctx::new`. | `src/pipeline/mod.rs:36-52,130-140` | -| n-2 | `watch::detect::Outcome` mirrors `review::candidates::Upsert` with a hand-written converter. | `src/watch/detect.rs:20-38,292` | -| n-3 | `Req::form_get` re-parses the entire body per call. | `src/http/mod.rs:46-48` | -| n-4 | `routes.rs` is 1,040 lines mixing pages, mutations, and formatting helpers. | `src/http/routes.rs` | -| n-5 | `enqueue_manual_rebuild` invents its own identity string format (`aur_commit|recipe_hash|manual`) distinct from candidate identities. | `src/pipeline/mod.rs:295-298` | -| n-6 | `recipe_at` is `pub` though only used inside `steps.rs`. | `src/pipeline/steps.rs:435` | - ---- - -## 7. Prioritized recommendations - -1. **Fix C-1 now.** Bind authentication to the random session id inside - `auth.rs` (session set → set of authenticated sids); gate on the sid; - delete the `auth=1` cookie. ~30 lines, entirely inside `http/auth.rs` + - two call sites. Add a test that a hand-crafted `Cookie: auth=1` gets 302. -2. **Make `canonical_json` honest** (M-2): rename to `digest_json`, propagate - the serialization error instead of `"{}"`, and (cheap) serialize through a - `BTreeMap`-normalizing value so the name could eventually be true. -3. **Give the schema an owner** (M-1): move the ~40 stray SQL statements into - `db/queries.rs`/`db/builds.rs` (mechanical), then mark `Writer::call/tx/send` - `pub(crate)` so future SQL must land in `db/`. Same trick for the shims - dependency (M-4): point `publish.rs::package_name` at `pkginfo::pkginfo_text`, - delete `shims::read_pkginfo`/`parse_pkginfo`, and make `shims` a - `pub(crate)`-visible test module (or move it under `tests/` support). -4. **Repair the approve error channel** (M-3): `approve()` should return - `Result<Approval, ApproveError>` where `ApproveError = Stale(Stale) | - System(Error)`; give `bulk()` its own refusal reasons instead of - `Stale::NotPending` overload; return `Option<Approval>` (or nothing) for - rejects. -5. **Pick one publish lock** (M-5) and say so in one comment. -6. **Break the two dependency cycles** (M-6, M-7): move `StageB` (or a plain - `StageBCacheRow`) into `db/model.rs`; move `skip_on_non_vcs` into `recipe.rs` - (it is a recipe question, not a watcher question) — both are one-file moves - that make the layering a DAG. -7. **Enum-ify the state machines** (M-8), starting with `build_state`: parse at - the row boundary, expose `fn can_transition(from, to) -> bool`, and replace - `set_state(&str)` with typed transitions. This is the largest change on the - list; do it after 1-6. -8. **Gate the test hooks** (M-9): a `#[serde(default)] TestHooks` submodule of - `Config` documented as test-only (or a cargo feature), and honor the pinned - clock in `secs_ago`/`secs_ahead` (m-1). -9. **De-duplicate**: `hosts()` → `pkgver` or a small `urlutil`; one shared - `pkgbuild_bodies()` used by both `diff.rs` and `risk.rs` (m-2); a - `CANDIDATE_COLS` constant (m-3); route all audit writes through `db::audit` - (m-4). -10. **Sweep the minors** in whatever order they cross your path: delete the - no-op (m-5), use `cfg.lease_secs` (m-6), propagate fsync errors (m-7), - remove dead params (m-8), decide the row-error policy (m-9). - ---- - -## 8. Verdict - -The domain design is strong — the approval-echo/hash/CAS chain is a coherent -mechanism for the invariant it serves, and the crash-recovery story (leases + -reaper-first dispatcher loop + step checkpoints) is better than most systems -three times this size. What the codebase lacks is *enforcement*: the boundaries -everyone clearly has in mind (schema lives in `db/`, shims are test-only, states -have legal transitions, sessions are secrets) are conventions that any future -commit can violate without a compiler complaint. The fix list is mostly small, -mechanical, and in the code's own style. Fix C-1 today; the rest will make the -next hundred commits safer. |
