diff --git a/extensions/codex/src/app-server/models.test.ts b/extensions/codex/src/app-server/models.test.ts index dae41e485c4..2af3aa5df76 100644 --- a/extensions/codex/src/app-server/models.test.ts +++ b/extensions/codex/src/app-server/models.test.ts @@ -1,37 +1,8 @@ -import { EventEmitter } from "node:events"; -import { PassThrough, Writable } from "node:stream"; import { afterEach, describe, expect, it, vi } from "vitest"; import { CodexAppServerClient } from "./client.js"; import { listCodexAppServerModels } from "./models.js"; import { resetSharedCodexAppServerClientForTests } from "./shared-client.js"; - -function createClientHarness() { - const stdout = new PassThrough(); - const writes: string[] = []; - const stdin = new Writable({ - write(chunk, _encoding, callback) { - writes.push(chunk.toString()); - callback(); - }, - }); - const process = Object.assign(new EventEmitter(), { - stdin, - stdout, - stderr: new PassThrough(), - killed: false, - kill: vi.fn(() => { - process.killed = true; - }), - }); - const client = CodexAppServerClient.fromTransportForTests(process); - return { - client, - writes, - send(message: unknown) { - stdout.write(`${JSON.stringify(message)}\n`); - }, - }; -} +import { createClientHarness } from "./test-support.js"; describe("listCodexAppServerModels", () => { afterEach(() => { diff --git a/extensions/codex/src/app-server/shared-client.test.ts b/extensions/codex/src/app-server/shared-client.test.ts index 3edee7b50a4..52fb552eeec 100644 --- a/extensions/codex/src/app-server/shared-client.test.ts +++ b/extensions/codex/src/app-server/shared-client.test.ts @@ -1,38 +1,8 @@ -import { EventEmitter } from "node:events"; -import { PassThrough, Writable } from "node:stream"; import { afterEach, describe, expect, it, vi } from "vitest"; import { CodexAppServerClient, MIN_CODEX_APP_SERVER_VERSION } from "./client.js"; import { listCodexAppServerModels } from "./models.js"; import { resetSharedCodexAppServerClientForTests } from "./shared-client.js"; - -function createClientHarness() { - const stdout = new PassThrough(); - const writes: string[] = []; - const stdin = new Writable({ - write(chunk, _encoding, callback) { - writes.push(chunk.toString()); - callback(); - }, - }); - const process = Object.assign(new EventEmitter(), { - stdin, - stdout, - stderr: new PassThrough(), - killed: false, - kill: vi.fn(() => { - process.killed = true; - }), - }); - const client = CodexAppServerClient.fromTransportForTests(process); - return { - client, - process, - writes, - send(message: unknown) { - stdout.write(`${JSON.stringify(message)}\n`); - }, - }; -} +import { createClientHarness } from "./test-support.js"; describe("shared Codex app-server client", () => { afterEach(() => { diff --git a/extensions/codex/src/app-server/test-support.ts b/extensions/codex/src/app-server/test-support.ts new file mode 100644 index 00000000000..acf3f47704b --- /dev/null +++ b/extensions/codex/src/app-server/test-support.ts @@ -0,0 +1,33 @@ +import { EventEmitter } from "node:events"; +import { PassThrough, Writable } from "node:stream"; +import { vi } from "vitest"; +import { CodexAppServerClient } from "./client.js"; + +export function createClientHarness() { + const stdout = new PassThrough(); + const writes: string[] = []; + const stdin = new Writable({ + write(chunk, _encoding, callback) { + writes.push(chunk.toString()); + callback(); + }, + }); + const process = Object.assign(new EventEmitter(), { + stdin, + stdout, + stderr: new PassThrough(), + killed: false, + kill: vi.fn(() => { + process.killed = true; + }), + }); + const client = CodexAppServerClient.fromTransportForTests(process); + return { + client, + process, + writes, + send(message: unknown) { + stdout.write(`${JSON.stringify(message)}\n`); + }, + }; +}