test: tighten codex run attempt watchdog assertions

This commit is contained in:
Peter Steinberger
2026-05-10 02:13:39 +01:00
parent 3bd64d60df
commit 8065f36bee

View File

@@ -1019,36 +1019,33 @@ describe("runCodexAppServerAttempt", () => {
});
await vi.waitFor(() => expect(handleRequest).toBeTypeOf("function"), { interval: 1 });
await expect(
handleRequest?.({
id: "request-tool-1",
method: "item/tool/call",
params: {
threadId: "thread-1",
turnId: "turn-1",
callId: "call-1",
namespace: null,
tool: "message",
arguments: { action: "send", text: "already sent" },
},
}),
).resolves.toMatchObject({
success: false,
contentItems: [
{
type: "inputText",
text: expect.stringMatching(
/^(Unknown OpenClaw tool: message|Action send requires a target\.)$/u,
),
},
],
});
const toolResult = (await handleRequest?.({
id: "request-tool-1",
method: "item/tool/call",
params: {
threadId: "thread-1",
turnId: "turn-1",
callId: "call-1",
namespace: null,
tool: "message",
arguments: { action: "send", text: "already sent" },
},
})) as {
contentItems?: Array<{ text?: string; type?: string }>;
success?: boolean;
};
expect(toolResult.success).toBe(false);
expect(toolResult.contentItems?.[0]?.type).toBe("inputText");
expect(toolResult.contentItems?.[0]?.text).toMatch(
/^(Unknown OpenClaw tool: message|Action send requires a target\.)$/u,
);
await expect(run).resolves.toMatchObject({
aborted: true,
timedOut: true,
promptError: "codex app-server turn idle timed out waiting for turn/completed",
});
const result = await run;
expect(result.aborted).toBe(true);
expect(result.timedOut).toBe(true);
expect(result.promptError).toBe(
"codex app-server turn idle timed out waiting for turn/completed",
);
await vi.waitFor(
() =>
expect(request).toHaveBeenCalledWith("turn/interrupt", {
@@ -1107,34 +1104,35 @@ describe("runCodexAppServerAttempt", () => {
});
await vi.waitFor(() => expect(handleRequest).toBeTypeOf("function"), { interval: 1 });
await expect(
handleRequest?.({
id: "request-tool-1",
method: "item/tool/call",
params: {
threadId: "thread-1",
turnId: "turn-1",
callId: "call-1",
namespace: null,
tool: "message",
arguments: { action: "send", text: "already sent" },
},
}),
).resolves.toMatchObject({ success: false });
const toolResult = (await handleRequest?.({
id: "request-tool-1",
method: "item/tool/call",
params: {
threadId: "thread-1",
turnId: "turn-1",
callId: "call-1",
namespace: null,
tool: "message",
arguments: { action: "send", text: "already sent" },
},
})) as { success?: boolean };
expect(toolResult.success).toBe(false);
await notify(rateLimitsUpdated(Math.ceil(Date.now() / 1000) + 120));
await expect(run).resolves.toMatchObject({
aborted: true,
timedOut: true,
promptError: "codex app-server turn idle timed out waiting for turn/completed",
});
expect(warn).toHaveBeenCalledWith(
"codex app-server turn idle timed out waiting for completion",
expect.objectContaining({
timeoutMs: 5,
lastActivityReason: "request:item/tool/call:response",
}),
const result = await run;
expect(result.aborted).toBe(true);
expect(result.timedOut).toBe(true);
expect(result.promptError).toBe(
"codex app-server turn idle timed out waiting for turn/completed",
);
const warnCall = warn.mock.calls.find(
([message]) => message === "codex app-server turn idle timed out waiting for completion",
);
const warnData = warnCall?.[1] as
| { lastActivityReason?: string; timeoutMs?: number }
| undefined;
expect(warnData?.timeoutMs).toBe(5);
expect(warnData?.lastActivityReason).toBe("request:item/tool/call:response");
});
it("keeps waiting when Codex emits a raw assistant item after a dynamic tool response", async () => {
@@ -1183,20 +1181,19 @@ describe("runCodexAppServerAttempt", () => {
});
await vi.waitFor(() => expect(handleRequest).toBeTypeOf("function"), { interval: 1 });
await expect(
handleRequest?.({
id: "request-tool-1",
method: "item/tool/call",
params: {
threadId: "thread-1",
turnId: "turn-1",
callId: "call-1",
namespace: null,
tool: "message",
arguments: { action: "send", text: "already sent" },
},
}),
).resolves.toMatchObject({ success: false });
const toolResult = (await handleRequest?.({
id: "request-tool-1",
method: "item/tool/call",
params: {
threadId: "thread-1",
turnId: "turn-1",
callId: "call-1",
namespace: null,
tool: "message",
arguments: { action: "send", text: "already sent" },
},
})) as { success?: boolean };
expect(toolResult.success).toBe(false);
await notify({
method: "rawResponseItem/completed",
params: {
@@ -1211,7 +1208,7 @@ describe("runCodexAppServerAttempt", () => {
},
});
await new Promise((resolve) => setTimeout(resolve, 20));
expect(request).not.toHaveBeenCalledWith("turn/interrupt", expect.anything());
expect(request.mock.calls.some(([method]) => method === "turn/interrupt")).toBe(false);
await notify({
method: "turn/completed",
@@ -1222,12 +1219,11 @@ describe("runCodexAppServerAttempt", () => {
},
});
await expect(run).resolves.toMatchObject({
aborted: false,
timedOut: false,
promptError: null,
});
expect(request).not.toHaveBeenCalledWith("turn/interrupt", expect.anything());
const result = await run;
expect(result.aborted).toBe(false);
expect(result.timedOut).toBe(false);
expect(result.promptError).toBeNull();
expect(request.mock.calls.some(([method]) => method === "turn/interrupt")).toBe(false);
});
it("logs raw assistant item context when the terminal watchdog fires", async () => {