fix(core): normalize Windows PATH-like env keys for shell execution#1904
fix(core): normalize Windows PATH-like env keys for shell execution#1904DennisYu07 merged 3 commits intoQwenLM:mainfrom
Conversation
|
Issues & Suggestions
The function always normalizes to Path (title-case). However, Node.js on Windows typically uses PATH (all-caps) as the conventional key. The choice of Path seems arbitrary — Windows itself is case-insensitive, but downstream tools (e.g., cross-platform Node libraries) may expect PATH. Consider using PATH as canonical instead, or at minimum document why Path was chosen.
When both Path and PATH exist with different values, the function silently discards one. A safer approach would be to merge/concatenate both values with const mergedValue = [...new Set( This avoids silently dropping directories from the user's PATH. The current behavior could cause the exact same "command not found" problem it's trying to fix, just with the other key's directories missing.
normalized['Path'] ?? normalized[pathKeys[0] as keyof NodeJS.ProcessEnv]; pathKeys[0] is already a string, and NodeJS.ProcessEnv uses string index signatures. The cast is unnecessary.
normalizePathEnvForWindows(process.env) is called on every shell spawn, even though process.env rarely changes at runtime. This is cheap but could be cached if performance matters. Not a blocker.
The two test cases (PTY and child_process) are nearly identical — 28 lines duplicated. Consider extracting a shared helper: function setupConflictingPathEnv() { ... }
While the try/finally cleanup is correct, mutating process.env in tests is fragile. If mockPlatform or other mocks throw before the try block, environment state leaks. Consider using vi.stubEnv() if available in the test framework, which handles cleanup automatically. |
|
Thanks for the detailed review. I pushed follow-up changes to address the points you raised.
The targeted shellExecutionService test file still passes locally (39/39). |
TLDR
This PR addresses a Windows command resolution edge case by normalizing PATH-like environment keys before shell spawn.
On Windows, both
PathandPATHcan coexist inprocess.envwith different values. That ambiguity may cause spawned processes to resolve commands from an unintended key, which can lead to"not recognized"errors in extension-driven command execution (related to #1892).This change:
Pathand removes duplicate PATH-like keysDive Deeper
Problem
Issue #1892 reports that commands available in user environment (e.g.,
flutter) may fail when executed through the extension flow on Windows.Root Cause
Windows treats env keys case-insensitively, but Node.js
process.envcan still contain multiple PATH-like keys (Path,PATH) as separate object keys.If these keys diverge, child process resolution may use an unintended value, causing command lookup failure.
Fix
Implemented
normalizePathEnvForWindows(env)inpackages/core/src/services/shellExecutionService.ts:key.toLowerCase() === 'path')PathApplied normalization before spawn in both:
Validation Scope
packages/core/src/services/shellExecutionService.test.ts:Risk / Compatibility
Reviewer Test Plan
Expected:
Testing Matrix
Linked issues / bugs
Fixes #1892
Screenshots
repro_issue_1892_force_conflict.js (click to expand)
npm run test --workspace packages/core -- src/services/shellExecutionService.test.ts --coverage.enabled false