Skip to content

Commit 949e967

Browse files
test(api): pin the deadline-versus-cancellation classification
New test `completePrompt should report a deadline as TimeoutError rather than AbortError`: the SDK mock stays pending until the merged timeout signal aborts, then rejects with the SDK's own abort error - the shape the locked SDK produces. The provider must classify it as a timeout. Control: disabling the TimeoutError-reason branch makes the assertion fail with 'expected AbortError ... to match object { name: TimeoutError }', so the fix has a real red/green pair. openai-native.spec 126 passed, tsc --noEmit 0 errors, eslint --max-warnings=0 exit 0.
1 parent 2abd8dd commit 949e967

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎src/api/providers/__tests__/openai-native.spec.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,22 @@ describe("OpenAiNativeHandler", () => {
18821882
expect(requestSignal?.aborted).toBe(true)
18831883
})
18841884

1885+
it("completePrompt should report a deadline as TimeoutError rather than AbortError", async () => {
1886+
// The locked SDK surfaces its own abort error once the request signal aborts; a deadline that
1887+
// fired must not be reported as a caller stop.
1888+
mockResponsesCreate.mockImplementationOnce(async (_body: unknown, options: { signal?: AbortSignal }) => {
1889+
await new Promise<void>((resolve) => {
1890+
options.signal?.addEventListener("abort", () => resolve(), { once: true })
1891+
})
1892+
const abortLike = new Error("Request was aborted.")
1893+
abortLike.name = "APIUserAbortError"
1894+
throw abortLike
1895+
})
1896+
1897+
await expect(handler.completePrompt("Test prompt", { timeoutMs: 50 })).rejects.toMatchObject({
1898+
name: "TimeoutError",
1899+
})
1900+
})
18851901
it("completePrompt should merge the external signal and timeoutMs together", async () => {
18861902
const controller = new AbortController()
18871903
mockResponsesCreate.mockResolvedValue({

0 commit comments

Comments
 (0)