summaryrefslogtreecommitdiffstats
path: root/README.md
blob: 1ee56e325918f35648596a58d1351fac040cca28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# 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
  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.
* **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 `<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).