Lightweight coding agent that runs in your terminal
Rust
Support Windows registry overrides for `requirements.toml` (#55456)
johnl-oai18795fc12571
diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lockindex 958d6ca2cb..c403f0b5a0 100644--- a/codex-rs/Cargo.lock+++ b/codex-rs/Cargo.lock@@ -2867,6 +2867,7 @@ dependencies = ["wildmatch","winapi-util","windows-sys 0.61.2",+ "winreg 0.55.0",][[package]]diff --git a/codex-rs/Cargo.toml b/codex-rs/Cargo.tomlindex 5e1b303315..8392dea799 100644--- a/codex-rs/Cargo.toml+++ b/codex-rs/Cargo.toml@@ -553,6 +553,7 @@ whoami = "1.6.1"wildmatch = "2.6.1"winapi-util = "0.1.11"windows-sys = "0.61.2"+winreg = "0.55.0"# Keep the zip 2.x feature set. In zip 9, `bzip2-rs` selects the bzip2-sys# backend we already build; the default selects libbz2-rs-sys instead.zip = { version = "9.0.0", default-features = false, features = [diff --git a/codex-rs/config/Cargo.toml b/codex-rs/config/Cargo.tomlindex 0fc87168fa..42d19e2b91 100644--- a/codex-rs/config/Cargo.toml+++ b/codex-rs/config/Cargo.toml@@ -63,6 +63,7 @@ windows-sys = { workspace = true, features = ["Win32_System_Com","Win32_UI_Shell",] }+winreg = { workspace = true }[dev-dependencies]pretty_assertions = { workspace = true }diff --git a/codex-rs/config/src/loader/mod.rs b/codex-rs/config/src/loader/mod.rsindex 46dbb8b055..e65847ce49 100644--- a/codex-rs/config/src/loader/mod.rs+++ b/codex-rs/config/src/loader/mod.rs@@ -814,6 +814,16 @@ fn windows_codex_system_dir() -> PathBuf {#[cfg(windows)]fn windows_system_requirements_toml_file() -> io::Result<AbsolutePathBuf> {+ if let Ok(path) = winreg::RegKey::predef(winreg::enums::HKEY_LOCAL_MACHINE)+ .open_subkey_with_flags(+ r"SOFTWARE\Policies\OpenAI\Codex",+ winreg::enums::KEY_READ | winreg::enums::KEY_WOW64_64KEY,+ )+ .and_then(|key| key.get_value::<std::ffi::OsString, _>("RequirementsPath"))+ {+ return AbsolutePathBuf::from_absolute_path_checked(path);+ }+let requirements_toml_file = windows_codex_system_dir().join("requirements.toml");AbsolutePathBuf::try_from(requirements_toml_file)}@@ -2006,24 +2016,13 @@ foo = "xyzzy"#[cfg(windows)]#[test]- fn windows_system_requirements_toml_file_uses_expected_suffix() {+ fn windows_codex_system_dir_uses_expected_suffix() {let expected = windows_program_data_dir_from_known_folder().unwrap_or_else(|_| PathBuf::from(DEFAULT_PROGRAM_DATA_DIR_WINDOWS)).join("OpenAI")- .join("Codex")- .join("requirements.toml");- assert_eq!(- windows_system_requirements_toml_file()- .expect("requirements.toml path")- .as_path(),- expected.as_path()- );- assert!(- windows_system_requirements_toml_file()- .expect("requirements.toml path")- .as_path()- .ends_with(Path::new("OpenAI").join("Codex").join("requirements.toml"))- );+ .join("Codex");+ assert_eq!(windows_codex_system_dir(), expected);+ assert!(windows_codex_system_dir().ends_with(Path::new("OpenAI").join("Codex")));}#[cfg(windows)]diff --git a/codex-rs/utils/absolute-path/src/lib.rs b/codex-rs/utils/absolute-path/src/lib.rsindex 4da56db06d..8751e9fc8f 100644--- a/codex-rs/utils/absolute-path/src/lib.rs+++ b/codex-rs/utils/absolute-path/src/lib.rs@@ -477,10 +477,17 @@ mod tests {#[test]fn from_absolute_path_checked_rejects_relative_path() {- let err = AbsolutePathBuf::from_absolute_path_checked("relative/path")- .expect_err("relative path should fail");-- assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput);+ for path in [+ "",+ "relative/path",+ r"C:requirements.toml",+ r"\requirements.toml",+ ] {+ let err = AbsolutePathBuf::from_absolute_path_checked(path)+ .expect_err("relative path should fail");++ assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput);+ }}#[test]