diff options
| author | aur-build <aur-build@localhost> | 2026-11-18 19:00:25 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-18 19:00:25 +0000 |
| commit | 8835a0a86c82d922a2d674f3543c331dc9adb9e5 (patch) | |
| tree | 7ac728613b7d24b28dee4fd7ba30d2137e8f7554 | |
| parent | 76a214ed4d82d8937a3ec38c27d4d59304b8fac3 (diff) | |
| download | aur-build-8835a0a86c82d922a2d674f3543c331dc9adb9e5.tar.gz aur-build-8835a0a86c82d922a2d674f3543c331dc9adb9e5.zip | |
docs: the review's decisions, and the invariants that hold them
The structural findings are only durable if they are written down as rules with
the test that enforces each one, so:
`docs/INVARIANTS.md` gains a second table. The first one is the twelve numbered
invariants from DESIGN.md §2 — claims about what the system does. The new one is
about how the code is allowed to be shaped: SQL has one owner, a version is
formatted in one place, the dependency arrows point one way, the state machines
are the ones the transition table defines, the production binary carries no test
scaffolding, the served index has one lock, `canonical_json` is canonical in
fact, the session id is the credential, and a pinned clock pins everything
derived from it. Each row names the test that fails if the shape regresses.
`docs/DECISIONS.md` gains the decisions the review turned into code — the session
id as the credential, `db/` as a boundary that does not hand out connections, a
stale review and a broken database being different answers, shims compiled out of
production, states as enums with compare-and-swap writes, unreadable rows failing
the query, and only momentary I/O counting as transient. Two existing entries
were amended rather than added to: the publisher lock (there is now one, and the
second one that used to sit inside it is gone) and the test hooks (they are a
gated submodule now, not fields on the production config).
`README.md` says where the shims live and that none of them exist in a plain
`cargo build`.
| -rw-r--r-- | README.md | 8 | ||||
| -rw-r--r-- | docs/DECISIONS.md | 112 | ||||
| -rw-r--r-- | docs/INVARIANTS.md | 23 |
3 files changed, 135 insertions, 8 deletions
@@ -59,7 +59,7 @@ src/ 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 + 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 @@ -90,6 +90,12 @@ 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. +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: diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index a32d67a..68f1fee 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -84,13 +84,27 @@ nothing should be withdrawn automatically — a human has to decide whether the mirror or the upstream is wrong. The row appears on Attention with both versions and no action button. -## `publish_fault`, `shim_fail` and `shim_kill_parent` are test hooks in the config - -Three fields exist only so the harness can reproduce failures it cannot otherwise -cause: a crash between the rename and the signature, a tool that exits non-zero, -and a process killed mid-step with a signal it cannot catch. They are inert when -unset, and the alternative — an in-process simulation of a crash — can be caught -and cleaned up by accident, which is precisely what I5 must not allow. +## The test hooks are a gated submodule, not fields on `Config` + +`publish_fault`, `shim_fail`, `shim_kill_parent` and their siblings exist only so +the harness can reproduce failures it cannot otherwise cause: a crash between the +rename and the signature, a tool that exits non-zero, and a process killed +mid-step with a signal it cannot catch. The alternative — an in-process +simulation of a crash — can be caught and cleaned up by accident, which is +precisely what I5 must not allow. + +They are no longer seven `Option` fields on the production `Config`, and the +branches that consult them are no longer compiled into the binary at all. Under +the default features there is a `TestHooks` type with no fields, the shims and +their binaries do not exist, and `Config::child_env` exports nothing; the fault +branches in `publish` are `#[cfg]`-ed away rather than guarded by a runtime +`if`. A production binary that carries its own fault injection is a binary in +which someone will eventually ask whether a fault can be triggered from the +network, and the honest answer will be "not today". + +**Cost.** The test harness depends on the crate with `features = ["test-support"]`, +so `cargo test` and `cargo build` compile slightly different libraries — which is +the point, and is why `production_surface.rs` asserts the default build is clean. ## CAS baseline comes from the candidate, not from the live pointer @@ -108,6 +122,90 @@ 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. +There is now exactly one such lock, `REPO_LOCK`, taken at the top of `publish()` +for the whole sequence — file rewrite, signature, index update — and by +`withdraw_package`, which rewrites the same files. There used to be a second one +(`PUBLISH_LOCK`) covering a shorter span inside the first, which gave the +appearance of a second serialization point and would have been the natural place +for the next writer to acquire the wrong one. A test fails if a second lock +guarding the served index appears. + +## The session id is the credential, not a cookie the client controls + +Login used to set `auth=1`, so the secret was the *name* of a cookie and anyone +who could type `Cookie: auth=1` was the reviewer. Sessions are now a map the +server owns — a random sid minted at login, marked authenticated only in the +server's table — and the cookie carries the sid and nothing else. Logging in +rotates the sid, so a session id that a previous identity might have leaked is +useless after a re-login; logging out deletes the entry, so the id stops working +rather than being re-interpreted. + +**Cost.** Sessions are per-process and lost on restart, so a server restart signs +everyone out. For a single-operator tool that is a feature: the same restart that +reloads the binary also revokes every session it was running under. + +## `db/` is a boundary, and the writer does not hand out connections + +Every SQL statement in the crate lives in `db/`. `Writer::call`, `tx` and `send` +are `pub(crate)`, and the raw door the test harness needs exists only under +`test-support`. A module that needs the database asks `db/` for a typed query; +if the query does not exist, writing it is the change to make. + +**Cost.** `db/` is large, and a one-off ad-hoc query now costs a function instead +of a line. That is the trade: the schema's shape is knowable from one directory, +and a grep for a table name finds every reader of it. + +## A stale review and a broken database are different answers + +`approve()` used to return an `Approval` with `id: 0` when the transaction +failed, which the UI then rendered as "someone else got there first" — telling a +reviewer their click lost a race it did not lose, and hiding an I/O error behind +a message that invites them to retry. It returns `Result<Approval, ApproveError>` +now, with `Stale` (the review moved: 409, re-render the current diff) kept apart +from `System` (the database failed: 500, name the cause). `bulk()` answers the +same way, per row. + +## The shims are test-only, and the real `.PKGINFO` parser is the only one + +The publish path used to read a package's name out of the archive with a +simplified parser that the shim harness also had a copy of, which meant +production was tested against a model of the format rather than the format. There +is one parser (`pkginfo::parse_pkginfo`), the shims are behind `test-support`, +and the shim binaries are not built by default. + +## States are enums, and writing one is a compare-and-swap + +`build.state`, `candidate.state`, `step.state`, `release.state` and +`subscription.state` were free text, and `current_state` returned `""` for a +build that did not exist. They are five enums now, parsed at the row boundary — a +state the code does not define is an error, not a default — and every transition +is a conditional update (`WHERE state IN (…)`), so a worker whose lease expired +finds its write refused instead of quietly overwriting the state of the build +somebody else now owns. A zombie finishing a live build is the failure mode this +prevents, and it is silent in the old shape. + +**Cost.** The transition table is real code that has to be kept honest with the +schema, and `failed → running` is legal (I5 says a failed build resumes on its +own row), which is not obvious and is commented where it is defined. + +## A row that cannot be read fails the query + +`filter_map(|r| r.ok())` was used in some queries and not others, so a row that +failed to deserialize was sometimes skipped and sometimes an error — and the +skips were invisible. The policy is now uniform: if a row cannot be read, the +query fails. A silently missing package is worse than a failed page, because the +missing package looks like an absent one. `setting_i64` is the one documented +exception, because a *setting* falling back to its default is the designed +behaviour, not a lost row. + +## Only momentary I/O is transient + +`is_transient` classified every `Io` error as retryable, so ENOSPC and EACCES +were retried with the same backoff as a connection reset — a full disk produced a +build that retried until it gave up, blaming a network that was fine. Retryable +now means the kinds that can genuinely pass on the next attempt: would-block, +timed out, interrupted, broken pipe, connection reset/refused/aborted. + ## 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 diff --git a/docs/INVARIANTS.md b/docs/INVARIANTS.md index 3e9c7ae..c148961 100644 --- a/docs/INVARIANTS.md +++ b/docs/INVARIANTS.md @@ -42,3 +42,26 @@ 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). + +## Structural invariants, and the test that holds each one + +The rest of this file is about the twelve numbered invariants, which are claims +about what the system does. The ones below are claims about how the code is +allowed to be shaped — the kind that a review finds once and that a test then +holds forever, because a convention nobody checks erodes back into inconsistency +within a few commits. Each is enforced by a test that reads the source tree and +fails on the shape, not on behaviour. + +| Invariant | Test | +|---|---| +| SQL has one owner: `db/`. No other module holds a statement or touches a rusqlite connection. | `schema_ownership::no_sql_statements_outside_the_db_module` | +| A version string is formatted in exactly one place, `pkgver::full_version` — never again as a `CASE` in SQL. | `schema_ownership::only_rust_formats_a_version` | +| Dependency direction: `db` does not know about `review`/`watch`/`pipeline`; `review` does not call back into the watcher; `watch` does not reach into the pipeline or the UI; `recipe` is a leaf. | `layers::persistence_names_nothing_above_itself` · `layers::review_does_not_call_back_into_the_watcher` · `layers::the_watcher_does_not_reach_into_the_pipeline_or_the_ui` · `layers::the_recipe_leaf_depends_on_nothing_above_it` | +| The five state machines are enums. A row whose state text the code does not define is an error, not an empty string, and a transition the table does not define is refused rather than applied. | `state_machine::the_machine_refuses_a_transition_it_does_not_define` · `state_machine::a_state_the_code_does_not_know_is_an_error_not_an_empty_string` · `state_machine::every_state_round_trips_through_its_column_text` · `state_machine::an_unnamed_state_in_any_row_is_an_error` | +| A worker that lost its lease cannot write over the worker that owns the build. | `state_machine::a_zombie_worker_cannot_finish_a_build_it_no_longer_owns` | +| The production binary contains no test scaffolding: no shim harness, no shim binaries, no ungated fault-injection branch, and a default config with no hooks attached. | `production_surface::no_production_module_references_the_shim_harness` · `production_surface::the_shim_binaries_are_test_only` · `production_surface::the_publish_hot_path_has_no_ungated_test_branch` · `production_surface::a_default_config_has_no_hooks_attached` | +| The served index has exactly one serialization lock, so no second lock can be added that does not know about the first. | `production_surface::the_served_index_has_exactly_one_serialization_lock` | +| The rules a reviewer reads are the same rules the machine scored: no private copies of the host rule, the body-changed rule, or a hand-built audit row. | `production_surface::the_review_modules_do_not_keep_private_copies_of_the_rules` · `production_surface::audit_rows_are_built_by_the_constructors_not_by_hand` | +| `canonical_json` is canonical in fact — key order is a property of the bytes, not of the struct declaration — and a value that cannot be serialized is an error, never an empty object that hashes like a real identity. | `hash::the_rendering_is_canonical_in_fact_not_in_name` · `hash::a_value_that_cannot_be_serialized_is_an_error_not_an_empty_object` | +| The session id is the credential: a cookie a client typed by hand proves nothing, and logging out invalidates the id rather than flipping a bit inside a cookie the client controls. | `http::a_forged_auth_cookie_is_not_a_session` · `http::login_rotates_the_session_and_logout_ends_it` | +| A pinned clock pins everything derived from it, including lease expiry — a test that freezes time must not compute a real-clock deadline. | `time::a_pinned_clock_moves_relative_arithmetic_with_it` · `time::a_lease_taken_under_a_pinned_clock_expires_against_that_clock` | |
