Skip to content

Commit cf6a2dc

Browse files
committed
✅ test(providers): fix test assertions for merged signal patterns (#404)
Providers that merge request options into body need signal passed as separate second arg, not merged into the params object.
1 parent 8ba71b8 commit cf6a2dc

12 files changed

Lines changed: 74 additions & 39 deletions

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ describe("GeminiHandler", () => {
131131
expect(handler["client"].models.generateContent).toHaveBeenCalledWith({
132132
model: GEMINI_MODEL_NAME,
133133
contents: [{ role: "user", parts: [{ text: "Test prompt" }] }],
134-
config: {
134+
config: expect.objectContaining({
135135
httpOptions: undefined,
136136
temperature: 1,
137-
},
137+
abortSignal: expect.any(AbortSignal),
138+
}),
138139
})
139140
})
140141

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,14 @@ describe("MistralHandler", () => {
465465
const prompt = "Test prompt"
466466
const result = await handler.completePrompt(prompt)
467467

468-
expect(mockComplete).toHaveBeenCalledWith({
469-
model: mockOptions.apiModelId,
470-
messages: [{ role: "user", content: prompt }],
471-
temperature: 0,
472-
})
468+
expect(mockComplete).toHaveBeenCalledWith(
469+
{
470+
model: mockOptions.apiModelId,
471+
messages: [{ role: "user", content: prompt }],
472+
temperature: 0,
473+
},
474+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
475+
)
473476

474477
expect(result).toBe("Test response")
475478
})

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,17 @@ describe("NativeOllamaHandler", () => {
166166
})
167167

168168
describe("completePrompt", () => {
169-
it("should complete a prompt without streaming", async () => {
170-
mockChat.mockResolvedValue({
171-
message: { content: "This is the response" },
169+
it("should complete a prompt with streaming", async () => {
170+
mockChat.mockImplementation(async function* () {
171+
yield { message: { content: "This is the response" } }
172172
})
173173

174174
const result = await handler.completePrompt("Tell me a joke")
175175

176176
expect(mockChat).toHaveBeenCalledWith({
177177
model: "llama2",
178178
messages: [{ role: "user", content: "Tell me a joke" }],
179-
stream: false,
179+
stream: true,
180180
options: {
181181
temperature: 0,
182182
},
@@ -185,8 +185,8 @@ describe("NativeOllamaHandler", () => {
185185
})
186186

187187
it("should not include num_ctx in completePrompt by default", async () => {
188-
mockChat.mockResolvedValue({
189-
message: { content: "Response" },
188+
mockChat.mockImplementation(async function* () {
189+
yield { message: { content: "Response" } }
190190
})
191191

192192
await handler.completePrompt("Test prompt")
@@ -211,8 +211,8 @@ describe("NativeOllamaHandler", () => {
211211

212212
handler = new NativeOllamaHandler(options)
213213

214-
mockChat.mockResolvedValue({
215-
message: { content: "Response" },
214+
mockChat.mockImplementation(async function* () {
215+
yield { message: { content: "Response" } }
216216
})
217217

218218
await handler.completePrompt("Test prompt")

‎src/api/providers/__tests__/opencode-go.spec.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ describe("OpencodeGoHandler", () => {
156156
max_completion_tokens: 32768,
157157
temperature: expect.any(Number),
158158
}),
159+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
159160
)
160161
})
161162
})
@@ -171,6 +172,7 @@ describe("OpencodeGoHandler", () => {
171172
stream: false,
172173
max_completion_tokens: 32768,
173174
}),
175+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
174176
)
175177
})
176178

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ describe("OpenRouterHandler", () => {
269269
temperature: 0,
270270
top_p: undefined,
271271
}),
272-
{ headers: { "x-anthropic-beta": "fine-grained-tool-streaming-2025-05-14" } },
272+
expect.objectContaining({
273+
headers: { "x-anthropic-beta": "fine-grained-tool-streaming-2025-05-14" },
274+
signal: expect.any(AbortSignal),
275+
}),
273276
)
274277
})
275278

@@ -312,7 +315,10 @@ describe("OpenRouterHandler", () => {
312315
}),
313316
]),
314317
}),
315-
{ headers: { "x-anthropic-beta": "fine-grained-tool-streaming-2025-05-14" } },
318+
expect.objectContaining({
319+
headers: { "x-anthropic-beta": "fine-grained-tool-streaming-2025-05-14" },
320+
signal: expect.any(AbortSignal),
321+
}),
316322
)
317323
})
318324

@@ -553,7 +559,10 @@ describe("OpenRouterHandler", () => {
553559
messages: [{ role: "user", content: "test prompt" }],
554560
stream: false,
555561
},
556-
{ headers: { "x-anthropic-beta": "fine-grained-tool-streaming-2025-05-14" } },
562+
expect.objectContaining({
563+
headers: { "x-anthropic-beta": "fine-grained-tool-streaming-2025-05-14" },
564+
signal: expect.any(AbortSignal),
565+
}),
557566
)
558567
})
559568

‎src/api/providers/__tests__/qwen-code-native-tools.spec.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ describe("QwenCodeHandler Native Tools", () => {
103103
]),
104104
parallel_tool_calls: true,
105105
}),
106+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
106107
)
107108
})
108109

@@ -126,6 +127,7 @@ describe("QwenCodeHandler Native Tools", () => {
126127
expect.objectContaining({
127128
tool_choice: "auto",
128129
}),
130+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
129131
)
130132
})
131133

@@ -237,6 +239,7 @@ describe("QwenCodeHandler Native Tools", () => {
237239
expect.objectContaining({
238240
parallel_tool_calls: true,
239241
}),
242+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
240243
)
241244
})
242245

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ describe("RequestyHandler", () => {
210210
stream_options: { include_usage: true },
211211
temperature: 0,
212212
}),
213+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
213214
)
214215
})
215216

@@ -243,6 +244,7 @@ describe("RequestyHandler", () => {
243244
thinking: { type: "adaptive" },
244245
temperature: undefined,
245246
}),
247+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
246248
)
247249
})
248250

@@ -314,6 +316,7 @@ describe("RequestyHandler", () => {
314316
]),
315317
tool_choice: "auto",
316318
}),
319+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
317320
)
318321
})
319322

@@ -412,12 +415,15 @@ describe("RequestyHandler", () => {
412415

413416
expect(result).toBe("test completion")
414417

415-
expect(mockCreate).toHaveBeenCalledWith({
416-
model: mockOptions.requestyModelId,
417-
max_tokens: 8192,
418-
messages: [{ role: "system", content: "test prompt" }],
419-
temperature: 0,
420-
})
418+
expect(mockCreate).toHaveBeenCalledWith(
419+
{
420+
model: mockOptions.requestyModelId,
421+
max_tokens: 8192,
422+
messages: [{ role: "system", content: "test prompt" }],
423+
temperature: 0,
424+
},
425+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
426+
)
421427
})
422428

423429
it("omits temperature for Claude Fable 5 in completePrompt", async () => {
@@ -429,12 +435,15 @@ describe("RequestyHandler", () => {
429435

430436
await handler.completePrompt("test prompt")
431437

432-
expect(mockCreate).toHaveBeenCalledWith({
433-
model: "anthropic/claude-fable-5",
434-
max_tokens: 8192,
435-
messages: [{ role: "system", content: "test prompt" }],
436-
temperature: undefined,
437-
})
438+
expect(mockCreate).toHaveBeenCalledWith(
439+
{
440+
model: "anthropic/claude-fable-5",
441+
max_tokens: 8192,
442+
messages: [{ role: "system", content: "test prompt" }],
443+
temperature: undefined,
444+
},
445+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
446+
)
438447
})
439448

440449
it("handles API errors", async () => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe("SambaNovaHandler", () => {
148148
stream: true,
149149
stream_options: { include_usage: true },
150150
}),
151-
undefined,
151+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
152152
)
153153
})
154154
})

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ describe("UnboundHandler", () => {
9090
mode: "architect",
9191
},
9292
}),
93+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
9394
)
9495
})
9596
})

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ describe("XAIHandler", () => {
106106
store: false,
107107
include: ["reasoning.encrypted_content"],
108108
}),
109+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
109110
)
110111
})
111112

@@ -235,6 +236,7 @@ describe("XAIHandler", () => {
235236
tool_choice: "auto",
236237
parallel_tool_calls: true,
237238
}),
239+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
238240
)
239241
})
240242

@@ -272,6 +274,7 @@ describe("XAIHandler", () => {
272274
reasoning_effort: "high",
273275
}),
274276
}),
277+
expect.objectContaining({ signal: expect.any(AbortSignal) }),
275278
)
276279
})
277280

0 commit comments

Comments
 (0)