mirror of
https://github.com/openai/codex.git
synced 2026-11-10 21:00:47 +00:00
Add setup regression coverage for Windows helper lookup
This commit is contained in:
@@ -409,38 +409,11 @@ mod tests {
|
||||
use super::helper_version_suffix;
|
||||
use super::materialized_file_name;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::ffi::OsString;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use tempfile::TempDir;
|
||||
|
||||
struct EnvVarGuard {
|
||||
key: &'static str,
|
||||
original: Option<OsString>,
|
||||
}
|
||||
|
||||
impl EnvVarGuard {
|
||||
fn set(key: &'static str, value: &std::ffi::OsStr) -> Self {
|
||||
let original = std::env::var_os(key);
|
||||
unsafe {
|
||||
std::env::set_var(key, value);
|
||||
}
|
||||
Self { key, original }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for EnvVarGuard {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
match &self.original {
|
||||
Some(value) => std::env::set_var(self.key, value),
|
||||
None => std::env::remove_var(self.key),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copy_from_source_if_needed_copies_missing_destination() {
|
||||
let tmp = TempDir::new().expect("tempdir");
|
||||
@@ -634,7 +607,6 @@ mod tests {
|
||||
fs::write(&canonical_exe, b"codex").expect("write canonical exe");
|
||||
fs::write(&helper, b"runner").expect("write helper");
|
||||
symlink_file(&canonical_exe, &launcher_exe);
|
||||
let _codex_home_guard = EnvVarGuard::set("CODEX_HOME", codex_home.as_os_str());
|
||||
|
||||
let resolved = bundled_executable_path_for_exe(&launcher_exe, "codex-command-runner.exe")
|
||||
.expect("helper path");
|
||||
|
||||
@@ -1367,6 +1367,40 @@ mod tests {
|
||||
assert_eq!(resolved, setup_exe);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn setup_exe_lookup_follows_canonicalized_launcher_path() {
|
||||
let tmp = TempDir::new().expect("tempdir");
|
||||
let codex_home = tmp.path().join("codex-home");
|
||||
let release_dir = codex_home
|
||||
.join("packages")
|
||||
.join("standalone")
|
||||
.join("releases")
|
||||
.join("0.142.5-x86_64-pc-windows-msvc");
|
||||
let bin_dir = release_dir.join(BIN_DIRNAME);
|
||||
let resources_dir = release_dir.join(RESOURCES_DIRNAME);
|
||||
let launcher_dir = tmp
|
||||
.path()
|
||||
.join("AppData")
|
||||
.join("Local")
|
||||
.join("Programs")
|
||||
.join("OpenAI")
|
||||
.join("Codex")
|
||||
.join(BIN_DIRNAME);
|
||||
fs::create_dir_all(&bin_dir).expect("create package bin dir");
|
||||
fs::create_dir_all(&resources_dir).expect("create resources dir");
|
||||
fs::create_dir_all(&launcher_dir).expect("create launcher dir");
|
||||
let canonical_exe = bin_dir.join("codex.exe");
|
||||
let launcher_exe = launcher_dir.join("codex.exe");
|
||||
let setup_exe = resources_dir.join("codex-windows-sandbox-setup.exe");
|
||||
fs::write(&canonical_exe, b"codex").expect("write canonical exe");
|
||||
fs::write(&setup_exe, b"setup").expect("write setup exe");
|
||||
symlink_file(&canonical_exe, &launcher_exe);
|
||||
|
||||
let resolved = find_setup_exe_for_current_exe(&launcher_exe).expect("setup exe");
|
||||
|
||||
assert_eq!(resolved, setup_exe);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn loopback_proxy_url_parsing_rejects_non_loopback_and_zero_port() {
|
||||
assert_eq!(
|
||||
@@ -1397,6 +1431,16 @@ mod tests {
|
||||
assert_eq!(proxy_ports_from_env(&env), vec![1081, 8080]);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn symlink_file(original: &Path, link: &Path) {
|
||||
std::os::unix::fs::symlink(original, link).expect("create symlink");
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn symlink_file(original: &Path, link: &Path) {
|
||||
std::os::windows::fs::symlink_file(original, link).expect("create symlink");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offline_proxy_settings_ignore_proxy_env_when_online_identity_selected() {
|
||||
let mut env = HashMap::new();
|
||||
|
||||
Reference in New Issue
Block a user