Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions apps/server/src/codexAppServerManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,47 @@ describe("collab child conversation routing", () => {
});
});

describe("handleResponse", () => {
function createHandleResponseHarness() {
const manager = new CodexAppServerManager();
const resolve = vi.fn();
const reject = vi.fn();
const timeout = setTimeout(() => {}, 10_000);
const pending = new Map<string, { method: string; timeout: ReturnType<typeof setTimeout>; resolve: (v: unknown) => void; reject: (e: Error) => void }>();
pending.set("1", { method: "test/method", timeout, resolve, reject });
const context = { pending } as unknown;

const handleResponse = (
manager as unknown as {
handleResponse: (context: unknown, response: { id: string | number; result?: unknown; error?: { code?: number; message?: string } }) => void;
}
).handleResponse.bind(manager);

return { handleResponse, context, pending, resolve, reject, timeout };
}

it("resolves the pending request on a successful response", () => {
const { handleResponse, context, resolve, reject } = createHandleResponseHarness();
handleResponse(context, { id: 1, result: { ok: true } });
expect(resolve).toHaveBeenCalledWith({ ok: true });
expect(reject).not.toHaveBeenCalled();
});

it("rejects when the response has an error with a message", () => {
const { handleResponse, context, resolve, reject } = createHandleResponseHarness();
handleResponse(context, { id: 1, error: { code: -32600, message: "Invalid request" } });
expect(reject).toHaveBeenCalledWith(expect.objectContaining({ message: "test/method failed: Invalid request" }));
expect(resolve).not.toHaveBeenCalled();
});

it("rejects when the response has an error with a code but no message", () => {
const { handleResponse, context, resolve, reject } = createHandleResponseHarness();
handleResponse(context, { id: 1, error: { code: -32600 } });
expect(reject).toHaveBeenCalledWith(expect.objectContaining({ message: "test/method failed: error code -32600" }));
expect(resolve).not.toHaveBeenCalled();
});
});

describe.skipIf(!process.env.CODEX_BINARY_PATH)("startSession live Codex resume", () => {
it("keeps prior thread history when resuming with a changed runtime mode", async () => {
const workspaceDir = mkdtempSync(path.join(os.tmpdir(), "codex-live-resume-"));
Expand Down
5 changes: 3 additions & 2 deletions apps/server/src/codexAppServerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1283,8 +1283,9 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
clearTimeout(pending.timeout);
context.pending.delete(key);

if (response.error?.message) {
pending.reject(new Error(`${pending.method} failed: ${String(response.error.message)}`));
if (response.error) {
const detail = response.error.message ?? `error code ${response.error.code}`;
pending.reject(new Error(`${pending.method} failed: ${detail}`));
return;
}

Expand Down