From 66814ddb86009de7a519f167db634dab3e924fa8 Mon Sep 17 00:00:00 2001 From: aur-build Date: Fri, 20 Nov 2026 23:53:42 +0000 Subject: src: keep every remaining test-only item out of the release build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/db/model/state.rs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/db/model/state.rs') diff --git a/src/db/model/state.rs b/src/db/model/state.rs index f773f5b..dcc9b84 100644 --- a/src/db/model/state.rs +++ b/src/db/model/state.rs @@ -73,14 +73,33 @@ pub mod candidate_kind { pub const FIRST_INTRODUCTION: &str = "first_introduction"; } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] -pub enum ReleaseState { - Published, - Withdrawn, - FailedUnbuilt, +/// 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 release_state { + use super::*; + + #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] + #[serde(rename_all = "snake_case")] + pub enum ReleaseState { + Published, + Withdrawn, + FailedUnbuilt, + } } +/// The state column of a release row. `ReleaseRow` is public and its `state` field is typed here, so the type stays reachable in a release build only through this alias. +/// +/// `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 release_state::ReleaseState; + +#[cfg(not(feature = "test-support"))] +pub(crate) use release_state::ReleaseState; + impl ReleaseState { const ALL: &'static [ReleaseState] = &[ ReleaseState::Published, -- cgit v1.2.3