Repository navigation
Conversation
|
@codex review |
|
撤回此 PR。经在复现环境中排查,issue #4265 的真实根因与 PR 描述的「Windows PATH 检测缺陷」不符——在我的环境下 npm-global 自始至终在注册表 PATH 中,后端 scan_cli_version 能正常检测到工具。实际漏检发生在「点击更新之后」,疑为更新窗口期二进制短暂不可用 + 前端未自动重新探测所致,与本 PR 的后端探测改动无关。抱歉带来困扰,issue 根因我另行更正。 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1be028337b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /// 漏掉。`where` 走的是 shell 侧的标准 PATH 解析,能覆盖自定义 npm prefix 等场景。 | ||
| #[cfg(target_os = "windows")] | ||
| fn try_get_version_windows(tool: &str) -> ShellProbe { | ||
| let tool_path = match resolve_path_default(tool) { |
There was a problem hiding this comment.
Use a refreshed PATH source before relying on where
In the Windows custom-prefix case described by this change, this still launches cmd /C where with the Tauri process environment. Microsoft documents where as searching the current directory and PATH (https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/where), and the fallback scanner also extends from the same std::env::var_os("PATH"); when the npm prefix only exists in the user's shell/profile or in a newer environment block that the GUI process has not inherited, where returns nothing and the fallback repeats the same stale PATH scan. That leaves codex/opencode reported as not installed for the scenario this patch is intended to fix, so the Windows probe needs to refresh/augment PATH from a source other than the current process before resolving the tool.
Useful? React with 👍 / 👎.
| .map(|value| value.to_string_lossy().into_owned()) | ||
| .unwrap_or_default(); | ||
|
|
||
| match run_windows_tool_version_command(&tool_path, &new_path) { |
There was a problem hiding this comment.
Filter where results before executing them
When where returns a match from WindowsApps or the current directory before the real npm shim, this branch executes that path immediately. The existing scanner intentionally filters PATH entries through should_skip_cli_path_env_dir, but this new path bypasses that guard; if an App Execution Alias/protocol stub exits non-zero, try_get_version_windows returns FoundButFailed and the caller will not fall back to scan_cli_version, so a valid later installation is hidden behind the alias. Reuse the same skip logic or iterate to the next where result before running --version.
Useful? React with 👍 / 👎.
Summary / 概述
修复 Windows 上「改了 npm prefix 后,
npm i -g安装的 CLI 工具(codex / opencode)在 设置 → 关于 显示为『未安装』,而默认 prefix 的 Claude Code 检测正常」的问题。根因
get_single_tool_version_impl(src-tauri/src/commands/misc.rs)的else分支存在平台不对称:try_get_version通过登录 shell($SHELL -lic "tool --version")查询,会加载.zshrc/.bashrc、获得完整用户 PATH;只有NotFound才 fallback 到scan_cli_version。scan_cli_version。而scan_cli_version用的是进程级std::env::var_os("PATH")(GUI/Tauri 进程的 PATH)+ 文件存在性检查。当自定义 npm prefix 目录仅由 shell profile / 系统环境注入、未进入 GUI 进程 PATH 时,就会漏检。已有的修复 PR #2286(pnpm 全局安装检测)、PR #2822(mise 路径)只对非 Windows 生效,Windows 这条路径从未被修过。
修复
新增
try_get_version_windows,与非 Windows 的try_get_version结构对称:resolve_path_default(cmd /C where,shell 侧标准 PATH 解析)定位命令行默认命中的真实可执行文件;--version(复用既有run_windows_tool_version_command,仍不直接cmd /C {tool},避免误触发 App Execution Alias / 协议处理器);where找不到时返回NotFound,由调用方 fallback 到scan_cli_version的常见目录扫描。调用点(
misc.rsWindows 分支)改为与非 Windows 一致的match … NotFound => scan_cli_version, found => found形态。复用既有且经测试的resolve_path_default/run_windows_tool_version_command/extract_version,未引入重复实现。Related Issue / 关联 Issue
Fixes #4265
Screenshots / 截图
N/A —— 纯后端检测逻辑变更,无 UI 文案改动。
How verified / 验证方式
cargo fmt --check✅ 干净cargo clippy✅ 无新增告警(仅有与本次改动无关的既有告警)cargo test commands::misc::tests✅ 无新增失败:53 通过;6 个失败全在anchored_upgrade_windows::*(升级命令生成,非检测路径),在干净的main上同样复现,属既有问题、与本次改动无关。手动验证场景(对应 issue):
%APPDATA%\npm)—— 所有工具检测正常(回归,走scan_cli_versionfallback)。npm i -g @openai/codex/opencode-ai—— 现在可检测到(新增where路径)。where找不到工具 —— 仍 fallback 到scan_cli_version(兜底保留)。Checklist / 检查清单
pnpm typecheckpasses / 通过 TypeScript 类型检查(无前端改动)pnpm format:checkpasses / 通过代码格式检查(无前端改动)cargo clippypasses (if Rust code changed) / 通过 Clippy 检查(修改了 Rust 代码)