fix: use ide.runCommand when Windows host connects to WSL
When the VS Code extension runs on Windows but connects to WSL, direct shell spawning fails because process.platform is "win32" but commands should execute in the Linux WSL environment. This caused: spawn powershell.exe ENOENT The fix detects this scenario and falls back to ide.runCommand(), letting VS Code handle the remote terminal execution properly. Fixes #9661 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
97e9bc1b47
commit
c565bdc464
2 changed files with 34 additions and 1 deletions
|
|
@ -114,7 +114,16 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
|
|||
const ideInfo = await extras.ide.getIdeInfo();
|
||||
const toolCallId = extras.toolCallId || "";
|
||||
|
||||
if (ENABLED_FOR_REMOTES.includes(ideInfo.remoteName)) {
|
||||
// When extension host runs on Windows but connects to WSL, we can't spawn
|
||||
// shells directly - the platform is "win32" but commands should run in Linux.
|
||||
// Use ide.runCommand() instead to let VS Code handle the remote execution.
|
||||
const isWindowsHostWithWslRemote =
|
||||
process.platform === "win32" && ideInfo.remoteName === "wsl";
|
||||
|
||||
if (
|
||||
ENABLED_FOR_REMOTES.includes(ideInfo.remoteName) &&
|
||||
!isWindowsHostWithWslRemote
|
||||
) {
|
||||
// For streaming output
|
||||
if (extras.onPartialOutput) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -644,6 +644,30 @@ describe("runTerminalCommandImpl", () => {
|
|||
).resolves.toBeDefined();
|
||||
});
|
||||
|
||||
it("should use ide.runCommand when Windows host connects to WSL", async () => {
|
||||
// When extension runs on Windows but connects to WSL, we can't spawn
|
||||
// shells directly - must use ide.runCommand instead
|
||||
const originalPlatform = process.platform;
|
||||
Object.defineProperty(process, "platform", { value: "win32" });
|
||||
|
||||
try {
|
||||
const extras = createMockExtras({ remoteName: "wsl" });
|
||||
|
||||
const result = await runTerminalCommandImpl(
|
||||
{ command: "echo test" },
|
||||
extras,
|
||||
);
|
||||
|
||||
// Should fall back to ide.runCommand, not try to spawn powershell.exe
|
||||
expect(mockRunCommand).toHaveBeenCalledWith("echo test");
|
||||
expect(result[0].content).toContain("Terminal output not available");
|
||||
} finally {
|
||||
Object.defineProperty(process, "platform", {
|
||||
value: originalPlatform,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("should handle dev-container environment", async () => {
|
||||
mockGetWorkspaceDirs.mockResolvedValue(["file:///workspace"]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue