From b9b04b92d286025f25b88413448c1f82add64725 Mon Sep 17 00:00:00 2001 From: David Wiesen Date: Fri, 17 Apr 2026 03:05:28 -0700 Subject: [PATCH] Fix missing Windows core env vars --- codex-rs/core/src/exec_env.rs | 37 ++++++++++++++++++++++++++--- codex-rs/core/src/exec_env_tests.rs | 6 +++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/codex-rs/core/src/exec_env.rs b/codex-rs/core/src/exec_env.rs index 83ac8ad379..cce744b6d6 100644 --- a/codex-rs/core/src/exec_env.rs +++ b/codex-rs/core/src/exec_env.rs @@ -7,6 +7,40 @@ use std::collections::HashSet; pub const CODEX_THREAD_ID_ENV_VAR: &str = "CODEX_THREAD_ID"; +#[cfg(windows)] +const CORE_VARS: &[&str] = &[ + // Core path resolution + "PATH", + "PATHEXT", + // Shell and system roots + "COMSPEC", + "SYSTEMROOT", + "SYSTEMDRIVE", + // User context and profiles + "HOME", + "USERNAME", + "USERDOMAIN", + "USERPROFILE", + "HOMEDRIVE", + "HOMEPATH", + // Program locations + "PROGRAMFILES", + "PROGRAMFILES(X86)", + "PROGRAMW6432", + "PROGRAMDATA", + // App data and caches + "LOCALAPPDATA", + "APPDATA", + // Temp locations + "TEMP", + "TMP", +]; + +#[cfg(not(windows))] +const CORE_VARS: &[&str] = &[ + "HOME", "LOGNAME", "PATH", "SHELL", "USER", "USERNAME", "TMPDIR", "TEMP", "TMP", +]; + /// Construct an environment map based on the rules in the specified policy. The /// resulting map can be passed directly to `Command::envs()` after calling /// `env_clear()` to ensure no unintended variables are leaked to the spawned @@ -38,9 +72,6 @@ where ShellEnvironmentPolicyInherit::All => vars.into_iter().collect(), ShellEnvironmentPolicyInherit::None => HashMap::new(), ShellEnvironmentPolicyInherit::Core => { - const CORE_VARS: &[&str] = &[ - "HOME", "LOGNAME", "PATH", "SHELL", "USER", "USERNAME", "TMPDIR", "TEMP", "TMP", - ]; let allow: HashSet<&str> = CORE_VARS.iter().copied().collect(); let is_core_var = |name: &str| { if cfg!(target_os = "windows") { diff --git a/codex-rs/core/src/exec_env_tests.rs b/codex-rs/core/src/exec_env_tests.rs index 6f001b5828..9e750c7527 100644 --- a/codex-rs/core/src/exec_env_tests.rs +++ b/codex-rs/core/src/exec_env_tests.rs @@ -172,6 +172,9 @@ fn test_core_inherit_respects_case_insensitive_names_on_windows() { let vars = make_vars(&[ ("Path", "C:\\Windows\\System32"), ("TEMP", "C:\\Temp"), + ("SystemRoot", "C:\\Windows"), + ("APPDATA", "C:\\Users\\codex\\AppData\\Roaming"), + ("ProgramFiles", "C:\\Program Files"), ("FOO", "bar"), ]); @@ -186,6 +189,9 @@ fn test_core_inherit_respects_case_insensitive_names_on_windows() { let mut expected: HashMap = hashmap! { "Path".to_string() => "C:\\Windows\\System32".to_string(), "TEMP".to_string() => "C:\\Temp".to_string(), + "SystemRoot".to_string() => "C:\\Windows".to_string(), + "APPDATA".to_string() => "C:\\Users\\codex\\AppData\\Roaming".to_string(), + "ProgramFiles".to_string() => "C:\\Program Files".to_string(), }; expected.insert(CODEX_THREAD_ID_ENV_VAR.to_string(), thread_id.to_string());