@@ -170,22 +170,26 @@ test("buildContainerEnvFile falls back to the host GH token on WSL2", async () =
170170 const sandboxCreate = await loadFreshEsm < SandboxCreateModule > ( "lib/sandbox/commands/create.js" ) ;
171171 const tmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "agent-infra-env-file-wsl2-token-" ) ) ;
172172 const calls : string [ ] = [ ] ;
173+ let hostEnvDir = "" ;
173174
174175 try {
175176 const envFile = sandboxCreate . buildContainerEnvFile ( [ ] , "wsl2" , ( engine , cmd , args ) => {
176177 calls . push ( `${ engine } :${ cmd } :${ args . join ( " " ) } ` ) ;
177178 return "" ;
178179 } , {
179180 tmpDir,
181+ mkdtempFn : ( prefix : string ) => {
182+ hostEnvDir = fs . mkdtempSync ( prefix ) ;
183+ return hostEnvDir ;
184+ } ,
180185 runSafeFn : ( cmd : string , args : string [ ] ) => {
181186 calls . push ( `host:${ cmd } :${ args . join ( " " ) } ` ) ;
182187 return "ghp_host_token" ;
183188 }
184189 } ) ;
185- const envPath = required ( envFile . dockerArgs [ 1 ] ) ;
186190
187191 assert . deepEqual ( calls , [ "wsl2:gh:auth token" , "host:gh:auth token" ] ) ;
188- assert . equal ( fs . readFileSync ( envPath , "utf8" ) , "GH_TOKEN=ghp_host_token\n" ) ;
192+ assert . equal ( fs . readFileSync ( path . join ( hostEnvDir , "env" ) , "utf8" ) , "GH_TOKEN=ghp_host_token\n" ) ;
189193 assert . ok ( ! envFile . dockerArgs . some ( ( arg ) => arg . includes ( "ghp_host_token" ) ) ) ;
190194 } finally {
191195 fs . rmSync ( tmpDir , { recursive : true , force : true } ) ;
@@ -195,17 +199,21 @@ test("buildContainerEnvFile falls back to the host GH token on WSL2", async () =
195199test ( "buildContainerEnvFile keeps the WSL2 engine token as the preferred result" , async ( ) => {
196200 const sandboxCreate = await loadFreshEsm < SandboxCreateModule > ( "lib/sandbox/commands/create.js" ) ;
197201 const tmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "agent-infra-env-file-wsl2-preferred-" ) ) ;
202+ let hostEnvDir = "" ;
198203
199204 try {
200205 const envFile = sandboxCreate . buildContainerEnvFile ( [ ] , "wsl2" , ( ) => "ghp_engine_token" , {
201206 tmpDir,
207+ mkdtempFn : ( prefix : string ) => {
208+ hostEnvDir = fs . mkdtempSync ( prefix ) ;
209+ return hostEnvDir ;
210+ } ,
202211 runSafeFn : ( ) => {
203212 throw new Error ( "host fallback must not run" ) ;
204213 }
205214 } ) ;
206- const envPath = required ( envFile . dockerArgs [ 1 ] ) ;
207215
208- assert . equal ( fs . readFileSync ( envPath , "utf8" ) , "GH_TOKEN=ghp_engine_token\n" ) ;
216+ assert . equal ( fs . readFileSync ( path . join ( hostEnvDir , "env" ) , "utf8" ) , "GH_TOKEN=ghp_engine_token\n" ) ;
209217 } finally {
210218 fs . rmSync ( tmpDir , { recursive : true , force : true } ) ;
211219 }
0 commit comments