@@ -3,6 +3,8 @@ import * as vscode from "vscode"
33import { existsSync } from "fs"
44import { userInfo } from "os"
55import { getShell } from "../shell"
6+ import { BaseTerminal } from "../../integrations/terminal/BaseTerminal"
7+ import { Terminal } from "../../integrations/terminal/Terminal"
68
79vi . mock ( "vscode" , ( ) => ( {
810 workspace : {
@@ -77,12 +79,17 @@ describe("Shell Detection Tests", () => {
7779 vi . mocked ( userInfo ) . mockReturnValue ( { shell : null } as any )
7880 // Default: PowerShell 7 is not installed, so the probe falls back to legacy.
7981 vi . mocked ( existsSync ) . mockReturnValue ( false )
82+ // Clear Zoo profile override and execa shell path between tests.
83+ Terminal . setTerminalProfile ( undefined )
84+ BaseTerminal . setExecaShellPath ( undefined )
8085 } )
8186
8287 afterEach ( ( ) => {
8388 Object . defineProperty ( process , "platform" , { value : originalPlatform } )
8489 process . env = originalEnv
8590 vscode . workspace . getConfiguration = originalGetConfig
91+ Terminal . setTerminalProfile ( undefined )
92+ BaseTerminal . setExecaShellPath ( undefined )
8693 vi . clearAllMocks ( )
8794 } )
8895
@@ -515,4 +522,77 @@ describe("Shell Detection Tests", () => {
515522 expect ( getShell ( ) ) . toBe ( "/bin/bash" )
516523 } )
517524 } )
525+
526+ // --------------------------------------------------------------------------
527+ // Zoo profile override (Terminal.getProfileShell) takes precedence
528+ // --------------------------------------------------------------------------
529+ describe ( "Zoo profile override" , ( ) => {
530+ it ( "uses Zoo profile shell over VS Code default profile" , ( ) => {
531+ Object . defineProperty ( process , "platform" , { value : "win32" } )
532+ // VS Code default profile is PowerShell
533+ vi . mocked ( existsSync ) . mockReturnValue ( true )
534+ mockVsCodeConfig ( "windows" , "PowerShell" , {
535+ PowerShell : { path : "C:\\Program Files\\PowerShell\\7\\pwsh.exe" } ,
536+ } )
537+ // Zoo profile override points to Git Bash
538+ Terminal . setTerminalProfile ( "Git Bash" )
539+ vi . spyOn ( Terminal , "getProfileShell" ) . mockReturnValue ( {
540+ shellPath : "C:\\Program Files\\Git\\bin\\bash.exe" ,
541+ } )
542+ expect ( getShell ( ) ) . toBe ( "C:\\Program Files\\Git\\bin\\bash.exe" )
543+ } )
544+
545+ it ( "falls through to VS Code default when Zoo profile has no resolvable shell" , ( ) => {
546+ Object . defineProperty ( process , "platform" , { value : "win32" } )
547+ vi . mocked ( existsSync ) . mockImplementation ( ( p ) => String ( p ) === "C:\\Program Files\\PowerShell\\7\\pwsh.exe" )
548+ mockVsCodeConfig ( "windows" , "PowerShell" , {
549+ PowerShell : { path : "C:\\Program Files\\PowerShell\\7\\pwsh.exe" } ,
550+ } )
551+ Terminal . setTerminalProfile ( "Unresolvable" )
552+ vi . spyOn ( Terminal , "getProfileShell" ) . mockReturnValue ( undefined )
553+ expect ( getShell ( ) ) . toBe ( "C:\\Program Files\\PowerShell\\7\\pwsh.exe" )
554+ } )
555+ } )
556+
557+ // --------------------------------------------------------------------------
558+ // Explicit execa shell path takes highest precedence
559+ // --------------------------------------------------------------------------
560+ describe ( "Execa shell path override" , ( ) => {
561+ it ( "uses explicit execa shell path over VS Code config" , ( ) => {
562+ Object . defineProperty ( process , "platform" , { value : "win32" } )
563+ vi . mocked ( existsSync ) . mockReturnValue ( true )
564+ mockVsCodeConfig ( "windows" , "PowerShell" , {
565+ PowerShell : { path : "C:\\Program Files\\PowerShell\\7\\pwsh.exe" } ,
566+ } )
567+ BaseTerminal . setExecaShellPath ( "C:\\Program Files\\Git\\bin\\bash.exe" )
568+ expect ( getShell ( ) ) . toBe ( "C:\\Program Files\\Git\\bin\\bash.exe" )
569+ } )
570+
571+ it ( "uses explicit execa shell path over Zoo profile override" , ( ) => {
572+ Object . defineProperty ( process , "platform" , { value : "linux" } )
573+ mockVsCodeConfig ( "linux" , null , { } )
574+ Terminal . setTerminalProfile ( "fish" )
575+ vi . spyOn ( Terminal , "getProfileShell" ) . mockReturnValue ( {
576+ shellPath : "/usr/bin/fish" ,
577+ } )
578+ BaseTerminal . setExecaShellPath ( "/bin/zsh" )
579+ expect ( getShell ( ) ) . toBe ( "/bin/zsh" )
580+ } )
581+
582+ it ( "falls through to VS Code config when execa shell path is not set" , ( ) => {
583+ Object . defineProperty ( process , "platform" , { value : "linux" } )
584+ vi . mocked ( existsSync ) . mockImplementation ( ( p ) => String ( p ) === "/usr/bin/fish" )
585+ mockVsCodeConfig ( "linux" , "fish" , {
586+ fish : { path : "/usr/bin/fish" } ,
587+ } )
588+ expect ( getShell ( ) ) . toBe ( "/usr/bin/fish" )
589+ } )
590+
591+ it ( "rejects non-allowlisted execa shell path and uses fallback" , ( ) => {
592+ Object . defineProperty ( process , "platform" , { value : "linux" } )
593+ mockVsCodeConfig ( "linux" , null , { } )
594+ BaseTerminal . setExecaShellPath ( "/opt/evil/shell" )
595+ expect ( getShell ( ) ) . toBe ( "/bin/bash" )
596+ } )
597+ } )
518598} )
0 commit comments