diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index 19b5611c7e..b87dad9d64 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -2846,6 +2846,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.toml index 86fcd7faba..441e29bbe7 100644 --- a/codex-rs/Cargo.toml +++ b/codex-rs/Cargo.toml @@ -548,6 +548,7 @@ whoami = "1.6.1" wildmatch = "2.6.1" winapi-util = "0.1.11" windows-sys = "0.61.2" +winreg = "0.55.0" zip = "2.4.2" zstd = "0.13" diff --git a/codex-rs/config/Cargo.toml b/codex-rs/config/Cargo.toml index b4be94bb58..7b94e8f24c 100644 --- a/codex-rs/config/Cargo.toml +++ b/codex-rs/config/Cargo.toml @@ -62,6 +62,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.rs index 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 { + 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::("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.rs index 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"); + 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); + assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput); + } } #[test]