mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-21 05:32:53 +00:00
test(codex): share app-server client harness
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
33
extensions/codex/src/app-server/test-support.ts
Normal file
33
extensions/codex/src/app-server/test-support.ts
Normal file
@@ -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`);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user