@@ -58,19 +58,42 @@ const recordCommandTrace = Effect.fnUntraced(function* <A, E, R>(effect: Effect.
5858} ) ;
5959
6060describe ( "readEnvironmentFromLoginShell probe" , ( ) => {
61- it . each ( [ "/bin/bash" , "/opt/homebrew/bin/fish" ] ) (
62- "captures PATH with a noninteractive login probe for %s" ,
63- ( shell ) => {
64- const execFile = vi . fn ( ( ) => "__T3CODE_ENV_PATH_START__\n/a:/b\n__T3CODE_ENV_PATH_END__\n" ) ;
65-
66- expect ( readEnvironmentFromLoginShell ( shell , [ "PATH" ] , execFile ) ) . toEqual ( { PATH : "/a:/b" } ) ;
67- expect ( execFile ) . toHaveBeenCalledExactlyOnceWith (
68- shell ,
69- [ "-lc" , expect . stringContaining ( "printenv PATH || true" ) ] ,
70- { encoding : "utf8" , timeout : 5000 } ,
71- ) ;
72- } ,
73- ) ;
61+ it ( "uses a shell-agnostic printenv PATH probe" , ( ) => {
62+ const execFile = vi . fn <
63+ (
64+ file : string ,
65+ args : ReadonlyArray < string > ,
66+ options : { encoding : "utf8" ; timeout : number } ,
67+ ) => string
68+ > ( ( ) => "__T3CODE_ENV_PATH_START__\n/a:/b\n__T3CODE_ENV_PATH_END__\n" ) ;
69+
70+ expect ( readEnvironmentFromLoginShell ( "/opt/homebrew/bin/fish" , [ "PATH" ] , execFile ) . PATH ) . toBe (
71+ "/a:/b" ,
72+ ) ;
73+ expect ( execFile ) . toHaveBeenCalledTimes ( 1 ) ;
74+
75+ const firstCall = execFile . mock . calls [ 0 ] as
76+ | [ string , ReadonlyArray < string > , { encoding : "utf8" ; timeout : number } ]
77+ | undefined ;
78+ expect ( firstCall ) . toBeDefined ( ) ;
79+ if ( ! firstCall ) {
80+ throw new Error ( "Expected execFile to be called" ) ;
81+ }
82+
83+ const [ shell , args , options ] = firstCall ;
84+ expect ( shell ) . toBe ( "/opt/homebrew/bin/fish" ) ;
85+ expect ( args ) . toHaveLength ( 2 ) ;
86+ expect ( args ?. [ 0 ] ) . toBe ( "-ilc" ) ;
87+ expect ( args ?. [ 1 ] ) . toContain ( "printenv PATH || true" ) ;
88+ expect ( args ?. [ 1 ] ) . toContain ( "__T3CODE_ENV_PATH_START__" ) ;
89+ expect ( args ?. [ 1 ] ) . toContain ( "__T3CODE_ENV_PATH_END__" ) ;
90+ expect ( options ) . toEqual ( {
91+ encoding : "utf8" ,
92+ timeout : 5000 ,
93+ detached : true ,
94+ stdio : [ "ignore" , "pipe" , "ignore" ] ,
95+ } ) ;
96+ } ) ;
7497} ) ;
7598
7699describe ( "readPathFromLaunchctl" , ( ) => {
@@ -106,7 +129,7 @@ describe("readPathFromLaunchctl", () => {
106129} ) ;
107130
108131describe ( "readEnvironmentFromLoginShell" , ( ) => {
109- it ( "captures zsh environment interactively with job control disabled " , ( ) => {
132+ it ( "extracts multiple environment variables from a login shell command " , ( ) => {
110133 const execFile = vi . fn <
111134 (
112135 file : string ,
@@ -128,11 +151,7 @@ describe("readEnvironmentFromLoginShell", () => {
128151 PATH : "/a:/b" ,
129152 SSH_AUTH_SOCK : "/tmp/secretive.sock" ,
130153 } ) ;
131- expect ( execFile ) . toHaveBeenCalledExactlyOnceWith (
132- "/bin/zsh" ,
133- [ "+m" , "-ilc" , expect . stringContaining ( "printenv SSH_AUTH_SOCK || true" ) ] ,
134- { encoding : "utf8" , timeout : 5000 } ,
135- ) ;
154+ expect ( execFile ) . toHaveBeenCalledTimes ( 1 ) ;
136155 } ) ;
137156
138157 it ( "omits environment variables that are missing or empty" , ( ) => {
0 commit comments