From dca9629b747d58256cadc865539fce925d799d21 Mon Sep 17 00:00:00 2001 From: leiming2333 Date: Sat, 3 Oct 2026 17:56:56 +0800 Subject: [PATCH] =?UTF-8?q?test(launcher):=20=E6=97=A0=E7=AC=A6=E5=8F=B7?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E7=89=B9=E6=9D=83=E6=97=B6=E5=9B=9E=E9=80=80?= =?UTF-8?q?=20junction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Windows 上创建目录软链需要开发者模式或管理员权限,普通权限的机器上 symlink_dir 返回错误 1314(客户端没有所需的特权),该测试直接失败。 GitHub CI 的 runner 以管理员运行所以未暴露。 junction 与软链同为 reparse point,canonicalize 解析行为一致: symlink_dir 失败时用 mklink /J 建 junction,被测的链接解析逻辑不变, 测试在无特权机器上也能跑出真实结果(dream_skin_library 已用跳过 处理同类问题,此处跳过会失去链接解析的覆盖,故改为回退)。 --- crates/codex-plus-core/tests/launcher.rs | 27 +++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/codex-plus-core/tests/launcher.rs b/crates/codex-plus-core/tests/launcher.rs index 4b7840e71..c888661ca 100644 --- a/crates/codex-plus-core/tests/launcher.rs +++ b/crates/codex-plus-core/tests/launcher.rs @@ -202,7 +202,7 @@ fn app_paths_resolves_portable_current_link_to_directory_version() { std::fs::create_dir_all(&target).unwrap(); std::fs::write(target.join("Codex.exe"), "").unwrap(); std::fs::write(target.join("version"), "42.1.0\n").unwrap(); - std::os::windows::fs::symlink_dir(&target, ¤t).unwrap(); + link_current_dir(&target, ¤t); assert_eq!( codex_app_version(¤t).as_deref(), @@ -210,6 +210,31 @@ fn app_paths_resolves_portable_current_link_to_directory_version() { ); } +/// 建目录软链需要开发者模式或管理员权限(Windows 错误 1314);拿不到特权时 +/// 退回 junction。junction 与软链都是 reparse point,`canonicalize` 的解析 +/// 行为一致,被测逻辑不受影响,测试在无特权的机器上也能验证链接解析。 +#[cfg(windows)] +fn link_current_dir(target: &Path, link: &Path) { + if std::os::windows::fs::symlink_dir(target, link).is_ok() { + return; + } + let output = std::process::Command::new("cmd") + .args([ + "/c", + "mklink", + "/J", + &link.to_string_lossy(), + &target.to_string_lossy(), + ]) + .output() + .expect("运行 mklink /J 创建 junction 失败"); + assert!( + output.status.success(), + "junction 创建失败:{}", + String::from_utf8_lossy(&output.stderr) + ); +} + #[test] fn app_paths_extracts_codex_version_from_macos_bundle_plist() { let temp = tempfile::tempdir().unwrap();