Simplify linux sandbox test arg0 dispatch

This commit is contained in:
pakrym-oai
2026-03-23 09:21:40 -07:00
parent 1b5636e0fb
commit f0124c0f0d
3 changed files with 13 additions and 38 deletions
-1
View File
@@ -2168,7 +2168,6 @@ version = "0.0.0"
dependencies = [
"cc",
"clap",
"codex-arg0",
"codex-core",
"codex-protocol",
"codex-utils-absolute-path",
-1
View File
@@ -28,7 +28,6 @@ serde_json = { workspace = true }
url = { workspace = true }
[target.'cfg(target_os = "linux")'.dev-dependencies]
codex-arg0 = { workspace = true }
ctor = { workspace = true }
pretty_assertions = { workspace = true }
tempfile = { workspace = true }
+13 -36
View File
@@ -1,47 +1,24 @@
// Aggregates all former standalone integration tests as modules.
use codex_arg0::Arg0PathEntryGuard;
use codex_arg0::arg0_dispatch;
use ctor::ctor;
use tempfile::TempDir;
use std::path::Path;
struct TestCodexAliasesGuard {
_codex_home: TempDir,
_arg0: Arg0PathEntryGuard,
}
const CODEX_HOME_ENV_VAR: &str = "CODEX_HOME";
const LINUX_SANDBOX_ARG0: &str = "codex-linux-sandbox";
// This code runs before any other tests are run.
// It allows the test binary to behave like codex-linux-sandbox based on arg0.
// It allows the test binary to behave like codex-linux-sandbox when re-execed
// via current_exe() with argv[0] overridden.
#[ctor]
pub static CODEX_ALIASES_TEMP_DIR: TestCodexAliasesGuard = unsafe {
#[allow(clippy::unwrap_used)]
let codex_home = tempfile::Builder::new()
.prefix("codex-linux-sandbox-tests")
.tempdir()
.unwrap();
let previous_codex_home = std::env::var_os(CODEX_HOME_ENV_VAR);
fn dispatch_linux_sandbox_arg0() {
let argv0 = std::env::args_os().next().unwrap_or_default();
let exe_name = Path::new(&argv0)
.file_name()
.and_then(|s| s.to_str())
.unwrap_or("");
// Safety: #[ctor] runs before test threads start.
unsafe {
std::env::set_var(CODEX_HOME_ENV_VAR, codex_home.path());
if exe_name == LINUX_SANDBOX_ARG0 {
codex_linux_sandbox::run_main();
}
#[allow(clippy::unwrap_used)]
let arg0 = arg0_dispatch().unwrap();
match previous_codex_home.as_ref() {
Some(value) => unsafe {
std::env::set_var(CODEX_HOME_ENV_VAR, value);
},
None => unsafe {
std::env::remove_var(CODEX_HOME_ENV_VAR);
},
}
TestCodexAliasesGuard {
_codex_home: codex_home,
_arg0: arg0,
}
};
}
mod landlock;
mod managed_proxy;