@@ -25,10 +25,13 @@ test("Codex process resolves command overrides and escaped Windows launchers", (
2525 assert . equal ( codexProcessCommand ( { } ) , "codex" ) ;
2626 assert . equal ( codexProcessCommand ( { CODEX_BIN : " custom-codex " } ) , "custom-codex" ) ;
2727 assert . equal (
28- codexProcessCommand ( {
29- CODEX_BIN : "custom-codex" ,
30- CLAWSWEEPER_PREFER_WINDOWS_CODEX_APP : "1" ,
31- } ) ,
28+ codexProcessCommand (
29+ {
30+ CODEX_BIN : "custom-codex" ,
31+ CLAWSWEEPER_PREFER_WINDOWS_CODEX_APP : "1" ,
32+ } ,
33+ "win32" ,
34+ ) ,
3235 "custom-codex" ,
3336 ) ;
3437 assert . deepEqual ( codexSpawnInvocation ( [ "exec" , "-" ] , { CODEX_BIN : "codex" } , "linux" ) , {
@@ -52,6 +55,7 @@ test("Codex process resolves command overrides and escaped Windows launchers", (
5255 const root = mkdtempSync ( tmpPrefix ) ;
5356 const binDir = join ( root , "bin" ) ;
5457 mkdirSync ( binDir ) ;
58+ writeFileSync ( join ( binDir , "codex" ) , "#!/bin/sh\r\n" ) ;
5559 writeFileSync ( join ( binDir , "codex.cmd" ) , "@echo off\r\n" ) ;
5660 try {
5761 const invocation = codexSpawnInvocation (
@@ -81,6 +85,74 @@ test("Codex process resolves command overrides and escaped Windows launchers", (
8185 ) ;
8286} ) ;
8387
88+ test ( "Windows Codex selection prefers PATH and falls back to the Desktop app" , ( ) => {
89+ const root = mkdtempSync ( tmpPrefix ) ;
90+ const pathBin = join ( root , "path-bin" ) ;
91+ const unsupportedBin = join ( root , "unsupported-bin" ) ;
92+ const fallbackPathBin = join ( root , "fallback-path-bin" ) ;
93+ const localAppData = join ( root , "local-app-data" ) ;
94+ const desktopCodex = join ( localAppData , "OpenAI" , "Codex" , "bin" , "codex.exe" ) ;
95+ mkdirSync ( pathBin ) ;
96+ mkdirSync ( unsupportedBin ) ;
97+ mkdirSync ( fallbackPathBin ) ;
98+ mkdirSync ( join ( localAppData , "OpenAI" , "Codex" , "bin" ) , { recursive : true } ) ;
99+ writeFileSync ( join ( pathBin , "codex.exe" ) , "" ) ;
100+ writeFileSync ( join ( unsupportedBin , "codex" ) , "#!/bin/sh\r\n" ) ;
101+ writeFileSync ( join ( fallbackPathBin , "codex.exe" ) , "" ) ;
102+ writeFileSync ( desktopCodex , "" ) ;
103+ try {
104+ const pathEnv = {
105+ LOCALAPPDATA : localAppData ,
106+ Path : pathBin ,
107+ PATHEXT : ".EXE" ,
108+ SystemRoot : String . raw `C:\Windows` ,
109+ } ;
110+ const pathInvocation = codexSpawnInvocation ( [ "exec" ] , pathEnv , "win32" , root ) ;
111+ assert . equal ( pathInvocation . command , join ( pathBin , "codex.exe" ) ) ;
112+
113+ const desktopEnv = { ...pathEnv , Path : "" } ;
114+ assert . equal ( codexProcessCommand ( desktopEnv , "win32" , root ) , desktopCodex ) ;
115+ const desktopInvocation = codexSpawnInvocation ( [ "exec" ] , desktopEnv , "win32" , root ) ;
116+ assert . equal ( desktopInvocation . command , desktopCodex ) ;
117+
118+ const unsupportedEnv = { ...pathEnv , Path : unsupportedBin } ;
119+ assert . equal ( codexProcessCommand ( unsupportedEnv , "win32" , root ) , desktopCodex ) ;
120+ const unsupportedInvocation = codexSpawnInvocation ( [ "exec" ] , unsupportedEnv , "win32" , root ) ;
121+ assert . equal ( unsupportedInvocation . command , desktopCodex ) ;
122+
123+ const laterPathEnv = { ...pathEnv , Path : `${ unsupportedBin } ${ delimiter } ${ fallbackPathBin } ` } ;
124+ const laterPathInvocation = codexSpawnInvocation ( [ "exec" ] , laterPathEnv , "win32" , root ) ;
125+ assert . equal ( laterPathInvocation . command , join ( fallbackPathBin , "codex.exe" ) ) ;
126+ } finally {
127+ rmSync ( root , { recursive : true , force : true } ) ;
128+ }
129+ } ) ;
130+
131+ test ( "Windows Codex selection resolves relative PATH entries from the launch cwd" , ( ) => {
132+ const root = mkdtempSync ( tmpPrefix ) ;
133+ const launcherDir = join ( root , "launcher" ) ;
134+ const targetDir = join ( root , "target" ) ;
135+ const localAppData = join ( root , "local-app-data" ) ;
136+ const desktopCodex = join ( localAppData , "OpenAI" , "Codex" , "bin" , "codex.exe" ) ;
137+ mkdirSync ( launcherDir ) ;
138+ mkdirSync ( join ( targetDir , "bin" ) , { recursive : true } ) ;
139+ mkdirSync ( join ( localAppData , "OpenAI" , "Codex" , "bin" ) , { recursive : true } ) ;
140+ writeFileSync ( join ( targetDir , "bin" , "codex.exe" ) , "" ) ;
141+ writeFileSync ( desktopCodex , "" ) ;
142+ try {
143+ const env = {
144+ LOCALAPPDATA : localAppData ,
145+ Path : "bin" ,
146+ PATHEXT : ".EXE" ,
147+ SystemRoot : String . raw `C:\Windows` ,
148+ } ;
149+ assert . equal ( codexProcessCommand ( env , "win32" , launcherDir ) , desktopCodex ) ;
150+ assert . equal ( codexProcessCommand ( env , "win32" , targetDir ) , "codex" ) ;
151+ } finally {
152+ rmSync ( root , { recursive : true , force : true } ) ;
153+ }
154+ } ) ;
155+
84156test ( "Codex process resolves extensionless Windows node shebang shims" , ( ) => {
85157 const root = mkdtempSync ( tmpPrefix ) ;
86158 const binDir = join ( root , "bin" ) ;
0 commit comments