Skip to content

fix(vscode): use shell on Windows when spawning npm/ocr in CliService#490

Open
addielaruee wants to merge 1 commit into
alibaba:mainfrom
addielaruee:fix/vscode-windows-npm-spawn-shell
Open

fix(vscode): use shell on Windows when spawning npm/ocr in CliService#490
addielaruee wants to merge 1 commit into
alibaba:mainfrom
addielaruee:fix/vscode-windows-npm-spawn-shell

Conversation

@addielaruee

Copy link
Copy Markdown

Description

On Windows, node is node.exe (which child_process.spawn can execute directly), but npm and the ocr CLI are .cmd wrapper scripts. Node's spawn cannot execute a .cmd file unless shell: true is set. As reported in #453, this made the VS Code extension's environment-check page false-report "npm not detected" even though npm --version works in every terminal. The same gap would also stop runRaw from launching the ocr CLI to actually run a review on Windows.

The install method already sets shell: process.platform === 'win32', but the two other spawn call sites did not:

  • probeCommand — used for the node / npm / ocr environment detection.
  • runRaw — used to run a review (and llm test).

This PR adds shell: process.platform === 'win32' to both, matching install's existing pattern. On macOS/Linux the option evaluates to false, so behavior there is unchanged.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • yarn test passes locally in extensions/vscode (11 suites, 95 tests).
  • Added CliService.shell.test.ts, which mocks child_process.spawn and asserts the shell option per platform (win32true, others → false) for both probeCommand and runRaw. I confirmed the new tests fail when the fix is reverted, so they actually guard the behavior.
  • tsc --noEmit -p tsconfig.extension.json and eslint pass (no new warnings).
  • Manual testing on Windows — I don't have a Windows machine, so the live npm.cmd path was verified by code inspection against the root cause in Windows 环境下vs code插件检测误报"未检测到 npm"(spawn 未使用 shell 模式) #453 and the already-correct install method, plus the platform-conditional unit tests above. Behavior on macOS/Linux is provably unchanged (shell stays false).

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (no user-facing docs affected)
  • I have signed the CLA (will sign when the CLA bot posts on this PR)

Related Issues

Closes #453

On Windows, `node` is `node.exe` (spawnable directly) but `npm` and the
`ocr` CLI are `.cmd` wrapper scripts, which Node's `child_process.spawn`
cannot execute without `shell: true`. This made the extension's
environment check false-report "npm not detected" even though
`npm --version` works in every terminal, and would also stop `runRaw`
from launching the ocr CLI to run a review.

`probeCommand` (environment detection) and `runRaw` (review execution)
were missing the `shell: process.platform === 'win32'` option that the
`install` method already sets. Add it to both, matching `install`'s
pattern. Behavior on macOS/Linux is unchanged (`shell` stays `false`).

Add CliService.shell.test.ts, which mocks `child_process.spawn` to
assert the shell option per platform, verifying the cross-platform fix
without needing a live Windows environment.

Fixes alibaba#453
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions

Copy link
Copy Markdown
Contributor

OpenCodeReview: No comments generated. Looks good to me.

@lizhengfeng101

Copy link
Copy Markdown
Collaborator

Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows 环境下vs code插件检测误报"未检测到 npm"(spawn 未使用 shell 模式)

3 participants