fix(terminal): use detected shell for execa and vscode terminal creation (#321)#333
fix(terminal): use detected shell for execa and vscode terminal creation (#321)#333F915 wants to merge 7 commits into
Conversation
…ion (Zoo-Code-Org#321) Connect the existing getShell() to both terminal creation paths to fix the Windows shell mismatch where AI generates pwsh syntax but commands execute in cmd.exe. - ExecaTerminalProcess: use getShell() instead of shell: true - Terminal: pass shellPath: getShell() to createTerminal Fixes Zoo-Code-Org#321
…gration (Zoo-Code-Org#321) Update two test cases that previously expected shell: true to now expect shell: expect.any(String), reflecting the change from shell: true to getShell() in ExecaTerminalProcess. Refs Zoo-Code-Org#321 Co-authored-by: Zoo Code Contributor <contributor@zoocode.dev>
📝 WalkthroughWalkthroughTwo terminal integration files now explicitly invoke ChangesExplicit shell path selection via getShell()
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 8f5fb7a1-993e-4d1d-987f-4466eb7afe09
📒 Files selected for processing (3)
src/integrations/terminal/ExecaTerminalProcess.tssrc/integrations/terminal/Terminal.tssrc/integrations/terminal/__tests__/ExecaTerminalProcess.spec.ts
Mock getShell() to verify the fallback actually uses the detected shell instead of just checking for any string value. Suggested-by: CodeRabbit
…ll() integration (Zoo-Code-Org#321) PR Zoo-Code-Org#333 added shellPath and iconPath to Terminal constructor but TerminalRegistry.spec.ts assertions were not updated, causing 4 test failures on ubuntu-latest CI.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/integrations/terminal/__tests__/TerminalRegistry.spec.ts (1)
39-40: ⚡ Quick winAssert
getShell()invocation to prevent hardcoded-shell regressions.You already assert the resulting
shellPath, but addingexpect(shellUtils.getShell).toHaveBeenCalled()makes this test fail if production code hardcodes the same string instead of calling the resolver.Suggested test hardening
it("creates terminal with PAGER set appropriately for platform", () => { TerminalRegistry.createTerminal("/test/path", "vscode") + expect(shellUtils.getShell).toHaveBeenCalledTimes(1) expect(mockCreateTerminal).toHaveBeenCalledWith({ cwd: "/test/path", name: "Roo Code", iconPath: expect.objectContaining({ id: expect.any(String) }), env: { PAGER, ROO_ACTIVE: "true", VTE_VERSION: "0", PROMPT_EOL_MARK: "", }, shellPath: "/mock/fallback-shell", }) })Also applies to: 60-61, 83-84, 107-108, 130-131
🤖 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/integrations/terminal/__tests__/TerminalRegistry.spec.ts` around lines 39 - 40, Add assertions that the shell resolver is actually invoked: after each vi.spyOn(shellUtils, "getShell").mockReturnValue("/mock/fallback-shell") in the TerminalRegistry.spec tests, add expect(shellUtils.getShell).toHaveBeenCalled() (or toHaveBeenCalledTimes(1)) to ensure production code calls shellUtils.getShell rather than hardcoding the path; apply this to the occurrences around the tests that set up mocked shells (the blocks using vi.spyOn(shellUtils, "getShell") and asserting shellPath).
🤖 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.
Nitpick comments:
In `@src/integrations/terminal/__tests__/TerminalRegistry.spec.ts`:
- Around line 39-40: Add assertions that the shell resolver is actually invoked:
after each vi.spyOn(shellUtils,
"getShell").mockReturnValue("/mock/fallback-shell") in the TerminalRegistry.spec
tests, add expect(shellUtils.getShell).toHaveBeenCalled() (or
toHaveBeenCalledTimes(1)) to ensure production code calls shellUtils.getShell
rather than hardcoding the path; apply this to the occurrences around the tests
that set up mocked shells (the blocks using vi.spyOn(shellUtils, "getShell") and
asserting shellPath).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 11da761d-d24d-4448-bec2-2eb4363d25fa
📒 Files selected for processing (1)
src/integrations/terminal/__tests__/TerminalRegistry.spec.ts
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Related GitHub Issue
Closes: #321
Description
Zoo Code correctly detects the user's configured default shell (e.g., PowerShell) and tells the AI to generate commands using that shell's syntax, but the Inline Terminal actually executed commands in
cmd.exe. This caused:Write-Host) to fail with "not recognized" errorscmd.exeencodes output using the system codepage (e.g., CP936 for zh-CN) rather than UTF-8, making characters unreadable. Running commands in the user's configured shell (PowerShell) makes it easier and safer to configure UTF-8 encoding, though explicit configuration may still be needed.This PR connects the existing
getShell()function to both terminal creation paths so the detected shell flows through to execution.Core changes (2 files):
ExecaTerminalProcess.ts — Changed
shell: truetoshell: getShell(). The detected shell from VSCode'sterminal.integrated.defaultProfileis now passed to execa subprocess execution.Terminal.ts — Added
shellPath: getShell()tovscode.window.createTerminal(). Also addediconPath: new vscode.ThemeIcon("rocket")for terminal icon consistency.Test updates (2 files — assertions to match the new behavior):
ExecaTerminalProcess.spec.ts — Assertions updated from
shell: truetoshell: "/mock/fallback-shell"usingvitest.spyOnpattern.TerminalRegistry.spec.ts — Assertions updated to include the new
shellPathparameter and correctediconPathmatching forThemeIconinstances.Key design decision:
getShell()already validates against a built-in allowlist of ~80 approved shell paths and falls back to a safe default. No additional validation layer was needed at the call sites.Roadmap alignment: Reliability First — "Guarantee smooth operation across all locales and platforms."
Test Procedure
Unit tests:
Type checking:
Manual verification (Windows with PowerShell configured):
Prerequisites: PowerShell configured with UTF-8 encoding.
Write-Host "test"in Zoo Code Inline Terminal'Write-Host' is not recognized as an internal or external commandtestecho "中文测试"in Zoo Code Inline Terminal中文测试(PowerShell with UTF-8 configured)Pre-Submission Checklist
Screenshots / Video
N/A — backend fix with no visible UI changes.
Documentation Updates
The shell integration docs need the following updates:
terminal.integrated.defaultProfilesetting, rather than always defaulting tocmd.exe(Windows) orsh(Unix)cmd.exeencodes output using the system codepage rather than UTF-8. Running in the configured shell (e.g., PowerShell) enables easier UTF-8 configuration, though explicit setup is still required.These updates will ensure the documentation accurately describes the current behavior rather than the pre-fix state.
Additional Notes
None.
Get in Touch
Discord: Yon (yon.sinc)
Summary by CodeRabbit