summaryrefslogtreecommitdiffstats
path: root/src/db/model/mod.rs
Commit message (Collapse)AuthorAgeFilesLines
* src,tests: say each thing once, in the code or not at allaur-build9 days1-5/+0
| | | | | | | | | | | | | The repeated explanations go: sixteen copies of why a `pub` under `test-support` has two declarations, six notes about where a test moved from, forty-three banner comments naming the section they sit above. The prose that stays is the prose the code cannot say — a hand-written Debug that keeps a token out of a log line, a git pipe that would deadlock if the write came first, an end-of-string check that has to precede the separator skip. Enum docs in error.rs collapse to the line that names what the type is; the argument for why it is shaped that way is in the variants.
* rustfmt,lints: pin the formatting, adopt the idiom lints, pay them offaur-build9 days1-2/+2
| | | | | | | | | | | | | | | 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.
* src,sandbox,http: three more fields nobody read, and the check that missed themaur-build10 days1-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* src: keep every remaining test-only item out of the release buildaur-build11 days1-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The auditor was right and my "Rust has no test-conditional visibility" defence was wrong. Two shapes do it, and both are now used wherever the item allows. For free functions, methods, consts and statics: one body behind two visibility declarations. #[cfg(feature = "test-support")] pub fn probe(..) -> .. { probe_impl(..) } #[cfg(not(feature = "test-support"))] pub(crate) fn probe(..) -> .. { probe_impl(..) } fn probe_impl(..) -> .. { .. } The value lives once in a private `*_impl` / `*_VALUE`, so the aliases cannot drift apart. For types: a private inner module holding the real definition, re-exported under a feature gate. mod kata_backend { pub struct KataBackend { .. } } #[cfg(feature = "test-support")] pub use kata_backend::KataBackend; #[cfg(not(feature = "test-support"))] pub(crate) use kata_backend::KataBackend; A `pub` item inside a private module has no nameable path from outside, but it is visible enough to appear in a public trait signature — which is why `Exit`, the return type of `Sandbox::run`, narrows this way and would not as a plain `pub(crate) struct`. `ReleaseState` earns its keep the same route: `ReleaseRow` is public and its `state` field is typed here. Verified with an external crate against the built library: naming `Exit`, `SandboxInfo`, `KataBackend`, `LoopbackBackend`, `RemoteBackend`, `ReleaseState`, `BulkRefusal` or `LogTail` from a release build is `error[E0603]: .. is private`; with `test-support` the same program compiles. Where narrowing needed a re-export split by feature (`db::MIGRATIONS`, `model::ReleaseState`) the alias is split; where nothing in the crate used the alias (`watch::sync_mirror`) it is gone rather than gated.
* db, sandbox: apply the dispositions the table decidedaur-build11 days1-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Six db items are now gated behind `test-support`, each with a comment saying what it is for and why production never calls it: builds::claim production leases a batch; `claim_batch` is what the dispatcher runs settings::set_setting the readers are used, the setter is not Writer::shutdown the server runs until the process ends snapshots::snapshot_by_commit world::world_members production writes world snapshots, never reads one back member by member invariants::unapproved_index_entries gated, not relocated: reading it needs this module's private helpers, and widening those to let a test out would be the wrong trade Gating them exposed three things they were the only user of, and each is gated with them rather than left compiling into a binary that cannot reach it: `Msg::Shutdown` and its loop arm, and `model::json_or`. `arch-census.py --write-budget` also stopped erasing the `test_surface` section — two writers of one file must not delete each other's axis, or the ratchet quietly stops checking it. `steps::touch` is deleted, not narrowed. Nothing called it — not production, not a test. The census had credited it to `tests/shims.rs`, where the word appears inside a string. In sandbox, two tests moved into `src/sandbox/kata.rs`: the container record a lease provisions, and the TTL expiry of a sandbox that never dials in. Neither builds a fixture. `KataBackend::shared_for`, `provision_request`, `sandbox_cr` and `K8sSandboxProvisioner::for_config` are `pub(crate)` as a result. `KataBackend::reclaim` is deleted — same story as `touch`. It forwarded to `self.provisioner.reclaim`, which the reaping site already calls itself, and the TTL test the census credited it for implements the *trait's* `reclaim` on a null provisioner. Same word, different function. Two honest costs, both recorded rather than smoothed over: - `Provisioner` and `ProvisionRequest` are now named by nobody outside `sandbox`, yet cannot be narrowed: `LocalAgentProvisioner` is `pub` because two fixture tests construct it, and Rust forbids a public type implementing a private trait or taking a private parameter type. `sandbox.deadonly` therefore rises 0 → 2, with the reason here as the ratchet demands. - `agent_sandbox_config()` now exists in both `tests/kata.rs` and `src/sandbox/kata.rs`. Three of that file's remaining tests still need it, and a test helper cannot be shared across the crate boundary without making it public again. sandbox: 27 pub / 15 dead -> 22 pub / 10 dead. Suite: 284 passed, 0 failed, 0 ignored. Clippy clean.
* hash, time, db::model: move the pure clock and digest tests homeaur-build11 days1-0/+28
| | | | | | | | | | | | | | | | | | | | | | tests/hash.rs held three tests and none of them belonged there. Two were about `canonical_json` and moved into src/hash.rs. The third asserted that the identity digest is a pure function of an identity's own fields — a property of `db::model::Identity`, not of the hashing helper it happens to call — so it moved to db::model, where the thing it tests lives. The file is now empty and is deleted; the tests are moves, not losses, and each is named in its new module. tests/time.rs held three tests, two of which were clock arithmetic with no dependencies at all. They moved into src/time.rs. The third pins a build lease against a pinned clock and needs a database, so it stayed where a database is available. No visibility changed in this commit: `canonical_json` is used in production and stays public, and `time::pin`/`unpin` are ungated test escapes that the disposition table will decide on rather than being quietly narrowed here as a side effect. Suite: 281 passed, 0 failed, 0 ignored. Release build: zero warnings.
* db: close what nothing reaches, and say what cannot be closeddev11 days1-14/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | db handed out 226 items and 36 of them were named by nobody at all — not by the crate, not by the tests. Making them private is the whole of this commit, but the interesting part is what the compiler said afterwards. Twenty-five closed cleanly. Eleven did not, and they are the ones worth writing down: AuditRow, NoticeRow, PackageRow, Subscription, StepRow, Unbuilt, OpenReview, ReviewSubject, Migration, Writer, predecessors. None is named outside db, yet none can be made private, because a public query returns them and callers bind them with `let` and call methods on them. They are load-bearing and invisible to a name search. So the census's `dead` count means "the name is never written outside the module", which is a lead rather than a verdict, and the census now says so: the way to find out which flagged items are real is to privatize them and let rustc answer. Those eleven are budgeted with that reason, not zeroed to make a number look good. Nineteen items turned out to be dead code rather than merely unexported — set_release, set_candidate, set_pkgbase, set_profile, set_kind, current_state, index_pkgbase_drift, wal_stats, call_for_tests, put_notice, is_ours, list_pkgbases, set_unpinable, artifact_id_by_digest_in, subscription_poll_interval, the four never-emitted notice kinds, and StateEnum::as_str, which the impl_state_enum macro was required to define for all five enums while nothing called it through the trait. Privatizing is what proved they were unused; leaving them private-but-present would have just hidden dead code behind a narrower address. Ten items became pub(crate): the Writer actor's call/tx/send surface, Readers, the StateEnum trait, json_or, predecessors, DEFAULT_SETTINGS. `Db.readers` was named nowhere outside db, so the field closed with the type. db: 226 pub / 36 dead-only -> 201 pub / 11 dead-only. 277 passed / 0 failed, clippy -D warnings clean, schema_ownership and architecture green.
* db: one module per aggregate, and an interface you can readdev11 days1-0/+217
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).