diff --git a/src/utils/__tests__/shell.spec.ts b/src/utils/__tests__/shell.spec.ts index 8f370e4d7f..828e7b62a2 100644 --- a/src/utils/__tests__/shell.spec.ts +++ b/src/utils/__tests__/shell.spec.ts @@ -173,23 +173,27 @@ describe("Shell Detection Tests", () => { expect(getShell()).toBe("C:\\Windows\\System32\\cmd.exe") }) - it("respects userInfo() if no VS Code config is available and shell is allowed", () => { + it("defaults to Windows PowerShell when VS Code has no configured profile", () => { + // Modern VS Code launches PowerShell by default on Windows (issue #82), so + // getShell() should report PowerShell rather than falling through to cmd.exe. vscode.workspace.getConfiguration = () => ({ get: () => undefined }) as any vi.mocked(userInfo).mockReturnValue({ shell: "C:\\Program Files\\PowerShell\\7\\pwsh.exe" } as any) - expect(getShell()).toBe("C:\\Program Files\\PowerShell\\7\\pwsh.exe") + expect(getShell()).toBe("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe") }) - it("falls back to safe shell when userInfo() returns non-allowlisted shell", () => { - vscode.workspace.getConfiguration = () => ({ get: () => undefined }) as any - vi.mocked(userInfo).mockReturnValue({ shell: "C:\\Custom\\PowerShell.exe" } as any) + it("falls back to safe shell when the configured profile path is non-allowlisted", () => { + mockVsCodeConfig("windows", "Custom", { + Custom: { path: "C:\\Custom\\evil.exe" }, + }) expect(getShell()).toBe("C:\\Windows\\System32\\cmd.exe") }) - it("falls back to safe shell when COMSPEC is non-allowlisted", () => { - vscode.workspace.getConfiguration = () => ({ get: () => undefined }) as any - process.env.COMSPEC = "D:\\CustomCmd\\cmd.exe" + it("uses cmd.exe when a Command Prompt profile is explicitly configured", () => { + mockVsCodeConfig("windows", "Command Prompt", { + "Command Prompt": { path: "C:\\Windows\\System32\\cmd.exe" }, + }) expect(getShell()).toBe("C:\\Windows\\System32\\cmd.exe") }) diff --git a/src/utils/shell.ts b/src/utils/shell.ts index 45253c31b0..d39395ade3 100644 --- a/src/utils/shell.ts +++ b/src/utils/shell.ts @@ -188,7 +188,13 @@ function normalizeShellPath(path: string | string[] | undefined): string | null function getWindowsShellFromVSCode(): string | null { const { defaultProfileName, profiles } = getWindowsTerminalConfig() if (!defaultProfileName) { - return null + // No explicit Windows terminal profile is configured. VS Code's built-in + // default on modern Windows is PowerShell (not cmd.exe), and that is the + // shell the integrated terminal actually launches. Mirror it here so the + // system prompt advertises the real shell instead of falling through to + // COMSPEC (cmd.exe). Windows PowerShell is always present, so it is a safe + // allowlisted default. See issue #82. + return SHELL_PATHS.POWERSHELL_LEGACY } const profile = profiles[defaultProfileName]