fix(codex): harden model discovery fallback

This commit is contained in:
weishu
2026-08-09 09:04:28 +08:00
parent 3da9f7780a
commit cde0507bad
17 changed files with 387 additions and 8 deletions
@@ -0,0 +1,64 @@
import { EventEmitter } from 'node:events';
import { beforeEach, describe, expect, it, vi } from 'vitest';
const { execFileSyncMock, spawnMock } = vi.hoisted(() => ({
execFileSyncMock: vi.fn(() => 'codex-cli 1.0.0'),
spawnMock: vi.fn()
}));
vi.mock('node:child_process', async () => {
const actual = await vi.importActual<typeof import('node:child_process')>('node:child_process');
return {
...actual,
execFileSync: execFileSyncMock,
spawn: spawnMock
};
});
vi.mock('node:fs', async () => {
const actual = await vi.importActual<typeof import('node:fs')>('node:fs');
return { ...actual, existsSync: vi.fn(() => false) };
});
vi.mock('@/utils/process', () => ({
killProcessByChildProcess: vi.fn(async () => true)
}));
vi.mock('@/ui/logger', () => ({
logger: { debug: vi.fn() }
}));
import { CodexAppServerClient } from './codexAppServerClient';
function fakeStream(): EventEmitter & { setEncoding: ReturnType<typeof vi.fn> } {
return Object.assign(new EventEmitter(), { setEncoding: vi.fn() });
}
function fakeChild() {
return Object.assign(new EventEmitter(), {
stdin: { end: vi.fn(), write: vi.fn() },
stdout: fakeStream(),
stderr: fakeStream()
});
}
describe('CodexAppServerClient process cwd', () => {
beforeEach(() => {
execFileSyncMock.mockClear();
spawnMock.mockReset();
});
it('passes an explicit neutral cwd to the app-server process', async () => {
spawnMock.mockReturnValue(fakeChild());
const client = new CodexAppServerClient({ cwd: '/neutral-home' });
await client.connect();
expect(spawnMock).toHaveBeenCalledWith(
'codex',
['app-server'],
expect.objectContaining({ cwd: '/neutral-home' })
);
await client.disconnect();
});
});