@@ -521,6 +521,34 @@ describe("Shell Detection Tests", () => {
521521 expect ( getShell ( ) ) . toBe ( "/bin/zsh" )
522522 } )
523523
524+ it ( "macOS: handles boolean defaultProfileName without TypeError" , ( ) => {
525+ Object . defineProperty ( process , "platform" , { value : "darwin" } )
526+ const mockConfig = {
527+ get : vi . fn ( ( key : string ) => {
528+ if ( key === "defaultProfile.osx" ) return true
529+ if ( key === "profiles.osx" ) return { }
530+ return undefined
531+ } ) ,
532+ }
533+ vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue ( mockConfig as any )
534+
535+ expect ( getShell ( ) ) . toBe ( "/bin/zsh" )
536+ } )
537+
538+ it ( "macOS: handles array defaultProfileName without TypeError" , ( ) => {
539+ Object . defineProperty ( process , "platform" , { value : "darwin" } )
540+ const mockConfig = {
541+ get : vi . fn ( ( key : string ) => {
542+ if ( key === "defaultProfile.osx" ) return [ "zsh" ]
543+ if ( key === "profiles.osx" ) return { }
544+ return undefined
545+ } ) ,
546+ }
547+ vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue ( mockConfig as any )
548+
549+ expect ( getShell ( ) ) . toBe ( "/bin/zsh" )
550+ } )
551+
524552 it ( "macOS: handles object defaultProfileName without TypeError" , ( ) => {
525553 Object . defineProperty ( process , "platform" , { value : "darwin" } )
526554 const mockConfig = {
@@ -535,6 +563,25 @@ describe("Shell Detection Tests", () => {
535563 expect ( getShell ( ) ) . toBe ( "/bin/zsh" )
536564 } )
537565
566+ // Mutation-resistant: without the typeof guard, profiles[1] === profiles["1"] in JS,
567+ // so a numeric key that matches a real profile would return its path instead of falling back.
568+ it ( "macOS: ignores numeric defaultProfileName even when it matches a profile key" , ( ) => {
569+ Object . defineProperty ( process , "platform" , { value : "darwin" } )
570+ const mockConfig = {
571+ get : vi . fn ( ( key : string ) => {
572+ if ( key === "defaultProfile.osx" ) return 1
573+ // Profile keyed as "1" — would be reached by profiles[1] if the guard were absent
574+ if ( key === "profiles.osx" ) return { "1" : { path : "/usr/local/bin/zsh" } }
575+ return undefined
576+ } ) ,
577+ }
578+ vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue ( mockConfig as any )
579+
580+ // Guard treats 1 as null → getMacShellFromVSCode returns null → fallback to /bin/zsh
581+ // Without the guard it would return /usr/local/bin/zsh
582+ expect ( getShell ( ) ) . toBe ( "/bin/zsh" )
583+ } )
584+
538585 it ( "Linux: handles numeric defaultProfileName without TypeError" , ( ) => {
539586 Object . defineProperty ( process , "platform" , { value : "linux" } )
540587 const mockConfig = {
@@ -549,6 +596,34 @@ describe("Shell Detection Tests", () => {
549596 expect ( getShell ( ) ) . toBe ( "/bin/bash" )
550597 } )
551598
599+ it ( "Linux: handles boolean defaultProfileName without TypeError" , ( ) => {
600+ Object . defineProperty ( process , "platform" , { value : "linux" } )
601+ const mockConfig = {
602+ get : vi . fn ( ( key : string ) => {
603+ if ( key === "defaultProfile.linux" ) return true
604+ if ( key === "profiles.linux" ) return { }
605+ return undefined
606+ } ) ,
607+ }
608+ vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue ( mockConfig as any )
609+
610+ expect ( getShell ( ) ) . toBe ( "/bin/bash" )
611+ } )
612+
613+ it ( "Linux: handles array defaultProfileName without TypeError" , ( ) => {
614+ Object . defineProperty ( process , "platform" , { value : "linux" } )
615+ const mockConfig = {
616+ get : vi . fn ( ( key : string ) => {
617+ if ( key === "defaultProfile.linux" ) return [ "bash" ]
618+ if ( key === "profiles.linux" ) return { }
619+ return undefined
620+ } ) ,
621+ }
622+ vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue ( mockConfig as any )
623+
624+ expect ( getShell ( ) ) . toBe ( "/bin/bash" )
625+ } )
626+
552627 it ( "Linux: handles object defaultProfileName without TypeError" , ( ) => {
553628 Object . defineProperty ( process , "platform" , { value : "linux" } )
554629 const mockConfig = {
@@ -562,6 +637,24 @@ describe("Shell Detection Tests", () => {
562637
563638 expect ( getShell ( ) ) . toBe ( "/bin/bash" )
564639 } )
640+
641+ // Mutation-resistant: same pattern as macOS — numeric key matches profile "1" only if unguarded.
642+ it ( "Linux: ignores numeric defaultProfileName even when it matches a profile key" , ( ) => {
643+ Object . defineProperty ( process , "platform" , { value : "linux" } )
644+ const mockConfig = {
645+ get : vi . fn ( ( key : string ) => {
646+ if ( key === "defaultProfile.linux" ) return 1
647+ // Profile keyed as "1" — would be reached by profiles[1] if the guard were absent
648+ if ( key === "profiles.linux" ) return { "1" : { path : "/usr/bin/fish" } }
649+ return undefined
650+ } ) ,
651+ }
652+ vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue ( mockConfig as any )
653+
654+ // Guard treats 1 as null → getLinuxShellFromVSCode returns null → fallback to /bin/bash
655+ // Without the guard it would return /usr/bin/fish
656+ expect ( getShell ( ) ) . toBe ( "/bin/bash" )
657+ } )
565658 } )
566659
567660 // --------------------------------------------------------------------------
0 commit comments