Compare commits

...

1 Commits

Author SHA1 Message Date
David Wiesen
b9b04b92d2 Fix missing Windows core env vars 2026-04-17 03:05:28 -07:00
2 changed files with 40 additions and 3 deletions

View File

@@ -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") {

View File

@@ -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<String, String> = 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());