summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authordev <dev@example.com>2026-11-21 19:24:13 +0000
committerdev <dev@example.com>2026-11-21 19:24:13 +0000
commitdb11b540b1b4c60926c175cb5cd043c7555b99f3 (patch)
tree7b44a0a33951046b4b5efa435317cb2dbf5b9e45 /tests
parent689b82bfe36660c18cbce66a3f05550c4d02dc12 (diff)
downloadaur-build-db11b540b1b4c60926c175cb5cd043c7555b99f3.tar.gz
aur-build-db11b540b1b4c60926c175cb5cd043c7555b99f3.zip
tools,tests: count the pub(crate) items nothing outside their own file reaches
`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`.
Diffstat (limited to 'tests')
-rw-r--r--tests/architecture-budget.json137
-rw-r--r--tests/architecture.rs172
2 files changed, 274 insertions, 35 deletions
diff --git a/tests/architecture-budget.json b/tests/architecture-budget.json
index 7a95341..4ac33de 100644
--- a/tests/architecture-budget.json
+++ b/tests/architecture-budget.json
@@ -1,24 +1,24 @@
{
"dead_code": {
"allowlist": {
- "db.Migration": "the row type of `MIGRATIONS`, which is `pub` only under `test-support`; production walks the table through `db::migrate` without naming it",
- "db.PackageRow": "what `index_packages` hands back to `http`, the publish step and the `aur-build` binary, which bind it without naming it",
- "db.Subscription": "what `get_subscription` and `list_subscriptions` hand back to `watch`, `usecase`, the binary and tests/detect.rs",
- "db.Unbuilt": "the attention row `approved_but_unbuilt` returns to the web UI and to tests/crash.rs",
- "pkginfo.Installed": "what `parse_installed` answers with, read line by line by `pipeline` and tests/world.rs",
- "pkginfo.PkgInfo": "what `parse_pkginfo` answers with; `pipeline`, `shims` and tests/world.rs read its fields, never its name",
- "review.BulkItem": "one outcome of `approve::bulk`, which tests/approve.rs drives directly",
- "sandbox.ProvisionRequest": "the argument of `Provisioner::provision`, the trait the public `LocalAgentProvisioner` implements",
- "sandbox.Provisioner": "implemented by the test-gated public `LocalAgentProvisioner`; a private trait on a public impl is E0445",
- "shims.FakeInstalled": "the whole `shims` module is `test-support`-gated, so a release build never compiles it",
- "shims.FakePackage": "the whole `shims` module is `test-support`-gated, so a release build never compiles it",
- "shims.Manifest": "returned by `manifest()`, which the shim tests read; the module is `test-support`-gated",
- "time.VirtualClock": "lives in the `test-support`-gated clock module, behind the gated `virtualize()` that returns it",
- "usecase.Checked": "what `usecase::detect` returns to the `aur-build` binary, which is a separate crate",
- "usecase.GcPlan": "what `usecase::plan_gc` returns to the `aur-build` binary, which is a separate crate",
- "usecase.Prepared": "what `prepare_review` and `view_review` return to the `aur-build` binary, which is a separate crate",
- "watch.CheckReport": "what `detect::check_pkgbase` returns; the test tier drives it and binds the value without naming it",
- "watch.StageA": "what `upstream::probe` returns; tests/ops.rs and tests/vcs.rs call `probe` directly"
+ "db.Migration": "the element type of `MIGRATIONS`, which is `pub` under `test-support`; narrowing it is `private_interfaces` - type `Migration` is more private than the item `MIGRATIONS`. Production walks the table through `db::migrate` without naming it",
+ "db.PackageRow": "what `index_packages` answers with, and `index_packages` is `pub`; narrowing the row is `private_interfaces` - type `PackageRow` is more private than the item `index_packages`. http, the publish step and the `aur-build` binary bind it without naming it",
+ "db.Subscription": "what `get_subscription` and `list_subscriptions` answer with, both `pub`; narrowing it is `private_interfaces` on `list_subscriptions`. `watch`, `usecase`, the binary and tests/detect.rs bind the value without naming the type",
+ "db.Unbuilt": "the attention row `approved_but_unbuilt` returns, and that fn is `pub`; narrowing it is `private_interfaces` on `approved_but_unbuilt`. The web UI and tests/crash.rs bind it without naming it",
+ "pkginfo.Installed": "what `parse_installed` answers with, and `parse_installed` is `pub`; narrowing it is `private_interfaces` on `parse_installed`. `pipeline`, `shims` and tests/world.rs read it line by line",
+ "pkginfo.PkgInfo": "what `parse_pkginfo` answers with, and `parse_pkginfo` is `pub`; narrowing it is `private_interfaces` on `parse_pkginfo`. `pipeline`, `shims` and tests/world.rs read its fields, never its name",
+ "review.BulkItem": "one outcome of `approve::bulk`, which is `pub` and which tests/approve.rs drives directly; narrowing the row is `private_interfaces` on `approve::bulk`",
+ "sandbox.ProvisionRequest": "the parameter of `Provisioner::provision`, a `pub` trait method - a `pub` trait method cannot take a `pub(crate)` parameter, so the compiler answers `type kata::ProvisionRequest is more private than the item kata::Provisioner::provision`",
+ "sandbox.Provisioner": "implemented by the test-gated `pub` `LocalAgentProvisioner` and returned by `KataBackend::bind`; a private trait on a public impl is E0445, and the compiler says `trait kata::Provisioner is more private than the item KataBackend::bind`",
+ "shims.FakeInstalled": "the element type of the `pub` field `Manifest::installed`, so narrowing it is `private_interfaces` on that field; the whole `shims` module is `test-support`-gated, so a release build never compiles it",
+ "shims.FakePackage": "the element type of the `pub` field `Manifest::packages`, so narrowing it is `private_interfaces` on that field; the whole `shims` module is `test-support`-gated, so a release build never compiles it",
+ "shims.Manifest": "returned by `manifest()`, which is `pub` and which seven test files read to assert what a build did; narrowing the type is `private_interfaces` on `manifest`. The module is `test-support`-gated",
+ "time.VirtualClock": "re-exported by the gated `pub use` that is the only public path to it; narrowing it is E0365 - `VirtualClock` is only public within the crate, and cannot be re-exported outside",
+ "usecase.Checked": "re-exported by `usecase`'s `pub use`, which is how the `aur-build` binary - a separate crate - names it; narrowing it is E0365, cannot be re-exported outside the crate",
+ "usecase.GcPlan": "re-exported by `usecase`'s `pub use` for the `aur-build` binary, a separate crate; narrowing it is E0365, cannot be re-exported outside the crate",
+ "usecase.Prepared": "re-exported by `usecase`'s `pub use` for the `aur-build` binary, a separate crate; narrowing it is E0365, cannot be re-exported outside the crate",
+ "watch.CheckReport": "what `detect::check_pkgbase` answers with, and that fn is `pub`; narrowing it is `private_interfaces` on `check_pkgbase`. The test tier drives it and binds the value without naming it",
+ "watch.StageA": "what `upstream::probe` answers with, and `probe` is `pub`; narrowing it is `private_interfaces` on `probe`. tests/ops.rs and tests/vcs.rs call `probe` directly"
},
"deadonly": {
"bin/gpg": 0,
@@ -59,6 +59,7 @@
"largest": 4,
"largest_file": "src/bin/gpg.rs",
"lines": 4,
+ "overwide": 0,
"priv": 0,
"pub": 0,
"test": 0
@@ -70,6 +71,7 @@
"largest": 4,
"largest_file": "src/bin/makechrootpkg.rs",
"lines": 4,
+ "overwide": 0,
"priv": 0,
"pub": 0,
"test": 0
@@ -81,6 +83,7 @@
"largest": 4,
"largest_file": "src/bin/makepkg.rs",
"lines": 4,
+ "overwide": 0,
"priv": 0,
"pub": 0,
"test": 0
@@ -92,6 +95,7 @@
"largest": 4,
"largest_file": "src/bin/mkarchroot.rs",
"lines": 4,
+ "overwide": 0,
"priv": 0,
"pub": 0,
"test": 0
@@ -103,6 +107,7 @@
"largest": 4,
"largest_file": "src/bin/pacman.rs",
"lines": 4,
+ "overwide": 0,
"priv": 0,
"pub": 0,
"test": 0
@@ -114,6 +119,7 @@
"largest": 4,
"largest_file": "src/bin/repo-add.rs",
"lines": 4,
+ "overwide": 0,
"priv": 0,
"pub": 0,
"test": 0
@@ -125,6 +131,7 @@
"largest": 50,
"largest_file": "src/bin/sandbox-agent.rs",
"lines": 50,
+ "overwide": 0,
"priv": 0,
"pub": 0,
"test": 0
@@ -133,9 +140,10 @@
"dead": 2,
"deadonly": 0,
"glob": 0,
- "largest": 701,
+ "largest": 699,
"largest_file": "src/config.rs",
- "lines": 701,
+ "lines": 699,
+ "overwide": 1,
"priv": 2,
"pub": 29,
"test": 2
@@ -146,7 +154,8 @@
"glob": 0,
"largest": 368,
"largest_file": "src/db/mod.rs",
- "lines": 3897,
+ "lines": 3890,
+ "overwide": 0,
"priv": 19,
"pub": 189,
"test": 11
@@ -155,9 +164,10 @@
"dead": 0,
"deadonly": 0,
"glob": 0,
- "largest": 430,
+ "largest": 428,
"largest_file": "src/error.rs",
- "lines": 430,
+ "lines": 428,
+ "overwide": 0,
"priv": 0,
"pub": 21,
"test": 0
@@ -169,6 +179,7 @@
"largest": 57,
"largest_file": "src/fetch.rs",
"lines": 57,
+ "overwide": 1,
"priv": 2,
"pub": 1,
"test": 0
@@ -180,6 +191,7 @@
"largest": 240,
"largest_file": "src/git.rs",
"lines": 240,
+ "overwide": 0,
"priv": 0,
"pub": 14,
"test": 0
@@ -188,9 +200,10 @@
"dead": 0,
"deadonly": 0,
"glob": 0,
- "largest": 111,
+ "largest": 112,
"largest_file": "src/hash.rs",
- "lines": 111,
+ "lines": 112,
+ "overwide": 0,
"priv": 0,
"pub": 7,
"test": 0
@@ -201,7 +214,8 @@
"glob": 0,
"largest": 565,
"largest_file": "src/http/routes/pages.rs",
- "lines": 2034,
+ "lines": 2035,
+ "overwide": 1,
"priv": 81,
"pub": 17,
"test": 5
@@ -213,6 +227,7 @@
"largest": 23,
"largest_file": "src/lib.rs",
"lines": 23,
+ "overwide": 0,
"priv": 0,
"pub": 0,
"test": 0
@@ -224,6 +239,7 @@
"largest": 314,
"largest_file": "src/main.rs",
"lines": 314,
+ "overwide": 0,
"priv": 0,
"pub": 0,
"test": 0
@@ -235,6 +251,7 @@
"largest": 455,
"largest_file": "src/ops.rs",
"lines": 455,
+ "overwide": 3,
"priv": 5,
"pub": 11,
"test": 3
@@ -245,7 +262,8 @@
"glob": 0,
"largest": 472,
"largest_file": "src/pipeline/steps.rs",
- "lines": 1411,
+ "lines": 1410,
+ "overwide": 8,
"priv": 16,
"pub": 21,
"test": 6
@@ -257,6 +275,7 @@
"largest": 117,
"largest_file": "src/pkginfo.rs",
"lines": 117,
+ "overwide": 0,
"priv": 0,
"pub": 6,
"test": 0
@@ -268,6 +287,7 @@
"largest": 559,
"largest_file": "src/pkgver/mod.rs",
"lines": 559,
+ "overwide": 0,
"priv": 0,
"pub": 7,
"test": 0
@@ -279,6 +299,7 @@
"largest": 459,
"largest_file": "src/recipe.rs",
"lines": 459,
+ "overwide": 0,
"priv": 0,
"pub": 7,
"test": 0
@@ -290,6 +311,7 @@
"largest": 301,
"largest_file": "src/review/diff.rs",
"lines": 915,
+ "overwide": 0,
"priv": 4,
"pub": 24,
"test": 4
@@ -298,9 +320,10 @@
"dead": 7,
"deadonly": 0,
"glob": 0,
- "largest": 508,
+ "largest": 507,
"largest_file": "src/sandbox/kata.rs",
- "lines": 1413,
+ "lines": 1408,
+ "overwide": 6,
"priv": 16,
"pub": 21,
"test": 7
@@ -312,6 +335,7 @@
"largest": 655,
"largest_file": "src/shims/mod.rs",
"lines": 655,
+ "overwide": 7,
"priv": 13,
"pub": 8,
"test": 4
@@ -320,9 +344,10 @@
"dead": 3,
"deadonly": 0,
"glob": 0,
- "largest": 243,
+ "largest": 245,
"largest_file": "src/time.rs",
- "lines": 243,
+ "lines": 245,
+ "overwide": 0,
"priv": 0,
"pub": 13,
"test": 3
@@ -334,6 +359,7 @@
"largest": 56,
"largest_file": "src/urlutil.rs",
"lines": 56,
+ "overwide": 0,
"priv": 0,
"pub": 1,
"test": 0
@@ -345,6 +371,7 @@
"largest": 124,
"largest_file": "src/usecase/reviews.rs",
"lines": 405,
+ "overwide": 0,
"priv": 0,
"pub": 30,
"test": 0
@@ -356,11 +383,54 @@
"largest": 296,
"largest_file": "src/watch/upstream.rs",
"lines": 1115,
+ "overwide": 0,
"priv": 12,
"pub": 21,
"test": 4
}
},
+ "over_visibility": {
+ "allowlist": {
+ "db.OpenReview": "returned by `open_in` and taken by `collapse_in`, both `pub(crate)` in this file; a private type behind a `pub(crate)` signature is the `private_interfaces` warning, so the type has to be as visible as the functions that carry it",
+ "db.Readers": "`Db` is `pub` and its `readers` field is `pub(crate)`, and a field cannot out-reach its own type; making `Readers` private is the `private_interfaces` warning on `db::Db::readers`",
+ "db.ReviewSubject": "`review_subject_in` is `pub(crate)` and answers with it, and another file binds the value: with the type private that call site is `error: type ReviewSubject is private`",
+ "ops.EvictPlan": "`plan_retention` is `pub(crate)` and returns `Vec<EvictPlan>`; with the type private, the caller that binds that Vec in another file is `error: type EvictPlan is private`",
+ "pipeline.SourceIdentity": "the `pub(crate)` field `Ctx::src` has this type, and a field may not be more reachable than its type; private `SourceIdentity` is the `private_interfaces` warning on `Ctx::src`",
+ "review.Assessment": "`assess` is `pub(crate)` and answers with it, so a private `Assessment` is `error: type Assessment is private` at every site in another file that binds the result",
+ "review.LOW": "declared inside the `pub mod level` nested in risk.rs and read as `level::LOW` by the scorer in the parent module; privacy does not reach upward to a parent, and `pub(super)` is not a form this crate admits, so `pub(crate)` is the narrowest that works",
+ "sandbox.provision_request": "declared inside the private `kata_backend` module (kata.rs:184) and called from the sibling `#[cfg(test)] mod tests` (kata.rs:421); privacy does not cross to a sibling - E0624 - and `pub(super)` is not a form this crate admits"
+ },
+ "overwide": {
+ "bin/gpg": 0,
+ "bin/makechrootpkg": 0,
+ "bin/makepkg": 0,
+ "bin/mkarchroot": 0,
+ "bin/pacman": 0,
+ "bin/repo-add": 0,
+ "bin/sandbox-agent": 0,
+ "config": 1,
+ "db": 0,
+ "error": 0,
+ "fetch": 1,
+ "git": 0,
+ "hash": 0,
+ "http": 1,
+ "lib": 0,
+ "main": 0,
+ "ops": 3,
+ "pipeline": 8,
+ "pkginfo": 0,
+ "pkgver": 0,
+ "recipe": 0,
+ "review": 0,
+ "sandbox": 6,
+ "shims": 7,
+ "time": 0,
+ "urlutil": 0,
+ "usecase": 0,
+ "watch": 0
+ }
+ },
"test_surface": {
"already-gated": 16,
"interface": 1,
@@ -372,9 +442,10 @@
"deadonly": 0,
"edges": 87,
"glob": 0,
- "largest": 701,
+ "largest": 699,
"largest_file": "src/config.rs",
- "lines": 15684,
+ "lines": 15671,
+ "overwide": 27,
"priv": 170,
"pub": 448,
"test": 49
diff --git a/tests/architecture.rs b/tests/architecture.rs
index 3eafcdc..b32ea54 100644
--- a/tests/architecture.rs
+++ b/tests/architecture.rs
@@ -224,6 +224,7 @@ struct Module {
test_only: usize,
dead_only: usize,
pub_crate: usize,
+ over_wide: usize,
globs: usize,
lines: usize,
}
@@ -301,6 +302,40 @@ impl Census {
}
}
+ // A `pub(crate)` item is over-wide when no file except the one that
+ // declares it writes its name: it offers the crate a thing nothing
+ // outside its own file reaches, and plain private is what it should be.
+ // `tests/` is not consulted — a separate crate cannot name a `pub(crate)`
+ // item, so a mention there says nothing. As with `dead`, a name declared
+ // in several files is flagged only when no file outside all of them says
+ // it, and the compiler, not this count, gives the verdict.
+ let mut pc_declared: BTreeMap<String, BTreeSet<PathBuf>> = BTreeMap::new();
+ for (path, text) in &texts {
+ for line in text.lines() {
+ if let Some(name) = pub_crate_decl(line) {
+ pc_declared.entry(name).or_default().insert(path.clone());
+ }
+ }
+ }
+ let over_allow = allowed_overwide_items();
+ for (name, files) in &pc_declared {
+ let read_outside = texts
+ .iter()
+ .any(|(path, text)| !files.contains(path) && mentions(text, name));
+ if read_outside {
+ continue;
+ }
+ for path in files {
+ let module = module_of(path);
+ // Argued, so not counted: the reason it stays `pub(crate)` is in
+ // the budget file next to its name, exactly as on the `pub` side.
+ if over_allow.contains(&format!("{module}.{name}")) {
+ continue;
+ }
+ modules.get_mut(&module).unwrap().over_wide += 1;
+ }
+ }
+
let mut edges: BTreeMap<String, BTreeSet<String>> = BTreeMap::new();
for (path, text) in &texts {
let source = module_of(path);
@@ -374,6 +409,27 @@ fn allowed_pub_items() -> BTreeSet<String> {
.unwrap_or_default()
}
+/// The `over_visibility.allowlist` keys — `module.item` for every `pub(crate)`
+/// item that stays `pub(crate)` by decision, with the compiler fact beside it.
+fn allowed_overwide_items() -> BTreeSet<String> {
+ let path = root().join("tests/architecture-budget.json");
+ let text = std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("read {}: {}", path.display(), e));
+ let value: serde_json::Value = serde_json::from_str(&text).expect("budget file is json");
+ value
+ .get("over_visibility")
+ .and_then(|d| d.get("allowlist"))
+ .and_then(|a| a.as_object())
+ .map(|a| {
+ a.keys()
+ .map(|k| {
+ assert!(!k.trim().is_empty(), "an over-wide permission key cannot be blank");
+ k.clone()
+ })
+ .collect()
+ })
+ .unwrap_or_default()
+}
+
/// A top-level section of the budget file, as `key -> allowed`.
fn budget_section(section: &str) -> BTreeMap<String, usize> {
let path = root().join("tests/architecture-budget.json");
@@ -513,11 +569,12 @@ fn glob_reexports_stay_on_the_allowlist() {
}
/// The four comparisons the ratchet makes, as `(key, actual)` pairs.
-fn budgeted(row: &Module) -> [(&'static str, usize); 4] {
+fn budgeted(row: &Module) -> [(&'static str, usize); 5] {
[
("pub", row.pub_items),
("dead", row.dead),
("deadonly", row.dead_only),
+ ("overwide", row.over_wide),
("glob", row.globs),
]
}
@@ -616,6 +673,7 @@ fn the_census_tool_and_this_test_agree() {
("test", mine.test_only),
("deadonly", mine.dead_only),
("priv", mine.pub_crate),
+ ("overwide", mine.over_wide),
("glob", mine.globs),
] {
let got = row.get(key).and_then(|v| v.as_u64()).unwrap_or(u64::MAX) as usize;
@@ -873,6 +931,69 @@ fn the_dead_code_allowlist_names_real_items() {
);
}
+/// The `over_visibility.allowlist` is a set of decisions too, and it is checked
+/// the same two ways: an entry must name something that is still `pub(crate)` in
+/// the module it names, and it must carry a reason worth reading.
+///
+/// The first direction matters more here than on the `pub` side. A `pub(crate)`
+/// item that has since gone private still matches a `module.item` key written
+/// against the module's declared names, so the check has to look at the
+/// `pub(crate)` declarations specifically — otherwise the permission quietly
+/// re-widens the item it was left behind by.
+#[test]
+fn the_over_visibility_allowlist_names_real_items() {
+ let path = root().join("tests/architecture-budget.json");
+ let text = std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("read {}: {}", path.display(), e));
+ let value: serde_json::Value = serde_json::from_str(&text).expect("budget file is json");
+ let allow = value
+ .get("over_visibility")
+ .and_then(|d| d.get("allowlist"))
+ .and_then(|a| a.as_object())
+ .expect("budget file has an over_visibility.allowlist object");
+
+ let mut pub_crate_declared: BTreeMap<String, BTreeSet<String>> = BTreeMap::new();
+ for path in src_files() {
+ let module = module_of(&path);
+ for line in std::fs::read_to_string(&path).expect("read source").lines() {
+ if let Some(name) = pub_crate_decl(line) {
+ pub_crate_declared.entry(module.clone()).or_default().insert(name);
+ }
+ }
+ }
+
+ let mut stale = Vec::new();
+ let mut blank = Vec::new();
+ for (key, reason) in allow {
+ let Some((module, name)) = key.split_once('.') else {
+ stale.push(format!("{key}: a key is `module.item`"));
+ continue;
+ };
+ if reason.as_str().map(|r| r.trim().len() < 20).unwrap_or(true) {
+ blank.push(key.clone());
+ }
+ if !pub_crate_declared
+ .get(module)
+ .is_some_and(|names| names.contains(name))
+ {
+ stale.push(format!("{key} at {reason}"));
+ }
+ }
+ stale.sort();
+ blank.sort();
+ assert!(
+ stale.is_empty(),
+ "these over-wide permissions name something that is no longer a `pub(crate)`\n\
+ item in that module — it went private, or it was never one:\n{}",
+ stale.join("\n")
+ );
+ assert!(
+ blank.is_empty(),
+ "these over-wide permissions have no reason (or one too short to be one):\n{}\n\
+ say what the compiler refuses to let go private, not that it felt safer.",
+ blank.join("\n")
+ );
+}
+
/// `tests/common/mod.rs` is compiled into every test binary, so the suite keeps
/// a crate-level `allow(dead_code)` there — a helper used by one binary is dead
/// code in the other twenty, and the lint would fire everywhere and mean
@@ -1037,6 +1158,53 @@ fn the_dead_code_budget_matches_the_code() {
);
}
+#[test]
+fn the_over_visibility_budget_matches_the_code() {
+ // The same self-consistency the dead-code budget is held to: the accepted
+ // count, the number in the `modules` section, and the number the census
+ // actually measures have to be one number, or the ratchet is checking a
+ // figure nothing reads.
+ let path = root().join("tests/architecture-budget.json");
+ let value: serde_json::Value =
+ serde_json::from_str(&std::fs::read_to_string(&path).expect("read budget")).expect("budget is json");
+ let modules = value.get("modules").and_then(|m| m.as_object()).expect("modules");
+ let over = value
+ .get("over_visibility")
+ .and_then(|d| d.get("overwide"))
+ .and_then(|d| d.as_object())
+ .expect("over_visibility.overwide");
+ let census = Census::take();
+
+ let mut mismatch = Vec::new();
+ for (module, row) in modules {
+ let stated = row.get("overwide").and_then(|v| v.as_u64()).unwrap_or(u64::MAX);
+ let accepted = over.get(module).and_then(|v| v.as_u64());
+ let actual = census
+ .modules
+ .get(module)
+ .map(|m| m.over_wide as u64)
+ .unwrap_or(u64::MAX);
+ if accepted != Some(stated) || stated != actual {
+ mismatch.push(format!(
+ "{module}: over_visibility.overwide {:?}, modules.overwide {stated}, actual {actual}",
+ accepted
+ ));
+ }
+ }
+ for module in over.keys() {
+ if !modules.contains_key(module) {
+ mismatch.push(format!("{module}: in over_visibility.overwide, absent from modules"));
+ }
+ }
+ mismatch.sort();
+ assert!(
+ mismatch.is_empty(),
+ "the budget contradicts itself about how many over-wide `pub(crate)` items a\n\
+ module has:\n{}",
+ mismatch.join("\n")
+ );
+}
+
/// Two tools write one file, so neither may erase what the other owns.
///
/// `tools/arch-census.py` writes the module numbers and the accepted dead-code
@@ -1063,7 +1231,7 @@ fn the_budget_writers_preserve_each_other() {
let after: serde_json::Value =
serde_json::from_str(&std::fs::read_to_string(&tmp).expect("read temp budget"))
.expect("written budget is json");
- for section in ["test_surface", "dead_code"] {
+ for section in ["test_surface", "dead_code", "over_visibility"] {
assert!(
after.get(section).is_some(),
"{tool} erased the `{section}` section it does not own"