From b49555262dcd04201507575e0ab4c166f4757d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 23 Oct 2026 15:14:57 +0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20forge-runner?= =?UTF-8?q?=20integration=20tests=20build=20as=20one=20binary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Five test binaries (builtin, flow, idmap, sandbox, unpack_subuid) are now one binary named integration, so the crate links one test executable instead of five. Test count unchanged at 27. Shared helper userns_available and can_run moved to tests/integration/common, deduplicated from builtin and sandbox. --- .../tests/{ => integration}/builtin.rs | 27 ++---------------- .../tests/integration/common/mod.rs | 28 +++++++++++++++++++ .../tests/{ => integration}/flow.rs | 0 .../tests/{ => integration}/idmap.rs | 0 crates/forge-runner/tests/integration/main.rs | 9 ++++++ .../tests/{ => integration}/sandbox.rs | 26 ++--------------- .../tests/{ => integration}/unpack_subuid.rs | 0 7 files changed, 41 insertions(+), 49 deletions(-) rename crates/forge-runner/tests/{ => integration}/builtin.rs (94%) create mode 100644 crates/forge-runner/tests/integration/common/mod.rs rename crates/forge-runner/tests/{ => integration}/flow.rs (100%) rename crates/forge-runner/tests/{ => integration}/idmap.rs (100%) create mode 100644 crates/forge-runner/tests/integration/main.rs rename crates/forge-runner/tests/{ => integration}/sandbox.rs (96%) rename crates/forge-runner/tests/{ => integration}/unpack_subuid.rs (100%) diff --git a/crates/forge-runner/tests/builtin.rs b/crates/forge-runner/tests/integration/builtin.rs similarity index 94% rename from crates/forge-runner/tests/builtin.rs rename to crates/forge-runner/tests/integration/builtin.rs index 2f841b2..b569211 100644 --- a/crates/forge-runner/tests/builtin.rs +++ b/crates/forge-runner/tests/integration/builtin.rs @@ -6,7 +6,6 @@ use std::collections::BTreeMap; use std::fs; use std::future::Future; use std::path::{Path, PathBuf}; -use std::process::Command; use std::time::{Duration, Instant}; use forge_ci::proto::{JobAssignment, Outcome}; @@ -20,6 +19,8 @@ use nix::unistd::Pid; use tokio::sync::mpsc; use tokio_util::sync::CancellationToken; +use crate::common::can_run; + /// Hands out a fixed rootfs for every image, with an env that the job can observe. struct LocalRootfs(PathBuf); @@ -43,30 +44,6 @@ impl ImageSource for LocalRootfs { } } -fn userns_available() -> bool { - let max = fs::read_to_string("/proc/sys/user/max_user_namespaces") - .ok() - .and_then(|s| s.trim().parse::().ok()) - .unwrap_or(0); - if max == 0 { - return false; - } - Command::new("unshare") - .args(["--user", "--map-root-user", "true"]) - .status() - .is_ok_and(|s| s.success()) -} - -/// Skips the test when user namespaces are unavailable. Returns `true` when the test should run. -fn can_run() -> bool { - if userns_available() { - true - } else { - eprintln!("skipping: unprivileged user namespaces are not available on this host"); - false - } -} - fn job(run: &str) -> JobAssignment { JobAssignment { job_id: "job_01".to_owned(), diff --git a/crates/forge-runner/tests/integration/common/mod.rs b/crates/forge-runner/tests/integration/common/mod.rs new file mode 100644 index 0000000..fe6d372 --- /dev/null +++ b/crates/forge-runner/tests/integration/common/mod.rs @@ -0,0 +1,28 @@ +//! Support code shared by the integration tests. + +use std::fs; +use std::process::Command; + +fn userns_available() -> bool { + let max = fs::read_to_string("/proc/sys/user/max_user_namespaces") + .ok() + .and_then(|s| s.trim().parse::().ok()) + .unwrap_or(0); + if max == 0 { + return false; + } + Command::new("unshare") + .args(["--user", "--map-root-user", "true"]) + .status() + .is_ok_and(|s| s.success()) +} + +/// Skips the test when user namespaces are unavailable. Returns `true` when the test should run. +pub fn can_run() -> bool { + if userns_available() { + true + } else { + eprintln!("skipping: unprivileged user namespaces are not available on this host"); + false + } +} diff --git a/crates/forge-runner/tests/flow.rs b/crates/forge-runner/tests/integration/flow.rs similarity index 100% rename from crates/forge-runner/tests/flow.rs rename to crates/forge-runner/tests/integration/flow.rs diff --git a/crates/forge-runner/tests/idmap.rs b/crates/forge-runner/tests/integration/idmap.rs similarity index 100% rename from crates/forge-runner/tests/idmap.rs rename to crates/forge-runner/tests/integration/idmap.rs diff --git a/crates/forge-runner/tests/integration/main.rs b/crates/forge-runner/tests/integration/main.rs new file mode 100644 index 0000000..9dea082 --- /dev/null +++ b/crates/forge-runner/tests/integration/main.rs @@ -0,0 +1,9 @@ +//! Integration tests for forge-runner, built as a single test binary. + +mod common; + +mod builtin; +mod flow; +mod idmap; +mod sandbox; +mod unpack_subuid; diff --git a/crates/forge-runner/tests/sandbox.rs b/crates/forge-runner/tests/integration/sandbox.rs similarity index 96% rename from crates/forge-runner/tests/sandbox.rs rename to crates/forge-runner/tests/integration/sandbox.rs index d10a486..a57240e 100644 --- a/crates/forge-runner/tests/sandbox.rs +++ b/crates/forge-runner/tests/integration/sandbox.rs @@ -15,36 +15,14 @@ use forge_runner::config::Limits; use forge_runner::sandbox::SandboxRequest; use forge_runner::sandbox::idmap::{IdMap, UsernsMode}; +use crate::common::can_run; + /// Utilities copied into the test rootfs. `sh` is the job shell, and the rest are used by the /// test scripts. const BINARIES: &[&str] = &[ "sh", "id", "cat", "grep", "touch", "sleep", "unshare", "chown", "stat", "mkdir", ]; -fn userns_available() -> bool { - let max = fs::read_to_string("/proc/sys/user/max_user_namespaces") - .ok() - .and_then(|s| s.trim().parse::().ok()) - .unwrap_or(0); - if max == 0 { - return false; - } - Command::new("unshare") - .args(["--user", "--map-root-user", "true"]) - .status() - .is_ok_and(|s| s.success()) -} - -/// Skips the test when user namespaces are unavailable. Returns `true` when the test should run. -fn can_run() -> bool { - if userns_available() { - true - } else { - eprintln!("skipping: unprivileged user namespaces are not available on this host"); - false - } -} - /// The shared libraries `ldd` reports for `binary`, as absolute host paths. fn shared_libs(binary: &Path) -> Vec { let Ok(out) = Command::new("ldd").arg(binary).output() else { diff --git a/crates/forge-runner/tests/unpack_subuid.rs b/crates/forge-runner/tests/integration/unpack_subuid.rs similarity index 100% rename from crates/forge-runner/tests/unpack_subuid.rs rename to crates/forge-runner/tests/integration/unpack_subuid.rs