@@ -45,6 +45,11 @@ function makeProcess(output: string): ChildProcessSpawner.ChildProcessHandle {
4545 } ) ;
4646}
4747
48+ function standardCommand ( command : ChildProcess . Command ) : ChildProcess . StandardCommand {
49+ assert . equal ( command . _tag , "StandardCommand" ) ;
50+ return command as ChildProcess . StandardCommand ;
51+ }
52+
4853function withProcessEnv < A , E , R > (
4954 env : NodeJS . ProcessEnv ,
5055 effect : Effect . Effect < A , E , R > ,
@@ -173,6 +178,60 @@ describe("DesktopShellEnvironment", () => {
173178 } ) ,
174179 ) ;
175180
181+ it . effect ( "marks POSIX login shell probes and supplies TERM=dumb when TERM is absent" , ( ) =>
182+ Effect . gen ( function * ( ) {
183+ const env : NodeJS . ProcessEnv = {
184+ SHELL : "/bin/zsh" ,
185+ PATH : "/usr/bin" ,
186+ } ;
187+ const commands : ChildProcess . Command [ ] = [ ] ;
188+
189+ yield * runShellEnvironment ( {
190+ env,
191+ platform : "linux" ,
192+ handler : ( command ) => {
193+ commands . push ( command ) ;
194+ return envOutput ( { PATH : "/usr/local/bin:/usr/bin" } ) ;
195+ } ,
196+ } ) ;
197+
198+ const command = standardCommand ( commands [ 0 ] as ChildProcess . Command ) ;
199+ assert . deepInclude ( command . args , "-ilc" ) ;
200+ assert . equal ( command . options . extendEnv , true ) ;
201+ assert . deepEqual ( command . options . env , {
202+ T3CODE_RESOLVING_ENVIRONMENT : "1" ,
203+ TERM : "dumb" ,
204+ } ) ;
205+ } ) ,
206+ ) ;
207+
208+ it . effect ( "preserves inherited TERM for POSIX login shell probes" , ( ) =>
209+ Effect . gen ( function * ( ) {
210+ const env : NodeJS . ProcessEnv = {
211+ SHELL : "/bin/zsh" ,
212+ PATH : "/usr/bin" ,
213+ TERM : "xterm-256color" ,
214+ } ;
215+ const commands : ChildProcess . Command [ ] = [ ] ;
216+
217+ yield * runShellEnvironment ( {
218+ env,
219+ platform : "darwin" ,
220+ handler : ( command ) => {
221+ commands . push ( command ) ;
222+ return envOutput ( { PATH : "/opt/homebrew/bin:/usr/bin" } ) ;
223+ } ,
224+ } ) ;
225+
226+ const command = standardCommand ( commands [ 0 ] as ChildProcess . Command ) ;
227+ assert . equal ( command . options . extendEnv , true ) ;
228+ assert . deepEqual ( command . options . env , {
229+ T3CODE_RESOLVING_ENVIRONMENT : "1" ,
230+ TERM : "xterm-256color" ,
231+ } ) ;
232+ } ) ,
233+ ) ;
234+
176235 it . effect ( "falls back to launchctl PATH on macOS when shell probing does not return one" , ( ) =>
177236 Effect . gen ( function * ( ) {
178237 const env : NodeJS . ProcessEnv = {
@@ -243,6 +302,31 @@ describe("DesktopShellEnvironment", () => {
243302 } ) ,
244303 ) ;
245304
305+ it . effect ( "does not add POSIX probe env to Windows PowerShell probes" , ( ) =>
306+ Effect . gen ( function * ( ) {
307+ const env : NodeJS . ProcessEnv = {
308+ PATH : "C:\\Windows\\System32" ,
309+ } ;
310+ const commands : ChildProcess . Command [ ] = [ ] ;
311+
312+ yield * runShellEnvironment ( {
313+ env,
314+ platform : "win32" ,
315+ handler : ( command ) => {
316+ commands . push ( command ) ;
317+ return envOutput ( { PATH : "C:\\Windows\\System32" } ) ;
318+ } ,
319+ } ) ;
320+
321+ assert . isAtLeast ( commands . length , 1 ) ;
322+ for ( const command of commands ) {
323+ const standard = standardCommand ( command ) ;
324+ assert . isUndefined ( standard . options . env ) ;
325+ assert . isUndefined ( standard . options . extendEnv ) ;
326+ }
327+ } ) ,
328+ ) ;
329+
246330 it . effect ( "logs command failures with safe probe context and the exact cause" , ( ) => {
247331 const env : NodeJS . ProcessEnv = {
248332 SHELL : "/bin/bash" ,
0 commit comments