summaryrefslogtreecommitdiffstats
path: root/tests/architecture.rs
Commit message (Collapse)AuthorAgeFilesLines
* rustfmt,lints: pin the formatting, adopt the idiom lints, pay them offaur-build9 days1-154/+66
| | | | | | | | | | | | | | | rustfmt.toml fixes the shape the tree is written in (120 columns, small items kept on one line) and one canonical pass makes it the truth. [lints.clippy] names the idiom lints worth enforcing and leaves out the two that would add doc-comment boilerplate rather than remove it. The tree pays them off here: write!/writeln! instead of push_str(&format!()), let-else instead of match-on-Option, borrows where a thread entry point only reads what it owns, no `&self` on a Copy state and no `self` nobody reads. ops::to_prometheus gains one gauge helper: a metric's HELP, TYPE and value are now emitted by the same call instead of three.
* tools,tests: count the pub(crate) items nothing outside their own file reachesdev10 days1-2/+170
| | | | | | | | | | | | | | | | | | | | | | | | | | | `pub(crate)` was the good state in the census by decree: `priv` was reported and deliberately left out of the budget, on the grounds that a rising count of crate-internal items is progress. That is true of `pub` -> `pub(crate)` and false of the next step. A `pub(crate)` item that no file except the one that declares it ever names is offering the whole crate a thing nothing reaches, and nothing in the suite said so. `overwide` counts them. Same shape as `deadonly`, on purpose: a per-module number that may only shrink, an item allowed to stay only by name in `over_visibility.allowlist`, and the compiler fact that forces it written beside the name. `--list-overwide` names every one with its file:line, and `tests/architecture.rs` mirrors the definition so the two implementations are cross-checked against each other, the way the census already is. Baseline, before any item is narrowed: 35 of 170 `pub(crate)` declarations are over-wide. Eight of them are already argued — a `pub(crate)` field cannot carry a private type, privacy does not reach up to a parent module or across to a sibling one, and `pub(super)` is not a form this crate admits — which leaves 27 unargued, and 27 is what the budget now holds. The count is a grep and a grep is a lead, not a verdict: the verdict is the compiler's, and it has to be asked under both profiles, because the `cfg(not(feature = "test-support"))` half of a feature-conditional declaration is never compiled by `cargo check --all-targets`.
* src,sandbox,http: three more fields nobody read, and the check that missed themaur-build10 days1-3/+16
| | | | | | | | | | | | | | | | | | | | | | | | A field scan that printed its first thirty lines missed the rest. Three `pub` fields were written and never read: `SandboxSpec::disk_mb`, copied off `cfg.min_free_disk_mb` into a spec no backend consulted — the dispatcher already checks the disk itself, so the knob stayed live and the plumbing around it was dead; `SandboxInfo::warm`, computed three ways by three backends and read by nobody; and `Server::handle`, a `JoinHandle` stored and never joined, which is what detaching a thread means and so was never load-bearing. All three are gone, their construction sites with them. Four more are written-but-never-read on purpose and now say so where they are declared: `Identity::upstream_pins` and `source_digests` reach the identity digest through `canonical_json`, not through a name; `VirtualClock::_owner` is the lease, and holding it unread is the whole mechanism; the `Ab`/`Ba` pair in `hash`'s canonical-json test exist to be serialized. `the_test_helpers_are_used` only looked at `pub` items, which left the blanket `allow(dead_code)` in `tests/common` exactly as able to hide a private helper as a public one — the objection was fair, and planting `fn planted_private_helper_never_used()` proved it passed while a dead private helper sat in the file. It now scans private declarations too, and fails on both the planted function and a planted struct.
* tests,tools: hold the dead-code zero in the ratchet, and prove the checks biteaur-build10 days1-0/+91
| | | | | | | | | | | | | | | | | | | | | | `dead_code.deadonly` is 0 for all 28 modules and the allowlist names the 18 items that stay `pub` by decision, so the remaining question is whether the ratchet can be broken quietly. Three tests close that. `the_dead_code_budget_matches_the_code` refuses a budget that contradicts itself: `modules.<m>.deadonly` is what `interfaces_stay_within_budget` reads and `dead_code.deadonly.<m>` is what `tools/arch-census.py --budget` reads, and both must equal the census — an edit to one alone is how a widening enters unnoticed. `the_dead_code_allowlist_names_real_items` refuses an entry whose item the module no longer declares, which is the permission that lets a deleted item return. `the_budget_writers_preserve_each_other` runs both writers against a copy of the file and fails if either erases the section it does not own, or rewrites the hand-written allowlist — the failure mode two tools sharing one file were always going to have. Each was checked by breaking it on purpose: a raised budget, a stale allowlist key, and a writer that drops the allowlist all fail loudly and pass again when reverted. README now says `--list-dead` exists and that a kept item is allowed by name in the budget file, because a ratchet nobody can inspect is not a ratchet.
* tests: make the blanket `allow(dead_code)` in the test tier worth keepingaur-build10 days1-5/+179
| | | | | | | | | | | | | | | | | | | | | `tests/common/mod.rs` opened with `#![allow(dead_code)]` and nothing else, which means it could have been hiding helpers no test called. It was not hiding many — `upstream2_commit` and nothing else at file scope — but "not many" is not a check, and the file cannot simply drop the allowance: it is compiled into every test binary, so a helper one binary uses is dead code in the other twenty and the lint fires everywhere and means nothing. So the allowance stays and the check moves up a level. `the_test_helpers_are_used` reads the file and fails on any `pub` item no test writes, counting a type as used when a field or method of it is — `Web::raw_request` hands back a `Raw` no test ever names. `every_fixture_is_referenced` does the same for `testcorpus/`, which had one entry, `git-submodules`, that no test had ever driven; it is gone. Both were checked by planting a dead helper and a dead fixture and watching the suite refuse them. `tests/dispatch.rs` also carried a function whose entire body was an `#[allow(dead_code)]` on `fn unused(_: AtomicBool, _: Config) {}` — the deadest code in the repository, with its two imports behind it.
* src: narrow what only its own module reads, and delete what nothing reads at allaur-build10 days1-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The census's 35 `deadonly` items were a lead, not a verdict, and the compiler answered it: 17 of them are read only inside their own module and were declared `pub` for no reason, so they are `pub(crate)` now — `db::OpenReview` and its two queries, `ReviewSubject` and its query, `fetch::Body`, `http`'s `form_get`, `query_get` and `Page::flash`, `ops::EvictPlan`, `usecase`'s `StageB`… — and two are read by nobody: `ReleaseState::can_transition` and `SubscriptionState::can_transition`, both already annotated "nothing consults this table today", which is the definition of dead rather than the argument for keeping. Narrowing them is what made the compiler look harder, and it found three more: `ReviewSubject::pkgbase` was selected out of the database and never read, `StageB::cached` was written in three places and never read, and `StageB::version` was never called. All gone, the SELECT column with them. The other 18 cannot be narrowed and now say so, once at the declaration and once in the budget file: a row type the `aur-build` binary binds without naming (`PackageRow`, `Checked`, `GcPlan`, `Prepared`), a type behind a `pub` fn a test calls (`Unbuilt`, `BulkItem`, `StageA`, `CheckReport`, `PkgInfo`, `Installed`, `Subscription`, `Manifest`), a trait a public test provisioner implements (`Provisioner`, `ProvisionRequest`), and three that a release build never even compiles because their module is `test-support`-gated (`shims::*`, `VirtualClock`). `deadonly` therefore means *dead and unargued* now: an allowlisted item leaves the dead columns, which is the only way the number can be held at zero forever. 448 pub, 49 dead, 0 unargued; 284 tests pass, one ignored, none lost.
* tools: key items by (module, name), and prove the surface by compilingaur-build10 days1-0/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The auditor's two counterexamples were both detector bugs, and they were the same class of bug as the ones before: the instrument was reading the source in a way that flattered the number. - Rows are keyed by `(module, name)`. Keyed by bare name, `pipeline::dispatch::Pool::shutdown` merged into the `db::Writer::shutdown` row, which is gated, so an ungated item was reported `already-gated`. - The production-mention index is built from lines with comments and string literals removed. Searching raw text made `review::approve::withdraw` look production-used because the *string* "withdraw" appears in an HTTP route pattern and an audit action; every real caller named `withdraw_package` or `withdraw_release_in`, which are different items. - A `pub` declaration inside a private module is not a public declaration. Without that, the inner-module narrowing made the detector report an `http::new` nobody could name. - For a name declared in several modules — `new`, `open`, `record`, `parse` — a bare mention elsewhere cannot be resolved, so the row is kept and flagged `ambiguous` rather than silently dropped, and `tools/test-surface-ambiguous.json` holds the human verdict. An ambiguous row with no verdict fails the architecture test; "the tool could not tell" is not a disposition. - The count rule was duplicated between `--json` and `--write-budget` and the two drifted the moment a rule was added to one. `tally()` is now the one place. `tools/release-surface-probe.py` replaces inference with compilation for the final claim. It writes a throwaway crate depending on `aur-build` twice, with and without `test-support`, and tries to name every dispositioned item from outside. A path that compiles with the feature proves the path is real; every such path must fail without it. Current result: 28 real external paths, 27 closed in a release build, and the one that stays open is `db::Writer`, which is public because `Db` has a `pub writer: Writer` field and Rust will not type a public field with a private type. That is recorded as `interface` in `tools/test-surface-interface.json` — a disposition that admits reachability and names the signature that forces it — and the probe fails if the file claims an item that is not in fact reachable, so it cannot quietly rot. The tool's own docstring and the generated table claimed "Rust has no test-conditional visibility". That was false and is gone, replaced with the two shapes that do it.
* tools: the test-surface detector credited four items with callers they lackaur-build11 days1-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An audit found that `internal` — the check deciding whether a test-only item has a real production caller — was crediting non-calls. Four items were sorted into `residue` on false evidence, and each false credit was a different mistake: db::cas_accepted_release a `pub use` continuation line at db/mod.rs:55. Production does this CAS through `cas_accepted_release_in` inside a transaction; the two names differ by three characters. shims::invocations the string "invocations.jsonl", plus a call from `called_with`, which is itself test-support gated. A test-only function cannot be evidence that another function is production-used. sandbox::LocalAgentProvisioner its own struct and impl headers. Production selects `K8sSandboxProvisioner`. sandbox::local_addr `listener.local_addr()` — std's method on a TcpListener, in sibling files. The census treats all of src/sandbox as one module, and a name match cannot tell a receiver's type. All four are gated now. `KataBackend::local_addr` had zero callers in src and zero in tests — `tests/remote_agent.rs` calls `RemoteBackend::local_addr`, a different type — so it is deleted rather than gated. The detector now strips string literals and comments, skips `use` statements including the continuation lines of a brace-delimited block, skips an item's own impl headers, and refuses to count a call made inside a `#[cfg(test)]` module or a `test-support`-gated item. The case a regex cannot resolve is `self.store_dir()` versus `listener.local_addr()`: identical to a name match. Rows whose only evidence is a call in method position are flagged `⚑`, listed in `tools/test-surface-confirmed.json` only after a human read the cited line, and `the_test_surface_is_disposed_of` fails on any unconfirmed one. Four rows are confirmed that way — `config.store_dir`, `http.cookie`, `ops.build_success_rate`, `watch.needs_stage_b`. The table now prints each item's in-module call sites as its own column, because the residue count is the one number this work cannot eliminate and the claim underneath it has to be checkable rather than asserted. Suite: 284 passed, 0 failed. Clippy clean. Release build clean.
* tools: decide the disposition of every test-only pub itemaur-build11 days1-0/+108
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The census could say which `pub` items nothing outside their module names, and which of those a test names. It could not say what to do about them, because the two questions that actually decide it are ones a raw-source name match cannot answer: Does a test *call* it, or merely mention it inside a string? Does production code *inside* the declaring module call it? `tools/test-surface.py` asks both, and `tools/test-surface.md` records the answer for all 61 items. Four dispositions, each with a hand-written reason kept in `tools/test-surface-reasons.json`: gate (9) production never calls it; a test does move-test (9) the test that names it builds no fixture, so it is a unit test in the wrong file narrow (6) no test calls it at all — census false positives, the name appears only inside a string literal residue (34) stays pub, and the honest column `residue` needs saying out loud. Rust has no test-conditional visibility: no attribute makes an item `pub` under one feature and `pub(crate)` under another, and `pub use` cannot re-export a `pub(crate)` item. An item that production needs *inside* its own module and a fixture-bound integration test needs from outside cannot be narrowed without breaking one side or the other. That is not a gap in this analysis; it is a gap in the language, and the way to close those 34 rows is to change the tests — move them into the module, or exercise the behaviour through the module's real entry point — not to invent a visibility that does not exist. So the column is ratcheted rather than wished away. `the_test_surface_is_disposed_of` fails if any row lacks a hand-written reason, and if any count — including `gate_pending`, items decided to be gated but not yet gated — exceeds its budget. It can only shrink. Two census limitations surfaced and are now written down rather than silently trusted: "module" means the top-level directory, so an item used only from a sibling file in the same module reads as dead; and mentions are matched over raw source, so a string counts as a reference. Six items were being counted as test-pinned on the strength of a string alone. No source file is edited here. This is the decision record the next commits apply. Suite: 284 passed, 0 failed. Release build: zero warnings.
* usecase: one implementation of each workflow, run by both front endsdev11 days1-10/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `main` opened the repository inline before its command match. `serve` opened it again, four calls in an order that matters. The web routes wrote subscriptions, toggles, notices and build retries straight through `db::`, so the CLI and the UI were two independent guesses at the same product, and the guesses had already drifted: `sub_add` fell back to repo id 1 where the CLI reported the repository as uninitialised, and `build_retry` remembered to write the audit row while nothing else did. `src/usecase/` is the workflow layer now — bootstrap, detect, reviews, subscriptions, builds, maintenance. A function earns a place here by having more than one step in an order that matters: `approve` records the decision *and* queues the build it authorises, because an approval that silently fails to queue is the exact failure the review queue exists to prevent, and both front ends had to remember to pair them. Nothing in the layer formats output or knows a status code exists. Where the two front ends genuinely disagree, the result carries the disagreement instead of resolving it: `Approved::queued` is a `Result` because a failed enqueue is fatal in the CLI — an approved candidate with no build is a stall nobody notices — and a soft failure in the UI, which has already committed the decision and can retry from the package page. `src/http/routes/mutations.rs` now contains no `db::` call at all, and `main.rs` is 314 lines with no multi-step sequence and nothing exported. Rank map: usecase 9, http 10, composition roots 11. The layer test enforces that usecase cannot name http, which is why `serve` starts the scheduler and the build pool but leaves the HTTP server to `main`. One user-visible message moves: `aur-build reject <missing>` now says `not found: candidate N` (the review layer's wording) instead of `no candidate #N` (main's). Both exit 1; the check moved with the workflow. 280 passed / 0 failed, clippy -D warnings clean, architecture 8/8.
* db: one module per aggregate, and an interface you can readdev11 days1-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | queries.rs was 1,501 lines holding 83 queries across seventeen aggregates, separated by comment banners that said "settings", "release", "notices" and then kept them in one file. The banners were the design; they just never got files. Each one has one now, verbatim — the split is provably content-only, the moved text being identical to the original as a sorted set of lines. model.rs and builds.rs were each two concerns deep, so they became directories. model.rs held what a row looks like and, separately, the state machines that say which moves are legal; builds.rs held the build machine and, below its own `step rows` banner, the step machine. The impl_state_enum! macro implements StateEnum for all five enums from one place, so it moved with its invocations rather than being exported across a boundary to chase them. They are directories rather than new sibling modules on purpose: `db::model::CandidateState` and `db::builds::steps` are used across the crate and by the integration tests, and renaming them would be a bigger change than the one being made. No call site and no test changed. db/mod.rs now lists its interface instead of spraying one. `pub use model::*` and `pub use queries::*` are gone, replaced by seventeen explicit exports, and the query modules are private — so a query that was not chosen for export is not reachable, and the width of the module is visible from its own text rather than only from a grep. The ratchet caught the win immediately: db.glob went 2 -> 0, which failed a_shrunk_interface_is_written_back until the budget was written back at the new value. db is off the glob allowlist now rather than holding a stale zero. 277 passed / 0 failed, clippy -D warnings clean, largest file in src/db 363 lines (candidates.rs, unchanged from before this work).
* tests: declare the layer map, and ratchet every interface widthdev11 days1-0/+579
Four greps in tests/layers.rs were the entire enforcement. They could say that db had stopped naming http; they could not say what the architecture is, could not place a new module, and said nothing about the twenty-odd modules nobody had tripped over yet. tests/architecture.rs declares the whole map instead. Every module in src/ gets a rank with the reason it sits there, and a module may name only modules ranked strictly below it — one rule, every module, cycles impossible by construction rather than by luck. The census says the graph already satisfies it, so the map is a description of what is true, not an aspiration the suite immediately fails on. The same file holds the interface budgets, because a boundary is only as strong as what it refuses to let you export: per module, how many pub items it hands out and how many of them nothing outside the module names. Budgets live in architecture-budget.json and move one way. A number that grows fails; a number that got smaller without being written back also fails, which is what stops a won gain from quietly becoming the new ceiling. Each rule was probed rather than trusted: naming http from db fails with `db (rank 3) names http (rank 9)`, tightening db.pub to 200 fails with `db.pub: 226 > 200`, and leaving a stale budget fails with `db.deadonly: budget 99, actual 36`. tests/layers.rs is deleted, not weakened. Three of its four rules are rank consequences now (db, review, recipe all sit below everything they were forbidden to name); the fourth, watch -> shims, was already covered by production_surface.rs, which greps every non-shim file for shims:: and would catch it in any module, not just watch. The census definition now lives in two languages, so the test checks them against each other the way the vercmp oracle checks the hand-written comparator: without python3 the note prints and the suite moves on. 277 passed / 0 failed (273 + 8 new - 4 subsumed), clippy -D warnings clean.