-
Notifications
You must be signed in to change notification settings - Fork 212
fix(shell): delegate VS Code profile reads to Terminal methods (issue #634) #1033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
edelauna
wants to merge
4
commits into
main
Choose a base branch
from
issue/634
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+385
−583
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6a6df2c
fix(terminal): align getShell() scope with Terminal config reads
edelauna f0ab3eb
fix(shell): delegate VS Code profile reads to Terminal methods
edelauna f089c04
Merge branch 'main' into issue/634
edelauna 9f9c544
Merge branch 'main' into issue/634
edelauna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
169 changes: 169 additions & 0 deletions
169
src/integrations/terminal/__tests__/shell-system-prompt-divergence.spec.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| // Regression test for https://github.com/Zoo-Code-Org/Zoo-Code/issues/634 | ||
| // | ||
| // When the user sets terminal.integrated.defaultProfile.windows in *workspace* | ||
| // settings, getShell() (used for the system prompt) picks it up via config.get() | ||
| // which merges all scopes, but Terminal.getConfiguredDefaultProfileName() only | ||
| // reads inspect().globalValue ?? inspect().defaultValue — intentionally excluding | ||
| // workspace for security. | ||
| // | ||
| // The result: the system prompt tells the model "you have PowerShell" but the | ||
| // actual terminal VS Code opens defaults to cmd.exe (or whatever VS Code picks | ||
| // when no global/default profile is set), so every PowerShell command fails. | ||
| // | ||
| // Run: node_modules/.bin/vitest run integrations/terminal/__tests__/shell-system-prompt-divergence.spec.ts | ||
|
|
||
| import { existsSync } from "fs" | ||
| import * as vscode from "vscode" | ||
|
|
||
| vi.mock("execa", () => ({ execa: vi.fn() })) | ||
| vi.mock("fs", () => ({ existsSync: vi.fn(() => false) })) | ||
| vi.mock("os", () => ({ userInfo: vi.fn(() => ({ shell: null })) })) | ||
|
|
||
| const mockedExistsSync = existsSync as unknown as ReturnType<typeof vi.fn> | ||
|
|
||
| const { Terminal } = await import("../Terminal") | ||
| const { getShell } = await import("../../../utils/shell") | ||
|
|
||
| describe("issue #634 — system prompt shell vs actual terminal shell divergence", () => { | ||
| let originalPlatform: NodeJS.Platform | ||
|
|
||
| beforeEach(() => { | ||
| originalPlatform = process.platform | ||
| Object.defineProperty(process, "platform", { value: "win32", configurable: true }) | ||
| Terminal.setTerminalProfile(undefined) | ||
| mockedExistsSync.mockReset() | ||
| // pwsh.exe exists — getShell() fallback path prefers PowerShell 7 over legacy | ||
| mockedExistsSync.mockImplementation((p: string) => p === "C:\\Program Files\\PowerShell\\7\\pwsh.exe") | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| Object.defineProperty(process, "platform", { value: originalPlatform, configurable: true }) | ||
| Terminal.setTerminalProfile(undefined) | ||
| vi.restoreAllMocks() | ||
| }) | ||
|
|
||
| /** | ||
| * Stubs VS Code config to simulate a workspace-scoped default profile. | ||
| * | ||
| * getShell() (shell.ts) uses getConfiguration("terminal.integrated").get() which | ||
| * returns the merged/effective value across all scopes — workspace value wins. | ||
| * | ||
| * Terminal.getConfiguredDefaultProfileName() uses inspect().globalValue ?? defaultValue, | ||
| * intentionally excluding workspace scope for security. Both undefined here. | ||
| */ | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| function stubWorkspaceScopedProfile(profileName: string, profilePath: string) { | ||
| const profiles = { [profileName]: { path: profilePath } } | ||
| vi.spyOn(vscode.workspace, "getConfiguration").mockImplementation((section?: string) => { | ||
| if (section === "terminal.integrated") { | ||
| return { | ||
| // get() merges all scopes — shell.ts uses this, picks up workspace value | ||
| get: (key: string) => { | ||
| if (key === "defaultProfile.windows") return profileName | ||
| if (key === "profiles.windows") return profiles | ||
| return undefined | ||
| }, | ||
| // Terminal uses inspect() and only reads globalValue ?? defaultValue | ||
| inspect: (_key: string) => ({ | ||
| defaultValue: undefined, | ||
| globalValue: undefined, | ||
| workspaceValue: profileName, | ||
| }), | ||
| } as unknown as vscode.WorkspaceConfiguration | ||
| } | ||
|
|
||
| if (section === "terminal.integrated.profiles") { | ||
| return { | ||
| inspect: (_key: string) => ({ | ||
| defaultValue: undefined, | ||
| globalValue: undefined, | ||
| workspaceValue: profiles, | ||
| }), | ||
| } as unknown as vscode.WorkspaceConfiguration | ||
| } | ||
|
|
||
| return { | ||
| get: (_key: string, dv?: unknown) => dv, | ||
| inspect: () => undefined, | ||
| } as unknown as vscode.WorkspaceConfiguration | ||
| }) | ||
| } | ||
|
|
||
| it("Terminal.getConfiguredDefaultProfileName ignores workspace-scoped profile (confirms the bug)", () => { | ||
| // User set PowerShell as default only in their workspace .vscode/settings.json | ||
| stubWorkspaceScopedProfile("PowerShell", "C:\\Program Files\\PowerShell\\7\\pwsh.exe") | ||
|
|
||
| // Terminal intentionally excludes workspace scope for security. | ||
| // With no global/default profile set, it returns undefined. | ||
| const terminalSeesProfileName = Terminal.getConfiguredDefaultProfileName("win32") | ||
| expect(terminalSeesProfileName).toBeUndefined() | ||
|
|
||
| // As a consequence, isActiveShellPowerShell returns false even though the | ||
| // user configured PowerShell — the terminal will not be treated as PowerShell. | ||
| expect(Terminal.isActiveShellPowerShell("win32")).toBe(false) | ||
| }) | ||
|
|
||
| it("getShell() and Terminal agree on PowerShell when the default profile is set at global/user scope", () => { | ||
| // When the profile is set at user (global) scope, both paths see the same value. | ||
| const profilePath = "C:\\Program Files\\Git\\bin\\bash.exe" // non-PowerShell so name-matching doesn't hide the bug | ||
| const profileName = "Git Bash" | ||
| vi.spyOn(vscode.workspace, "getConfiguration").mockImplementation((section?: string) => { | ||
| if (section === "terminal.integrated") { | ||
| return { | ||
| get: (key: string) => { | ||
| if (key === "defaultProfile.windows") return profileName | ||
| if (key === "profiles.windows") return { [profileName]: { path: profilePath } } | ||
| return undefined | ||
| }, | ||
| inspect: (_key: string) => ({ | ||
| defaultValue: undefined, | ||
| globalValue: profileName, | ||
| workspaceValue: undefined, | ||
| }), | ||
| } as unknown as vscode.WorkspaceConfiguration | ||
| } | ||
|
|
||
| if (section === "terminal.integrated.profiles") { | ||
| const profiles = { [profileName]: { path: profilePath } } | ||
| return { | ||
| inspect: (_key: string) => ({ | ||
| defaultValue: undefined, | ||
| globalValue: profiles, | ||
| workspaceValue: undefined, | ||
| }), | ||
| } as unknown as vscode.WorkspaceConfiguration | ||
| } | ||
|
|
||
| return { | ||
| get: (_key: string, dv?: unknown) => dv, | ||
| inspect: () => undefined, | ||
| } as unknown as vscode.WorkspaceConfiguration | ||
| }) | ||
| mockedExistsSync.mockImplementation((p: string) => p === profilePath) | ||
|
|
||
| const shellForSystemPrompt = getShell() | ||
| const terminalSeesProfileName = Terminal.getConfiguredDefaultProfileName("win32") | ||
|
|
||
| // Both agree: Git Bash | ||
| expect(terminalSeesProfileName).toBe(profileName) | ||
| expect(shellForSystemPrompt).toBe(profilePath) | ||
| }) | ||
|
|
||
| it("divergence: getShell() reports PowerShell but Terminal sees no profile when set at workspace scope only", () => { | ||
| stubWorkspaceScopedProfile("PowerShell", "C:\\Program Files\\PowerShell\\7\\pwsh.exe") | ||
|
|
||
| // getShell() uses config.get() → picks up workspace value → sees "PowerShell" name | ||
| // → name-match path returns pwsh.exe (since existsSync mocked true for it) | ||
| const shellForSystemPrompt = getShell() | ||
| expect(shellForSystemPrompt).toContain("PowerShell") | ||
|
|
||
| // Terminal.getConfiguredDefaultProfileName() uses inspect().globalValue → undefined | ||
| const terminalSeesProfileName = Terminal.getConfiguredDefaultProfileName("win32") | ||
| expect(terminalSeesProfileName).toBeUndefined() | ||
|
|
||
| // Terminal therefore can't identify the active shell as PowerShell | ||
| expect(Terminal.isActiveShellPowerShell("win32")).toBe(false) | ||
|
|
||
| // Divergence: system prompt claims PowerShell, Terminal has no profile → falls | ||
| // through to VS Code's own autodetect which may open cmd.exe on this machine. | ||
| }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.