From ae492c87ff66b9f2c8fec25a5ca917c438bf5858 Mon Sep 17 00:00:00 2001 From: aur-build Date: Sat, 21 Nov 2026 09:38:21 +0000 Subject: src: close the items the stricter detector surfaced MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The auditor's two counterexamples were real, and fixing the detector exposed seventeen more items it had never listed. Each was checked individually rather than dispositioned in bulk, and the check changed what the right answer was: - `review::approve::withdraw` — gated. The CLI and the web UI both go through `usecase::withdraw_package`; nothing invokes this. tests/pipeline.rs pins its invariants, so it is gated rather than deleted: the test is the cover for an operation production has not grown yet. - `pipeline::dispatch::Pool::shutdown` — gated. Production runs the pool until the process exits; a test needs the join to assert on effects after the threads stop. Its two fields now carry a matching `cfg_attr(allow(dead_code))` because in a release build they are stored and never read. - `shims::{mkarchroot,makechrootpkg,makepkg,gpg,pacman,record}` — plain `pub(crate)`. `run` dispatches to them by tool name; no module outside `shims` names them and no test calls them. The tool names appear in test *strings*, which is not a caller. - `db::Writer::start`, `fetch::open`, `http::Req::form`, `http::Page::new`, `http::Panel::new`, `http::render::BuildRow` — plain `pub(crate)`, same reason: used only from inside their own module. - `db::AuditEntry::system` — deleted. `audit_system` builds the row through the free `audit()`; nothing ever called the constructor, production or otherwise. - `pkgver::Version::display` — deleted, a wrapper around `to_string` with no callers. - `http::Server`, `watch::Stale`, `pkgver::Version` — private inner module with a gated alias. `Server` is what `spawn` hands back and `main` holds without naming; `Stale` is what `stale_rows` returns to `http` and `ops`; `Version` is what `parse` returns. All three must stay nameable to those callers in shape but not in name, which is exactly what the inner-module alias gives. Measured on the release build's public surface: 466 reachable public names at the start of this goal, 402 now, newly-public set empty. --- src/db/audit.rs | 9 --------- src/db/mod.rs | 3 ++- src/fetch.rs | 3 ++- src/http/mod.rs | 26 ++++++++++++++++++++++---- src/http/render.rs | 12 +++++++++--- src/pipeline/dispatch.rs | 11 +++++++++++ src/pkgver/mod.rs | 30 ++++++++++++++++++++++-------- src/review/approve.rs | 12 ++++++++++++ src/shims/mod.rs | 18 ++++++++++++------ src/watch/staleness.rs | 33 ++++++++++++++++++++++++++------- 10 files changed, 118 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/db/audit.rs b/src/db/audit.rs index ce9d0c8..45a3b46 100644 --- a/src/db/audit.rs +++ b/src/db/audit.rs @@ -60,15 +60,6 @@ impl<'a> AuditEntry<'a> { Self { at, actor_kind: "human", actor, action, entity, entity_id, detail } } - pub fn system( - at: &'a str, - action: &'a str, - entity: &'a str, - entity_id: &'a str, - detail: serde_json::Value, - ) -> Self { - Self { at, actor_kind: "system", actor: "", action, entity, entity_id, detail } - } } pub fn audit_in(tx: &rusqlite::Transaction<'_>, e: &AuditEntry<'_>) -> Result<()> { diff --git a/src/db/mod.rs b/src/db/mod.rs index e8a97b4..bf54be1 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -195,7 +195,8 @@ pub struct Writer { } impl Writer { - pub fn start(path: &Path) -> Result { +/// Only `Writer::open` in this module starts a writer. + pub(crate) fn start(path: &Path) -> Result { let conn = open(path, false)?; let (tx, rx) = unbounded::(); let alive = Arc::new(AtomicBool::new(true)); diff --git a/src/fetch.rs b/src/fetch.rs index 1d06051..bcbdbda 100644 --- a/src/fetch.rs +++ b/src/fetch.rs @@ -17,7 +17,8 @@ impl Read for Body { } } -pub fn open(url: &str) -> Result<(Body, Option)> { +/// Only `get` in this file opens a fetch result; the bare word `open` elsewhere is a variable, not this function. +pub(crate) fn open(url: &str) -> Result<(Body, Option)> { if let Some(path) = url.strip_prefix("file://") { let p = path.trim_start_matches('/'); let p = PathBuf::from(format!("/{p}")); diff --git a/src/http/mod.rs b/src/http/mod.rs index 4291021..60a1f2e 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -24,7 +24,8 @@ pub(crate) struct Req { } impl Req { - pub fn form(&self) -> &[(String, String)] { +/// Read by the route handlers, which are in this module; the word `form` in a test is a local parameter. + pub(crate) fn form(&self) -> &[(String, String)] { &self.form_pairs } pub fn form_get(&self, key: &str) -> Option { @@ -95,11 +96,28 @@ impl Res { } } -pub struct Server { - pub handle: std::thread::JoinHandle<()>, - pub addr: String, +/// The real definition. The module is private, so this `pub` +/// is not a nameable path from outside; the alias below is the +/// only way to reach it, and the alias is what carries the +/// feature-conditional visibility. +mod server { + pub struct Server { + pub handle: std::thread::JoinHandle<()>, + pub addr: String, + } } +/// the handle to a running HTTP listener. `spawn` returns it and `main` holds it without naming the type; the test harness stores it in a field because it needs the bound address. +/// +/// `pub` only under `test-support`. Production reaches the type +/// through its own module and never names it from outside; the +/// outside reader that needs the name is a test. +#[cfg(feature = "test-support")] +pub use server::Server; + +#[cfg(not(feature = "test-support"))] +pub(crate) use server::Server; + pub fn spawn(cfg: Config, db: Db) -> std::io::Result { let server = tiny_http::Server::http(&cfg.bind) .map_err(|e| std::io::Error::other(e.to_string()))?; diff --git a/src/http/render.rs b/src/http/render.rs index 4482380..d513c2a 100644 --- a/src/http/render.rs +++ b/src/http/render.rs @@ -38,7 +38,9 @@ pub use page::Page; pub(crate) use page::Page; impl Page { - pub fn new(title: &str, csrf: String) -> Self { + /// Built by the route handlers, which are in this module; nothing outside + /// `http` constructs a page header. + pub(crate) fn new(title: &str, csrf: String) -> Self { Self { title: title.into(), flash: String::new(), @@ -181,7 +183,8 @@ pub use panel::Panel; pub(crate) use panel::Panel; impl Panel { - pub fn new(title: &str, body: String) -> Self { + /// Built by the route handlers, which are in this module. + pub(crate) fn new(title: &str, body: String) -> Self { Self { title: title.into(), empty: body.trim().is_empty(), @@ -329,7 +332,10 @@ pub(crate) struct BuildLite { } #[derive(Debug, Clone)] -pub struct BuildRow { +/// A row of the builds table as the templates render it. Filled and read +/// entirely inside `http`; the `BuildRow` other modules name is `db::builds::BuildRow`, +/// a different type that happens to share the name. +pub(crate) struct BuildRow { pub id: String, pub id_short: String, pub pkgbase: String, diff --git a/src/pipeline/dispatch.rs b/src/pipeline/dispatch.rs index aea934e..35fe646 100644 --- a/src/pipeline/dispatch.rs +++ b/src/pipeline/dispatch.rs @@ -9,7 +9,12 @@ use crate::db::{self, builds, Db}; use crate::pipeline::{self, Outcome}; pub struct Pool { + // Read only by `shutdown`, which is compiled for the test tier: a release + // build starts the dispatcher and runs it until the process exits, so in + // that build these two fields are stored and never read. + #[cfg_attr(not(feature = "test-support"), allow(dead_code))] stop: Arc, + #[cfg_attr(not(feature = "test-support"), allow(dead_code))] handles: Vec>, } @@ -47,6 +52,12 @@ impl Pool { Pool { stop, handles } } + /// Stop the dispatcher threads and join them. + /// + /// Production runs the pool until the process exits; nothing asks it to + /// stop. A test needs the join, because it asserts on the pool's effects + /// and cannot do that while the threads are still running. + #[cfg(feature = "test-support")] pub fn shutdown(self) { self.stop.store(true, Ordering::SeqCst); for h in self.handles { diff --git a/src/pkgver/mod.rs b/src/pkgver/mod.rs index cc00877..c97b4a2 100644 --- a/src/pkgver/mod.rs +++ b/src/pkgver/mod.rs @@ -21,13 +21,30 @@ fn split_full_version(v: &str) -> (String, String, String) { } } -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct Version { - pub epoch: String, - pub pkgver: String, - pub pkgrel: String, +/// The real definition. The module is private, so this `pub` +/// is not a nameable path from outside; the alias below is the +/// only way to reach it, and the alias is what carries the +/// feature-conditional visibility. +mod version { + #[derive(Debug, Clone, PartialEq, Eq)] + pub struct Version { + pub epoch: String, + pub pkgver: String, + pub pkgrel: String, + } } +/// a parsed epoch-ver-rel. Every caller uses the value `parse` hands back without naming the type; the tests that pin the ordering do name it. +/// +/// `pub` only under `test-support`. Production reaches the type +/// through its own module and never names it from outside; the +/// outside reader that needs the name is a test. +#[cfg(feature = "test-support")] +pub use version::Version; + +#[cfg(not(feature = "test-support"))] +pub(crate) use version::Version; + impl fmt::Display for Version { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", full_version(&self.epoch, &self.pkgver, &self.pkgrel)) @@ -45,9 +62,6 @@ impl Version { fn epoch_as_i64(&self) -> i64 { self.epoch.trim().parse().unwrap_or(0) } - pub fn display(&self) -> String { - self.to_string() - } } pub fn compare( diff --git a/src/review/approve.rs b/src/review/approve.rs index f116a92..e1150b3 100644 --- a/src/review/approve.rs +++ b/src/review/approve.rs @@ -219,6 +219,18 @@ pub fn bulk( Ok(out) } +/// Withdraw a published release and unpublish its files. +/// +/// Nothing in production reaches this today: the CLI and the web UI both go +/// through `usecase::withdraw_package`, which withdraws a *package* and +/// republishes the repo. This is the single-release operation underneath what +/// that path will eventually use, and `tests/pipeline.rs` is what pins its +/// invariants — a second withdraw is refused, an unknown release is refused. +/// +/// So it is compiled only under `test-support`. A release build does not carry +/// an operation nothing invokes; when production grows the call, the gate comes +/// off and the test that already exists becomes the regression cover. +#[cfg(feature = "test-support")] pub fn withdraw(db: &Db, actor: &str, release_id: i64, reason: &str) -> Result<()> { let actor = actor.to_string(); let reason = reason.to_string(); diff --git a/src/shims/mod.rs b/src/shims/mod.rs index 4b29466..a877739 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -109,7 +109,8 @@ fn manifest_impl() -> Manifest { } } -pub fn record(tool: &str, args: &[String]) { +/// Called by `run` to log the invocation; nothing outside `shims` records a shim call. +pub(crate) fn record(tool: &str, args: &[String]) { let dir = match std::env::var("AUR_SHIM_DIR") { Ok(d) => d, Err(_) => return, @@ -206,7 +207,8 @@ pub fn run(tool: &str) -> i32 { } } -pub fn mkarchroot(args: &[String]) -> Result { +/// Reached only through `run`, which matches the tool name to it. The tool name appears in test strings, which is not a caller. +pub(crate) fn mkarchroot(args: &[String]) -> Result { let mut target = None; let mut skip = false; for a in args { @@ -229,7 +231,8 @@ pub fn mkarchroot(args: &[String]) -> Result { Ok(0) } -pub fn makechrootpkg(args: &[String], m: &Manifest) -> Result { +/// Reached only through `run`, which matches the tool name to it. The tool name appears in test strings, which is not a caller. +pub(crate) fn makechrootpkg(args: &[String], m: &Manifest) -> Result { if !args.iter().any(|a| a == "-r") { return Err("makechrootpkg: expected -r ".into()); } @@ -407,7 +410,8 @@ fn fake_sig(bytes: &[u8]) -> Vec { format!("-----BEGIN FAKE PGP SIGNATURE-----\n{}\n-----END FAKE PGP SIGNATURE-----\n", hash::hex(bytes)).into_bytes() } -pub fn makepkg(args: &[String], m: &Manifest) -> Result { +/// Reached only through `run`, which matches the tool name to it. The tool name appears in test strings, which is not a caller. +pub(crate) fn makepkg(args: &[String], m: &Manifest) -> Result { if args.iter().any(|a| a == "--vercheck" || a == "-V-check") { let v = m.vercheck.clone().unwrap_or_else(|| "1.0-1".into()); println!("{v}"); @@ -456,7 +460,8 @@ pub fn makepkg(args: &[String], m: &Manifest) -> Result { } } -pub fn pacman(args: &[String]) -> Result { +/// Reached only through `run`, which matches the tool name to it. The tool name appears in test strings, which is not a caller. +pub(crate) fn pacman(args: &[String]) -> Result { if args.iter().any(|a| a == "-U") { for path in args.iter().filter(|a| !a.starts_with('-')) { let p = std::path::Path::new(path); @@ -624,7 +629,8 @@ fn pkginfo_fields(pkg_bytes: &[u8]) -> Result<(String, String, String, String), Ok((info.name, info.version, info.arch, extra)) } -pub fn gpg(args: &[String]) -> Result { +/// Reached only through `run`, which matches the tool name to it. The tool name appears in test strings, which is not a caller. +pub(crate) fn gpg(args: &[String]) -> Result { let out = args .iter() .position(|a| a == "--output" || a == "-o") diff --git a/src/watch/staleness.rs b/src/watch/staleness.rs index 4e171a1..94813eb 100644 --- a/src/watch/staleness.rs +++ b/src/watch/staleness.rs @@ -7,15 +7,34 @@ pub enum Kind { Missing, } -#[derive(Debug, Clone)] -pub struct Stale { - pub kind: Kind, - pub pkgbase: String, - pub dependency: String, - pub built_with: String, - pub now: String, +/// The real definition. The module is private, so this `pub` +/// is not a nameable path from outside; the alias below is the +/// only way to reach it, and the alias is what carries the +/// feature-conditional visibility. +mod stale { + use super::*; + + #[derive(Debug, Clone)] + pub struct Stale { + pub kind: Kind, + pub pkgbase: String, + pub dependency: String, + pub built_with: String, + pub now: String, + } } +/// one row of the staleness report. `http` and `ops` read the report `stale_rows` returns, but only the staleness tests write the name. +/// +/// `pub` only under `test-support`. Production reaches the type +/// through its own module and never names it from outside; the +/// outside reader that needs the name is a test. +#[cfg(feature = "test-support")] +pub use stale::Stale; + +#[cfg(not(feature = "test-support"))] +pub(crate) use stale::Stale; + pub fn stale_rows(db: &Db) -> Result> { let rows = db::published_world_members(db)?; -- cgit v1.2.3