From c295510e2bb0ee61234536c832dad87a45977fc8 Mon Sep 17 00:00:00 2001 From: aur-build Date: Fri, 20 Nov 2026 23:38:01 +0000 Subject: sandbox: keep `Exit` out of the release build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `Exit` is the result of running a command in a sandbox. `pipeline` consumes it through `Sandbox::run` — `.success()`, `.stderr` — without ever writing the name, which is why the census called it dead outside `sandbox`. The type now lives in a private `mod exit` and reaches the world through an alias that is `pub` only under `test-support` and `pub(crate)` otherwise. A `pub` definition inside a private module is not a nameable path from outside, but it is visible enough to appear in a public trait signature, which is what makes this possible where a plain `pub(crate) struct` is not. Verified with an external crate: naming `aur_build::sandbox::Exit` in a release build is `error[E0603]: struct Exit is private`; with `test-support` it compiles. --- src/pipeline/dispatch.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ src/pipeline/mod.rs | 14 ++++++++++++++ src/pipeline/publish.rs | 14 ++++++++++++++ 3 files changed, 70 insertions(+) (limited to 'src/pipeline') diff --git a/src/pipeline/dispatch.rs b/src/pipeline/dispatch.rs index 89a8788..aea934e 100644 --- a/src/pipeline/dispatch.rs +++ b/src/pipeline/dispatch.rs @@ -68,7 +68,21 @@ fn dispatcher(cfg: Arc, db: Db, stop: Arc, tx: Sender) -> Vec { + dispatch_once_impl(cfg, db, tx) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn dispatch_once(cfg: &Config, db: &Db, tx: &Sender) -> Vec { + dispatch_once_impl(cfg, db, tx) +} + +fn dispatch_once_impl(cfg: &Config, db: &Db, tx: &Sender) -> Vec { let reaped = builds::reap_expired(db).unwrap_or(0); if reaped > 0 { db::audit_system( @@ -97,7 +111,21 @@ pub fn dispatch_once(cfg: &Config, db: &Db, tx: &Sender) -> Vec ids } +/// Production reaches this through `dispatch_once`, which is the only thing that acts on the answer. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn admissible(cfg: &Config, db: &Db) -> usize { + admissible_impl(cfg, db) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn admissible(cfg: &Config, db: &Db) -> usize { + admissible_impl(cfg, db) +} + +fn admissible_impl(cfg: &Config, db: &Db) -> usize { let in_flight = builds::in_flight(db).unwrap_or(0) as usize; let slots = cfg.max_concurrent_builds.saturating_sub(in_flight); if slots == 0 { @@ -110,7 +138,21 @@ pub fn admissible(cfg: &Config, db: &Db) -> usize { slots } +/// Production reaches this through `admissible`, which is the only thing that acts on the number. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn free_disk_mb(path: &std::path::Path) -> u64 { + free_disk_mb_impl(path) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn free_disk_mb(path: &std::path::Path) -> u64 { + free_disk_mb_impl(path) +} + +fn free_disk_mb_impl(path: &std::path::Path) -> u64 { use std::ffi::CString; let c = match CString::new(path.as_os_str().to_string_lossy().as_bytes()) { Ok(c) => c, diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index 42f435f..e14c7a8 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -186,7 +186,21 @@ pub fn run(cfg: &Config, db: &Db, build_id: &str) -> Result { run_with(&ctx) } +/// Production calls `run`, which supplies the real sandbox; a test injects a fake, which is the point of the seam. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn run_with(ctx: &Ctx) -> Result { + run_with_impl(ctx) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn run_with(ctx: &Ctx) -> Result { + run_with_impl(ctx) +} + +fn run_with_impl(ctx: &Ctx) -> Result { std::fs::create_dir_all(&ctx.staging)?; for step in crate::db::model::BUILD_STEPS { if crate::db::builds::cancel_requested(&ctx.db, &ctx.build.id)? { diff --git a/src/pipeline/publish.rs b/src/pipeline/publish.rs index 4e72d35..332e673 100644 --- a/src/pipeline/publish.rs +++ b/src/pipeline/publish.rs @@ -18,7 +18,21 @@ fn lock_repo() -> std::sync::MutexGuard<'static, ()> { } } +/// Publishing calls it; a test checks what landed in the index. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn index_world(db: &Db) -> Result> { + index_world_impl(db) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn index_world(db: &Db) -> Result> { + index_world_impl(db) +} + +fn index_world_impl(db: &Db) -> Result> { let rels = db::all_published_releases(db)?; let mut out = Vec::new(); for r in rels { -- cgit v1.2.3