













@@ -299,6 +299,41 @@ function mockCall(mock: unknown, label: string, index = 0): unknown[] {
299299return call;
300300}
301301302+async function waitForPromiseForTest<T>(
303+promise: Promise<T>,
304+timeoutMs: number,
305+label: string,
306+): Promise<T> {
307+let timer: ReturnType<typeof setTimeout> | undefined;
308+try {
309+return await Promise.race([
310+promise,
311+new Promise<never>((_resolve, reject) => {
312+timer = setTimeout(() => reject(new Error(`${label} timed out`)), timeoutMs);
313+}),
314+]);
315+} finally {
316+if (timer) {
317+clearTimeout(timer);
318+}
319+}
320+}
321+322+async function drainPromiseForTest(
323+promise: Promise<unknown>,
324+timeoutMs: number,
325+label: string,
326+): Promise<void> {
327+await waitForPromiseForTest(
328+promise.then(
329+() => undefined,
330+() => undefined,
331+),
332+timeoutMs,
333+label,
334+);
335+}
336+302337function openSocket(url: string): Promise<WebSocket> {
303338return new Promise((resolve, reject) => {
304339const socket = new WebSocket(url);
@@ -3153,7 +3188,8 @@ describe("runCodexAppServerAttempt", () => {
31533188params.runtimePlan = createCodexRuntimePlanFixture();
3154318931553190const run = runCodexAppServerAttempt(params);
3156-let completed = false;
3191+void run.catch(() => undefined);
3192+let runSettled = false;
31573193let diagnosticsSubscribed = true;
31583194try {
31593195await harness.waitForMethod("thread/start", 10_000);
@@ -3213,37 +3249,20 @@ describe("runCodexAppServerAttempt", () => {
32133249).toHaveLength(1);
32143250expect(activeDiagnosticToolKeys(diagnosticEvents)).toEqual(new Set());
321532513216-await harness.notify({
3217-method: "item/completed",
3218-params: {
3219-threadId: "thread-1",
3220-turnId: "turn-1",
3221-completedAtMs: Date.now(),
3222-item: {
3223-type: "dynamicToolCall",
3224-id: "call-echo-1",
3225-namespace: null,
3226-tool: "echo",
3227-arguments: {},
3228-status: "completed",
3229-contentItems: [{ type: "inputText", text: "echo done" }],
3230-success: true,
3231-durationMs: 1,
3232-},
3233-},
3234-});
3235-3236-await harness.completeTurn({ threadId: "thread-1", turnId: "turn-1" });
3237-completed = true;
3238-await run;
3252+harness.close();
3253+abortController.abort(new Error("test complete"));
3254+await drainPromiseForTest(run, 10_000, "Codex diagnostic test run cleanup");
3255+runSettled = true;
32393256} finally {
32403257if (diagnosticsSubscribed) {
32413258unsubscribeDiagnostics();
32423259}
3243-if (!completed) {
3260+if (!runSettled) {
32443261harness.close();
32453262abortController.abort(new Error("test cleanup"));
3246-await run.catch(() => {});
3263+await drainPromiseForTest(run, 1_000, "Codex diagnostic test failure cleanup").catch(
3264+() => undefined,
3265+);
32473266}
32483267}
32493268});
@@ -3299,7 +3318,7 @@ describe("runCodexAppServerAttempt", () => {
32993318contentItems: [{ type: "inputText", text: "Background task started." }],
33003319});
33013320expect(harness.requests.some((request) => request.method === "turn/interrupt")).toBe(false);
3302-const result = await run;
3321+const result = await waitForPromiseForTest(run, 20_000, "Codex terminal dynamic tool run");
33033322completed = true;
3304332333053324expect(result.timedOut).toBe(false);
@@ -3321,7 +3340,9 @@ describe("runCodexAppServerAttempt", () => {
33213340if (!completed) {
33223341harness.close();
33233342abortController.abort(new Error("test cleanup"));
3324-await run.catch(() => {});
3343+await drainPromiseForTest(run, 1_000, "Codex terminal dynamic tool cleanup").catch(
3344+() => undefined,
3345+);
33253346}
33263347}
33273348});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。