summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.rs28
-rw-r--r--src/db/migrations.rs13
-rw-r--r--src/db/mod.rs4
-rw-r--r--src/http/mod.rs14
-rw-r--r--src/http/routes/mod.rs14
-rw-r--r--src/ops.rs42
-rw-r--r--src/pipeline/dispatch.rs42
-rw-r--r--src/pipeline/mod.rs14
-rw-r--r--src/pipeline/publish.rs14
-rw-r--r--src/review/risk.rs13
-rw-r--r--src/sandbox/mod.rs25
-rw-r--r--src/shims/mod.rs28
-rw-r--r--src/watch/mirror.rs14
-rw-r--r--src/watch/mod.rs5
-rw-r--r--src/watch/upstream.rs28
15 files changed, 285 insertions, 13 deletions
diff --git a/src/config.rs b/src/config.rs
index bb60cc7..4f6cef0 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -90,7 +90,21 @@ impl Sandbox {
}
}
+ /// Validation consults it; the fixture-bound tests that assert it are the only outside readers.
+ ///
+ /// 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 shared_workspace(&self) -> bool {
+ Self::shared_workspace_impl(self)
+ }
+
+ #[cfg(not(feature = "test-support"))]
+ pub(crate) fn shared_workspace(&self) -> bool {
+ Self::shared_workspace_impl(self)
+ }
+
+ fn shared_workspace_impl(&self) -> bool {
match self {
Sandbox::Loopback => true,
Sandbox::Remote { shared_workspace, .. } => *shared_workspace,
@@ -354,7 +368,21 @@ impl Config {
pub fn staging_build_dir(&self, build_id: &str) -> PathBuf {
self.staging_dir().join(build_id)
}
+ /// The content-addressed store layout is this module's own business; a test pins where a blob lands.
+ ///
+ /// 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 store_dir(&self) -> PathBuf {
+ Self::store_dir_impl(self)
+ }
+
+ #[cfg(not(feature = "test-support"))]
+ pub(crate) fn store_dir(&self) -> PathBuf {
+ Self::store_dir_impl(self)
+ }
+
+ fn store_dir_impl(&self) -> PathBuf {
self.root.join("store")
}
pub fn store_path(&self, digest: &str) -> PathBuf {
diff --git a/src/db/migrations.rs b/src/db/migrations.rs
index cb01765..015610a 100644
--- a/src/db/migrations.rs
+++ b/src/db/migrations.rs
@@ -323,7 +323,12 @@ CREATE TABLE IF NOT EXISTS gc_run (
);
"#;
-pub static MIGRATIONS: &[Migration] = &[
+/// The migration list, in version order.
+///
+/// `db::migrate` walks it; nothing outside `db` asks for the list itself
+/// except a test that asserts it is ordered and complete. The table lives
+/// once, in `MIGRATIONS_ALL`, so the two aliases below cannot drift apart.
+static MIGRATIONS_ALL: &[Migration] = &[
Migration { version: 1, name: "core", sql: M_0001_CORE },
Migration { version: 2, name: "build", sql: M_0002_BUILD },
Migration { version: 3, name: "notices", sql: M_0003_NOTICES },
@@ -334,6 +339,12 @@ pub static MIGRATIONS: &[Migration] = &[
Migration { version: 8, name: "retention", sql: M_0008_RETENTION },
];
+#[cfg(feature = "test-support")]
+pub static MIGRATIONS: &[Migration] = MIGRATIONS_ALL;
+
+#[cfg(not(feature = "test-support"))]
+pub(crate) static MIGRATIONS: &[Migration] = MIGRATIONS_ALL;
+
pub(crate) const DEFAULT_SETTINGS: &[(&str, &str)] = &[
("max_concurrent_builds", "1"),
("build_timeout", "5400"),
diff --git a/src/db/mod.rs b/src/db/mod.rs
index 992a2b6..1266d9e 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -24,6 +24,10 @@ mod staleness;
mod subscriptions;
mod world;
+/// The alias is only ever used from outside `db`, and only by the test tier;
+/// `db::migrate` walks `migrations::MIGRATIONS` by its own path, so there is
+/// no crate-internal alias to keep in a production build.
+#[cfg(feature = "test-support")]
pub use migrations::MIGRATIONS;
pub(crate) use model::StateEnum;
/// Its only caller is the test-tier `world_members`, so it is gated with it.
diff --git a/src/http/mod.rs b/src/http/mod.rs
index a77869e..4291021 100644
--- a/src/http/mod.rs
+++ b/src/http/mod.rs
@@ -33,7 +33,21 @@ impl Req {
pub fn query_get(&self, key: &str) -> Option<String> {
self.query_pairs.iter().find(|(k, _)| k == key).map(|(_, v)| v.clone())
}
+ /// Reading a cookie off a request is internal plumbing; the auth tests need it in order to forge one.
+ ///
+ /// 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 cookie(&self, name: &str) -> Option<String> {
+ Self::cookie_impl(self, name)
+ }
+
+ #[cfg(not(feature = "test-support"))]
+ pub(crate) fn cookie(&self, name: &str) -> Option<String> {
+ Self::cookie_impl(self, name)
+ }
+
+ fn cookie_impl(&self, name: &str) -> Option<String> {
self.cookies.iter().find(|(k, _)| k == name).map(|(_, v)| v.clone())
}
}
diff --git a/src/http/routes/mod.rs b/src/http/routes/mod.rs
index 1ef7fde..0ffecb0 100644
--- a/src/http/routes/mod.rs
+++ b/src/http/routes/mod.rs
@@ -43,7 +43,21 @@ pub(crate) fn logout(req: &Req) -> Res {
res
}
+/// The router dispatches to it. The login tests drive a live listener, so they cannot move into the module.
+///
+/// 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 login(state: &State, req: &Req) -> Res {
+ login_impl(state, req)
+}
+
+#[cfg(not(feature = "test-support"))]
+pub(crate) fn login(state: &State, req: &Req) -> Res {
+ login_impl(state, req)
+}
+
+fn login_impl(state: &State, req: &Req) -> Res {
let given = req.form_get("password").unwrap_or_default();
let page = Page::new("Sign in", csrf(state, req));
if auth::password_ok(&state.cfg, &given) {
diff --git a/src/ops.rs b/src/ops.rs
index a40a326..fd3fb42 100644
--- a/src/ops.rs
+++ b/src/ops.rs
@@ -43,7 +43,21 @@ pub struct Metrics {
}
impl Metrics {
+ /// The metrics report computes it internally; a test checks the arithmetic.
+ ///
+ /// 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 build_success_rate(&self) -> f64 {
+ Self::build_success_rate_impl(self)
+ }
+
+ #[cfg(not(feature = "test-support"))]
+ pub(crate) fn build_success_rate(&self) -> f64 {
+ Self::build_success_rate_impl(self)
+ }
+
+ fn build_success_rate_impl(&self) -> f64 {
match self.succeeded + self.failed {
0 => 1.0,
n => self.succeeded as f64 / n as f64,
@@ -307,7 +321,19 @@ pub fn retention(cfg: &Config, db: &Db, keep: Option<usize>) -> Result<Retention
Ok(report)
}
-pub const STAGING_GRACE_SECS: i64 = 3600;
+/// How long a file may sit in staging before the sweep considers it abandoned.
+///
+/// The value lives once, in a private const, so the two visibility aliases below
+/// cannot drift apart. Production reaches the grace period through
+/// `run_maintenance`, which is the only thing that sweeps; a test that pins the
+/// number is a test, not a caller.
+const STAGING_GRACE_SECS_VALUE: i64 = 3600;
+
+#[cfg(feature = "test-support")]
+pub const STAGING_GRACE_SECS: i64 = STAGING_GRACE_SECS_VALUE;
+
+#[cfg(not(feature = "test-support"))]
+pub(crate) const STAGING_GRACE_SECS: i64 = STAGING_GRACE_SECS_VALUE;
pub fn release_files(cfg: &Config, db: &Db, release_id: i64) -> Result<Vec<PathBuf>> {
let mut out = Vec::new();
@@ -329,7 +355,21 @@ pub fn release_files(cfg: &Config, db: &Db, release_id: i64) -> Result<Vec<PathB
Ok(out)
}
+/// The maintenance pass calls it; a test pins what it sweeps without running the whole pass.
+///
+/// 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 sweep_staging(cfg: &Config, db: &Db, grace_secs: i64) -> Result<(usize, u64)> {
+ sweep_staging_impl(cfg, db, grace_secs)
+}
+
+#[cfg(not(feature = "test-support"))]
+pub(crate) fn sweep_staging(cfg: &Config, db: &Db, grace_secs: i64) -> Result<(usize, u64)> {
+ sweep_staging_impl(cfg, db, grace_secs)
+}
+
+fn sweep_staging_impl(cfg: &Config, db: &Db, grace_secs: i64) -> Result<(usize, u64)> {
let root = cfg.staging_dir();
let Ok(entries) = std::fs::read_dir(&root) else { return Ok((0, 0)) };
let now = time::now();
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<Config>, db: Db, stop: Arc<AtomicBool>, tx: Sender<String
}
}
+/// The scheduler loop calls it; a test drives single ticks and needs it directly.
+///
+/// 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 dispatch_once(cfg: &Config, db: &Db, tx: &Sender<String>) -> Vec<String> {
+ dispatch_once_impl(cfg, db, tx)
+}
+
+#[cfg(not(feature = "test-support"))]
+pub(crate) fn dispatch_once(cfg: &Config, db: &Db, tx: &Sender<String>) -> Vec<String> {
+ dispatch_once_impl(cfg, db, tx)
+}
+
+fn dispatch_once_impl(cfg: &Config, db: &Db, tx: &Sender<String>) -> Vec<String> {
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<String>) -> Vec<String>
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<Outcome> {
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<Outcome> {
+ run_with_impl(ctx)
+}
+
+#[cfg(not(feature = "test-support"))]
+pub(crate) fn run_with(ctx: &Ctx) -> Result<Outcome> {
+ run_with_impl(ctx)
+}
+
+fn run_with_impl(ctx: &Ctx) -> Result<Outcome> {
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<Vec<WorldMember>> {
+ index_world_impl(db)
+}
+
+#[cfg(not(feature = "test-support"))]
+pub(crate) fn index_world(db: &Db) -> Result<Vec<WorldMember>> {
+ index_world_impl(db)
+}
+
+fn index_world_impl(db: &Db) -> Result<Vec<WorldMember>> {
let rels = db::all_published_releases(db)?;
let mut out = Vec::new();
for r in rels {
diff --git a/src/review/risk.rs b/src/review/risk.rs
index 9a7145d..e48ca24 100644
--- a/src/review/risk.rs
+++ b/src/review/risk.rs
@@ -3,7 +3,18 @@ use crate::error::Result;
use crate::pkgver;
pub mod level {
- pub const LOW: &str = "low";
+ /// `MEDIUM` and `HIGH` are matched by the UI to order risk, so they are
+ /// genuinely public. `LOW` is only ever produced here and asserted by a
+ /// test, so it is crate-internal in a production build. The string lives
+ /// once, in `LOW_VALUE`, so the two aliases cannot drift.
+ const LOW_VALUE: &str = "low";
+
+ #[cfg(feature = "test-support")]
+ pub const LOW: &str = LOW_VALUE;
+
+ #[cfg(not(feature = "test-support"))]
+ pub(crate) const LOW: &str = LOW_VALUE;
+
pub const MEDIUM: &str = "medium";
pub const HIGH: &str = "high";
}
diff --git a/src/sandbox/mod.rs b/src/sandbox/mod.rs
index 3bd4b3b..6c90f7f 100644
--- a/src/sandbox/mod.rs
+++ b/src/sandbox/mod.rs
@@ -39,19 +39,26 @@ impl Cmd {
}
}
-#[derive(Debug)]
-pub struct Exit {
- pub code: Option<i32>,
- pub stdout: Vec<u8>,
- pub stderr: Vec<u8>,
-}
+mod exit {
+ #[derive(Debug)]
+ pub struct Exit {
+ pub code: Option<i32>,
+ pub stdout: Vec<u8>,
+ pub stderr: Vec<u8>,
+ }
-impl Exit {
- pub fn success(&self) -> bool {
- self.code == Some(0)
+ impl Exit {
+ pub fn success(&self) -> bool {
+ self.code == Some(0)
+ }
}
}
+#[cfg(feature = "test-support")]
+pub use exit::Exit;
+#[cfg(not(feature = "test-support"))]
+pub(crate) use exit::Exit;
+
#[derive(Debug, Clone)]
pub struct SandboxSpec {
pub profile: String,
diff --git a/src/shims/mod.rs b/src/shims/mod.rs
index fd515bc..4b29466 100644
--- a/src/shims/mod.rs
+++ b/src/shims/mod.rs
@@ -85,7 +85,21 @@ impl Default for Manifest {
}
}
+/// The shim reads its own manifest while dispatching a tool; tests read it to assert what a build did.
+///
+/// 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 manifest() -> Manifest {
+ manifest_impl()
+}
+
+#[cfg(not(feature = "test-support"))]
+pub(crate) fn manifest() -> Manifest {
+ manifest_impl()
+}
+
+fn manifest_impl() -> Manifest {
match std::env::var("AUR_SHIM_MANIFEST") {
Ok(p) => match std::fs::read_to_string(&p) {
Ok(s) => serde_json::from_str(&s).unwrap_or_default(),
@@ -491,7 +505,21 @@ pub const DB_SUFFIXES: [&str; 5] = [
".db.tar.xz",
];
+/// The shim validates its own `--db` argument; tests check the verdicts.
+///
+/// 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 valid_db_arg(p: &Path) -> bool {
+ valid_db_arg_impl(p)
+}
+
+#[cfg(not(feature = "test-support"))]
+pub(crate) fn valid_db_arg(p: &Path) -> bool {
+ valid_db_arg_impl(p)
+}
+
+fn valid_db_arg_impl(p: &Path) -> bool {
let name = p
.file_name()
.map(|s| s.to_string_lossy().into_owned())
diff --git a/src/watch/mirror.rs b/src/watch/mirror.rs
index 07a60c0..d7c793b 100644
--- a/src/watch/mirror.rs
+++ b/src/watch/mirror.rs
@@ -14,7 +14,21 @@ pub enum Sync {
Cloned { head: String },
}
+/// Detection calls it to move the mirror; the test that pins it drives a real sync.
+///
+/// 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 sync_mirror(cfg: &Config, db: &Db, name: &str, url: &str) -> Result<Sync> {
+ sync_mirror_impl(cfg, db, name, url)
+}
+
+#[cfg(not(feature = "test-support"))]
+pub(crate) fn sync_mirror(cfg: &Config, db: &Db, name: &str, url: &str) -> Result<Sync> {
+ sync_mirror_impl(cfg, db, name, url)
+}
+
+fn sync_mirror_impl(cfg: &Config, db: &Db, name: &str, url: &str) -> Result<Sync> {
let mirror = cfg.mirror_path(name);
let known_head = db::get_pkgbase(db, name)?.and_then(|p| p.aur_head.clone());
diff --git a/src/watch/mod.rs b/src/watch/mod.rs
index 839596a..46ef55a 100644
--- a/src/watch/mod.rs
+++ b/src/watch/mod.rs
@@ -7,5 +7,8 @@ pub mod staleness;
pub mod upstream;
pub use detect::{check_pkgbase, Outcome};
-pub use mirror::sync_mirror;
+// `mirror::sync_mirror` used to be re-exported here. Nothing used the alias —
+// `detect.rs` and `tests/detect.rs` both go through `watch::mirror` directly —
+// and a re-export of a conditionally-visible item has to be split by feature
+// too, so the dead alias is simply gone.
pub use scheduler::spawn_scheduler;
diff --git a/src/watch/upstream.rs b/src/watch/upstream.rs
index 002d72b..c3e4954 100644
--- a/src/watch/upstream.rs
+++ b/src/watch/upstream.rs
@@ -17,12 +17,40 @@ pub struct StageA {
}
impl StageA {
+ /// Detection consults it; the VCS test that asserts it needs a real mirror.
+ ///
+ /// 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 needs_stage_b(&self) -> bool {
+ Self::needs_stage_b_impl(self)
+ }
+
+ #[cfg(not(feature = "test-support"))]
+ pub(crate) fn needs_stage_b(&self) -> bool {
+ Self::needs_stage_b_impl(self)
+ }
+
+ fn needs_stage_b_impl(&self) -> bool {
self.moved || !self.unprobed.is_empty()
}
}
+/// Detection calls it on every expensive poll; the tests that pin it need a fixture.
+///
+/// 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 probe(recipe: &Recipe, accepted: &[UpstreamPin]) -> Result<StageA> {
+ probe_impl(recipe, accepted)
+}
+
+#[cfg(not(feature = "test-support"))]
+pub(crate) fn probe(recipe: &Recipe, accepted: &[UpstreamPin]) -> Result<StageA> {
+ probe_impl(recipe, accepted)
+}
+
+fn probe_impl(recipe: &Recipe, accepted: &[UpstreamPin]) -> Result<StageA> {
let mut pins = Vec::new();
let mut unprobed = Vec::new();
for entry in recipe.source_entries.iter().filter(|e| e.is_vcs()) {