mirror of
https://github.com/wu736139669/hapi.git
synced 2026-10-13 20:09:55 +00:00
fix(codex): harden model discovery fallback
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user