summaryrefslogtreecommitdiffstats
path: root/tests/common/mod.rs
Commit message (Collapse)AuthorAgeFilesLines
* docs: record the census, and make the README describe the tree that existsdev11 days1-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The census report gets its after-table, and the README's Layout gets rewritten — it had drifted into fiction, listing `db/queries.rs`'s successors as "queries" and omitting `usecase`, `error`, `hash`, `time`, `urlutil`, `git`, `fetch` and `recipe` entirely. It now states the ranks and says plainly that they are enforced by `tests/architecture.rs`, not kept in hope, and names the two commands that keep it true. This commit also carries the last of the narrowing that fell out of writing the report, because writing it meant actually reading the numbers: - `watch::upstream::resolve` looked test-only and was not — the tests contain an unrelated local function of the same name, which the census matches as a word. It is crate-internal and now says so. - `read_tree` closed with it. Its two integration tests were testing the module's own batching behaviour from outside, so they moved inside as unit tests with a throwaway git repo, which is where a test about one `ls-tree` and one `cat-file --batch` belongs. They lost nothing: the empty-blob and NUL-byte assertions came across verbatim, plus one the old test never made — binary blobs are still listed, just not read. - `Assessment::is_high`, `Tree::get`, `approve::current_accepted` and `diff::full_recipe_text` were dead once their callers closed, and are gone. - `set_risk_for_tests` is gone too. The bulk-refusal test needed a candidate marked high-risk, and the honest way to get one was for the fixture to write the row — `Env::execute` — rather than the library growing a public setter that exists only so a test can pass. That was the last budget above baseline apart from `error.pub`. `error.pub` stays at 21 against a baseline of 15, and the report says why: the six payload enums are constructed in four modules and matched in `error`, so they are interface. `error.dead` is 0. Final: 281 passed / 0 failed across 36 binaries (baseline 273), clippy -D warnings clean, release clean, census within budget.
* tests: stop copying git's locks, and stop git making themaur-build12 days1-1/+12
| | | | | | | | | | | | | copy_tree walked a live repo and tried to copy .git/objects/maintenance.lock after git's detached maintenance had already removed it - a claim, not content, and a copied index.lock would have made the copy refuse to run anyway. Locks are skipped now, and the test git helper runs with maintenance.auto and gc.auto off, so nothing repacks a repo behind a test that is still copying it. Background maintenance spawns in a sampled pair of binaries went 72 to 21; the rest come from the library's own clone and fetch, in directories nobody copies from. Five consecutive full-suite runs clean, against roughly two in three failing before.
* tests: prove the per-append delivery directly on the tailaur-build12 days1-1/+3
| | | | | | | | | | | The HTTP test cannot show delivery per append: the stream response is buffered until it ends, so every line lands in one read no matter what the tail is doing, and the sleeps that used to stage the appends proved nothing. The property moves to where it is observable - drive LogTail, append between reads, and each append has to arrive as its own event. The socket test keeps proving the wiring, the headers and the end event. copy_tree now names the file it failed on, which it did not do before.
* fix: what clippy -D warnings was holdingaur-build12 days1-2/+3
| | | | | Sandbox::default was a hand-written derivable_impl, and copy_tree borrowed an owned PathBuf.
* tests: build each fixture's repos once per binary and copy themaur-build12 days1-34/+160
| | | | | | | | | | | | | Every env_with_fixture call built an AUR stand-in and up to two upstreams from scratch - six git processes a repo, and most fixtures build three of them. The trees are built once per test binary under a cache and copied into the tempdir now, so each test still owns a mutable copy and fx.bump still commits into it. A recipe that names its own directories is the one thing the copy cannot get right, so those few rewrite their work tree and amend instead. Also stopped paying two git config calls and a rev-parse per repo: identity goes in the environment of every test git call, and a repo this file made has one branch and one commit, so the ref file is the tip.
* comments: keep only what the code cannot showaur-build12 days1-54/+0
| | | | | | | | | | | Stripped every comment that described what an item does, documented its arguments or fields, or cited the design docs (§n, I-n, m-n, decision n). 2247 comments down to 83. What survives: the section dividers that segment the large modules, the secret-handling warnings, the agent wire-frame directions, and the few notes without which the code they attach to reads as redundant, reorderable, or unsound.
* comments: say why, not whataur-build12 days1-30/+23
| | | | | | | | | | | | | | Every module-level `//!` header is gone, and the comments that remained either re-explained the line below them or had grown into paragraphs. Density went from one comment line per 6.7 lines of code to one per 10. 827 insertions against 2194 deletions across 86 files. What survived: the invariants (I1-I12), the design cross-references into DESIGN.md, and the notes recording a bug that was found and fixed — those are the comments that carry weight, because they answer a question the code cannot answer about itself. What did not: restating a function signature in prose, and narration of the statement underneath.
* config: the test hooks are a gated submodule, not the production surfaceaur-build13 days1-12/+18
| | | | | | | | | | | | | | | | | | | | | | | Seven fields sat on `Config` next to `signing_key_id` and `bind`: a PATH override, three shim protocol variables, a fault-injection point in the middle of `publish()`, and two more shims could obey. m-9's complaint was not that they exist — the shims are how I4, I5 and I9 are tested for real, and a mock would have asserted the mock's own behaviour — but that nothing said which of these was production and which was scaffolding, and the publish path carried a test branch on every real publish. They are one `TestHooks` submodule now, documented as what it is, and the whole submodule is `#[cfg(feature = "test-support")]` — the same feature that already gates the shims and the raw SQL escape hatch, and which only this crate's own dev-dependency turns on. A production build has no `hooks` field, no shim protocol in `child_env`, and no fault-injection branch in `publish()`; the serialized config skips the section entirely when nothing is hooked, so a real `config.json` never mentions any of it. `TestHooks::is_empty()` names the state a real process runs in, and three tests hold the line: the hook fields may be declared exactly once and only inside `TestHooks`, every `publish_fault` read in `publish.rs` must sit behind the feature gate, and a default config serializes without a trace of hooks.
* time: relative arithmetic honors the pinned clockaur-build13 days1-0/+20
| | | | | | | | | | | | | | | | | | | `now()` returned the pinned instant when a test had pinned one, but `secs_ago`/`secs_ahead` called `Utc::now()` directly (m-1). Anything built from them — every lease expiry, every `next_check_at`, every cooldown cutoff — was therefore computed against the real wall clock and then compared against the pinned one. A test that pinned 2026-01-01 and took a 90-second lease got an expiry 90 seconds after *today*, so the reaper comparing `lease_expires_at < now()` saw a lease that would not expire for a century, or one that had expired millions of seconds ago, depending on which way the pin pointed. The test still passed, because nothing asserted on the number. Both now go through a `base()` that reads the pinned instant, so a pinned test computes and compares on the same clock. `tests/time.rs` pins the arithmetic directly and then does the thing the bug actually broke: claim a lease under a pinned clock, assert the expiry is 90 seconds after the pinned now, assert the reaper sees nothing yet, advance the pinned clock 91 seconds, and assert it reaps.
* db: the schema gets an owner — every statement moves into db/, and the ↵aur-build13 days1-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | writer stops handing out connections Twelve modules outside `db/` contained hand-rolled SQL — 22 statements in `ops.rs`, 17 in `approve.rs`, 15 in `candidates.rs`, 11 in `publish.rs`, and a dozen more scattered through `watch`, `pipeline`, `http` — which meant the blast radius of a schema change was "any module", and `db/` was a directory rather than a boundary. The audit trail alone was defined in four places with three different detail payloads. Every statement now lives in `db/`. New modules `db::candidates` and `db::approvals` own their tables (including the 21-column candidate select, spelled once as `CANDIDATE_COLS` instead of four times); `db::queries` gains the metrics reads, the retention reads and writes, the publish writes (`insert_release_in`, `cas_accepted_release_in`, `remove_index_packages_in`), the staleness reads and the source-cache lookups; `db::builds` gains `set_release_in`. Where a mutation is a *decision* — the collapse rules, the approval gate, the publish compare-and-swap — the decision stays where it was and the statements are called through the transaction handle, so the atomicity is unchanged and only the SQL moved. `audit_in` is the in-transaction audit append, and `audit` is now a wrapper over it: a decision and its audit row commit together or not at all, which is what I10 actually claims. Enforcement is two-layered, because one layer is a lie. `Writer::call`, `tx` and `send` are `pub(crate)`, which keeps the crate's *users* out — the integration tests and the shim binaries — but `pub(crate)` is crate-wide, so on its own it would not stop `approve.rs` from writing SQL tomorrow. The layer that does is `tests/schema_ownership.rs`: it walks `src/` and fails the build if a statement literal or a rusqlite statement call appears outside `src/db/`. It was checked against a deliberate violation. The test harness still needs to construct states no typed API reaches, so the raw door exists but only under the `test-support` feature, which nothing but this crate's own dev-dependency enables; a production binary cannot see it.
* http: the session id is the credential, not a cookie a client can typeaur-build13 days1-0/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | The gate asked whether the request carried `Cookie: auth=1`, and login did nothing but set that literal value, so the password protected the login form and nothing else: anyone could read the reviews, the audit log, the settings and the build logs by typing the cookie themselves, and the CSRF step then happily minted them a session to POST with. The random sid machinery was already there and already unguessable; it was just never bound to the flag that said "someone authenticated". A session now carries that flag. `auth.rs` holds a map of live sids to whether they passed the password gate; `authenticate` can only flip a sid this process minted, so a login attempt cannot mint a session as a side effect. `gate` asks `is_authenticated(sid)` and nothing else, and the `auth` cookie is gone from both the login response and the logout one. Login rotates the sid rather than promoting the anonymous one, so the session that existed before the password was typed is never the one that carries the privilege after it; logout drops the sid, which invalidates its derived CSRF token with it. Two tests, both over a bare socket because a client that follows redirects turns "you are not signed in" into the login page's 200 and hides the whole point: `a_forged_auth_cookie_is_not_a_session` (the exact forgery, on every sensitive surface, GET and POST) and `login_rotates_the_session_and_logout_ends_it` (rotation, dead pre-login sid, dead logged-out sid). The audit actor is honest now too: with a password set, only an authenticated session is "web".
* ops: retention that never lies about what is on disk, metrics that cannot ↵aur-build14 days1-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | drift, and a backup that restores Three §15 features, each with a failure mode worth designing against. **Retention** evicts the files of releases beyond the keep window and never deletes a row. The artifact keeps its digest, size and provenance and gains a purged_at, so the record says 'these bytes existed and were dropped at T' instead of continuing to claim a file that is no longer there. A package, its signature, its build log and its cached sources are evicted as one unit — a package whose log is gone but whose bytes remain is the worst outcome: full price, no explanation. Shared content-addressed files are reference-checked against every *retained* release first, because two releases built from the same source share one cached archive and aging one out must not corrupt the other. The currently accepted release and anything still backing an in_index package are kept regardless of how far down the list they sit: deleting the bytes the index is pointing at is the one thing retention must never do. **Staging sweep** derives 'abandoned' rather than guessing it: the dir's build is terminal, or has no build row at all, and the dir is older than a grace period. A dir whose build is running is left alone however old it looks, because a long build is not an abandoned one. **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 path is added; a query cannot drift. Includes queue depth, the review-debt age histogram (not just how many reviews are pending but how stale they are), build success rate, WAL size, stale counts by reason and staging usage. A fresh install reports success rate 1.0 rather than NaN or 0%, so an empty system does not page anyone. Served at GET /metrics and by 'aur-build metrics'. **Backup** uses VACUUM INTO on the writer connection, so it cannot interleave with a write, and refuses to overwrite an existing file — a backup that silently replaces last week's backup is a way of losing the only copy on the day you need it. The snapshot is then reopened and checked for schema version and approval rows: if it does not open on its own it is a file, not a backup. New CLI: metrics, gc [--keep N] [--dry-run], backup <path>. tests/ops.rs: 9 tests. 170 tests pass, clippy clean.
* http: surfaces driven by live state — staleness, downgrades, deps, rebuild ↵aur-build14 days1-0/+147
| | | | | | | | | | | | | | | | | | | | | | | | | | | (I6) Attention, the package page and the builds page now answer real questions instead of rendering empty tables: - Attention lists outdated dependencies derived from the recorded world snapshots, naming the dependency that moved, what the artifact was built against and what the index holds now; also missing dependencies and downgrades (AUR offering a lower version than we serve), which is an announcement for a human, not a build request. - The package page shows depends-on from the recipe we actually serve and needed-by from the packages whose recipes name it, plus staleness and the aur_commit timeline, each release linking into cgit at that exact commit. - Builds rows carry the version they are about, in both the live and the recently-finished table. - A manual rebuild reuses the approved source identity and mints no approval (I6); the test asserts the approval count is unchanged before and after the rebuild runs. - A paused subscription is not observed at all: detection returns Paused without polling, so pausing a broken package stops it opening reviews. - Staleness stays computed on read (§10.2). Nothing stores a stale flag, so nothing can serve a stale lie. Also: dep-client fixture added for dependency pairs.
* watch: two-stage VCS watcher — ls-remote probe, pkgver() resolution, pin ↵aur-build14 days1-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | capture (§5.2) Stage A probes every VCS source in source=() with git ls-remote, respecting #commit/#tag/#branch fragments, and returns one UpstreamPin per source. If the tip set equals the accepted release's pins, nothing can have changed and Stage B never runs — the common case costs one round trip per source and no clone. svn/hg have no cheap universal probe, so they are reported as unprobed and force Stage B rather than being silently treated as unchanged. Stage B runs only on movement: it fetches into a persistent vcs_cache (rather than re-cloning a multi-gigabyte upstream daily), runs makepkg --vercheck, and captures the pins from the clone it already has. Results are cached on (pkgbase, recipe_hash, upstream_tip) with a per-pkgbase cooldown, and a process-wide slot cap bounds concurrent resolutions. The resolved epoch:pkgver-pkgrel plus the pins go into identity_hash, so a different commit is a different thing to approve. Also fixes a misclassification the new path exposed: a VCS source's digest is its pin, so upstream movement showed up as an integrity_alert. Integrity events are now restricted to fixed downloads; VCS movement under a frozen pkgver is pin_drift, as §5.2 specifies. New fixtures git-multi (two upstreams) and git-tagged (#tag pin). 10 tests in tests/vcs.rs.
* pipeline: ten-step build machine with atomic signed publishaur-build2026-11-171-0/+12
| | | | | | | | | | | | | | | | | | | | | materialize -> plan -> chroot -> sources -> pkgver -> build -> collect -> verify -> ingest -> publish, each checkpointed in build_step so a worker that dies resumes at the next incomplete step without repeating the expensive one (I5). Step 0 materializes from the local mirror only and re-hashes the tree: there is no path from 'AUR moved since the review' to 'we built it anyway' (I3). Step 4 re-resolves a VCS pkgver and refuses when it no longer matches the approved identity. Publish renders the index to .tmp, fsyncs, commits release + package rows and the accepted pointer under a compare-and-swap, then renames over the served database and signs it, so a crash leaves the old index byte-for-byte intact (I4) and every index entry traces back to an approval (I1). Ingest records the world snapshot as the BUILDINFO installed set intersected with our own packages, which is what keeps staleness meaningful (I12). 17 shim-driven end-to-end tests, including kill-mid-publish and crash-resume, with no root, network, or real chroot.
* test: toolchain shims and the fake-package corpus (§16a)aur-build2026-11-171-0/+151
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The harness that makes the rest of this developable. Six real binaries named exactly like the tools the pipeline shells out to, sharing one shim module, driven entirely by environment so no production code path is test-only: AUR_SHIM_DIR where invocations are recorded (jsonl) AUR_SHIM_MANIFEST the fixture manifest to obey AUR_SHIM_FAIL optional tool forced to fail makechrootpkg emits real .pkg.tar.zst files with .PKGINFO and .BUILDINFO (the full chroot world, which is why §10.1 filters it), makepkg answers --printsrcinfo and --vercheck for Stage B, repo-add rebuilds a gzip'd .db with %FILENAME%/%VERSION%/%SHA256SUM% DESC entries, gpg writes a detached signature, mkarchroot creates a warm root. Each one records its invocation so tests assert on what actually ran. testcorpus/ holds 17 fixtures, each a PKGBUILD plus a manifest with the scripted outcome: plain-make, with-patch, install-hooks, skip-checksum, split-pkgbase, build-fails, check-fails, missing-dep, dep-cycle, epoch-bump, pkgrel-reset, downgrade, digest-drift, pin-drift, git-sourced, git-submodules, unresolvable. The harness commits a fixture into a real git repo standing in for AUR, materialises a local upstream git repo for VCS fixtures, and swaps payload bytes for the drift cases. Config.child_env is what puts the shims on PATH for child processes, so the pipeline runs completely unmodified under test. Part of P0 (DESIGN.md §17).
* feat: AUR mirror watcher, recipe parsing, candidate creationaur-build2026-11-171-0/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The detection path (§5.1, §5.1a, §5.3, §7.1): * git helpers, all subprocess git in one auditable place. Mirrors are cloned with --mirror and polled with git ls-remote, fetching only when the tip actually moved; --no-prune keeps history we may need forever. * .SRCINFO parsing (authoritative) with a PKGBUILD fallback, and source=() parsing that keeps VCS kind, #commit/#tag/#branch refs and the filename:: form. * recipe_hash over the whole snapshot tree, so a shipped patch is part of the recipe and cannot change silently. * source digest resolution: declared checksums are trusted-as-declared (makepkg enforces them, no bandwidth), local files are hashed from the mirror, and SKIP sources are downloaded and stream-hashed into the content-addressed source cache. Detection always re-fetches SKIP sources — answering from our own cache would defeat drift detection. * candidate creation with base = current_accepted_release, collapse in place while unviewed, supersede only once a human has looked, and a previously rejected identity is not re-raised. * non-publishable change handling (I11): unchanged version string means no review, but never silence — recipe drift and pin drift become notices, and a changed digest on a remote source with an unchanged version becomes a high-severity integrity_alert. Also vercmp + dep-string parsing with the ALPM test vectors, and the approval record with optimistic concurrency (§7.1a) that the CLI and web layers will both call. 16 detection tests against real file:// git fixtures, incl. I2 across three unattended detections and I11 for all three drift kinds. Part of P0 (DESIGN.md §17).
* feat: SQLite schema, migrations, single writer actoraur-build2026-11-171-0/+177
The §11 data model as four migrations, plus the §11a concurrency model: one writer thread owning the write connection (mutations arrive as closures over a crossbeam channel, so SQLITE_BUSY is not part of the design) and thread-local read-only connections under WAL. Invariants that are database guarantees rather than conventions: I7 partial unique index -> at most one pending_review per pkgbase I3 UNIQUE(pkgbase_id, identity_hash) -> no duplicate candidates I10 audit table rejects UPDATE and DELETE by trigger §16 current_accepted_release_id moves only by compare-and-swap Also: vercmp + dependency-string parsing (ALPM algorithm, no libalpm), hash helpers including recipe_hash over the whole AUR tree, the clock helper that stamps every write, and the config/root layout. Part of P0 (DESIGN.md §17).