mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 18:18:43 +00:00
fix(codex): probe Windows cmd wrappers via cmd shell
This commit is contained in:
committed by
Kai (Tam Nhu) Tran
parent
eaa37c749e
commit
210ec33c04
@@ -53,12 +53,14 @@ function runCodexProbe(codexPath: string, args: string[]): string | undefined {
|
|||||||
|
|
||||||
if (needsShell) {
|
if (needsShell) {
|
||||||
const cmdString = [codexPath, ...args].map(escapeShellArg).join(' ');
|
const cmdString = [codexPath, ...args].map(escapeShellArg).join(' ');
|
||||||
return childProcess.execFileSync('cmd.exe', ['/d', '/s', '/c', cmdString], {
|
const result = childProcess.spawnSync(cmdString, {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
stdio: ['ignore', 'pipe', 'ignore'],
|
stdio: ['ignore', 'pipe', 'ignore'],
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
windowsHide: true,
|
windowsHide: true,
|
||||||
|
shell: 'cmd.exe',
|
||||||
});
|
});
|
||||||
|
return result.status === 0 ? result.stdout : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return childProcess.execFileSync(codexPath, args, {
|
return childProcess.execFileSync(codexPath, args, {
|
||||||
|
|||||||
@@ -58,19 +58,35 @@ describe('codex-detector', () => {
|
|||||||
process.env.CCS_CODEX_PATH = fakeCodex;
|
process.env.CCS_CODEX_PATH = fakeCodex;
|
||||||
Object.defineProperty(process, 'platform', { value: 'win32' });
|
Object.defineProperty(process, 'platform', { value: 'win32' });
|
||||||
|
|
||||||
const execFileSyncSpy = spyOn(childProcess, 'execFileSync').mockImplementation((command, args) => {
|
const spawnSyncSpy = spyOn(childProcess, 'spawnSync').mockImplementation((command) => {
|
||||||
return String(command).includes('cmd.exe') && Array.isArray(args) && args.join(' ').includes('--help')
|
const commandString = String(command);
|
||||||
? 'Codex CLI\n -c, --config <key=value>\n'
|
return {
|
||||||
: 'codex-cli 0.118.0-alpha.3';
|
pid: 123,
|
||||||
|
output: ['', '', ''],
|
||||||
|
stdout: commandString.includes('--help')
|
||||||
|
? 'Codex CLI\n -c, --config <key=value>\n'
|
||||||
|
: 'codex-cli 0.118.0-alpha.3',
|
||||||
|
stderr: '',
|
||||||
|
status: 0,
|
||||||
|
signal: null,
|
||||||
|
} as unknown as ReturnType<typeof childProcess.spawnSync>;
|
||||||
});
|
});
|
||||||
|
|
||||||
const info = getCodexBinaryInfo();
|
const info = getCodexBinaryInfo();
|
||||||
|
const calls = spawnSyncSpy.mock.calls;
|
||||||
|
const cmdWrapperProbeCall = calls.find(([command]) => {
|
||||||
|
return String(command).includes(fakeCodex);
|
||||||
|
});
|
||||||
|
|
||||||
expect(execFileSyncSpy).toHaveBeenCalled();
|
expect(spawnSyncSpy).toHaveBeenCalled();
|
||||||
|
expect(cmdWrapperProbeCall).toBeDefined();
|
||||||
|
expect((cmdWrapperProbeCall?.[1] as Record<string, unknown> | undefined)?.shell).toBe(
|
||||||
|
'cmd.exe'
|
||||||
|
);
|
||||||
expect(info?.needsShell).toBe(true);
|
expect(info?.needsShell).toBe(true);
|
||||||
expect(info?.features).toContain('config-overrides');
|
expect(info?.features).toContain('config-overrides');
|
||||||
|
|
||||||
execFileSyncSpy.mockRestore();
|
spawnSyncSpy.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('keeps the cmd wrapper when Windows PATH exposes codex.cmd and a sibling ps1 also exists', () => {
|
it('keeps the cmd wrapper when Windows PATH exposes codex.cmd and a sibling ps1 also exists', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user