Skip to content

Commit c1dfba9

Browse files
author
easonLiangWorldedtech
committed
test(api): tighten completion cancellation assertions
Two completion-path assertion gaps (rows 4506478027, 4506478090): the deadline test only matched the TimeoutError name, so a wrong phase string would still pass - it now asserts the full message; and no test covered completePrompt receiving the SDK's own AbortError with no options, where the request signal's reason is undefined - the new case locks the optional guard on the reason read. Controls: flipping the phase makes the message assertion fail, and dropping the optional guard turns the new case's rejection into a TypeError.
1 parent a836297 commit c1dfba9

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,10 @@ describe("OpenAiNativeHandler", () => {
19371937

19381938
await expect(handler.completePrompt("Test prompt", { timeoutMs: 50 })).rejects.toMatchObject({
19391939
name: "TimeoutError",
1940+
// Assert the full message too: name-only passes even if the phase is
1941+
// wrong, and the phase is what separates a completion deadline from a
1942+
// discovery deadline for callers.
1943+
message: "The OpenAI Native completion request timed out",
19401944
})
19411945
})
19421946
it("completePrompt should merge the external signal and timeoutMs together", async () => {
@@ -1960,6 +1964,22 @@ describe("OpenAiNativeHandler", () => {
19601964
expect(mergedSignal.aborted).toBe(true)
19611965
})
19621966

1967+
it("completePrompt should normalize an SDK AbortError when no options are passed", async () => {
1968+
// With no options the request signal is a fresh controller whose reason is
1969+
// undefined: the optional guard on the reason read must hold, and the SDK’s
1970+
// own AbortError must still normalize to the contract error.
1971+
mockResponsesCreate.mockImplementationOnce(async () => {
1972+
const abortError = new Error("socket closed by abort")
1973+
abortError.name = "AbortError"
1974+
throw abortError
1975+
})
1976+
1977+
await expect(handler.completePrompt("Test prompt")).rejects.toMatchObject({
1978+
name: "AbortError",
1979+
message: "The OpenAI Native request was aborted",
1980+
})
1981+
})
1982+
19631983
it("completePrompt should reject with AbortError when the abortSignal is already aborted", async () => {
19641984
mockResponsesCreate.mockImplementation((_body: unknown, options: { signal?: AbortSignal }) => {
19651985
if (options?.signal?.aborted) {

0 commit comments

Comments
 (0)