Conversation
📝 WalkthroughWalkthroughShell detection now uses shared VS Code terminal profile inspection across platforms, with updated fallback and validation tests. Regression coverage verifies workspace-scope isolation and agreement between terminal detection and system-prompt shell selection. ChangesShell resolution
Lint metadata
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant getShell
participant Terminal
participant VSCode
participant FileSystem
getShell->>Terminal: read configured default profile
Terminal->>VSCode: inspect global terminal settings
Terminal->>FileSystem: validate resolved shell path
FileSystem-->>Terminal: path availability
Terminal-->>getShell: return shell or fallback
Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (4)
src/utils/__tests__/shell.spec.ts (3)
323-380: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winFold the workspace-scope stub into
mockVsCodeConfig.Both scope-isolation tests re-implement the helper with
workspaceValueinstead ofglobalValue; ascope: "global" | "workspace"option would remove ~40 duplicated lines and keep the two stubs from drifting.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils/__tests__/shell.spec.ts` around lines 323 - 380, Update mockVsCodeConfig to accept a scope option such as "global" or "workspace" and populate the corresponding inspect value while leaving the other scope undefined. Refactor both scope-isolation tests to use this helper instead of redefining vscode.workspace.getConfiguration, preserving their platform-specific profile and shell expectations.
453-460: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTest name overstates what it asserts.
The array is
[<allowlisted PS7>, "pwsh"], so first-entry and first-allowlisted resolution are indistinguishable. Put a non-allowlisted entry first if the intent is to pin "first allowlisted"; otherwise rename to "uses first path in array".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils/__tests__/shell.spec.ts` around lines 453 - 460, Update the test around getShell() so it distinguishes first-allowlisted resolution from simply selecting the first array entry: place a non-allowlisted path before the valid PowerShell path while retaining the expected allowlisted result. Keep the test name only if it now verifies that behavior; otherwise rename it to describe first-array-entry selection.
39-60: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
_platformKeyis now unused — the stub ignores the inspected key.Every call site still passes
"windows"/"osx"/"linux", which reads as if platform-specific keys are being exercised when they are not. Either drop the parameter or haveinspectassert the expected key (defaultProfile.<platformKey>/<platformKey>) so the tests actually pin the key names the implementation reads.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils/__tests__/shell.spec.ts` around lines 39 - 60, The mockVsCodeConfig helper accepts an unused _platformKey, so the tests do not validate platform-specific configuration keys. Update both inspect stubs in mockVsCodeConfig to assert the expected key names using platformKey—defaultProfile.<platformKey> for terminal.integrated and <platformKey> for terminal.integrated.profiles—while preserving their existing returned values.src/utils/shell.ts (1)
138-140: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueOptional: extract the PowerShell-7-or-legacy selection.
The same
existsSync(POWERSHELL_7) ? … : POWERSHELL_LEGACYexpression appears twice.♻️ Proposed refactor
+function preferredWindowsPowerShell(): string { + return existsSync(SHELL_PATHS.POWERSHELL_7) ? SHELL_PATHS.POWERSHELL_7 : SHELL_PATHS.POWERSHELL_LEGACY +}Also applies to: 156-165
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils/shell.ts` around lines 138 - 140, Extract the duplicated PowerShell 7-or-legacy path selection into a shared helper or local symbol, then reuse it in both Windows branches of the shell-detection logic. Preserve the existing existsSync(SHELL_PATHS.POWERSHELL_7) preference and legacy fallback behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/integrations/terminal/__tests__/shell-system-prompt-divergence.spec.ts`:
- Around line 1-13: Update the header comment in the shell-system-prompt
divergence regression test to describe the post-fix behavior: getShell() now
uses Terminal.getConfiguredDefaultProfileName() and getConfiguredProfiles()
rather than config.get(), so remove the obsolete workspace-scope divergence
explanation and revise the test description to reflect the behavior being
protected.
- Around line 151-168: The divergence spec still describes pre-fix behavior;
update
src/integrations/terminal/__tests__/shell-system-prompt-divergence.spec.ts lines
151-168 to assert convergence, with getShell() ignoring the workspace-only
profile and returning the Windows no-profile fallback. Update lines 1-13 to
document that both paths use global/default scope, and revise lines 45-53 to
correct the helper documentation and remove the obsolete terminal.integrated
get() branch.
- Around line 45-53: Update the stub helper’s documentation near getShell() to
remove the obsolete explanation that getShell() reads the merged
terminal.integrated get() value and that the get() branch is exercised. Keep
only comments describing the configuration behavior still relevant to the code
under test, including the inspect() handling if applicable.
---
Nitpick comments:
In `@src/utils/__tests__/shell.spec.ts`:
- Around line 323-380: Update mockVsCodeConfig to accept a scope option such as
"global" or "workspace" and populate the corresponding inspect value while
leaving the other scope undefined. Refactor both scope-isolation tests to use
this helper instead of redefining vscode.workspace.getConfiguration, preserving
their platform-specific profile and shell expectations.
- Around line 453-460: Update the test around getShell() so it distinguishes
first-allowlisted resolution from simply selecting the first array entry: place
a non-allowlisted path before the valid PowerShell path while retaining the
expected allowlisted result. Keep the test name only if it now verifies that
behavior; otherwise rename it to describe first-array-entry selection.
- Around line 39-60: The mockVsCodeConfig helper accepts an unused _platformKey,
so the tests do not validate platform-specific configuration keys. Update both
inspect stubs in mockVsCodeConfig to assert the expected key names using
platformKey—defaultProfile.<platformKey> for terminal.integrated and
<platformKey> for terminal.integrated.profiles—while preserving their existing
returned values.
In `@src/utils/shell.ts`:
- Around line 138-140: Extract the duplicated PowerShell 7-or-legacy path
selection into a shared helper or local symbol, then reuse it in both Windows
branches of the shell-detection logic. Preserve the existing
existsSync(SHELL_PATHS.POWERSHELL_7) preference and legacy fallback behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 22b214de-4359-4bc7-ad65-21ebf84dda4b
📒 Files selected for processing (4)
src/eslint-suppressions.jsonsrc/integrations/terminal/__tests__/shell-system-prompt-divergence.spec.tssrc/utils/__tests__/shell.spec.tssrc/utils/shell.ts
Related GitHub Issue
Closes: #634
Description
Root cause: On Windows,
getShell()(used to build the system prompt) calledconfig.get("defaultProfile.windows")which merges all VS Code scopes including workspace.Terminal.getConfiguredDefaultProfileName()(used when actually opening a terminal) callsconfig.inspect().globalValue— intentionally excluding workspace scope, becauseterminal.integrated.defaultProfile.*is an APPLICATION-scoped setting. A workspace.vscode/settings.jsoncan contain the key, VS Code accepts it, but the terminal ignores it for security. The result: the system prompt told the model "you have PowerShell" while the terminal opened cmd.exe (or whatever VS Code autodetected), causing every shell command to fail.Fix: Deleted the parallel implementation in
shell.ts(getTerminalConfig,normalizeShellPath,getWindowsShellFromVSCode, etc.) and replaced it with a singlegetShellFromVSCode()that delegates toTerminal.getConfiguredDefaultProfileName()andTerminal.getConfiguredProfiles(). Both paths now read from the same inspect()-based source of truth. Also extractedpreferredWindowsPowerShell()to eliminate a duplicated PS7→legacy fallback expression.Tests:
shell.spec.tsstubs to useinspect()(matching the new implementation) and added a "Scope isolation" section asserting workspace-scoped profiles are ignored.shell-system-prompt-divergence.spec.tsas a regression anchor: confirmsTerminalignores workspace-scoped profiles, verifies both paths agree when a profile is set at global scope, and verifies convergence after the fix (workspace-only profile → both return the Windows no-profile fallback).Test Procedure
Unit tests:
E2E mock suite (76 passing, 3 pre-existing xAI failures unrelated to this change):
Pre-Submission Checklist
Additional Notes
The 3 failing E2E tests are all in the xAI provider suite and fail with a 403 "credits exhausted" error — pre-existing and unrelated to this change.
Summary by CodeRabbit