fix(agents): probe Windows installs without encoded PowerShell
This commit is contained in:
1 parent
717e9e6030
commit
f4d91b59fc
7 files changed
+1206
-791
No files matched your search
@@ -119,6 +119,16 @@ fn zcode_windows_finds_custom_installations_from_registered_paths() {
|
||||
fs::remove_dir_all(home).unwrap();
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[test]
|
||||
fn zcode_windows_display_name_matches_installer_variants() {
|
||||
assert!(windows_display_name_matches_zcode("ZCode"));
|
||||
assert!(windows_display_name_matches_zcode("ZCode (64-bit)"));
|
||||
assert!(windows_display_name_matches_zcode("ZCode Desktop"));
|
||||
assert!(!windows_display_name_matches_zcode("ZCodeHelper"));
|
||||
assert!(!windows_display_name_matches_zcode("MyZCode"));
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[test]
|
||||
fn zcode_windows_skips_stale_and_unrelated_registration_entries() {
|
||||
|
||||
@@ -87,6 +87,14 @@ fn windows_chatgpt_discovery_parser_accepts_registered_app_and_executable() {
|
||||
}
|
||||
|
||||
assert!(parse_windows_codex_app_discovery_output("MSEdgePWA:ChatGPT\r\n").is_none());
|
||||
assert_eq!(
|
||||
parse_windows_claude_desktop_version_output("VERSION:1.2.3\r\n").as_deref(),
|
||||
Some("1.2.3")
|
||||
);
|
||||
assert_eq!(
|
||||
parse_windows_codex_version_output("VERSION:26.901.51231\r\n").as_deref(),
|
||||
Some("26.901.51231")
|
||||
);
|
||||
|
||||
let registry_output = r"HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages\OpenAI.Codex_26.715.4045.0_x64__2p2nqsd0c76g0";
|
||||
assert_eq!(
|
||||
@@ -231,67 +239,35 @@ fn codex_store_version_resolves_only_the_selected_family_and_application() {
|
||||
let home = agent_test_home("codex-store-version-target");
|
||||
let executable = home.join("ChatGPT.exe");
|
||||
fs::write(&executable, b"test").unwrap();
|
||||
let install_location = windows_powershell_single_quoted_literal(&path_to_string(&home));
|
||||
let mocks = format!(
|
||||
r#"
|
||||
function Get-AppxPackage {{
|
||||
[pscustomobject]@{{ PackageFamilyName='OpenAI.ChatGPT_publisher'; Version='99.0.0.0'; PackageFullName='wrong-chatgpt' }}
|
||||
[pscustomobject]@{{ PackageFamilyName='OpenAI.CodexBeta_publisher'; Version='98.0.0.0'; PackageFullName='wrong-beta' }}
|
||||
[pscustomobject]@{{ PackageFamilyName='OpenAI.Codex_publisher'; Version='26.800.1.0'; PackageFullName='old-codex' }}
|
||||
[pscustomobject]@{{ PackageFamilyName='OpenAI.Codex_publisher'; Version='26.901.6511.0'; PackageFullName='selected-codex'; InstallLocation={install_location} }}
|
||||
}}
|
||||
function Get-AppxPackageManifest($Package) {{
|
||||
if ($Package -ne 'selected-codex') {{ throw 'wrong package' }}
|
||||
[pscustomobject]@{{ Package=@{{ Applications=@{{ Application=@(
|
||||
[pscustomobject]@{{ Id='Other'; Executable='wrong.exe' }},
|
||||
[pscustomobject]@{{ Id='App'; Executable='ChatGPT.exe' }}
|
||||
) }} }} }}
|
||||
}}
|
||||
"#
|
||||
fs::write(
|
||||
home.join("AppxManifest.xml"),
|
||||
r#"<Package><Applications>
|
||||
<Application Id="Other" Executable="wrong.exe" />
|
||||
<Application Id="App" Executable="ChatGPT.exe" />
|
||||
</Applications></Package>"#,
|
||||
)
|
||||
.unwrap();
|
||||
let package = WindowsAppxPackage {
|
||||
full_name: "OpenAI.Codex_26.901.6511.0_x64__publisher".to_string(),
|
||||
family_name: "OpenAI.Codex_publisher".to_string(),
|
||||
version: "26.901.6511.0".to_string(),
|
||||
install_location: home.clone(),
|
||||
};
|
||||
assert_eq!(
|
||||
windows_appx_executable(&package, Some("App")).as_deref(),
|
||||
Some(executable.as_path())
|
||||
);
|
||||
for (app_id, expected) in [
|
||||
("OpenAI.Codex_publisher!App", true),
|
||||
("OpenAI.Codex_publisher!Missing", false),
|
||||
("OpenAI.Codex_missing!App", false),
|
||||
] {
|
||||
let script = format!(
|
||||
"{mocks}\n{}",
|
||||
windows_codex_store_executable_script(app_id).unwrap()
|
||||
);
|
||||
let mut command = Command::new(windows_powershell_executable());
|
||||
command.args([
|
||||
"-NoLogo",
|
||||
"-NoProfile",
|
||||
"-NonInteractive",
|
||||
"-EncodedCommand",
|
||||
&windows_powershell_encoded_command(&script),
|
||||
]);
|
||||
configure_background_command(&mut command);
|
||||
let output = command_output_with_timeout(&mut command, Duration::from_secs(10))
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let target =
|
||||
parse_windows_codex_app_discovery_output(&String::from_utf8_lossy(&output.stdout));
|
||||
if expected {
|
||||
assert!(
|
||||
matches!(target, Some(DesktopAppTarget::Application(path)) if path == executable)
|
||||
);
|
||||
} else {
|
||||
assert!(target.is_none());
|
||||
}
|
||||
}
|
||||
assert!(windows_codex_store_executable_script("invalid").is_none());
|
||||
assert!(windows_codex_store_executable_script("!App").is_none());
|
||||
assert!(windows_codex_store_executable_script("OpenAI.Codex_publisher!").is_none());
|
||||
assert!(
|
||||
windows_codex_store_executable_script("OpenAI.Codex_o'brien!App")
|
||||
.unwrap()
|
||||
.contains("'OpenAI.Codex_o''brien'")
|
||||
assert!(windows_appx_executable(&package, Some("Missing")).is_none());
|
||||
assert_eq!(
|
||||
windows_appx_app_id(&package).as_deref(),
|
||||
Some("OpenAI.Codex_publisher!Other")
|
||||
);
|
||||
assert!(windows_codex_store_app_id_parts("invalid").is_none());
|
||||
assert!(windows_codex_store_app_id_parts("!App").is_none());
|
||||
assert!(windows_codex_store_app_id_parts("OpenAI.Codex_publisher!").is_none());
|
||||
assert_eq!(
|
||||
windows_codex_store_app_id_parts("OpenAI.Codex_o'brien!App"),
|
||||
Some(("OpenAI.Codex_o'brien", "App"))
|
||||
);
|
||||
fs::remove_dir_all(home).unwrap();
|
||||
}
|
||||
Reference in new issue
Block a user