mirror of
https://github.com/getpaseo/paseo.git
synced 2026-12-03 05:36:08 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb32ab924f |
@@ -1,3 +1,5 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { errorMonitor, once } from "node:events";
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
|
||||
import { createTestLogger } from "../../../../test-utils/test-logger.js";
|
||||
@@ -8,6 +10,52 @@ import {
|
||||
import { CodexAppServerClient, CodexAppServerExitError } from "./app-server-transport.js";
|
||||
|
||||
describe("Codex app-server transport", () => {
|
||||
test.skipIf(process.platform === "win32")(
|
||||
"keeps the provider exit diagnostic when initialization hits a closed stdin",
|
||||
async () => {
|
||||
const child = spawn(
|
||||
process.execPath,
|
||||
[
|
||||
"-e",
|
||||
[
|
||||
'process.on("message", () => process.exit(86));',
|
||||
'require("node:fs").closeSync(0);',
|
||||
'process.stdout.write("ready");',
|
||||
].join("\n"),
|
||||
],
|
||||
{ stdio: ["pipe", "pipe", "pipe", "ipc"] },
|
||||
);
|
||||
const client = new CodexAppServerClient(child, createTestLogger());
|
||||
try {
|
||||
await once(child.stdout, "data");
|
||||
// errorMonitor observes EPIPE without handling it on the transport's behalf.
|
||||
child.stdin.once(errorMonitor, () => child.send("exit"));
|
||||
await expect(client.request("initialize", {}, 2_000)).rejects.toMatchObject({
|
||||
name: "CodexAppServerExitError",
|
||||
exitCode: 86,
|
||||
});
|
||||
} finally {
|
||||
await client.dispose();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test("closes an active transport once when stdin fails before the child exits", async () => {
|
||||
const child = createCodexAppServerChildProcess();
|
||||
const client = new CodexAppServerClient(child, createTestLogger());
|
||||
const terminated = vi.fn();
|
||||
client.setUnexpectedTerminationHandler(terminated);
|
||||
const failure = new Error("write EPIPE");
|
||||
const first = expect(client.request("thread/read", {})).rejects.toBe(failure);
|
||||
const second = expect(client.request("thread/loaded/list", {})).rejects.toBe(failure);
|
||||
child.stdin.emit("error", failure);
|
||||
child.stdin.emit("error", failure);
|
||||
await Promise.all([first, second]);
|
||||
expect(client.hasPendingRequests()).toBe(false);
|
||||
expect(terminated).toHaveBeenCalledExactlyOnceWith(failure);
|
||||
await expect(client.request("thread/read", {})).rejects.toThrow("client is closed");
|
||||
});
|
||||
|
||||
test("classifies startup diagnostics delivered after the child exits", async () => {
|
||||
const child = createCodexAppServerChildProcess();
|
||||
const client = new CodexAppServerClient(child, createTestLogger());
|
||||
|
||||
@@ -268,6 +268,14 @@ export class CodexAppServerClient {
|
||||
this.handleUnexpectedTermination(err);
|
||||
});
|
||||
|
||||
const isInitializing = () =>
|
||||
Array.from(this.pending.values()).some((request) => request.method === "initialize");
|
||||
child.stdin.on("error", (error) => {
|
||||
// During startup, close owns the final stderr and exit reason. The startup
|
||||
// coordinator's deadline also covers a child that closes stdin and stays alive.
|
||||
if (!isInitializing()) this.terminateAfterStreamFailure(error);
|
||||
});
|
||||
|
||||
const reportExit = (code: number | null, signal: NodeJS.Signals | null) => {
|
||||
this.handleUnexpectedTermination(
|
||||
new CodexAppServerExitError({
|
||||
@@ -280,10 +288,7 @@ export class CodexAppServerClient {
|
||||
child.on("exit", (code, signal) => {
|
||||
// Startup retries need complete diagnostics. Node drains the child's
|
||||
// stdio before close, but exit can precede the final stderr data.
|
||||
const initializing = Array.from(this.pending.values()).some(
|
||||
(request) => request.method === "initialize",
|
||||
);
|
||||
if (!initializing) reportExit(code, signal);
|
||||
if (!isInitializing()) reportExit(code, signal);
|
||||
});
|
||||
child.on("close", reportExit);
|
||||
}
|
||||
@@ -381,10 +386,14 @@ export class CodexAppServerClient {
|
||||
}
|
||||
// A lost notification or server request cannot be replayed. Fail the session,
|
||||
// including live turns with no pending RPC, rather than dropping a stream unit.
|
||||
this.stdoutLineReader.close();
|
||||
this.terminateAfterStreamFailure(failure);
|
||||
}
|
||||
|
||||
private terminateAfterStreamFailure(failure: Error): void {
|
||||
if (this.disposed) return;
|
||||
this.handleUnexpectedTermination(failure);
|
||||
void this.dispose().catch((err) => {
|
||||
this.logger.warn({ err }, "Failed to terminate oversized Codex stdout producer");
|
||||
this.logger.warn({ err }, "Failed to terminate Codex app-server after stream failure");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user