# 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 rule everything else follows Nothing reaches a consumer without an `approval` row behind it. 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. ## Where builds run One `sandbox` object in `config.json` says where untrusted recipe code executes. It names exactly one kind, and a kind that is missing a field it needs — or a kind that does not exist — is a startup error, not a fallback: ```jsonc { "sandbox": { "kind": "loopback" } } // the default: subprocesses of this process { "sandbox": { "kind": "remote", // sandboxes dial in; you boot them "listen": "0.0.0.0:8787", "token": "…", "shared_workspace": true } } { "sandbox": { "kind": "agent-sandbox", // Kata VMs, provisioned per lease by the cluster "api": "https://k8s:6443", "namespace": "builds", "bearer": "…", "image": "aur-build-sandbox:latest", "listen": "0.0.0.0:8787", "token": "…", "shared_workspace": true } } ``` `loopback` is the default and needs nothing, which is what keeps a fresh `init` working with no configuration at all — and it is honest about what it is: the sandbox is the hub's own user, with no isolation. `remote` and `agent-sandbox` differ only in who boots the sandbox: an operator, or the cluster from an agent-sandbox CR whose `activeDeadlineSeconds` is the lease TTL, so the orchestrator enforces the deadline even if the hub dies. `shared_workspace` is required (explicitly, `true`) by both remote kinds. The build workspace is not shipped to the sandbox yet — `Run` frames carry a hub-side working directory — so a remote build only works where the staging directory is visible at the same path on both sides. Asserting it is what stops `"remote"` from silently meaning "on the hub". ## Layout Each layer may name only the layers beneath it. `tests/architecture.rs` encodes the ranks and fails the build on an upward edge, so the order below is enforced rather than documented in hope. ``` src/ main.rs CLI: init, subscribe, detect, reviews, show, approve, reject, build, rebuild, run, builds, status, packages, serve, audit, metrics, gc, backup — argument parsing, one use-case call, and printing; no workflow of its own usecase/ rank 9 — the workflows both front ends run: bootstrap (open/init/serve), detect, reviews (approve/reject/bulk), subscriptions, builds, maintenance (gc/backup/notices) http/ rank 10 — tiny_http server: routes, render, auth, SSE log tail; renders use-case results, holds no workflow itself ops.rs retention, metrics, VACUUM INTO backups pipeline/ rank 7 — the step machine, the dispatcher + worker pool, publishing watch/ rank 6 — detection: scheduler, cheap/expensive polls, upstream probes, source digests, staleness; `sources` is the one interface the pipeline builds against review/ rank 5 — candidates, diff panels, risk scoring, approval; `intake::record` is the single way a candidate is recorded shims/ the fake toolchain that makes the pipeline testable (test-support only) sandbox/ rank 3 — where build code runs: the backend seam, loopback, remote agent protocol + agent binary, kata adapter db/ rank 3 — SQLite: migrations, model rows, per-aggregate query modules, build state machine; `mod.rs` lists its exports explicitly, and a single writer actor owns writes recipe.rs rank 4 — PKGBUILD and .SRCINFO parsing config.rs rank 2 — one config file at /config.json fetch.rs, git.rs rank 2 — the two seams over the outside world pkgver/, pkginfo.rs, hash.rs, time.rs, urlutil.rs rank 1 — pure: vercmp and the dependency grammar, .PKGINFO and .BUILDINFO parsing (no libalpm), sha256 and canonical json, the clock seam, url and name shapes error.rs rank 0 — the crate's error type; the six variants behavior branches on carry typed payloads, not prose testcorpus/ the fixture packages the tests build for real templates/ askama templates, server-rendered static/ app.css and one vendored htmx ``` Two tools keep this honest, and both are meant to be run, not read once: ``` cargo test --test architecture # ranks, no cycles, no globs, interface budgets python3 tools/arch-census.py # the numbers; --list-dead names them, --budget checks the ratchet ``` ## Testing without root, network, or a real chroot `cargo test` runs the whole thing on an ordinary user account. Two mechanisms make that possible: * **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 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: * `pkgver::tests::the_live_vercmp_tier_is_recorded_not_silently_absent` needs pacman's `vercmp` on `PATH` and compares the hand-written comparator against it over ~1100 pairs. A second test, `vercmp_matches_the_recorded_oracle`, checks the same ~1100 pairs against a committed table, so the comparator is pinned on a machine with no pacman at all. * 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. ### Where a test lives A test goes in the module it tests, unless it needs something a unit test cannot have — the fixture corpus, a database, a real subprocess, a listening socket. `tests/` is for those, and `src/` holds the rest as `#[cfg(test)] mod tests`. That is a rule with a consequence, and the consequence is the reason it is worth stating: a test outside a module can only reach what the module exports, so every test that sat in `tests/` while testing something module-private was quietly keeping that thing `pub`. Moving the test home is what lets the item go private. `tools/test-surface.py` finds the ones still outstanding and `tools/test-surface.md` records what is being done about each. ## 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 `