|
1 | 1 | // Regression test for https://github.com/Zoo-Code-Org/Zoo-Code/issues/634 |
2 | 2 | // |
3 | | -// When the user sets terminal.integrated.defaultProfile.windows in *workspace* |
4 | | -// settings, getShell() (used for the system prompt) picks it up via config.get() |
5 | | -// which merges all scopes, but Terminal.getConfiguredDefaultProfileName() only |
6 | | -// reads inspect().globalValue ?? inspect().defaultValue — intentionally excluding |
7 | | -// workspace for security. |
| 3 | +// Root cause: getShell() (system prompt) used config.get() which merges all scopes |
| 4 | +// including workspace, while Terminal.getConfiguredDefaultProfileName() used |
| 5 | +// inspect().globalValue — intentionally excluding workspace scope for security. |
| 6 | +// terminal.integrated.defaultProfile.* is APPLICATION-scoped; workspace values are |
| 7 | +// technically accepted by VS Code but ignored by the terminal itself. |
8 | 8 | // |
9 | | -// The result: the system prompt tells the model "you have PowerShell" but the |
10 | | -// actual terminal VS Code opens defaults to cmd.exe (or whatever VS Code picks |
11 | | -// when no global/default profile is set), so every PowerShell command fails. |
| 9 | +// Fix: getShell() now delegates to Terminal.getConfiguredDefaultProfileName() and |
| 10 | +// Terminal.getConfiguredProfiles(), so both paths read the same inspect()-based values |
| 11 | +// and can never disagree. |
12 | 12 | // |
13 | 13 | // Run: node_modules/.bin/vitest run integrations/terminal/__tests__/shell-system-prompt-divergence.spec.ts |
14 | 14 |
|
@@ -44,12 +44,9 @@ describe("issue #634 — system prompt shell vs actual terminal shell divergence |
44 | 44 |
|
45 | 45 | /** |
46 | 46 | * Stubs VS Code config to simulate a workspace-scoped default profile. |
47 | | - * |
48 | | - * getShell() (shell.ts) uses getConfiguration("terminal.integrated").get() which |
49 | | - * returns the merged/effective value across all scopes — workspace value wins. |
50 | | - * |
51 | | - * Terminal.getConfiguredDefaultProfileName() uses inspect().globalValue ?? defaultValue, |
52 | | - * intentionally excluding workspace scope for security. Both undefined here. |
| 47 | + * globalValue is undefined for both the profile name and profiles map, |
| 48 | + * so Terminal (which reads only globalValue ?? defaultValue) sees no profile. |
| 49 | + * The workspace-scoped value is present to verify it is correctly ignored. |
53 | 50 | */ |
54 | 51 | function stubWorkspaceScopedProfile(profileName: string, profilePath: string) { |
55 | 52 | const profiles = { [profileName]: { path: profilePath } } |
@@ -148,22 +145,23 @@ describe("issue #634 — system prompt shell vs actual terminal shell divergence |
148 | 145 | expect(shellForSystemPrompt).toBe(profilePath) |
149 | 146 | }) |
150 | 147 |
|
151 | | - it("divergence: getShell() reports PowerShell but Terminal sees no profile when set at workspace scope only", () => { |
| 148 | + it("convergence: getShell() and Terminal both ignore a workspace-scoped-only profile (fix verification)", () => { |
| 149 | + // beforeEach mocks existsSync to return true only for PS7 path. |
| 150 | + // Here we want to test the no-profile fallback, so make existsSync return false. |
| 151 | + mockedExistsSync.mockReturnValue(false) |
152 | 152 | stubWorkspaceScopedProfile("PowerShell", "C:\\Program Files\\PowerShell\\7\\pwsh.exe") |
153 | 153 |
|
154 | | - // getShell() uses config.get() → picks up workspace value → sees "PowerShell" name |
155 | | - // → name-match path returns pwsh.exe (since existsSync mocked true for it) |
156 | | - const shellForSystemPrompt = getShell() |
157 | | - expect(shellForSystemPrompt).toContain("PowerShell") |
158 | | - |
159 | | - // Terminal.getConfiguredDefaultProfileName() uses inspect().globalValue → undefined |
| 154 | + // Terminal reads only inspect().globalValue → no profile configured at global scope. |
160 | 155 | const terminalSeesProfileName = Terminal.getConfiguredDefaultProfileName("win32") |
161 | 156 | expect(terminalSeesProfileName).toBeUndefined() |
162 | 157 |
|
163 | | - // Terminal therefore can't identify the active shell as PowerShell |
164 | | - expect(Terminal.isActiveShellPowerShell("win32")).toBe(false) |
| 158 | + // After the fix, getShell() delegates to Terminal's inspect()-based methods, |
| 159 | + // so it also sees no profile. It falls back to the Windows no-profile default |
| 160 | + // (PS legacy, since existsSync returns false for PS7 in this test). |
| 161 | + const shellForSystemPrompt = getShell() |
| 162 | + expect(shellForSystemPrompt).toBe("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe") |
165 | 163 |
|
166 | | - // Divergence: system prompt claims PowerShell, Terminal has no profile → falls |
167 | | - // through to VS Code's own autodetect which may open cmd.exe on this machine. |
| 164 | + // Both paths agree: no profile resolved → no active shell identified as PowerShell. |
| 165 | + expect(Terminal.isActiveShellPowerShell("win32")).toBe(false) |
168 | 166 | }) |
169 | 167 | }) |
0 commit comments