mirror of
https://github.com/openai/codex.git
synced 2026-04-26 07:35:29 +00:00
chore(arg0): advisory-lock janitor for codex tmp paths (#10039)
## Description ### What changed - Switch the arg0 helper root from `~/.codex/tmp/path` to `~/.codex/tmp/path2` - Add `Arg0PathEntryGuard` to keep both the `TempDir` and an exclusive `.lock` file alive for the process lifetime - Add a startup janitor that scans `path2` and deletes only directories whose lock can be acquired ### Tests - `cargo clippy -p codex-arg0` - `cargo clippy -p codex-core` - `cargo test -p codex-arg0` - `cargo test -p codex-core`
This commit is contained in:
@@ -1,16 +1,57 @@
|
||||
// Aggregates all former standalone integration tests as modules.
|
||||
use std::ffi::OsString;
|
||||
|
||||
use codex_arg0::Arg0PathEntryGuard;
|
||||
use codex_arg0::arg0_dispatch;
|
||||
use ctor::ctor;
|
||||
use tempfile::TempDir;
|
||||
|
||||
struct TestCodexAliasesGuard {
|
||||
_codex_home: TempDir,
|
||||
_arg0: Arg0PathEntryGuard,
|
||||
_previous_codex_home: Option<OsString>,
|
||||
}
|
||||
|
||||
const CODEX_HOME_ENV_VAR: &str = "CODEX_HOME";
|
||||
|
||||
// This code runs before any other tests are run.
|
||||
// It allows the test binary to behave like codex and dispatch to apply_patch and codex-linux-sandbox
|
||||
// based on the arg0.
|
||||
// NOTE: this doesn't work on ARM
|
||||
#[ctor]
|
||||
pub static CODEX_ALIASES_TEMP_DIR: TempDir = unsafe {
|
||||
pub static CODEX_ALIASES_TEMP_DIR: TestCodexAliasesGuard = unsafe {
|
||||
#[allow(clippy::unwrap_used)]
|
||||
arg0_dispatch().unwrap()
|
||||
let codex_home = tempfile::Builder::new()
|
||||
.prefix("codex-core-tests")
|
||||
.tempdir()
|
||||
.unwrap();
|
||||
let previous_codex_home = std::env::var_os(CODEX_HOME_ENV_VAR);
|
||||
// arg0_dispatch() creates helper links under CODEX_HOME/tmp. Point it at a
|
||||
// test-owned temp dir so startup never mutates the developer's real ~/.codex.
|
||||
//
|
||||
// Safety: #[ctor] runs before tests start, so no test threads exist yet.
|
||||
unsafe {
|
||||
std::env::set_var(CODEX_HOME_ENV_VAR, codex_home.path());
|
||||
}
|
||||
|
||||
#[allow(clippy::unwrap_used)]
|
||||
let arg0 = arg0_dispatch().unwrap();
|
||||
// Restore the process environment immediately so later tests observe the
|
||||
// same CODEX_HOME state they started with.
|
||||
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,
|
||||
_previous_codex_home: previous_codex_home,
|
||||
}
|
||||
};
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
||||
Reference in New Issue
Block a user