fix(codex): prefer cmd wrappers over powershell on windows

- keep Windows Codex detection on the npm cmd shim when available

- add regression tests for cmd-first and ps1-to-cmd fallback selection
This commit is contained in:
Tam Nhu Tran
2026-04-14 17:35:30 -04:00
parent 9545499487
commit a94de010db
2 changed files with 34 additions and 11 deletions
+18 -9
View File
@@ -10,17 +10,26 @@ const CODEX_CONFIG_OVERRIDE_PROBE_ARGS = ['-c', 'model="gpt-5"', '--version'];
function buildWindowsCodexCandidates(matches: string[]): string[] {
const shellCandidates = matches.filter((entry) => /\.(exe|cmd|bat|ps1)$/i.test(entry));
const bareCandidates = matches.filter((entry) => !/\.(exe|cmd|bat|ps1)$/i.test(entry));
const prioritized: string[] = [];
for (const entry of shellCandidates) {
if (/\.(cmd|bat)$/i.test(entry)) {
prioritized.push(entry.replace(/\.(cmd|bat)$/i, '.ps1'));
const prioritized = shellCandidates.map((entry) => {
if (!/\.ps1$/i.test(entry)) {
return entry;
}
prioritized.push(entry);
}
prioritized.push(...bareCandidates);
return [...new Set(prioritized)];
for (const preferredExtension of ['.cmd', '.bat', '.exe']) {
const siblingCandidate = entry.replace(/\.ps1$/i, preferredExtension);
try {
if (fs.statSync(siblingCandidate).isFile()) {
return siblingCandidate;
}
} catch {
// Ignore missing sibling wrappers and keep the original PowerShell path.
}
}
return entry;
});
return [...new Set([...prioritized, ...bareCandidates])];
}
function runCodexProbe(codexPath: string, args: string[]): string | undefined {