test(codex): stabilize nullable-turn watch proof (#108456)

This commit is contained in:
Peter Steinberger
2026-07-15 13:44:09 -07:00
committed by GitHub
parent bc276f2858
commit bc55e1ea3e
@@ -49,9 +49,7 @@ const DISABLED_CODEX_WEB_SEARCH_THREAD_CONFIG_FINGERPRINT = JSON.stringify({
web_search: "disabled",
});
function writeCodexAppServerBinding(
...args: Parameters<typeof writeRawCodexAppServerBinding>
) {
function writeCodexAppServerBinding(...args: Parameters<typeof writeRawCodexAppServerBinding>) {
const [sessionFile, binding, lookup] = args;
return writeRawCodexAppServerBinding(
sessionFile,
@@ -704,7 +702,10 @@ describe("runCodexAppServerAttempt turn watches", () => {
expect(harness.request.mock.calls.some(([method]) => method === "turn/interrupt")).toBe(true);
});
it("counts handled nullable-turn elicitations as turn attempt progress", async () => {
it("refreshes the turn attempt watch for handled nullable-turn elicitations", async () => {
let nowMs = 1_000_000;
vi.spyOn(Date, "now").mockImplementation(() => nowMs);
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
const harness = createStartedThreadHarness();
vi.spyOn(elicitationBridge, "handleCodexAppServerElicitationRequest").mockResolvedValue({
action: "accept",
@@ -715,7 +716,7 @@ describe("runCodexAppServerAttempt turn watches", () => {
path.join(tempDir, "session.jsonl"),
path.join(tempDir, "workspace"),
);
params.timeoutMs = 100;
params.timeoutMs = 10_000;
const onRunProgress = vi.fn();
params.onRunProgress = onRunProgress;
@@ -732,10 +733,14 @@ describe("runCodexAppServerAttempt turn watches", () => {
),
fastWait,
);
const initialAttemptWatch = setTimeoutSpy.mock.calls.find(
([callback]) => typeof callback === "function" && callback.name === "fireAttemptIdleTimeout",
)?.[0];
if (typeof initialAttemptWatch !== "function") {
throw new Error("Expected the initial turn attempt watch timer");
}
nowMs += 6_000;
await new Promise((resolve) => {
setTimeout(resolve, 60);
});
await harness.handleServerRequest({
id: "request-null-turn-elicitation",
method: "mcpServer/elicitation/request",
@@ -749,9 +754,15 @@ describe("runCodexAppServerAttempt turn watches", () => {
_meta: null,
},
});
await new Promise((resolve) => {
setTimeout(resolve, 60);
});
await vi.waitFor(
() =>
expect(onRunProgress).toHaveBeenCalledWith(
expect.objectContaining({ reason: "request:mcpServer/elicitation/request:start" }),
),
fastWait,
);
nowMs += 6_000;
initialAttemptWatch();
expect(harness.request.mock.calls.some(([method]) => method === "turn/interrupt")).toBe(false);
await harness.completeTurn({ threadId: "thread-1", turnId: "turn-1" });