fix(cli): prevent PowerShell command hangs and fix non-zero exit code rejection - #13274
Open
maoxin1234 wants to merge 1 commit into
Open
maoxin1234 wants to merge 1 commit into
maoxin1234 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #13273.
In
extensions/cli, therunTerminalCommandtest "should handle non-existent commands" was intermittently hanging onwindows-latestuntil vitest's 30s timeout.Root Causes & Fixes:
PowerShell execution flags & stdin pipe:
powershell.exewas invoked without-NoProfileand-NonInteractive. On CI runners, profile loading or commands that trigger interactive prompts could cause PowerShell to block indefinitely waiting for user input.stdinopen as a pipe. Non-interactive CLI terminal commands never send stdin, so any subprocess waiting for EOF on standard input would hang.-NoProfileand-NonInteractiveto PowerShell arguments (both inextensions/cliandcore), and immediately calledchild.stdin?.end().Rejection condition on non-zero exit code:
child.on("close")previously only rejected ifcode !== 0 && stderr. If a non-zero exit code was returned with an empty stderr (e.g. error message written to stdout or buffered/empty), the tool unexpectedly resolved the promise instead of rejecting it.code !== 0 && code !== null, usingstderr || stdout || "Command failed"as the error message.Test timeout configuration:
TIMEOUT_MSwas defaulting to 180s even during tests unlessTEST_TERMINAL_TIMEOUTwas set, which was higher than vitest's 30stestTimeout.TEST_TERMINAL_TIMEOUT = "15000"invitest.setup.tsand provided a 15s fallback whenNODE_ENV === "test"so tool timeouts always fire before the test runner timeout.Verification
npx vitest run src/tools/runTerminalCommand.test.ts(9/9 passed, including new test for non-zero exit code with empty stderr)npm run typecheck(0 errors)npm run lint(0 errors)