# 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 /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 sandbox/ where build code runs: the backend seam, loopback, remote agent protocol + agent binary, kata adapter, failure fakes 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 (test-support only) 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`, `pacman`, `repo-add` and `gpg` — the tools the pipeline actually shells out to now that builds run in provisioned sandboxes — plus `mkarchroot` and `makechrootpkg`, kept as stand-ins for the real devtools so the shim protocol itself stays exercised. 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 the fake `pacman -U` refuses bytes that do not hash to the digest their name claims. The step machine cannot tell it is not in a sandbox, which is the point. Each shim is as strict as the tool it replaces — the fake `repo-add` refuses a database filename the real one refuses — because a shim that accepts more than its tool is how a broken publish path passes 200 tests and then fails on a real package. * **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. The sandbox seam (§8a of the design) is tested the same way — the interface is executed, not mocked: `tests/remote_agent.rs` drives a **full build over the real agent protocol** (frames, rendezvous, log streaming, blob round-trip, bad-token refusal) against the shims on a loopback socket, and `tests/failure_modes.rs` runs a `FakeBackend` that breaks sandboxes on purpose: dies mid-run (lease expiry → reaper → requeue), TTL bites mid-build, pool at quota (the build blocks on `sandbox-pool`, it does not fail), and a sandbox whose `pacman -Q` lies (fail-closed world mismatch). All of it is behind a `test-support` feature, which `cargo test` turns on through its dev-dependency on this crate and `cargo build` does not turn on at all: the shim binaries are not built, the `TestHooks` type has no fields, and the fault-injection branches in `publish` are not in the binary. `tests/production_surface.rs` fails if any of it leaks into the default build. 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 live kata tier needs `/dev/kvm` and a cluster (`AUR_KATA_API`); the kata rendezvous and TTL logic itself runs everywhere via a real `sandbox-agent` process with no VM. The old real-chroot tier retired with devtools; what it caught is recorded 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 `