diff options
| author | aur-build <aur-build@localhost> | 2026-11-18 10:16:12 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-18 10:16:12 +0000 |
| commit | 12fb09b0ad11c0d9305d606b3b4fced8ba04d385 (patch) | |
| tree | e33d6c974a4c31c01262ebec902c6c853152188b | |
| parent | bc63622a1a91f6e1036eb8e6824c04f922e2654e (diff) | |
| download | aur-build-12fb09b0ad11c0d9305d606b3b4fced8ba04d385.tar.gz aur-build-12fb09b0ad11c0d9305d606b3b4fced8ba04d385.zip | |
I9: the pipeline stops trusting paths the build could have placed, plus README and the invariant index
Three things.
**A real hole, closed.** `collect` scans the build's srcdir for
`*.pkg.tar.zst`, and `ingest` copies whatever those paths resolve to into the
content-addressed store — from where the bytes are served from our repo and
signed with our key. The paths are generated by our own scan, but their *targets*
are not: a PKGBUILD that drops a symlink called `evil.pkg.tar.zst` pointing at
the signing keyring, the database, or anyone's home directory would have its
target copied in, published and signed by us. The chroot is supposed to be the
layer that prevents that, and the chroot tier is gated — but two protection
layers must not be load-bearing on each other, and the control plane should not
depend on isolation for the safety of its own secrets.
`collect` now rejects symlinks and rejects anything whose canonicalized target
escapes the build's own staging directory, failing the build closed with the path
in the message. `i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir`
acts the attack out — the shim plants a symlink to the database file — and
asserts the build fails, the store is byte-for-byte untouched, and nothing
publishes. This is the last §2 invariant that had no named test; docs/INVARIANTS.md
says plainly which part of I9 this covers and which part belongs to the gated
chroot tier.
**README.md**, written for the person who has to operate this at 3am: the rule
everything else follows, the quick start, the layout, how the shim harness makes
the whole pipeline testable without root or network, the ops commands, the route
table, and the §14 constraints stated as the hard edges they are.
**docs/INVARIANTS.md**, mapping I1-I12 to the named tests that hold them, with
corroborating tests listed, and an explicit note on the two invariants enforced
by the schema (the partial unique index for I7, the append-only triggers for
I10/I7) so a future code path cannot forget them.
Also recorded in DECISIONS.md: metrics served without a session and why,
retention recording a purge instead of deleting the row, and the real-chroot tier
being explicitly skipped with what stands in for it and how to actually run it.
.gitignore already covered .pi/ but the goal-tracker files were tracked from
before the rule existed; untracked now so they stop appearing in every diff.
| -rw-r--r-- | .pi/.goals-pool-snapshot.json | 1 | ||||
| -rw-r--r-- | .pi/goals/.goal-ledger-checkpoint.json | 1 | ||||
| -rw-r--r-- | .pi/goals/active_goal_2026111720432444_mwl5tehk-xhe7fk.md | 299 | ||||
| -rw-r--r-- | .pi/goals/goal_events.jsonl | 45 | ||||
| -rw-r--r-- | README.md | 156 | ||||
| -rw-r--r-- | docs/DECISIONS.md | 76 | ||||
| -rw-r--r-- | docs/INVARIANTS.md | 44 | ||||
| -rw-r--r-- | src/config.rs | 9 | ||||
| -rw-r--r-- | src/pipeline/steps.rs | 24 | ||||
| -rw-r--r-- | src/shims/mod.rs | 19 | ||||
| -rw-r--r-- | tests/invariants.rs | 65 |
11 files changed, 392 insertions, 347 deletions
diff --git a/.pi/.goals-pool-snapshot.json b/.pi/.goals-pool-snapshot.json deleted file mode 100644 index 77c9a80..0000000 --- a/.pi/.goals-pool-snapshot.json +++ /dev/null @@ -1 +0,0 @@ -{"version":1,"dirMtimeMs":1794996104033.389,"goals":[{"id":"mwl5tehk-xhe7fk","objective":"Implement the AUR Build Server described in DESIGN.md as a single-process Rust binary in /workspace/aur-build, delivering phases P0–P4 (walking skeleton + test harness, VCS/pkgver detection, review web UI, durable build pipeline, staleness tracking), with every §2 invariant expressed as an executable test and the work committed incrementally to git.\n\nSUCCESS CRITERIA (observable):\n1. `cargo test` passes on the host with no `#[ignore]`-tier tests required; the §16a fake-package corpus and toolchain PATH shims drive the full step machine, publishing and crash-resume tests without root, network, or a real chroot.\n2. Invariants I1–I12 of §2 each have a named test that passes (I1 no-artifact-without-approval is a post-test query; I2 diff-base-is-last-accepted; I4 atomic publish survives kill-mid-publish; I5 step checkpoint/resume; I7 one open review enforced by the partial unique index; I12 world snapshots recorded).\n3. End-to-end against shims: subscribe pkgbase → detect → review → approve → build → publish a signed repo where both packages and the .db are signed, and the served index equals the set of current_accepted_release pointers (I8).\n4. Web UI serves the five §13 surfaces (Inbox, Builds, Attention, Index, Subscriptions) plus Ops/audit as server-rendered HTML; approve carries identity_hash + diff_digest and returns HTTP 409 on a stale approval (§7.1a).\n5. `cargo clippy` reports no errors; `git log` shows a sequence of small, meaningful commits from the initial scaffold to the final state; README documents build, run, and test commands.\n\nBOUNDARIES — IN SCOPE: P0, P1, P2, P3, P4 of §17, the §11 schema, §16 edge cases, §16a test harness, and one gated real-chroot integration attempt (devtools installed) if time permits.\nOUT OF SCOPE: everything in §20 (auto-approval policies, automatic dependency rebuilds, recipe-mutating hardening transforms, build-time upstream-pin honouring, network controls, cost-weighted admission, notifications), P5 polish, multi-tenancy/RBAC, non-x86_64 arches, and any change to DESIGN.md's decided decisions in §18.\n\nCONSTRAINTS (hard):\n- Rust edition 2021, no `async`/`await`, no tokio/axum/actix/reqwest/sqlx/libgit2; threads + crossbeam channels only; blocking HTTP via tiny_http; outbound HTTP via ureq; git by shelling out.\n- SQLite via rusqlite in WAL mode with exactly one writer actor thread (channel-based `Tx` enum) and thread-local read-only readers; no transaction may span a build step.\n- UI is server-rendered (askama or minijinja) with at most vendored htmx (~14 KB) plus ~30 lines of glue; no JS written by us beyond that glue, no bundler.\n- Fail closed on every pin assertion (recipe_hash, pkgver match against approved identity); non-publishable changes become `notice` rows, never candidates, never dropped (I11).\n- Provisioning: `sudo pacman -S --needed rustup devtools` (fall back to `pacman -S rust` only if rustup is unusable); no other system mutations; never commit secrets, the signing key, or build artifacts.\n- Commit incrementally: one commit per coherent step with a descriptive message; never a single monolithic commit; DESIGN.md stays untouched.\n- If a §19 open question blocks a design choice, pick the least-entangling option, record it in a `docs/DECISIONS.md` entry, and keep moving; stop and ask only if the choice is genuinely irreversible.\n\nIF BLOCKED: stop and ask the user (e.g. no network for crates, toolchain uninstallable, an invariant that cannot be made testable).","status":"active","autoContinue":true,"usage":{"tokensUsed":8635397,"activeSeconds":15531},"sisyphus":false,"createdAt":"2026-11-17T20:43:24.440Z","updatedAt":"2026-11-18T10:01:44.017Z","activePath":".pi/goals/active_goal_2026111720432444_mwl5tehk-xhe7fk.md","revision":817,"scheduler":{"version":1,"owner":"01a1eb32-2e3f-757c-a79a-21ac993facc5","generation":"dfbaf4f2-dad9-4dc6-9717-5038550aa75e","used":1,"phase":"running","repairUsed":false,"decision":{"kind":"ready","purpose":"kickoff"},"dispatch":{"id":"27430841-6f83-4343-a9fa-dd1c866de9d3","kind":"kickoff","claimedAt":1794985072841}},"taskList":{"tasks":[{"id":"task-setup","title":"Provision toolchain (pacman rustup + devtools) and initialize git","status":"complete","verificationContract":"`rustup show` and `cargo --version` work; `git -C /workspace/aur-build log` contains an initial commit with DESIGN.md, .gitignore, and a scaffolded Cargo.toml that `cargo build` compiles.","completedAt":"2026-11-17T20:48:20.900Z","evidence":"rustup 1.29.3 (pacman) + stable 1.100.0, devtools installed (mkarchroot/makechrootpkg present); git repo initialized on main with commit 3762c7c containing DESIGN.md, .gitignore, Cargo.toml; `cargo bu"},{"id":"task-p0","title":"P0 — walking skeleton + test harness (§17 P0, §16a)","status":"complete","subtasks":[{"id":"task-p0-schema","title":"SQLite schema, migrations, and single writer actor (§11, §11a)","status":"complete","verificationContract":"Migrations apply from empty DB; partial unique index rejects a second pending_review per pkgbase; audit table rejects UPDATE/DELETE by trigger; concurrent readers do not block the writer in a test.","completedAt":"2026-11-17T21:00:03.122Z","evidence":"tests/db.rs: 10 tests pass — migrations from empty + idempotent + WAL, default settings, I7 partial unique index rejects 2nd pending_review, candidate identity uniqueness, audit append-only triggers, "},{"id":"task-p0-shims","title":"Toolchain PATH shims + fake-package corpus (§16a)","status":"complete","verificationContract":"Fakes for mkarchroot/makechrootpkg/makepkg/repo-add/gpg/pacman record invocations and emit plausible .PKGINFO/.BUILDINFO/.sig per fixture manifest; at least plain-make, with-patch, skip-checksum, split-pkgbase, build-fails, missing-dep, epoch-bump, pkgrel-reset and downgrade fixtures exist and are driven by a test.","completedAt":"2026-11-17T21:31:09.120Z","evidence":"src/shims + src/bin/{mkarchroot,makechrootpkg,makepkg,repo-add,gpg,pacman}: shims record invocations to AUR_SHIM_DIR/invocations.jsonl, obey AUR_SHIM_MANIFEST, and emit real .pkg.tar.zst with .PKGINFO"},{"id":"task-p0-detect","title":"AUR mirror watcher: aur_commit pin, recipe_hash, source digests, candidate creation (§5.1, §5.1a, §5.3)","status":"complete","verificationContract":"Against a local file:// 'AUR' repo fixture: clone + ls-remote poll + fetch only on SHA move; snapshot records aur_commit and recipe_hash covering PKGBUILD/.SRCINFO/*.install/patches; SKIP sources are stream-hashed into source_cache; candidate.base is current_accepted_release; a brand-new pkgbase yields kind=first_introduction.","completedAt":"2026-11-17T21:20:02.693Z","evidence":"tests/detect.rs: 16 tests pass against real file:// git fixtures — clone+ls-remote poll with fetch only on SHA move (Sync::Unchanged vs Fetched), snapshot records aur_commit + recipe_hash covering shi"},{"id":"task-p0-approve","title":"Approval semantics + CLI approval path (§7.1, §7.1a, §7.2)","status":"complete","verificationContract":"CLI approve writes an immutable approval row with diff_digest and identity_hash; approving with a stale identity_hash or diff_digest is refused; collapse-in-place bumps revision without a new row while unviewed and freezes as superseded once viewed; a rejected identity is not re-detected.","completedAt":"2026-11-17T22:10:06.063Z","evidence":"tests/approve.rs: 10 tests pass incl. both-hash immutable approval row (migration 0006 trigger), stale identity/diff refused, collapse-in-place revision bump, viewed→superseded freeze, rejected identi"},{"id":"task-p0-build","title":"Build pipeline steps 0–9 and atomic signed publish (§8.1, §9)","status":"complete","verificationContract":"Shim-driven run of materialize→plan→chroot→sources→pkgver→build→collect→verify→ingest→publish; step 0 materializes from the local mirror and fails closed on recipe_hash mismatch; step 4 fails closed on pkgver mismatch; publish writes .tmp, fsyncs, renames, signs package and db, and updates current_accepted_release_id by compare-and-swap.","completedAt":"2026-11-17T21:58:00.936Z","evidence":"tests/pipeline.rs: 17 shim-driven e2e tests pass (fail-closed recipe_hash + pkgver, kill-mid-publish I4, crash-resume I5, CAS pointer, signed db+pkgs); cargo clippy clean"},{"id":"task-p0-invariants","title":"Executable invariant tests I1/I2/I4/I5/I8","status":"complete","verificationContract":"cargo test includes: post-run query proving no index entry lacks an approval (I1); multi-detection fixture proving the diff base is the last accepted version (I2); kill-mid-publish leaving the old index intact (I4); restart-resumes-at-next-incomplete-step with no duplicate side effects (I5); index set equals accepted-release pointers (I8).","completedAt":"2026-11-18T07:01:31.398Z","evidence":"tests/invariants.rs: 10 named invariant tests pass as post-conditions on real runs (I1 approval trace, I2 base after 5 detections, I3 recipe pin, I4 byte-identical index after mid-publish crash, I5 re"}],"completedAt":"2026-11-18T07:02:29.831Z","evidence":"All P0 children complete: schema+writer actor, shims+corpus, mirror watcher, approval semantics+CLI, 10-step pipeline with signed atomic publish, invariant index. 81 tests pass, clippy clean, 7 commit"},{"id":"task-p1","title":"P1 — VCS / computed pkgver detection (§5.2, §3)","status":"complete","subtasks":[{"id":"task-p1-stageA","title":"Stage A upstream probes over all VCS sources + persistent vcs_cache","status":"complete","verificationContract":"Parses source=() for git+/svn+/hg+ with #tag/#commit refs; probes via git ls-remote against local file:// repos; an unchanged HEAD set short-circuits before Stage B; multiple VCS sources each get their own pin entry.","completedAt":"2026-11-18T07:16:40.077Z","evidence":"tests/vcs.rs: stage_a_probes_every_vcs_source_not_just_the_first (git-multi → 2 pins matching both repo HEADs), stage_a_respects_a_tag_pin, stage_a_short_circuits_before_stage_b_when_nothing_moved (ma"},{"id":"task-p1-stageB","title":"Stage B pkgver() resolution with pin capture + identity tuple","status":"complete","verificationContract":"Resolved epoch:pkgver-pkgrel plus upstream_pins become part of identity_hash; cooldown and global concurrency cap enforced; cache keyed on (pkgbase, recipe_hash, upstream_tip); a git-sourced fixture produces a candidate whose pins match the fixture repo HEAD.","completedAt":"2026-11-18T07:17:57.387Z","evidence":"tests/vcs.rs: stage_b_resolves_pkgver_and_captures_the_pins (pins in identity_hash via Identity hash comparison), stage_b_is_cached_on_pkgbase_recipe_and_tip (cache row reuse + cooldown + re-resolve o"},{"id":"task-p1-notices","title":"Non-publishable change handling: pin_drift, recipe drift, digest drift → notice / integrity_alert (§5.2, §5.3, I11)","status":"complete","verificationContract":"pin-drift fixture yields a notice and no candidate; digest-drift fixture yields a high-severity integrity_alert and no candidate; SKIP-on-non-VCS is flagged as a risk signal; nothing publishable is silently dropped.","completedAt":"2026-11-18T07:29:10.456Z","evidence":"tests/notices.rs: 8 tests — digest-drift fixture → high-severity integrity_alert + no candidate, pin-drift → info notice + no candidate, recipe drift → warning, skip-checksum → HIGH risk signal 'skip-"}],"completedAt":"2026-11-18T07:30:36.958Z","evidence":"All three P1 children complete: Stage A probe (every VCS source, #tag/#commit, short-circuit), Stage B resolution (pin capture, cache on pkgbase+recipe_hash+tip, cooldown, concurrency cap), notices+ri"},{"id":"task-p2","title":"P2 — review surface (§12, §13, §6)","status":"complete","subtasks":[{"id":"task-p2-http","title":"tiny_http server, templating, thread-local readers, CSRF + session gate","status":"complete","verificationContract":"Thread-per-connection server renders all §12 routes; every POST requires a CSRF token; handlers never use the write connection; pages render with JS disabled.","completedAt":"2026-11-18T08:06:45.433Z","evidence":"tests/http.rs (14 tests, all pass): every_surface_renders covers all §12 routes on a live tiny_http server; every_post_requires_a_csrf_token asserts 403 for missing and forged tokens with zero rows wr"},{"id":"task-p2-inbox","title":"Inbox + diff panels + advisory risk scoring (§6, §7.1b)","status":"complete","verificationContract":"Review detail renders recipe / version / source-digest / upstream / source / dependency / build-env / install-hook panels, all based on accepted→candidate; risk signals computed and shown inline; base and aur_commit displayed with an AUR cgit link; first_introduction renders the full recipe with the subtle accent and no diff pane.","completedAt":"2026-11-18T08:07:10.624Z","evidence":"src/review/diff.rs now emits all eight §6 panels (recipe, version, source-digest, upstream, source, dependency, build-env, install-hook), each computed accepted→candidate; commit ab8d33d. tests/http.r"},{"id":"task-p2-approve409","title":"Optimistic-concurrency approve/reject + bulk operations (§7.1a, §7.4)","status":"complete","verificationContract":"Approve POST with a stale identity_hash/diff_digest returns 409 and re-renders the current diff with an explanation; bulk approve refuses high-risk items without per-item confirmation; reject requires a note and is re-openable.","completedAt":"2026-11-18T08:07:36.401Z","evidence":"tests/http.rs: a_stale_approval_is_a_409_that_renders_the_current_diff (upstream moves mid-review → 409, body explains the ground moved, re-render shows the new 9.9 version, zero approval rows written"},{"id":"task-p2-surfaces","title":"Subscriptions, Index, Builds, Attention, Ops/audit pages","status":"complete","verificationContract":"Each §13 surface renders from live DB state; Attention shows outdated-dependency, downgrade and blocked-build rows; the package page shows timeline, deps in/out, staleness and aur_commit history; manual rebuild reuses the approved source identity without a new approval (I6).","completedAt":"2026-11-18T08:23:18.650Z","evidence":"tests/surfaces.rs (7 tests): attention_lists_outdated_dependencies_from_the_recorded_world (dep-client stale after plain-make moves, dependency + built-against + now all named); attention_lists_a_down"}],"completedAt":"2026-11-18T08:24:11.640Z","evidence":"All four P2 children complete: tiny_http server + CSRF/session gate, inbox with the full eight-panel diff set, optimistic-concurrency approve/reject with 409-on-stale and per-item bulk confirmation, a"},{"id":"task-p3","title":"P3 — durability (§8.2, §8.3, §8.4)","status":"complete","subtasks":[{"id":"task-p3-dispatch","title":"Dispatcher actor, worker pool, leases, and reaper","status":"complete","verificationContract":"Dispatcher claims with BEGIN IMMEDIATE + lease expiry, requeues expired leases on startup, marks in-flight steps interrupted; the deterministic build id makes re-enqueue an INSERT OR IGNORE no-op; backpressure respects max_concurrent_builds and disk headroom.","completedAt":"2026-11-18T08:36:46.877Z","evidence":"src/pipeline/dispatch.rs + tests/dispatch.rs (9 tests): claim_batch runs SELECT+UPDATE in one BEGIN IMMEDIATE tx (db.writer.tx uses TransactionBehavior::Immediate); an_expired_lease_is_requeued_and_it"},{"id":"task-p3-crash","title":"Cancellation, retry policy, and crash-resume tests against shims (I5)","status":"complete","verificationContract":"A test kills the process mid-step and asserts resume at the next incomplete step with no duplicate side effects; cancel_requested stops a worker at a step boundary; deterministic build failures do not auto-retry and the release stays approved_but_unbuilt with the UI showing 'index still serving v1'.","completedAt":"2026-11-18T08:47:32.080Z","evidence":"tests/crash.rs (4 tests): a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work spawns the real aur-build binary, has a shim SIGKILL it inside the build step (asserts status.si"},{"id":"task-p3-sse","title":"SSE log tail + htmx live builds table","status":"complete","verificationContract":"GET /builds/:id/log.stream streams appended log bytes from a blocking thread; the builds table refreshes via htmx every 3s; vendored htmx is the only JS shipped and total vendored JS stays under 20 KB.","completedAt":"2026-11-18T09:01:22.683Z","evidence":"tests/live.rs (5 tests): the_log_stream_delivers_bytes_as_they_are_appended_and_then_ends — a producer thread appends to the log while the SSE stream is open and the reader must see those bytes BEFORE"}],"completedAt":"2026-11-18T09:03:07.796Z","evidence":"All three P3 children complete: dispatcher/worker pool/reaper with BEGIN IMMEDIATE claims and disk-headroom backpressure (e27e90a), a real SIGKILL mid-step crash test plus the approved_but_unbuilt fai"},{"id":"task-p4","title":"P4 — staleness, retention, metrics (§10, §15)","status":"pending","subtasks":[{"id":"task-p4-world","title":".PKGINFO/.BUILDINFO parsing and world_snapshot filtered to our own repo","status":"complete","verificationContract":"Ingest parses tar+text without libalpm; world_snapshot members are intersected with our index at ingest time (not query time); split pkgbases produce N package rows from one approval.","completedAt":"2026-11-18T09:12:33.747Z","evidence":"src/pkginfo.rs is now the production home for tar+text parsing (no libalpm); shims delegate to it and steps.rs uses it. tests/world.rs (5 tests) builds real .pkg.tar.zst archives and asserts: pkginfo "},{"id":"task-p4-stale","title":"Staleness query, downgrades, blocked_missing_dep, and dependents view","status":"complete","verificationContract":"stale_outdated and stale_missing are derived purely on read; a build with an unresolvable dep enters blocked_missing_dep, appears on Attention with the blocking pkgbase named, and the review page warns about missing deps before approval; the dep_edge view answers 'approving this marks N packages stale'.","completedAt":"2026-11-18T09:27:24.780Z","evidence":"tests/staleness.rs (6 tests): staleness_is_derived_on_read_and_nothing_stores_it (a sqlite_master/pragma_table_info scan asserts NO column anywhere stores staleness, and withdrawing a dependency flips"},{"id":"task-p4-ops","title":"Retention/GC, metrics endpoint, and backup helper","status":"pending","verificationContract":"Retention keeps N versions with logs and sources as a unit and sweeps abandoned staging dirs; GET /metrics emits prometheus text including queue depth, pending-review age histogram, build success rate and WAL size; backup uses VACUUM INTO (never cp of a live WAL db)."},{"id":"task-p4-deps","title":"vercmp + dependency-string parser and version-delta flagging (§4, §6)","status":"complete","verificationContract":"Hand-written vercmp and dep-string parser pass a table-driven test suite (epoch, pkgrel reset, alpha/numeric boundaries, provides/conflicts syntax); downgrade and epoch-bump detection use them and are covered by tests.","completedAt":"2026-11-18T09:44:44.096Z","evidence":"tests/versions.rs (12 tests). The table-driven suite became a differential one: vercmp_matches_the_system_oracle compares the hand-written comparator against pacman's own `vercmp` binary over a 34-fra"}]},{"id":"task-verify","title":"Final verification pass, real-chroot attempt, and documentation","status":"pending","verificationContract":"Full `cargo test` and `cargo clippy` run clean; every §2 invariant maps to a named passing test (list produced); README + docs/DECISIONS.md written; git history reviewed for incremental commits; the gated real-chroot integration attempt against devtools is run or explicitly recorded as skipped with the reason."}],"blockCompletion":true,"proposedAt":"2026-11-17T20:39:23.165Z"},"currentTaskId":"task-p4-ops"}]}
\ No newline at end of file diff --git a/.pi/goals/.goal-ledger-checkpoint.json b/.pi/goals/.goal-ledger-checkpoint.json deleted file mode 100644 index e7d3b18..0000000 --- a/.pi/goals/.goal-ledger-checkpoint.json +++ /dev/null @@ -1 +0,0 @@ -{"version":4,"format":"goal-ledger-checkpoint","createdAt":"2026-11-18T09:45:18.859Z","coveredBytes":13574,"coveredEvents":45,"acc":{"goals":[{"goalId":"mwl5tehk-xhe7fk","latestStatus":"active","latestFocus":false,"createdAt":"2026-11-17T20:43:24.440Z","resumedAt":"2026-11-18T06:57:52.837Z"}],"terminalGoals":[],"focusedGoalId":null,"focusGeneration":0,"focusGenByGoal":[]},"recentEventsByGoal":[["mwl5tehk-xhe7fk",[{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-crash","at":"2026-11-18T08:38:10.587Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-crash","evidence":"tests/crash.rs (4 tests): a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work spawns the real aur-build binary, has a shim SIGKILL it inside the build step (asserts status.si","at":"2026-11-18T08:47:32.080Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-sse","at":"2026-11-18T08:48:58.608Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-sse","evidence":"tests/live.rs (5 tests): the_log_stream_delivers_bytes_as_they_are_appended_and_then_ends — a producer thread appends to the log while the SSE stream is open and the reader must see those bytes BEFORE","at":"2026-11-18T09:01:22.685Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3","evidence":"All three P3 children complete: dispatcher/worker pool/reaper with BEGIN IMMEDIATE claims and disk-headroom backpressure (e27e90a), a real SIGKILL mid-step crash test plus the approved_but_unbuilt fai","at":"2026-11-18T09:03:07.796Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-world","at":"2026-11-18T09:04:51.588Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-world","evidence":"src/pkginfo.rs is now the production home for tar+text parsing (no libalpm); shims delegate to it and steps.rs uses it. tests/world.rs (5 tests) builds real .pkg.tar.zst archives and asserts: pkginfo ","at":"2026-11-18T09:12:33.748Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-stale","at":"2026-11-18T09:14:30.194Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-stale","evidence":"tests/staleness.rs (6 tests): staleness_is_derived_on_read_and_nothing_stores_it (a sqlite_master/pragma_table_info scan asserts NO column anywhere stores staleness, and withdrawing a dependency flips","at":"2026-11-18T09:27:24.780Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-deps","at":"2026-11-18T09:29:34.423Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-deps","evidence":"tests/versions.rs (12 tests). The table-driven suite became a differential one: vercmp_matches_the_system_oracle compares the hand-written comparator against pacman's own `vercmp` binary over a 34-fra","at":"2026-11-18T09:44:44.096Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-ops","at":"2026-11-18T09:45:18.852Z"}]]],"runtimeIndex":[["mwl5tehk-xhe7fk",{"recent":[{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-crash","at":"2026-11-18T08:38:10.587Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-crash","evidence":"tests/crash.rs (4 tests): a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work spawns the real aur-build binary, has a shim SIGKILL it inside the build step (asserts status.si","at":"2026-11-18T08:47:32.080Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-sse","at":"2026-11-18T08:48:58.608Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-sse","evidence":"tests/live.rs (5 tests): the_log_stream_delivers_bytes_as_they_are_appended_and_then_ends — a producer thread appends to the log while the SSE stream is open and the reader must see those bytes BEFORE","at":"2026-11-18T09:01:22.685Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3","evidence":"All three P3 children complete: dispatcher/worker pool/reaper with BEGIN IMMEDIATE claims and disk-headroom backpressure (e27e90a), a real SIGKILL mid-step crash test plus the approved_but_unbuilt fai","at":"2026-11-18T09:03:07.796Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-world","at":"2026-11-18T09:04:51.588Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-world","evidence":"src/pkginfo.rs is now the production home for tar+text parsing (no libalpm); shims delegate to it and steps.rs uses it. tests/world.rs (5 tests) builds real .pkg.tar.zst archives and asserts: pkginfo ","at":"2026-11-18T09:12:33.748Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-stale","at":"2026-11-18T09:14:30.194Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-stale","evidence":"tests/staleness.rs (6 tests): staleness_is_derived_on_read_and_nothing_stores_it (a sqlite_master/pragma_table_info scan asserts NO column anywhere stores staleness, and withdrawing a dependency flips","at":"2026-11-18T09:27:24.780Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-deps","at":"2026-11-18T09:29:34.423Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-deps","evidence":"tests/versions.rs (12 tests). The table-driven suite became a differential one: vercmp_matches_the_system_oracle compares the hand-written comparator against pacman's own `vercmp` binary over a 34-fra","at":"2026-11-18T09:44:44.096Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-ops","at":"2026-11-18T09:45:18.852Z"}],"activity":[{"type":"goal_created","goalId":"mwl5tehk-xhe7fk","objective":"Implement the AUR Build Server described in DESIGN.md as a single-process Rust binary in /workspace/aur-build, delivering phases P0–P4 (walking skeleton + test harness, VCS/pkgver detection, review web UI, durable build pipeline, staleness tracking), with every §2 invariant expressed as an executable test and the work committed incrementally to git.\n\nSUCCESS CRITERIA (observable):\n1. `cargo test` passes on the host with no `#[ignore]`-tier tests required; the §16a fake-package corpus and toolchain PATH shims drive the full step machine, publishing and crash-resume tests without root, network, or a real chroot.\n2. Invariants I1–I12 of §2 each have a named test that passes (I1 no-artifact-without-approval is a post-test query; I2 diff-base-is-last-accepted; I4 atomic publish survives kill-mid-publish; I5 step checkpoint/resume; I7 one open review enforced by the partial unique index; I12 world snapshots recorded).\n3. End-to-end against shims: subscribe pkgbase → detect → review → approve → build → publish a signed repo where both packages and the .db are signed, and the served index equals the set of current_accepted_release pointers (I8).\n4. Web UI serves the five §13 surfaces (Inbox, Builds, Attention, Index, Subscriptions) plus Ops/audit as server-rendered HTML; approve carries identity_hash + diff_digest and returns HTTP 409 on a stale approval (§7.1a).\n5. `cargo clippy` reports no errors; `git log` shows a sequence of small, meaningful commits from the initial scaffold to the final state; README documents build, run, and test commands.\n\nBOUNDARIES — IN SCOPE: P0, P1, P2, P3, P4 of §17, the §11 schema, §16 edge cases, §16a test harness, and one gated real-chroot integration attempt (devtools installed) if time permits.\nOUT OF SCOPE: everything in §20 (auto-approval policies, automatic dependency rebuilds, recipe-mutating hardening transforms, build-time upstream-pin honouring, network controls, cost-weighted admission, notifications), P5 polish, multi-tenancy/RBAC, non-x86_64 arches, and any change to DESIGN.md's decided decisions in §18.\n\nCONSTRAINTS (hard):\n- Rust edition 2021, no `async`/`await`, no tokio/axum/actix/reqwest/sqlx/libgit2; threads + crossbeam channels only; blocking HTTP via tiny_http; outbound HTTP via ureq; git by shelling out.\n- SQLite via rusqlite in WAL mode with exactly one writer actor thread (channel-based `Tx` enum) and thread-local read-only readers; no transaction may span a build step.\n- UI is server-rendered (askama or minijinja) with at most vendored htmx (~14 KB) plus ~30 lines of glue; no JS written by us beyond that glue, no bundler.\n- Fail closed on every pin assertion (recipe_hash, pkgver match against approved identity); non-publishable changes become `notice` rows, never candidates, never dropped (I11).\n- Provisioning: `sudo pacman -S --needed rustup devtools` (fall back to `pacman -S rust` only if rustup is unusable); no other system mutations; never commit secrets, the signing key, or build artifacts.\n- Commit incrementally: one commit per coherent step with a descriptive message; never a single monolithic commit; DESIGN.md stays untouched.\n- If a §19 open question blocks a design choice, pick the least-entangling option, record it in a `docs/DECISIONS.md` entry, and keep moving; stop and ask only if the choice is genuinely irreversible.\n\nIF BLOCKED: stop and ask the user (e.g. no network for crates, toolchain uninstallable, an invariant that cannot be made testable).","sisyphus":false,"autoContinue":true,"at":"2026-11-17T20:43:24.440Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-setup","at":"2026-11-17T20:43:42.908Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-setup","evidence":"rustup 1.29.3 (pacman) + stable 1.100.0, devtools installed (mkarchroot/makechrootpkg present); git repo initialized on main with commit 3762c7c containing DESIGN.md, .gitignore, Cargo.toml; `cargo bu","at":"2026-11-17T20:48:20.900Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-schema","at":"2026-11-17T20:48:42.903Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-schema","evidence":"tests/db.rs: 10 tests pass — migrations from empty + idempotent + WAL, default settings, I7 partial unique index rejects 2nd pending_review, candidate identity uniqueness, audit append-only triggers, ","at":"2026-11-17T21:00:03.124Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-detect","at":"2026-11-17T21:00:47.994Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-detect","evidence":"tests/detect.rs: 16 tests pass against real file:// git fixtures — clone+ls-remote poll with fetch only on SHA move (Sync::Unchanged vs Fetched), snapshot records aur_commit + recipe_hash covering shi","at":"2026-11-17T21:20:02.693Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-shims","at":"2026-11-17T21:21:27.981Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-shims","evidence":"src/shims + src/bin/{mkarchroot,makechrootpkg,makepkg,repo-add,gpg,pacman}: shims record invocations to AUR_SHIM_DIR/invocations.jsonl, obey AUR_SHIM_MANIFEST, and emit real .pkg.tar.zst with .PKGINFO","at":"2026-11-17T21:31:09.121Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-build","at":"2026-11-17T21:32:52.768Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-build","evidence":"tests/pipeline.rs: 17 shim-driven e2e tests pass (fail-closed recipe_hash + pkgver, kill-mid-publish I4, crash-resume I5, CAS pointer, signed db+pkgs); cargo clippy clean","at":"2026-11-17T21:58:00.937Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-approve","at":"2026-11-17T21:58:43.315Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-approve","evidence":"tests/approve.rs: 10 tests pass incl. both-hash immutable approval row (migration 0006 trigger), stale identity/diff refused, collapse-in-place revision bump, viewed→superseded freeze, rejected identi","at":"2026-11-17T22:10:06.063Z"},{"type":"goal_paused","goalId":"mwl5tehk-xhe7fk","reason":"user","status":"paused","at":"2026-11-17T22:12:03.674Z"},{"type":"goal_resumed","goalId":"mwl5tehk-xhe7fk","reason":"user","at":"2026-11-18T06:57:52.837Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-invariants","evidence":"tests/invariants.rs: 10 named invariant tests pass as post-conditions on real runs (I1 approval trace, I2 base after 5 detections, I3 recipe pin, I4 byte-identical index after mid-publish crash, I5 re","at":"2026-11-18T07:01:31.400Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0","evidence":"All P0 children complete: schema+writer actor, shims+corpus, mirror watcher, approval semantics+CLI, 10-step pipeline with signed atomic publish, invariant index. 81 tests pass, clippy clean, 7 commit","at":"2026-11-18T07:02:29.831Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p1-stageA","at":"2026-11-18T07:04:12.225Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p1-stageA","evidence":"tests/vcs.rs: stage_a_probes_every_vcs_source_not_just_the_first (git-multi → 2 pins matching both repo HEADs), stage_a_respects_a_tag_pin, stage_a_short_circuits_before_stage_b_when_nothing_moved (ma","at":"2026-11-18T07:16:40.078Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p1-stageB","evidence":"tests/vcs.rs: stage_b_resolves_pkgver_and_captures_the_pins (pins in identity_hash via Identity hash comparison), stage_b_is_cached_on_pkgbase_recipe_and_tip (cache row reuse + cooldown + re-resolve o","at":"2026-11-18T07:17:57.387Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p1-notices","at":"2026-11-18T07:19:15.892Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p1-notices","evidence":"tests/notices.rs: 8 tests — digest-drift fixture → high-severity integrity_alert + no candidate, pin-drift → info notice + no candidate, recipe drift → warning, skip-checksum → HIGH risk signal 'skip-","at":"2026-11-18T07:29:10.457Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p1","evidence":"All three P1 children complete: Stage A probe (every VCS source, #tag/#commit, short-circuit), Stage B resolution (pin capture, cache on pkgbase+recipe_hash+tip, cooldown, concurrency cap), notices+ri","at":"2026-11-18T07:30:36.958Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p2-http","at":"2026-11-18T07:32:27.434Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p2-http","evidence":"tests/http.rs (14 tests, all pass): every_surface_renders covers all §12 routes on a live tiny_http server; every_post_requires_a_csrf_token asserts 403 for missing and forged tokens with zero rows wr","at":"2026-11-18T08:06:45.433Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p2-inbox","evidence":"src/review/diff.rs now emits all eight §6 panels (recipe, version, source-digest, upstream, source, dependency, build-env, install-hook), each computed accepted→candidate; commit ab8d33d. tests/http.r","at":"2026-11-18T08:07:10.624Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p2-approve409","evidence":"tests/http.rs: a_stale_approval_is_a_409_that_renders_the_current_diff (upstream moves mid-review → 409, body explains the ground moved, re-render shows the new 9.9 version, zero approval rows written","at":"2026-11-18T08:07:36.401Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p2-surfaces","at":"2026-11-18T08:08:13.901Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p2-surfaces","evidence":"tests/surfaces.rs (7 tests): attention_lists_outdated_dependencies_from_the_recorded_world (dep-client stale after plain-make moves, dependency + built-against + now all named); attention_lists_a_down","at":"2026-11-18T08:23:18.652Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p2","evidence":"All four P2 children complete: tiny_http server + CSRF/session gate, inbox with the full eight-panel diff set, optimistic-concurrency approve/reject with 409-on-stale and per-item bulk confirmation, a","at":"2026-11-18T08:24:11.640Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-dispatch","at":"2026-11-18T08:25:05.524Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-dispatch","evidence":"src/pipeline/dispatch.rs + tests/dispatch.rs (9 tests): claim_batch runs SELECT+UPDATE in one BEGIN IMMEDIATE tx (db.writer.tx uses TransactionBehavior::Immediate); an_expired_lease_is_requeued_and_it","at":"2026-11-18T08:36:46.878Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-crash","at":"2026-11-18T08:38:10.587Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-crash","evidence":"tests/crash.rs (4 tests): a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work spawns the real aur-build binary, has a shim SIGKILL it inside the build step (asserts status.si","at":"2026-11-18T08:47:32.080Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-sse","at":"2026-11-18T08:48:58.608Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-sse","evidence":"tests/live.rs (5 tests): the_log_stream_delivers_bytes_as_they_are_appended_and_then_ends — a producer thread appends to the log while the SSE stream is open and the reader must see those bytes BEFORE","at":"2026-11-18T09:01:22.685Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3","evidence":"All three P3 children complete: dispatcher/worker pool/reaper with BEGIN IMMEDIATE claims and disk-headroom backpressure (e27e90a), a real SIGKILL mid-step crash test plus the approved_but_unbuilt fai","at":"2026-11-18T09:03:07.796Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-world","at":"2026-11-18T09:04:51.588Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-world","evidence":"src/pkginfo.rs is now the production home for tar+text parsing (no libalpm); shims delegate to it and steps.rs uses it. tests/world.rs (5 tests) builds real .pkg.tar.zst archives and asserts: pkginfo ","at":"2026-11-18T09:12:33.748Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-stale","at":"2026-11-18T09:14:30.194Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-stale","evidence":"tests/staleness.rs (6 tests): staleness_is_derived_on_read_and_nothing_stores_it (a sqlite_master/pragma_table_info scan asserts NO column anywhere stores staleness, and withdrawing a dependency flips","at":"2026-11-18T09:27:24.780Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-deps","at":"2026-11-18T09:29:34.423Z"},{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-deps","evidence":"tests/versions.rs (12 tests). The table-driven suite became a differential one: vercmp_matches_the_system_oracle compares the hand-written comparator against pacman's own `vercmp` binary over a 34-fra","at":"2026-11-18T09:44:44.096Z"},{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-ops","at":"2026-11-18T09:45:18.852Z"}],"oracle":[],"lifecycle":{"type":"goal_resumed","goalId":"mwl5tehk-xhe7fk","reason":"user","at":"2026-11-18T06:57:52.837Z"},"lastActivityEvent":{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-ops","at":"2026-11-18T09:45:18.852Z"}}]]}
\ No newline at end of file diff --git a/.pi/goals/active_goal_2026111720432444_mwl5tehk-xhe7fk.md b/.pi/goals/active_goal_2026111720432444_mwl5tehk-xhe7fk.md deleted file mode 100644 index e920f78..0000000 --- a/.pi/goals/active_goal_2026111720432444_mwl5tehk-xhe7fk.md +++ /dev/null @@ -1,299 +0,0 @@ -{ - "version": 3, - "id": "mwl5tehk-xhe7fk", - "objective": "Implement the AUR Build Server described in DESIGN.md as a single-process Rust binary in /workspace/aur-build, delivering phases P0–P4 (walking skeleton + test harness, VCS/pkgver detection, review web UI, durable build pipeline, staleness tracking), with every §2 invariant expressed as an executable test and the work committed incrementally to git.\n\nSUCCESS CRITERIA (observable):\n1. `cargo test` passes on the host with no `#[ignore]`-tier tests required; the §16a fake-package corpus and toolchain PATH shims drive the full step machine, publishing and crash-resume tests without root, network, or a real chroot.\n2. Invariants I1–I12 of §2 each have a named test that passes (I1 no-artifact-without-approval is a post-test query; I2 diff-base-is-last-accepted; I4 atomic publish survives kill-mid-publish; I5 step checkpoint/resume; I7 one open review enforced by the partial unique index; I12 world snapshots recorded).\n3. End-to-end against shims: subscribe pkgbase → detect → review → approve → build → publish a signed repo where both packages and the .db are signed, and the served index equals the set of current_accepted_release pointers (I8).\n4. Web UI serves the five §13 surfaces (Inbox, Builds, Attention, Index, Subscriptions) plus Ops/audit as server-rendered HTML; approve carries identity_hash + diff_digest and returns HTTP 409 on a stale approval (§7.1a).\n5. `cargo clippy` reports no errors; `git log` shows a sequence of small, meaningful commits from the initial scaffold to the final state; README documents build, run, and test commands.\n\nBOUNDARIES — IN SCOPE: P0, P1, P2, P3, P4 of §17, the §11 schema, §16 edge cases, §16a test harness, and one gated real-chroot integration attempt (devtools installed) if time permits.\nOUT OF SCOPE: everything in §20 (auto-approval policies, automatic dependency rebuilds, recipe-mutating hardening transforms, build-time upstream-pin honouring, network controls, cost-weighted admission, notifications), P5 polish, multi-tenancy/RBAC, non-x86_64 arches, and any change to DESIGN.md's decided decisions in §18.\n\nCONSTRAINTS (hard):\n- Rust edition 2021, no `async`/`await`, no tokio/axum/actix/reqwest/sqlx/libgit2; threads + crossbeam channels only; blocking HTTP via tiny_http; outbound HTTP via ureq; git by shelling out.\n- SQLite via rusqlite in WAL mode with exactly one writer actor thread (channel-based `Tx` enum) and thread-local read-only readers; no transaction may span a build step.\n- UI is server-rendered (askama or minijinja) with at most vendored htmx (~14 KB) plus ~30 lines of glue; no JS written by us beyond that glue, no bundler.\n- Fail closed on every pin assertion (recipe_hash, pkgver match against approved identity); non-publishable changes become `notice` rows, never candidates, never dropped (I11).\n- Provisioning: `sudo pacman -S --needed rustup devtools` (fall back to `pacman -S rust` only if rustup is unusable); no other system mutations; never commit secrets, the signing key, or build artifacts.\n- Commit incrementally: one commit per coherent step with a descriptive message; never a single monolithic commit; DESIGN.md stays untouched.\n- If a §19 open question blocks a design choice, pick the least-entangling option, record it in a `docs/DECISIONS.md` entry, and keep moving; stop and ask only if the choice is genuinely irreversible.\n\nIF BLOCKED: stop and ask the user (e.g. no network for crates, toolchain uninstallable, an invariant that cannot be made testable).", - "status": "active", - "autoContinue": true, - "usage": { - "tokensUsed": 8635397, - "activeSeconds": 15531 - }, - "sisyphus": false, - "createdAt": "2026-11-17T20:43:24.440Z", - "updatedAt": "2026-11-18T10:01:44.017Z", - "activePath": ".pi/goals/active_goal_2026111720432444_mwl5tehk-xhe7fk.md", - "revision": 817, - "scheduler": { - "version": 1, - "owner": "01a1eb32-2e3f-757c-a79a-21ac993facc5", - "generation": "dfbaf4f2-dad9-4dc6-9717-5038550aa75e", - "used": 1, - "phase": "running", - "repairUsed": false, - "decision": { - "kind": "ready", - "purpose": "kickoff" - }, - "dispatch": { - "id": "27430841-6f83-4343-a9fa-dd1c866de9d3", - "kind": "kickoff", - "claimedAt": 1794985072841 - } - }, - "taskList": { - "tasks": [ - { - "id": "task-setup", - "title": "Provision toolchain (pacman rustup + devtools) and initialize git", - "status": "complete", - "verificationContract": "`rustup show` and `cargo --version` work; `git -C /workspace/aur-build log` contains an initial commit with DESIGN.md, .gitignore, and a scaffolded Cargo.toml that `cargo build` compiles.", - "completedAt": "2026-11-17T20:48:20.900Z", - "evidence": "rustup 1.29.3 (pacman) + stable 1.100.0, devtools installed (mkarchroot/makechrootpkg present); git repo initialized on main with commit 3762c7c containing DESIGN.md, .gitignore, Cargo.toml; `cargo bu" - }, - { - "id": "task-p0", - "title": "P0 — walking skeleton + test harness (§17 P0, §16a)", - "status": "complete", - "subtasks": [ - { - "id": "task-p0-schema", - "title": "SQLite schema, migrations, and single writer actor (§11, §11a)", - "status": "complete", - "verificationContract": "Migrations apply from empty DB; partial unique index rejects a second pending_review per pkgbase; audit table rejects UPDATE/DELETE by trigger; concurrent readers do not block the writer in a test.", - "completedAt": "2026-11-17T21:00:03.122Z", - "evidence": "tests/db.rs: 10 tests pass — migrations from empty + idempotent + WAL, default settings, I7 partial unique index rejects 2nd pending_review, candidate identity uniqueness, audit append-only triggers, " - }, - { - "id": "task-p0-shims", - "title": "Toolchain PATH shims + fake-package corpus (§16a)", - "status": "complete", - "verificationContract": "Fakes for mkarchroot/makechrootpkg/makepkg/repo-add/gpg/pacman record invocations and emit plausible .PKGINFO/.BUILDINFO/.sig per fixture manifest; at least plain-make, with-patch, skip-checksum, split-pkgbase, build-fails, missing-dep, epoch-bump, pkgrel-reset and downgrade fixtures exist and are driven by a test.", - "completedAt": "2026-11-17T21:31:09.120Z", - "evidence": "src/shims + src/bin/{mkarchroot,makechrootpkg,makepkg,repo-add,gpg,pacman}: shims record invocations to AUR_SHIM_DIR/invocations.jsonl, obey AUR_SHIM_MANIFEST, and emit real .pkg.tar.zst with .PKGINFO" - }, - { - "id": "task-p0-detect", - "title": "AUR mirror watcher: aur_commit pin, recipe_hash, source digests, candidate creation (§5.1, §5.1a, §5.3)", - "status": "complete", - "verificationContract": "Against a local file:// 'AUR' repo fixture: clone + ls-remote poll + fetch only on SHA move; snapshot records aur_commit and recipe_hash covering PKGBUILD/.SRCINFO/*.install/patches; SKIP sources are stream-hashed into source_cache; candidate.base is current_accepted_release; a brand-new pkgbase yields kind=first_introduction.", - "completedAt": "2026-11-17T21:20:02.693Z", - "evidence": "tests/detect.rs: 16 tests pass against real file:// git fixtures — clone+ls-remote poll with fetch only on SHA move (Sync::Unchanged vs Fetched), snapshot records aur_commit + recipe_hash covering shi" - }, - { - "id": "task-p0-approve", - "title": "Approval semantics + CLI approval path (§7.1, §7.1a, §7.2)", - "status": "complete", - "verificationContract": "CLI approve writes an immutable approval row with diff_digest and identity_hash; approving with a stale identity_hash or diff_digest is refused; collapse-in-place bumps revision without a new row while unviewed and freezes as superseded once viewed; a rejected identity is not re-detected.", - "completedAt": "2026-11-17T22:10:06.063Z", - "evidence": "tests/approve.rs: 10 tests pass incl. both-hash immutable approval row (migration 0006 trigger), stale identity/diff refused, collapse-in-place revision bump, viewed→superseded freeze, rejected identi" - }, - { - "id": "task-p0-build", - "title": "Build pipeline steps 0–9 and atomic signed publish (§8.1, §9)", - "status": "complete", - "verificationContract": "Shim-driven run of materialize→plan→chroot→sources→pkgver→build→collect→verify→ingest→publish; step 0 materializes from the local mirror and fails closed on recipe_hash mismatch; step 4 fails closed on pkgver mismatch; publish writes .tmp, fsyncs, renames, signs package and db, and updates current_accepted_release_id by compare-and-swap.", - "completedAt": "2026-11-17T21:58:00.936Z", - "evidence": "tests/pipeline.rs: 17 shim-driven e2e tests pass (fail-closed recipe_hash + pkgver, kill-mid-publish I4, crash-resume I5, CAS pointer, signed db+pkgs); cargo clippy clean" - }, - { - "id": "task-p0-invariants", - "title": "Executable invariant tests I1/I2/I4/I5/I8", - "status": "complete", - "verificationContract": "cargo test includes: post-run query proving no index entry lacks an approval (I1); multi-detection fixture proving the diff base is the last accepted version (I2); kill-mid-publish leaving the old index intact (I4); restart-resumes-at-next-incomplete-step with no duplicate side effects (I5); index set equals accepted-release pointers (I8).", - "completedAt": "2026-11-18T07:01:31.398Z", - "evidence": "tests/invariants.rs: 10 named invariant tests pass as post-conditions on real runs (I1 approval trace, I2 base after 5 detections, I3 recipe pin, I4 byte-identical index after mid-publish crash, I5 re" - } - ], - "completedAt": "2026-11-18T07:02:29.831Z", - "evidence": "All P0 children complete: schema+writer actor, shims+corpus, mirror watcher, approval semantics+CLI, 10-step pipeline with signed atomic publish, invariant index. 81 tests pass, clippy clean, 7 commit" - }, - { - "id": "task-p1", - "title": "P1 — VCS / computed pkgver detection (§5.2, §3)", - "status": "complete", - "subtasks": [ - { - "id": "task-p1-stageA", - "title": "Stage A upstream probes over all VCS sources + persistent vcs_cache", - "status": "complete", - "verificationContract": "Parses source=() for git+/svn+/hg+ with #tag/#commit refs; probes via git ls-remote against local file:// repos; an unchanged HEAD set short-circuits before Stage B; multiple VCS sources each get their own pin entry.", - "completedAt": "2026-11-18T07:16:40.077Z", - "evidence": "tests/vcs.rs: stage_a_probes_every_vcs_source_not_just_the_first (git-multi → 2 pins matching both repo HEADs), stage_a_respects_a_tag_pin, stage_a_short_circuits_before_stage_b_when_nothing_moved (ma" - }, - { - "id": "task-p1-stageB", - "title": "Stage B pkgver() resolution with pin capture + identity tuple", - "status": "complete", - "verificationContract": "Resolved epoch:pkgver-pkgrel plus upstream_pins become part of identity_hash; cooldown and global concurrency cap enforced; cache keyed on (pkgbase, recipe_hash, upstream_tip); a git-sourced fixture produces a candidate whose pins match the fixture repo HEAD.", - "completedAt": "2026-11-18T07:17:57.387Z", - "evidence": "tests/vcs.rs: stage_b_resolves_pkgver_and_captures_the_pins (pins in identity_hash via Identity hash comparison), stage_b_is_cached_on_pkgbase_recipe_and_tip (cache row reuse + cooldown + re-resolve o" - }, - { - "id": "task-p1-notices", - "title": "Non-publishable change handling: pin_drift, recipe drift, digest drift → notice / integrity_alert (§5.2, §5.3, I11)", - "status": "complete", - "verificationContract": "pin-drift fixture yields a notice and no candidate; digest-drift fixture yields a high-severity integrity_alert and no candidate; SKIP-on-non-VCS is flagged as a risk signal; nothing publishable is silently dropped.", - "completedAt": "2026-11-18T07:29:10.456Z", - "evidence": "tests/notices.rs: 8 tests — digest-drift fixture → high-severity integrity_alert + no candidate, pin-drift → info notice + no candidate, recipe drift → warning, skip-checksum → HIGH risk signal 'skip-" - } - ], - "completedAt": "2026-11-18T07:30:36.958Z", - "evidence": "All three P1 children complete: Stage A probe (every VCS source, #tag/#commit, short-circuit), Stage B resolution (pin capture, cache on pkgbase+recipe_hash+tip, cooldown, concurrency cap), notices+ri" - }, - { - "id": "task-p2", - "title": "P2 — review surface (§12, §13, §6)", - "status": "complete", - "subtasks": [ - { - "id": "task-p2-http", - "title": "tiny_http server, templating, thread-local readers, CSRF + session gate", - "status": "complete", - "verificationContract": "Thread-per-connection server renders all §12 routes; every POST requires a CSRF token; handlers never use the write connection; pages render with JS disabled.", - "completedAt": "2026-11-18T08:06:45.433Z", - "evidence": "tests/http.rs (14 tests, all pass): every_surface_renders covers all §12 routes on a live tiny_http server; every_post_requires_a_csrf_token asserts 403 for missing and forged tokens with zero rows wr" - }, - { - "id": "task-p2-inbox", - "title": "Inbox + diff panels + advisory risk scoring (§6, §7.1b)", - "status": "complete", - "verificationContract": "Review detail renders recipe / version / source-digest / upstream / source / dependency / build-env / install-hook panels, all based on accepted→candidate; risk signals computed and shown inline; base and aur_commit displayed with an AUR cgit link; first_introduction renders the full recipe with the subtle accent and no diff pane.", - "completedAt": "2026-11-18T08:07:10.624Z", - "evidence": "src/review/diff.rs now emits all eight §6 panels (recipe, version, source-digest, upstream, source, dependency, build-env, install-hook), each computed accepted→candidate; commit ab8d33d. tests/http.r" - }, - { - "id": "task-p2-approve409", - "title": "Optimistic-concurrency approve/reject + bulk operations (§7.1a, §7.4)", - "status": "complete", - "verificationContract": "Approve POST with a stale identity_hash/diff_digest returns 409 and re-renders the current diff with an explanation; bulk approve refuses high-risk items without per-item confirmation; reject requires a note and is re-openable.", - "completedAt": "2026-11-18T08:07:36.401Z", - "evidence": "tests/http.rs: a_stale_approval_is_a_409_that_renders_the_current_diff (upstream moves mid-review → 409, body explains the ground moved, re-render shows the new 9.9 version, zero approval rows written" - }, - { - "id": "task-p2-surfaces", - "title": "Subscriptions, Index, Builds, Attention, Ops/audit pages", - "status": "complete", - "verificationContract": "Each §13 surface renders from live DB state; Attention shows outdated-dependency, downgrade and blocked-build rows; the package page shows timeline, deps in/out, staleness and aur_commit history; manual rebuild reuses the approved source identity without a new approval (I6).", - "completedAt": "2026-11-18T08:23:18.650Z", - "evidence": "tests/surfaces.rs (7 tests): attention_lists_outdated_dependencies_from_the_recorded_world (dep-client stale after plain-make moves, dependency + built-against + now all named); attention_lists_a_down" - } - ], - "completedAt": "2026-11-18T08:24:11.640Z", - "evidence": "All four P2 children complete: tiny_http server + CSRF/session gate, inbox with the full eight-panel diff set, optimistic-concurrency approve/reject with 409-on-stale and per-item bulk confirmation, a" - }, - { - "id": "task-p3", - "title": "P3 — durability (§8.2, §8.3, §8.4)", - "status": "complete", - "subtasks": [ - { - "id": "task-p3-dispatch", - "title": "Dispatcher actor, worker pool, leases, and reaper", - "status": "complete", - "verificationContract": "Dispatcher claims with BEGIN IMMEDIATE + lease expiry, requeues expired leases on startup, marks in-flight steps interrupted; the deterministic build id makes re-enqueue an INSERT OR IGNORE no-op; backpressure respects max_concurrent_builds and disk headroom.", - "completedAt": "2026-11-18T08:36:46.877Z", - "evidence": "src/pipeline/dispatch.rs + tests/dispatch.rs (9 tests): claim_batch runs SELECT+UPDATE in one BEGIN IMMEDIATE tx (db.writer.tx uses TransactionBehavior::Immediate); an_expired_lease_is_requeued_and_it" - }, - { - "id": "task-p3-crash", - "title": "Cancellation, retry policy, and crash-resume tests against shims (I5)", - "status": "complete", - "verificationContract": "A test kills the process mid-step and asserts resume at the next incomplete step with no duplicate side effects; cancel_requested stops a worker at a step boundary; deterministic build failures do not auto-retry and the release stays approved_but_unbuilt with the UI showing 'index still serving v1'.", - "completedAt": "2026-11-18T08:47:32.080Z", - "evidence": "tests/crash.rs (4 tests): a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work spawns the real aur-build binary, has a shim SIGKILL it inside the build step (asserts status.si" - }, - { - "id": "task-p3-sse", - "title": "SSE log tail + htmx live builds table", - "status": "complete", - "verificationContract": "GET /builds/:id/log.stream streams appended log bytes from a blocking thread; the builds table refreshes via htmx every 3s; vendored htmx is the only JS shipped and total vendored JS stays under 20 KB.", - "completedAt": "2026-11-18T09:01:22.683Z", - "evidence": "tests/live.rs (5 tests): the_log_stream_delivers_bytes_as_they_are_appended_and_then_ends — a producer thread appends to the log while the SSE stream is open and the reader must see those bytes BEFORE" - } - ], - "completedAt": "2026-11-18T09:03:07.796Z", - "evidence": "All three P3 children complete: dispatcher/worker pool/reaper with BEGIN IMMEDIATE claims and disk-headroom backpressure (e27e90a), a real SIGKILL mid-step crash test plus the approved_but_unbuilt fai" - }, - { - "id": "task-p4", - "title": "P4 — staleness, retention, metrics (§10, §15)", - "status": "pending", - "subtasks": [ - { - "id": "task-p4-world", - "title": ".PKGINFO/.BUILDINFO parsing and world_snapshot filtered to our own repo", - "status": "complete", - "verificationContract": "Ingest parses tar+text without libalpm; world_snapshot members are intersected with our index at ingest time (not query time); split pkgbases produce N package rows from one approval.", - "completedAt": "2026-11-18T09:12:33.747Z", - "evidence": "src/pkginfo.rs is now the production home for tar+text parsing (no libalpm); shims delegate to it and steps.rs uses it. tests/world.rs (5 tests) builds real .pkg.tar.zst archives and asserts: pkginfo " - }, - { - "id": "task-p4-stale", - "title": "Staleness query, downgrades, blocked_missing_dep, and dependents view", - "status": "complete", - "verificationContract": "stale_outdated and stale_missing are derived purely on read; a build with an unresolvable dep enters blocked_missing_dep, appears on Attention with the blocking pkgbase named, and the review page warns about missing deps before approval; the dep_edge view answers 'approving this marks N packages stale'.", - "completedAt": "2026-11-18T09:27:24.780Z", - "evidence": "tests/staleness.rs (6 tests): staleness_is_derived_on_read_and_nothing_stores_it (a sqlite_master/pragma_table_info scan asserts NO column anywhere stores staleness, and withdrawing a dependency flips" - }, - { - "id": "task-p4-ops", - "title": "Retention/GC, metrics endpoint, and backup helper", - "status": "pending", - "verificationContract": "Retention keeps N versions with logs and sources as a unit and sweeps abandoned staging dirs; GET /metrics emits prometheus text including queue depth, pending-review age histogram, build success rate and WAL size; backup uses VACUUM INTO (never cp of a live WAL db)." - }, - { - "id": "task-p4-deps", - "title": "vercmp + dependency-string parser and version-delta flagging (§4, §6)", - "status": "complete", - "verificationContract": "Hand-written vercmp and dep-string parser pass a table-driven test suite (epoch, pkgrel reset, alpha/numeric boundaries, provides/conflicts syntax); downgrade and epoch-bump detection use them and are covered by tests.", - "completedAt": "2026-11-18T09:44:44.096Z", - "evidence": "tests/versions.rs (12 tests). The table-driven suite became a differential one: vercmp_matches_the_system_oracle compares the hand-written comparator against pacman's own `vercmp` binary over a 34-fra" - } - ] - }, - { - "id": "task-verify", - "title": "Final verification pass, real-chroot attempt, and documentation", - "status": "pending", - "verificationContract": "Full `cargo test` and `cargo clippy` run clean; every §2 invariant maps to a named passing test (list produced); README + docs/DECISIONS.md written; git history reviewed for incremental commits; the gated real-chroot integration attempt against devtools is run or explicitly recorded as skipped with the reason." - } - ], - "blockCompletion": true, - "proposedAt": "2026-11-17T20:39:23.165Z" - }, - "currentTaskId": "task-p4-ops" -} - -# Goal Prompt - -Implement the AUR Build Server described in DESIGN.md as a single-process Rust binary in /workspace/aur-build, delivering phases P0–P4 (walking skeleton + test harness, VCS/pkgver detection, review web UI, durable build pipeline, staleness tracking), with every §2 invariant expressed as an executable test and the work committed incrementally to git. - -SUCCESS CRITERIA (observable): -1. `cargo test` passes on the host with no `#[ignore]`-tier tests required; the §16a fake-package corpus and toolchain PATH shims drive the full step machine, publishing and crash-resume tests without root, network, or a real chroot. -2. Invariants I1–I12 of §2 each have a named test that passes (I1 no-artifact-without-approval is a post-test query; I2 diff-base-is-last-accepted; I4 atomic publish survives kill-mid-publish; I5 step checkpoint/resume; I7 one open review enforced by the partial unique index; I12 world snapshots recorded). -3. End-to-end against shims: subscribe pkgbase → detect → review → approve → build → publish a signed repo where both packages and the .db are signed, and the served index equals the set of current_accepted_release pointers (I8). -4. Web UI serves the five §13 surfaces (Inbox, Builds, Attention, Index, Subscriptions) plus Ops/audit as server-rendered HTML; approve carries identity_hash + diff_digest and returns HTTP 409 on a stale approval (§7.1a). -5. `cargo clippy` reports no errors; `git log` shows a sequence of small, meaningful commits from the initial scaffold to the final state; README documents build, run, and test commands. - -BOUNDARIES — IN SCOPE: P0, P1, P2, P3, P4 of §17, the §11 schema, §16 edge cases, §16a test harness, and one gated real-chroot integration attempt (devtools installed) if time permits. -OUT OF SCOPE: everything in §20 (auto-approval policies, automatic dependency rebuilds, recipe-mutating hardening transforms, build-time upstream-pin honouring, network controls, cost-weighted admission, notifications), P5 polish, multi-tenancy/RBAC, non-x86_64 arches, and any change to DESIGN.md's decided decisions in §18. - -CONSTRAINTS (hard): -- Rust edition 2021, no `async`/`await`, no tokio/axum/actix/reqwest/sqlx/libgit2; threads + crossbeam channels only; blocking HTTP via tiny_http; outbound HTTP via ureq; git by shelling out. -- SQLite via rusqlite in WAL mode with exactly one writer actor thread (channel-based `Tx` enum) and thread-local read-only readers; no transaction may span a build step. -- UI is server-rendered (askama or minijinja) with at most vendored htmx (~14 KB) plus ~30 lines of glue; no JS written by us beyond that glue, no bundler. -- Fail closed on every pin assertion (recipe_hash, pkgver match against approved identity); non-publishable changes become `notice` rows, never candidates, never dropped (I11). -- Provisioning: `sudo pacman -S --needed rustup devtools` (fall back to `pacman -S rust` only if rustup is unusable); no other system mutations; never commit secrets, the signing key, or build artifacts. -- Commit incrementally: one commit per coherent step with a descriptive message; never a single monolithic commit; DESIGN.md stays untouched. -- If a §19 open question blocks a design choice, pick the least-entangling option, record it in a `docs/DECISIONS.md` entry, and keep moving; stop and ask only if the choice is genuinely irreversible. - -IF BLOCKED: stop and ask the user (e.g. no network for crates, toolchain uninstallable, an invariant that cannot be made testable). - -## Progress - -- Status: running -- Auto-continue: on -- Sisyphus mode: no -- Time spent: 4h18m51s -- Tokens used: 8.6M (8,635,397) tokens -## Tasks - -<!-- blockCompletion: true --> -- [x] task-setup: Provision toolchain (pacman rustup + devtools) and initialize git — evidence: rustup 1.29.3 (pacman) + stable 1.100.0, devtools installed (mkarchroot/makechrootpkg present); git repo initialized on main with commit 3762c7c containing DESIGN.md, .gitignore, Cargo.toml; `cargo bu -- [x] task-p0: P0 — walking skeleton + test harness (§17 P0, §16a) — evidence: All P0 children complete: schema+writer actor, shims+corpus, mirror watcher, approval semantics+CLI, 10-step pipeline with signed atomic publish, invariant index. 81 tests pass, clippy clean, 7 commit -- [x] task-p1: P1 — VCS / computed pkgver detection (§5.2, §3) — evidence: All three P1 children complete: Stage A probe (every VCS source, #tag/#commit, short-circuit), Stage B resolution (pin capture, cache on pkgbase+recipe_hash+tip, cooldown, concurrency cap), notices+ri -- [x] task-p2: P2 — review surface (§12, §13, §6) — evidence: All four P2 children complete: tiny_http server + CSRF/session gate, inbox with the full eight-panel diff set, optimistic-concurrency approve/reject with 409-on-stale and per-item bulk confirmation, a -- [x] task-p3: P3 — durability (§8.2, §8.3, §8.4) — evidence: All three P3 children complete: dispatcher/worker pool/reaper with BEGIN IMMEDIATE claims and disk-headroom backpressure (e27e90a), a real SIGKILL mid-step crash test plus the approved_but_unbuilt fai -- [ ] task-p4: P4 — staleness, retention, metrics (§10, §15) -- [ ] task-verify: Final verification pass, real-chroot attempt, and documentation — contract: Full `cargo test` and `cargo clippy` run clean; every §2 invariant maps to a named passing test (list produced); README + docs/DECISIONS.md written; git history reviewed for incremental commits; the gated real-chroot integration attempt against devtools is run or explicitly recorded as skipped with the reason. - diff --git a/.pi/goals/goal_events.jsonl b/.pi/goals/goal_events.jsonl deleted file mode 100644 index 13cf644..0000000 --- a/.pi/goals/goal_events.jsonl +++ /dev/null @@ -1,45 +0,0 @@ -{"type":"goal_created","goalId":"mwl5tehk-xhe7fk","objective":"Implement the AUR Build Server described in DESIGN.md as a single-process Rust binary in /workspace/aur-build, delivering phases P0–P4 (walking skeleton + test harness, VCS/pkgver detection, review web UI, durable build pipeline, staleness tracking), with every §2 invariant expressed as an executable test and the work committed incrementally to git.\n\nSUCCESS CRITERIA (observable):\n1. `cargo test` passes on the host with no `#[ignore]`-tier tests required; the §16a fake-package corpus and toolchain PATH shims drive the full step machine, publishing and crash-resume tests without root, network, or a real chroot.\n2. Invariants I1–I12 of §2 each have a named test that passes (I1 no-artifact-without-approval is a post-test query; I2 diff-base-is-last-accepted; I4 atomic publish survives kill-mid-publish; I5 step checkpoint/resume; I7 one open review enforced by the partial unique index; I12 world snapshots recorded).\n3. End-to-end against shims: subscribe pkgbase → detect → review → approve → build → publish a signed repo where both packages and the .db are signed, and the served index equals the set of current_accepted_release pointers (I8).\n4. Web UI serves the five §13 surfaces (Inbox, Builds, Attention, Index, Subscriptions) plus Ops/audit as server-rendered HTML; approve carries identity_hash + diff_digest and returns HTTP 409 on a stale approval (§7.1a).\n5. `cargo clippy` reports no errors; `git log` shows a sequence of small, meaningful commits from the initial scaffold to the final state; README documents build, run, and test commands.\n\nBOUNDARIES — IN SCOPE: P0, P1, P2, P3, P4 of §17, the §11 schema, §16 edge cases, §16a test harness, and one gated real-chroot integration attempt (devtools installed) if time permits.\nOUT OF SCOPE: everything in §20 (auto-approval policies, automatic dependency rebuilds, recipe-mutating hardening transforms, build-time upstream-pin honouring, network controls, cost-weighted admission, notifications), P5 polish, multi-tenancy/RBAC, non-x86_64 arches, and any change to DESIGN.md's decided decisions in §18.\n\nCONSTRAINTS (hard):\n- Rust edition 2021, no `async`/`await`, no tokio/axum/actix/reqwest/sqlx/libgit2; threads + crossbeam channels only; blocking HTTP via tiny_http; outbound HTTP via ureq; git by shelling out.\n- SQLite via rusqlite in WAL mode with exactly one writer actor thread (channel-based `Tx` enum) and thread-local read-only readers; no transaction may span a build step.\n- UI is server-rendered (askama or minijinja) with at most vendored htmx (~14 KB) plus ~30 lines of glue; no JS written by us beyond that glue, no bundler.\n- Fail closed on every pin assertion (recipe_hash, pkgver match against approved identity); non-publishable changes become `notice` rows, never candidates, never dropped (I11).\n- Provisioning: `sudo pacman -S --needed rustup devtools` (fall back to `pacman -S rust` only if rustup is unusable); no other system mutations; never commit secrets, the signing key, or build artifacts.\n- Commit incrementally: one commit per coherent step with a descriptive message; never a single monolithic commit; DESIGN.md stays untouched.\n- If a §19 open question blocks a design choice, pick the least-entangling option, record it in a `docs/DECISIONS.md` entry, and keep moving; stop and ask only if the choice is genuinely irreversible.\n\nIF BLOCKED: stop and ask the user (e.g. no network for crates, toolchain uninstallable, an invariant that cannot be made testable).","sisyphus":false,"autoContinue":true,"at":"2026-11-17T20:43:24.440Z"} -{"type":"task_list_set","goalId":"mwl5tehk-xhe7fk","taskCount":7,"blockCompletion":true,"at":"2026-11-17T20:43:24.440Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-setup","at":"2026-11-17T20:43:42.908Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-setup","evidence":"rustup 1.29.3 (pacman) + stable 1.100.0, devtools installed (mkarchroot/makechrootpkg present); git repo initialized on main with commit 3762c7c containing DESIGN.md, .gitignore, Cargo.toml; `cargo bu","at":"2026-11-17T20:48:20.900Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-schema","at":"2026-11-17T20:48:42.903Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-schema","evidence":"tests/db.rs: 10 tests pass — migrations from empty + idempotent + WAL, default settings, I7 partial unique index rejects 2nd pending_review, candidate identity uniqueness, audit append-only triggers, ","at":"2026-11-17T21:00:03.124Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-detect","at":"2026-11-17T21:00:47.994Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-detect","evidence":"tests/detect.rs: 16 tests pass against real file:// git fixtures — clone+ls-remote poll with fetch only on SHA move (Sync::Unchanged vs Fetched), snapshot records aur_commit + recipe_hash covering shi","at":"2026-11-17T21:20:02.693Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-shims","at":"2026-11-17T21:21:27.981Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-shims","evidence":"src/shims + src/bin/{mkarchroot,makechrootpkg,makepkg,repo-add,gpg,pacman}: shims record invocations to AUR_SHIM_DIR/invocations.jsonl, obey AUR_SHIM_MANIFEST, and emit real .pkg.tar.zst with .PKGINFO","at":"2026-11-17T21:31:09.121Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-build","at":"2026-11-17T21:32:52.768Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-build","evidence":"tests/pipeline.rs: 17 shim-driven e2e tests pass (fail-closed recipe_hash + pkgver, kill-mid-publish I4, crash-resume I5, CAS pointer, signed db+pkgs); cargo clippy clean","at":"2026-11-17T21:58:00.937Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-approve","at":"2026-11-17T21:58:43.315Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-approve","evidence":"tests/approve.rs: 10 tests pass incl. both-hash immutable approval row (migration 0006 trigger), stale identity/diff refused, collapse-in-place revision bump, viewed→superseded freeze, rejected identi","at":"2026-11-17T22:10:06.063Z"} -{"type":"goal_paused","goalId":"mwl5tehk-xhe7fk","reason":"user","status":"paused","at":"2026-11-17T22:12:03.674Z"} -{"type":"goal_resumed","goalId":"mwl5tehk-xhe7fk","reason":"user","at":"2026-11-18T06:57:52.837Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0-invariants","evidence":"tests/invariants.rs: 10 named invariant tests pass as post-conditions on real runs (I1 approval trace, I2 base after 5 detections, I3 recipe pin, I4 byte-identical index after mid-publish crash, I5 re","at":"2026-11-18T07:01:31.400Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p0","evidence":"All P0 children complete: schema+writer actor, shims+corpus, mirror watcher, approval semantics+CLI, 10-step pipeline with signed atomic publish, invariant index. 81 tests pass, clippy clean, 7 commit","at":"2026-11-18T07:02:29.831Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p1-stageA","at":"2026-11-18T07:04:12.225Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p1-stageA","evidence":"tests/vcs.rs: stage_a_probes_every_vcs_source_not_just_the_first (git-multi → 2 pins matching both repo HEADs), stage_a_respects_a_tag_pin, stage_a_short_circuits_before_stage_b_when_nothing_moved (ma","at":"2026-11-18T07:16:40.078Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p1-stageB","evidence":"tests/vcs.rs: stage_b_resolves_pkgver_and_captures_the_pins (pins in identity_hash via Identity hash comparison), stage_b_is_cached_on_pkgbase_recipe_and_tip (cache row reuse + cooldown + re-resolve o","at":"2026-11-18T07:17:57.387Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p1-notices","at":"2026-11-18T07:19:15.892Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p1-notices","evidence":"tests/notices.rs: 8 tests — digest-drift fixture → high-severity integrity_alert + no candidate, pin-drift → info notice + no candidate, recipe drift → warning, skip-checksum → HIGH risk signal 'skip-","at":"2026-11-18T07:29:10.457Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p1","evidence":"All three P1 children complete: Stage A probe (every VCS source, #tag/#commit, short-circuit), Stage B resolution (pin capture, cache on pkgbase+recipe_hash+tip, cooldown, concurrency cap), notices+ri","at":"2026-11-18T07:30:36.958Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p2-http","at":"2026-11-18T07:32:27.434Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p2-http","evidence":"tests/http.rs (14 tests, all pass): every_surface_renders covers all §12 routes on a live tiny_http server; every_post_requires_a_csrf_token asserts 403 for missing and forged tokens with zero rows wr","at":"2026-11-18T08:06:45.433Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p2-inbox","evidence":"src/review/diff.rs now emits all eight §6 panels (recipe, version, source-digest, upstream, source, dependency, build-env, install-hook), each computed accepted→candidate; commit ab8d33d. tests/http.r","at":"2026-11-18T08:07:10.624Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p2-approve409","evidence":"tests/http.rs: a_stale_approval_is_a_409_that_renders_the_current_diff (upstream moves mid-review → 409, body explains the ground moved, re-render shows the new 9.9 version, zero approval rows written","at":"2026-11-18T08:07:36.401Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p2-surfaces","at":"2026-11-18T08:08:13.901Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p2-surfaces","evidence":"tests/surfaces.rs (7 tests): attention_lists_outdated_dependencies_from_the_recorded_world (dep-client stale after plain-make moves, dependency + built-against + now all named); attention_lists_a_down","at":"2026-11-18T08:23:18.652Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p2","evidence":"All four P2 children complete: tiny_http server + CSRF/session gate, inbox with the full eight-panel diff set, optimistic-concurrency approve/reject with 409-on-stale and per-item bulk confirmation, a","at":"2026-11-18T08:24:11.640Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-dispatch","at":"2026-11-18T08:25:05.524Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-dispatch","evidence":"src/pipeline/dispatch.rs + tests/dispatch.rs (9 tests): claim_batch runs SELECT+UPDATE in one BEGIN IMMEDIATE tx (db.writer.tx uses TransactionBehavior::Immediate); an_expired_lease_is_requeued_and_it","at":"2026-11-18T08:36:46.878Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-crash","at":"2026-11-18T08:38:10.587Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-crash","evidence":"tests/crash.rs (4 tests): a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work spawns the real aur-build binary, has a shim SIGKILL it inside the build step (asserts status.si","at":"2026-11-18T08:47:32.080Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-sse","at":"2026-11-18T08:48:58.608Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3-sse","evidence":"tests/live.rs (5 tests): the_log_stream_delivers_bytes_as_they_are_appended_and_then_ends — a producer thread appends to the log while the SSE stream is open and the reader must see those bytes BEFORE","at":"2026-11-18T09:01:22.685Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p3","evidence":"All three P3 children complete: dispatcher/worker pool/reaper with BEGIN IMMEDIATE claims and disk-headroom backpressure (e27e90a), a real SIGKILL mid-step crash test plus the approved_but_unbuilt fai","at":"2026-11-18T09:03:07.796Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-world","at":"2026-11-18T09:04:51.588Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-world","evidence":"src/pkginfo.rs is now the production home for tar+text parsing (no libalpm); shims delegate to it and steps.rs uses it. tests/world.rs (5 tests) builds real .pkg.tar.zst archives and asserts: pkginfo ","at":"2026-11-18T09:12:33.748Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-stale","at":"2026-11-18T09:14:30.194Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-stale","evidence":"tests/staleness.rs (6 tests): staleness_is_derived_on_read_and_nothing_stores_it (a sqlite_master/pragma_table_info scan asserts NO column anywhere stores staleness, and withdrawing a dependency flips","at":"2026-11-18T09:27:24.780Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-deps","at":"2026-11-18T09:29:34.423Z"} -{"type":"task_complete","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-deps","evidence":"tests/versions.rs (12 tests). The table-driven suite became a differential one: vercmp_matches_the_system_oracle compares the hand-written comparator against pacman's own `vercmp` binary over a 34-fra","at":"2026-11-18T09:44:44.096Z"} -{"type":"task_started","goalId":"mwl5tehk-xhe7fk","taskId":"task-p4-ops","at":"2026-11-18T09:45:18.852Z"} diff --git a/README.md b/README.md new file mode 100644 index 0000000..41ea57e --- /dev/null +++ b/README.md @@ -0,0 +1,156 @@ +# aur-build + +A build server for AUR packages: it watches recipes, shows a human what changed, +and publishes a signed pacman repository containing **only what a human +approved**. One process, no async runtime, no external services. + +The design is in [`DESIGN.md`](DESIGN.md). The invariants it must never violate +are in [`docs/INVARIANTS.md`](docs/INVARIANTS.md), each mapped to a named test. +Judgement calls where the design left an opening are in +[`docs/DECISIONS.md`](docs/DECISIONS.md). + +## The rule everything else follows + +Nothing reaches a consumer without an `approval` row behind it (I1). Every other +behaviour is downstream of that: the review page freezes the exact bytes a human +looked at and hashes them, the approve request must echo both hashes, the build +re-checks the recipe pin and the resolved version before it runs, and publish +refuses if the accepted pointer moved underneath it. + +## Quick start + +```sh +cargo build --release +target/release/aur-build --root /var/lib/aur-build init --repo aur +sudo -u aurbuild target/release/aur-build --root /var/lib/aur-build serve +``` + +Then subscribe and drive a package through once by hand: + +```sh +aur-build subscribe some-pkg +aur-build detect some-pkg # or wait for the watcher +aur-build reviews # candidate ids +aur-build show 12 # the diff panels + the two hashes +aur-build approve 12 --yes # approves exactly what was just rendered +aur-build build 12 # enqueue; the dispatcher picks it up on serve +aur-build packages # what the index is serving +``` + +`serve` runs the watcher, the HTTP UI, the dispatcher and the reaper in one +process. The CLI and the UI drive the same code paths, so anything the web +interface can do, an operator can do from a shell at 3am. + +## Layout + +``` +src/ + main.rs CLI: init, subscribe, detect, reviews, show, approve, reject, + build, rebuild, run, builds, status, packages, serve, audit, + metrics, gc, backup + config.rs one config file at <root>/config.json + db/ SQLite: migrations, model rows, queries, build state machine + mod.rs single writer actor + thread-local read-only readers + watch/ detection: scheduler, cheap/expensive polls, upstream probes, + source digests, staleness derivation + review/ candidates, diff panels, risk scoring, approval + pipeline/ the step machine, the dispatcher + worker pool, publishing + pkgver/ vercmp and the dependency-string grammar + pkginfo.rs .PKGINFO / .BUILDINFO parsing (no libalpm) + http/ tiny_http server: routes, render, auth, SSE log tail + ops.rs retention, metrics, VACUUM INTO backups + shims/ the fake toolchain that makes the pipeline testable +testcorpus/ the fixture packages the tests build for real +templates/ askama templates, server-rendered +static/ app.css and one vendored htmx +docs/ DECISIONS.md, INVARIANTS.md +``` + +## Testing without root, network, or a real chroot + +`cargo test` runs the whole thing on an ordinary user account. Two mechanisms +make that possible (§16a): + +* **PATH shims.** `src/bin/` contains `makepkg`, `makechrootpkg`, `mkarchroot`, + `repo-add`, `gpg` and `pacman`. Pointing `path_prepend` at the directory cargo + built them into makes the *unmodified* pipeline drive a fake toolchain: it + still runs real subprocesses, still reads their stdout and exit codes, still + gets real `.pkg.tar.zst` files with real `.PKGINFO` and `.BUILDINFO` inside + them, and still signs them with a fake key. The step machine cannot tell it is + not in a chroot, which is the point. +* **The fixture corpus.** `testcorpus/` holds ~20 synthetic packages, each with + a `PKGBUILD` and a manifest describing what the shims should emit: a split + pkgbase, a build that fails, a recipe whose payload drifts under a `SKIP` + checksum, a VCS package with a local upstream repo, a downgrade, an epoch bump, + a package with an unsatisfiable dependency. Tests drive the real code against + these rather than against mocks of the code. + +Crash tests are real: `shim_kill_parent` makes a shim `SIGKILL` the pipeline +process mid-step, and a separate test spawns the compiled binary and kills *it*, +then asserts a fresh process resumes from the step checkpoints with no duplicate +work and the old index still byte-identical. + +Some tests are gated on the host and skip themselves with a printed note rather +than failing: + +* `versions::vercmp_matches_the_system_oracle` needs pacman's `vercmp` on `PATH` + and compares the hand-written comparator against it over ~1100 pairs. +* The real-chroot tier needs root, network and devtools. It is recorded as + skipped in `docs/DECISIONS.md` rather than silently absent. + +## Operations + +```sh +aur-build metrics # Prometheus text, same as GET /metrics +aur-build gc --keep 3 # evict files beyond the retention window +aur-build gc --keep 3 --dry-run # show what would go +aur-build backup /backups/aur.db # VACUUM INTO; refuses to overwrite +``` + +Retention never deletes a row. An evicted artifact keeps its digest, size and +provenance and gains a `purged_at`, so the database says "these bytes existed and +were dropped at T" instead of continuing to claim a file that is gone. The +currently accepted release and anything still backing an index entry are never +evicted, however old they are. + +Metrics are computed from live state on every scrape — there are no counters +incremented at event sites, because a counter maintained by every code path is a +counter that quietly drifts the first time a code path is added. + +## Web UI + +Server-rendered HTML with at most one vendored JavaScript file (htmx, ~15.6 KB +gzipped on the wire) and no build step. The review surface ships no JavaScript +at all; a test greps the rendered page for `<script` to keep it that way. + +| Surface | Path | +|---|---| +| Inbox (reviews) | `/`, `/reviews`, `/reviews/:id` | +| Builds | `/builds`, `/builds/:id`, `/builds/:id/log.txt`, `/builds/:id/log.stream` | +| Attention | `/attention` | +| Index | `/packages`, `/packages/:name` | +| Subscriptions | `/subscriptions` | +| Ops / audit | `/audit`, `/settings`, `/metrics`, `/healthz` | + +Approve is a POST carrying `identity_hash` and `diff_digest`. If either no +longer matches what the candidate became while the reviewer was reading, the +server answers **409** and re-renders the current state, so a reviewer can never +approve bytes they did not see (§7.1a). Every POST requires a CSRF token bound +to the session; the whole site is gated behind a password by default. + +## Constraints this codebase keeps + +From §14, and they are not suggestions: + +* No `async`/`await`, no tokio. Threads and crossbeam channels; blocking HTTP + with `tiny_http`, outbound HTTP with `ureq`. +* SQLite in WAL with exactly one writer thread reached over a channel. Readers + are thread-local and read-only — asserted by a test. No transaction spans a + build step. +* Git by shelling out; no libgit2. +* `vercmp` and the dependency grammar are hand-written; no libalpm. They are + checked against pacman's own `vercmp` where that binary exists. +* Fail closed. A pin that does not match, a recipe hash that drifted, a package + with no signature, a symlink in the srcdir: the build stops and says why. A + change that is real but not publishable becomes a `notice` — never a candidate, + never silently dropped (I11). diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index c681c05..76c46c7 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -107,3 +107,79 @@ rewrite. A `static Mutex` around `publish()` gives the same guarantee with less machinery; the critical section is the db file rewrite, never a build. The lock poison is cleared deliberately: atomic publish means a panic cannot have left a half-written db, so wedging the queue would be worse than continuing. + +## The pipeline refuses symlinks in the srcdir, even though a chroot should make that moot + +`collect` scans the build's srcdir for `*.pkg.tar.zst`, and `ingest` copies +whatever those paths resolve to into the content-addressed store — from where +the bytes are served from our repo and signed with our key. The paths are ours +(the scan generates them) but their *targets* are not: a PKGBUILD that drops a +symlink named `evil.pkg.tar.zst` pointing at the signing keyring, the database, +or anyone's home directory would have its target copied in and published. + +**Choice.** `collect` rejects any entry that is a symlink, and any entry whose +canonicalized target escapes the build's own staging directory. The build fails +closed with the path in the message. `tests/invariants.rs::i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir` +acts the attack out through a shim hook rather than arguing it is unlikely. + +**Cost.** A legitimate build that stages a package outside its srcdir and +symlinks it in now fails. That is a build we want to fail: it is telling us the +recipe does something we cannot see the whole of. + +**Why this is not a substitute for the chroot.** I9's real enforcement is +isolation, and that tier is gated. This is the narrower claim that the control +plane does not *depend* on isolation for its own secrets — the layers should not +be load-bearing on each other. + +## Metrics are served without a session + +Everything else in the UI is behind a password. `/metrics` is not, because a +Prometheus scraper has no session to present, and the alternative — teaching the +scraper to log in and hold a cookie — puts a credential in a monitoring config +to protect numbers. + +**Choice.** `/metrics` returns counts only: queue depth, review debt and its age +histogram, build success rate, WAL size, index size, stale counts by reason, +staging usage. No package names, no versions, no audit detail, no paths. The +bind address is loopback by default, which is where that is safe; anyone exposing +it further is exposing their own choice of numbers, not their recipe history. + +**Cost.** A visitor on the host can see how busy the server is. If that ever +matters, the fix is a scrape token, not a session. + +## Retention records a purge instead of deleting the row + +The schema exists so that "which bytes produced this installed package" stays +answerable years later (§11a). Disk cannot be kept forever, so something has to +give, and the honest option is to let the *bytes* go while the *record* stays. + +**Choice.** Eviction deletes the package, signature, build log and cached +sources of releases beyond the keep window — as a unit, because a package whose +log is gone but whose bytes remain is full price for no explanation — and sets +`purged_at` on the release and its artifact rows. The digest and size survive, so +the database says "these bytes existed, hashed to this, and were dropped at T" +rather than continuing to claim a file that is no longer there. Shared +content-addressed files are reference-checked against every *retained* release +first: two releases built from the same source share one cached archive, and +aging one out must not corrupt the other. + +**Cost.** A `purged_at` column on two tables, and a UI that has to say "bytes no +longer held" rather than offering a download that 404s. + +## The real-chroot integration tier is recorded as skipped, not silently absent + +§16a gates the tier that needs root, network and devtools. On this host the +tier was not run: it requires a privileged Arch chroot (`mkarchroot` over the +real mirror database), a signing key with a real passphrase, and outbound +network to the AUR, none of which the environment provides. + +**What stands in its place.** The shim tier drives the *unmodified* pipeline +against fake tools that produce real archives, and the crash tests kill real +processes with real signals. The parts the gated tier would exercise that the +shims cannot: `mkarchroot`'s actual root construction, `makechrootpkg`'s +copy-on-write snapshot semantics, GPG's passphrase handling, and the behaviour +of a PKGBUILD that escapes its sandbox in ways a symlink does not capture. + +**How to run it.** Install devtools, create a signing key, set `signing_key_id` +and leave `path_prepend` unset so the real tools are found on `PATH`, then +subscribe to a real pkgbase and drive it through `aur-build serve`. diff --git a/docs/INVARIANTS.md b/docs/INVARIANTS.md new file mode 100644 index 0000000..3e9c7ae --- /dev/null +++ b/docs/INVARIANTS.md @@ -0,0 +1,44 @@ +# §2 invariants, and the test that holds each one + +Every invariant in DESIGN.md §2 maps to at least one named test. The primary +name is listed first; corroborating tests are listed after it. Run any of them +with `cargo test --test <file> <name>`. + +| # | Invariant | Test | +|---|---|---| +| **I1** | Every artifact in a served index traces to an `approval` row. | `invariants::i1_every_index_entry_traces_back_to_an_approval` · `pipeline::i1_no_index_entry_without_an_approval` · `pipeline::publish_refuses_without_an_approval_behind_it` · `db::i1_query_flags_index_entries_without_approval` | +| **I2** | A review's base is the pkgbase's `current_accepted_release`, not the last detected candidate. | `invariants::i2_base_is_the_last_accepted_version_after_many_detections` · `detect::i2_diff_base_is_the_last_accepted_version_however_many_detections_arrive` | +| **I3** | Candidate identity is content-addressed over everything that becomes a byte. | `invariants::i3_materialization_fails_closed_on_the_recipe_pin` · `detect::epoch_and_pkgrel_are_part_of_the_identity` · `detect::recipe_hash_covers_shipped_patches` · `detect::detection_is_idempotent_and_records_no_duplicate_candidate` · `db::candidate_identity_is_unique_per_pkgbase` | +| **I4** | Publishing is the only externally visible step, and it is atomic and serialized. | `invariants::i4_kill_mid_publish_leaves_the_old_index_byte_identical` · `pipeline::i4_kill_mid_publish_leaves_the_old_index_intact` · `pipeline::a_stale_accepted_pointer_refuses_to_publish` | +| **I5** | Every step is idempotent and checkpointed; a worker can die at any instant. | `invariants::i5_resume_after_a_crash_repeats_no_completed_step` · `pipeline::i5_a_restarted_build_resumes_at_the_next_incomplete_step` · `crash::a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work` · `dispatch::a_reaped_build_resumes_at_the_next_incomplete_step_with_no_duplicate_work` | +| **I6** | A manual rebuild reuses the approved source identity, with no new approval. | `invariants::i6_manual_rebuild_publishes_the_same_version_without_a_new_approval` · `pipeline::i6_manual_rebuild_reuses_the_approved_identity` · `surfaces::a_manual_rebuild_reuses_the_approved_identity_without_a_new_approval` | +| **I7** | At most one open review per pkgbase; a newer detection collapses into it. | `invariants::i7_the_schema_refuses_a_second_open_review` · `db::i7_second_open_review_is_rejected_by_the_database` · `approve::collapse_in_place_bumps_revision_without_a_new_row` | +| **I8** | The index is exactly the set of `current_accepted_release` pointers. | `invariants::i8_index_equals_the_accepted_pointers` · `pipeline::i8_served_index_holds_exactly_the_accepted_pointers` | +| **I9** | Build hosts are untrusted: a malicious PKGBUILD must not reach the DB, the signing key, or another build. | `invariants::i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir` | +| **I10** | Every state transition is recorded, append-only, with actor and timestamp. | `invariants::i10_audit_is_append_only_and_records_the_decisions` · `db::audit_log_is_append_only` · `surfaces::the_builds_page_names_the_version_and_the_audit_page_records_the_decision` | +| **I11** | A non-publishable change never silently disappears; it becomes a `notice`. | `notices::i11_nothing_publishable_is_ever_silently_dropped` · `detect::recipe_drift_under_a_static_version_is_a_notice_not_a_candidate` · `vcs::a_moved_tip_with_an_unchanged_pkgver_is_a_notice_not_a_candidate` · `notices::digest_drift_is_a_high_severity_integrity_alert_and_no_candidate` | +| **I12** | Every release records the set of our own packages it was built against. | `invariants::i12_every_build_records_a_world_snapshot` · `pipeline::i12_world_snapshot_is_recorded_at_ingest` · `world::the_world_snapshot_is_intersected_with_our_index_at_ingest_time` · `db::world_snapshot_dedupes_by_hash` | + +## What I9 does and does not cover + +The full statement of I9 is enforced by the chroot, and the chroot tier is gated +behind root and network (§16a). What is *not* gated, and what +`i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir` pins, is +the pipeline's own hygiene: `collect` scans the srcdir for `*.pkg.tar.zst` and +`ingest` copies whatever those paths resolve to into the content-addressed +store, from where the bytes are served from our repo and signed with our key. A +build that could make one of those paths be a symlink to the keyring or the +database would turn a missing chroot into a signed artifact of our own secrets. +The test acts that attack out — the shim plants a symlink to the database file — +and asserts the build fails closed, the store is untouched, and nothing +publishes. + +## Invariants that are properties of the schema, not of a code path + +Two of these are enforced by SQLite itself so that no future code path can forget +them, and each has a test that tries to violate it through the database rather +than through the application: + +* I7 — a partial unique index on `candidate (pkgbase_id) WHERE state='pending_review'`. +* I10 — `UPDATE`/`DELETE` triggers on `audit`, and on `approval` (§7.2, the + approval record is immutable because it is the only proof of what a human saw). diff --git a/src/config.rs b/src/config.rs index 127c5a3..7effa53 100644 --- a/src/config.rs +++ b/src/config.rs @@ -59,6 +59,11 @@ pub struct Config { /// the pipeline, mid-step. This is how a real crash is reproduced for I5 — /// not a caught error, an uncatchable death. Never set in production. pub shim_kill_parent: Option<String>, + /// Make the build shim plant a symlink to this path in its srcdir, so a test + /// can act out the I9 attack: an untrusted PKGBUILD smuggling bytes in from + /// outside its own staging dir. + #[serde(default)] + pub shim_plant_link: Option<String>, /// How many builds may run at once (§8.2 backpressure). Default 1, which /// also means the chroot pool only needs one warm root. pub max_concurrent_builds: usize, @@ -98,6 +103,7 @@ impl Default for Config { publish_fault: None, shim_fail: None, shim_kill_parent: None, + shim_plant_link: None, max_concurrent_builds: 1, lease_secs: 90, min_free_disk_mb: 1024, @@ -151,6 +157,9 @@ impl Config { if let Some(k) = &self.shim_kill_parent { cmd.env("AUR_SHIM_KILL_PARENT", k); } + if let Some(l) = &self.shim_plant_link { + cmd.env("AUR_SHIM_PLANT_LINK", l); + } } /// Create the directory tree the server needs. Idempotent. diff --git a/src/pipeline/steps.rs b/src/pipeline/steps.rs index 3f575bd..db7032c 100644 --- a/src/pipeline/steps.rs +++ b/src/pipeline/steps.rs @@ -261,7 +261,31 @@ fn collect(ctx: &Ctx) -> Result<StepResult> { .filter(|p| p.to_string_lossy().ends_with(".pkg.tar.zst")) .collect(); entries.sort(); + // I9: the build is untrusted. In production it runs in a chroot, but the + // control plane must not *depend* on that for its own safety. Everything + // below takes a path that a PKGBUILD could have arranged to exist in the + // srcdir, and the next step copies whatever that path points at into the + // content-addressed store — from where it is served from our repo and signed + // with our key. A symlink to the signing keyring, the database, or anyone's + // home directory would otherwise become a signed artifact we publish. So: + // no symlinks, and the resolved target must live inside this build's own + // staging directory. Anything else fails the build closed. + let staging_root = ctx.staging.canonicalize()?; for path in entries { + if std::fs::symlink_metadata(&path).map(|m| m.file_type().is_symlink()).unwrap_or(true) { + return Err(Error::fail_closed(format!( + "{} is a symlink; a build may not smuggle bytes in from outside its own staging dir (I9)", + path.display() + ))); + } + let resolved = path.canonicalize()?; + if !resolved.starts_with(&staging_root) { + return Err(Error::fail_closed(format!( + "{} resolves outside this build's staging dir ({staging_root:?}); refusing to ingest it (I9)", + path.display() + ))); + } + let path = resolved; let bytes = std::fs::read(&path)?; let (digest, size) = crate::hash::digest_file(&path)?; // Read what the package says about itself out of the archive, rather diff --git a/src/shims/mod.rs b/src/shims/mod.rs index 754bbb4..46dd98f 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -291,9 +291,28 @@ pub fn makechrootpkg(args: &[String], m: &Manifest) -> Result<i32, String> { } } } + plant_link_if_asked(&startdir); Ok(0) } +/// I9 test hook: drop a symlink into the srcdir pointing wherever the test names, +/// standing in for a PKGBUILD that tries to smuggle outside bytes into the +/// artifact store. The pipeline must refuse it; see `collect` in steps.rs. +fn plant_link_if_asked(startdir: &Path) { + let target = match std::env::var("AUR_SHIM_PLANT_LINK") { + Ok(t) if !t.is_empty() => t, + _ => return, + }; + let link = startdir.join("planted.pkg.tar.zst"); + #[cfg(unix)] + { + let _ = std::fs::remove_file(&link); + if let Err(e) = std::fs::symlink(&target, &link) { + eprintln!("shim: could not plant {link:?} -> {target}: {e}"); + } + } +} + fn packages_to_emit(m: &Manifest, startdir: &Path) -> Vec<FakePackage> { if !m.packages.is_empty() { return m.packages.clone(); diff --git a/tests/invariants.rs b/tests/invariants.rs index c1a70ad..2bdbc8b 100644 --- a/tests/invariants.rs +++ b/tests/invariants.rs @@ -10,7 +10,7 @@ mod common; -use aur_build::db::{self, model::*}; +use aur_build::db::{self, builds, model::*}; use aur_build::pipeline::{self, publish}; use aur_build::review::approve::approve as do_approve; use aur_build::review::{candidates, diff}; @@ -394,3 +394,66 @@ fn index_db_names(path: &std::path::Path) -> Vec<String> { names.dedup(); names } + +/// I9: build hosts are treated as untrusted — a malicious PKGBUILD must not +/// reach the control plane's data or smuggle foreign bytes into what we publish. +/// +/// The real enforcement is the chroot, and that tier is gated. What is *not* +/// gated, and what this pins, is the pipeline's own hygiene: `collect` scans the +/// srcdir for `*.pkg.tar.zst` and `ingest` copies whatever those paths point at +/// into the content-addressed store, from where the bytes are served from our +/// repo and signed with our key. If a build could make one of those paths be a +/// symlink to the signing keyring or the database, isolation would be the only +/// thing standing between a hostile AUR recipe and a signed artifact of our own +/// secret files. It must not be. So the pipeline refuses symlinks and refuses +/// anything that resolves outside the build's own staging directory, and this +/// test acts the attack out rather than arguing it away. +#[test] +fn i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir() { + let (mut env, _fx) = env_with_fixture("plain-make"); + aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, "plain-make").unwrap(); + let c = candidates::pending_candidates(&env.db).unwrap().remove(0); + let dd = diff::render_and_store(&env.db, &env.cfg, &c).unwrap(); + let c = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap(); + do_approve(&env.db, "t", c.id, &c.identity_hash, &dd, None).unwrap(); + let c = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap(); + let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap(); + + // Something a build must never get to publish: our own database file. + let secret = env.cfg.db_path(); + let store_before = dir_listing(&env.cfg.store_dir()); + env.cfg.shim_plant_link = Some(secret.display().to_string()); + + let out = pipeline::run(&env.cfg, &env.db, &id); + env.cfg.shim_plant_link = None; + let err = match out { + Err(e) => e.to_string(), + other => panic!("a build that smuggled in a symlink must fail closed, got {other:?}"), + }; + assert!( + err.contains("staging") || err.contains("symlink"), + "the failure should say why it refused: {err}" + ); + + // The refused bytes never reached the store, and nothing was published. + assert_eq!( + dir_listing(&env.cfg.store_dir()), + store_before, + "the store must be untouched by a refused build" + ); + assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, build_state::FAILED); + assert!(db::index_version(&env.db, "plain-make").unwrap().is_none(), "nothing publishes from a failed build"); + // And the database itself is intact — the build read it, it did not become it. + assert!(secret.exists()); +} + +fn dir_listing(dir: &std::path::Path) -> Vec<String> { + let mut out = Vec::new(); + if let Ok(entries) = std::fs::read_dir(dir) { + for e in entries.flatten() { + out.push(e.path().display().to_string()); + } + } + out.sort(); + out +} |
