Skip to content

Commit d46cb9e

Browse files
committed
test(api): strengthen abort signal merge tests across providers
1 parent eef19dd commit d46cb9e

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,14 @@ describe("OpenAiCodexHandler.completePrompt", () => {
256256
global.fetch = mockFetch
257257

258258
const controller = new AbortController()
259-
await handler.completePrompt("test prompt", { abortSignal: controller.signal })
259+
const promise = handler.completePrompt("test prompt", { abortSignal: controller.signal })
260+
controller.abort()
261+
await promise
260262

261263
expect(mockFetch).toHaveBeenCalled()
262264
const fetchOptions = (mockFetch as any).mock.calls[0][1]
263265
expect(fetchOptions.signal).toBeDefined()
266+
expect(fetchOptions.signal.aborted).toBe(true)
264267
})
265268

266269
it("should merge abortSignal and timeoutMs together", async () => {
@@ -289,11 +292,14 @@ describe("OpenAiCodexHandler.completePrompt", () => {
289292
global.fetch = mockFetch
290293

291294
const controller = new AbortController()
292-
await handler.completePrompt("test prompt", { abortSignal: controller.signal, timeoutMs: 5000 })
295+
const promise = handler.completePrompt("test prompt", { abortSignal: controller.signal, timeoutMs: 5000 })
296+
controller.abort()
297+
await promise
293298

294299
expect(mockFetch).toHaveBeenCalled()
295300
const fetchOptions = (mockFetch as any).mock.calls[0][1]
296301
expect(fetchOptions.signal).toBeDefined()
302+
expect(fetchOptions.signal.aborted).toBe(true)
297303
})
298304

299305
it("should return empty string when no output text found", async () => {

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ describe("BaseOpenAiCompatibleProvider completePrompt", () => {
5959
const controller = new AbortController()
6060
await handler.completePrompt("test prompt", { abortSignal: controller.signal })
6161

62-
expect(mockCreate).toHaveBeenCalledWith(
63-
expect.objectContaining({ model: "test-model" }),
64-
expect.objectContaining({ signal: controller.signal }),
65-
)
62+
expect(mockCreate.mock.calls[0][1].signal).toBe(controller.signal)
6663
})
6764

6865
it("should pass timeoutMs through to client as timeout", async () => {
@@ -76,10 +73,7 @@ describe("BaseOpenAiCompatibleProvider completePrompt", () => {
7673

7774
await handler.completePrompt("test prompt", { timeoutMs: 5000 })
7875

79-
expect(mockCreate).toHaveBeenCalledWith(
80-
expect.objectContaining({ model: "test-model" }),
81-
expect.objectContaining({ timeout: 5000 }),
82-
)
76+
expect(mockCreate.mock.calls[0][1].timeout).toBe(5000)
8377
})
8478

8579
it("should pass both signal and timeout when both are provided", async () => {
@@ -94,10 +88,8 @@ describe("BaseOpenAiCompatibleProvider completePrompt", () => {
9488
const controller = new AbortController()
9589
await handler.completePrompt("test prompt", { abortSignal: controller.signal, timeoutMs: 5000 })
9690

97-
expect(mockCreate).toHaveBeenCalledWith(
98-
expect.objectContaining({ model: "test-model" }),
99-
expect.objectContaining({ signal: controller.signal, timeout: 5000 }),
100-
)
91+
expect(mockCreate.mock.calls[0][1].signal).toBe(controller.signal)
92+
expect(mockCreate.mock.calls[0][1].timeout).toBe(5000)
10193
})
10294

10395
it("should work without options (backward compatible)", async () => {

0 commit comments

Comments
 (0)