From 7a97f24a0e1689d05a384fd3079334ea8f343338 Mon Sep 17 00:00:00 2001 From: lucaronin Date: Sat, 2 May 2026 18:41:38 +0200 Subject: [PATCH] fix: detect codex windows npm shims --- src-tauri/src/codex_cli.rs | 52 +++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/codex_cli.rs b/src-tauri/src/codex_cli.rs index 3d5a5abe..92a2e2fb 100644 --- a/src-tauri/src/codex_cli.rs +++ b/src-tauri/src/codex_cli.rs @@ -39,13 +39,21 @@ fn find_codex_binary() -> Result { } fn find_codex_binary_on_path() -> Option { - crate::hidden_command("which") + crate::hidden_command(codex_path_lookup_command()) .arg("codex") .output() .ok() .and_then(|output| path_from_successful_output(&output)) } +fn codex_path_lookup_command() -> &'static str { + if cfg!(windows) { + "where" + } else { + "which" + } +} + fn find_codex_binary_in_user_shell() -> Option { user_shell_candidates() .into_iter() @@ -102,13 +110,27 @@ fn codex_binary_candidates() -> Vec { fn codex_binary_candidates_for_home(home: &Path) -> Vec { let mut candidates = vec![ home.join(".local/bin/codex"), + home.join(".local/bin/codex.exe"), home.join(".codex/bin/codex"), + home.join(".codex/bin/codex.exe"), home.join(".local/share/mise/shims/codex"), + home.join(".local/share/mise/shims/codex.exe"), home.join(".asdf/shims/codex"), + home.join(".asdf/shims/codex.exe"), home.join(".npm-global/bin/codex"), + home.join(".npm-global/bin/codex.cmd"), + home.join(".npm-global/bin/codex.exe"), home.join(".npm/bin/codex"), + home.join(".npm/bin/codex.cmd"), + home.join(".npm/bin/codex.exe"), home.join(".bun/bin/codex"), + home.join(".bun/bin/codex.exe"), home.join(".linuxbrew/bin/codex"), + home.join("AppData/Roaming/npm/codex.cmd"), + home.join("AppData/Roaming/npm/codex.exe"), + home.join("AppData/Local/pnpm/codex.cmd"), + home.join("AppData/Local/pnpm/codex.exe"), + home.join("scoop/shims/codex.exe"), PathBuf::from("/home/linuxbrew/.linuxbrew/bin/codex"), PathBuf::from("/usr/local/bin/codex"), PathBuf::from("/opt/homebrew/bin/codex"), @@ -705,6 +727,34 @@ exit 2 } } + #[test] + fn codex_binary_candidates_include_windows_npm_and_toolchain_shims() { + let home = PathBuf::from("C:/Users/alex"); + let candidates = codex_binary_candidates_for_home(&home); + let expected = [ + home.join(".local/bin/codex.exe"), + home.join(".local/share/mise/shims/codex.exe"), + home.join(".asdf/shims/codex.exe"), + home.join(".npm-global/bin/codex.cmd"), + home.join(".npm-global/bin/codex.exe"), + home.join(".npm/bin/codex.cmd"), + home.join(".npm/bin/codex.exe"), + home.join("AppData/Roaming/npm/codex.cmd"), + home.join("AppData/Roaming/npm/codex.exe"), + home.join("AppData/Local/pnpm/codex.cmd"), + home.join("AppData/Local/pnpm/codex.exe"), + home.join("scoop/shims/codex.exe"), + ]; + + for candidate in expected { + assert!( + candidates.contains(&candidate), + "missing {}", + candidate.display() + ); + } + } + #[test] fn codex_binary_candidates_include_nvm_managed_node_installs() { let home = tempfile::tempdir().unwrap();