Skip to content

Commit 97916f4

Browse files
test(poe): observe the request start instead of sleeping in the capture case
The compile lane's lint step reported one error on the previous head: src/api/providers/__tests__/poe.spec.ts 874:42 error Unexpected use of setTimeout (poll with vi.waitFor on the observable condition), from the spec's own 200ms delay inside the mocked call. The case now observes the request having started - vi.waitFor on mockGenerateText being called once with interval 1, so the poll cannot outlast the deadline it is about to mutate away - and the mocked call hangs on its own abort listener instead of a timer, with the deadline widened to 250ms so the mutation lands first. Control re-proved after the rewrite: 1 failed of 45 with the capture removed (the guard reading options.timeoutMs again) and 45 passed with configuredTimeoutUsable in place. Ordering fixed for this commit: prettier first, then eslint --max-warnings=0 over the touched files (exit 0), then the spec re-run (45/45), then tsc --noEmit (exit 0). The previous head was pushed with a lint run that predated prettier's normalisation, which is why the local run read clean while CI disagreed. src/eslint-suppressions.json untouched; no changeset, no CHANGELOG, hooks not skipped.
1 parent 0e51532 commit 97916f4

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

‎src/api/providers/__tests__/poe.spec.ts‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -866,16 +866,23 @@ describe("PoeHandler", () => {
866866
it("classifies a fired timeout against the timeoutMs value that built the signal", async () => {
867867
// mergeAbortSignalAndTimeout reads timeoutMs once, when the signal is built. The
868868
// classification side must read the same decision: a caller that rewrites
869-
// options.timeoutMs while the request is in flight (20 -> 0 here) would otherwise
870-
// make our own fired TimeoutError read as a plain caller abort. Red without
871-
// capturing the usability decision next to the merge call.
869+
// options.timeoutMs while the request is in flight (250 -> 0 here) would otherwise
870+
// make our own fired TimeoutError read as a plain caller abort. The request having
871+
// begun is observed rather than slept on, and the deadline is wide enough that the
872+
// mutation is certain to land before it fires.
872873
const handler = new PoeHandler({ poeApiKey: "key", apiModelId: "openai/gpt-4o" })
873-
mockGenerateText.mockImplementationOnce(async () => {
874-
await new Promise<void>((resolve) => setTimeout(resolve, 200))
875-
return { text: "too late" }
876-
})
877-
const options = { timeoutMs: 20 }
874+
mockGenerateText.mockImplementationOnce(
875+
() =>
876+
new Promise<{ text: string }>((_resolve, reject) => {
877+
const signal = mockGenerateText.mock.calls[0][0].abortSignal as AbortSignal
878+
signal.addEventListener("abort", () => reject(signal.reason), { once: true })
879+
}),
880+
)
881+
const options = { timeoutMs: 250 }
878882
const promise = handler.completePrompt("test prompt", options)
883+
// Poll on the observable fact that the request started, with a 1ms interval so the
884+
// poll cannot itself outlast the deadline being mutated away.
885+
await vi.waitFor(() => expect(mockGenerateText).toHaveBeenCalledTimes(1), { interval: 1 })
879886
options.timeoutMs = 0
880887
await expect(promise).rejects.toMatchObject({ name: "TimeoutError" })
881888
})

0 commit comments

Comments
 (0)