mirror of
https://github.com/openai/codex.git
synced 2026-11-30 00:10:49 +00:00
Support Windows registry overrides for requirements.toml (#55456)
Read `RequirementsPath` from the 64-bit registry view of `HKLM\SOFTWARE\Policies\OpenAI\Codex` to select the system requirements file on Windows. Require an absolute path and return an error for relative values. If the registry key or value cannot be read, retain the default `OpenAI\Codex\requirements.toml` location under ProgramData.
Expand absolute-path validation tests to cover empty, drive-relative, and root-relative paths. Update the Windows default-directory test to remain independent of registry overrides.
GitOrigin-RevId: c31045d749e32cf266b389245ae4db2440156e8e
(cherry picked from commit 18795fc125)
This commit is contained in:
Generated
+1
@@ -2846,6 +2846,7 @@ dependencies = [
|
||||
"wildmatch",
|
||||
"winapi-util",
|
||||
"windows-sys 0.61.2",
|
||||
"winreg 0.55.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ windows-sys = { workspace = true, features = [
|
||||
"Win32_System_Com",
|
||||
"Win32_UI_Shell",
|
||||
] }
|
||||
winreg = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = { workspace = true }
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user