diff --git a/src/utils/__tests__/shell.spec.ts b/src/utils/__tests__/shell.spec.ts index 8f370e4d7f1..3388a9de89d 100644 --- a/src/utils/__tests__/shell.spec.ts +++ b/src/utils/__tests__/shell.spec.ts @@ -247,6 +247,8 @@ describe("Shell Detection Tests", () => { it("falls back to /bin/zsh if no config, userInfo, or env variable is set", () => { vscode.workspace.getConfiguration = () => ({ get: () => undefined }) as any + // With the fix, getShellFromEnv() returns null when SHELL is not set, + // so it falls back to the safe default from getSafeFallbackShell() expect(getShell()).toBe("/bin/zsh") }) }) @@ -303,6 +305,8 @@ describe("Shell Detection Tests", () => { it("falls back to /bin/bash if nothing is set", () => { vscode.workspace.getConfiguration = () => ({ get: () => undefined }) as any + // With the fix, getShellFromEnv() returns null when SHELL is not set, + // so it falls back to the safe default from getSafeFallbackShell() expect(getShell()).toBe("/bin/bash") }) }) @@ -345,6 +349,8 @@ describe("Shell Detection Tests", () => { throw new Error("userInfo error") }) delete process.env.SHELL + // With the fix, getShellFromEnv() returns null when SHELL is not set, + // so it falls back to the safe default from getSafeFallbackShell() expect(getShell()).toBe("/bin/bash") }) }) diff --git a/src/utils/shell.ts b/src/utils/shell.ts index 45253c31b08..d52969a8bd7 100644 --- a/src/utils/shell.ts +++ b/src/utils/shell.ts @@ -269,18 +269,14 @@ function getShellFromEnv(): string | null { if (process.platform === "win32") { // On Windows, COMSPEC typically holds cmd.exe - return env.COMSPEC || "C:\\Windows\\System32\\cmd.exe" + return env.COMSPEC || null } - if (process.platform === "darwin") { - // On macOS/Linux, SHELL is commonly the environment variable - return env.SHELL || "/bin/zsh" + // On Unix-like systems (macOS, Linux), SHELL is the environment variable + if (process.platform === "darwin" || process.platform === "linux") { + return env.SHELL || null } - if (process.platform === "linux") { - // On Linux, SHELL is commonly the environment variable - return env.SHELL || "/bin/bash" - } return null }