Skip to content

Commit 5a5ff93

Browse files
committed
fix: update tests to expect tool_call_partial chunks for streaming
The providers now yield tool_call_partial chunks during streaming, and the NativeToolCallParser is responsible for reassembling them into complete tool_call chunks. Updated tests to match this new behavior.
1 parent 690d745 commit 5a5ff93

File tree

2 files changed

+52
-21
lines changed

2 files changed

+52
-21
lines changed

src/api/providers/__tests__/minimax.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,13 @@ describe("MiniMaxHandler", () => {
372372
const firstChunk = await stream.next()
373373

374374
expect(firstChunk.done).toBe(false)
375+
// Provider now yields tool_call_partial chunks, NativeToolCallParser handles reassembly
375376
expect(firstChunk.value).toEqual({
376-
type: "tool_call",
377+
type: "tool_call_partial",
378+
index: 0,
377379
id: "tool-123",
378380
name: "get_weather",
379-
arguments: JSON.stringify({ city: "London" }),
381+
arguments: undefined,
380382
})
381383
})
382384
})

src/api/providers/__tests__/openai.spec.ts

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,31 @@ describe("OpenAiHandler", () => {
269269
chunks.push(chunk)
270270
}
271271

272-
const toolCallChunks = chunks.filter((chunk) => chunk.type === "tool_call")
273-
expect(toolCallChunks).toHaveLength(1)
274-
expect(toolCallChunks[0]).toEqual({
275-
type: "tool_call",
272+
// Provider now yields tool_call_partial chunks, NativeToolCallParser handles reassembly
273+
const toolCallPartialChunks = chunks.filter((chunk) => chunk.type === "tool_call_partial")
274+
expect(toolCallPartialChunks).toHaveLength(3)
275+
// First chunk has id and name
276+
expect(toolCallPartialChunks[0]).toEqual({
277+
type: "tool_call_partial",
278+
index: 0,
276279
id: "call_1",
277280
name: "test_tool",
278-
arguments: '{"arg":"value"}',
281+
arguments: "",
282+
})
283+
// Subsequent chunks have arguments
284+
expect(toolCallPartialChunks[1]).toEqual({
285+
type: "tool_call_partial",
286+
index: 0,
287+
id: undefined,
288+
name: undefined,
289+
arguments: '{"arg":',
290+
})
291+
expect(toolCallPartialChunks[2]).toEqual({
292+
type: "tool_call_partial",
293+
index: 0,
294+
id: undefined,
295+
name: undefined,
296+
arguments: '"value"}',
279297
})
280298
})
281299

@@ -318,11 +336,12 @@ describe("OpenAiHandler", () => {
318336
chunks.push(chunk)
319337
}
320338

321-
// Tool calls should still be yielded via the fallback mechanism
322-
const toolCallChunks = chunks.filter((chunk) => chunk.type === "tool_call")
323-
expect(toolCallChunks).toHaveLength(1)
324-
expect(toolCallChunks[0]).toEqual({
325-
type: "tool_call",
339+
// Provider now yields tool_call_partial chunks, NativeToolCallParser handles reassembly
340+
const toolCallPartialChunks = chunks.filter((chunk) => chunk.type === "tool_call_partial")
341+
expect(toolCallPartialChunks).toHaveLength(1)
342+
expect(toolCallPartialChunks[0]).toEqual({
343+
type: "tool_call_partial",
344+
index: 0,
326345
id: "call_fallback",
327346
name: "fallback_tool",
328347
arguments: '{"test":"fallback"}',
@@ -819,12 +838,21 @@ describe("OpenAiHandler", () => {
819838
chunks.push(chunk)
820839
}
821840

822-
const toolCallChunks = chunks.filter((chunk) => chunk.type === "tool_call")
823-
expect(toolCallChunks).toHaveLength(1)
824-
expect(toolCallChunks[0]).toEqual({
825-
type: "tool_call",
841+
// Provider now yields tool_call_partial chunks, NativeToolCallParser handles reassembly
842+
const toolCallPartialChunks = chunks.filter((chunk) => chunk.type === "tool_call_partial")
843+
expect(toolCallPartialChunks).toHaveLength(2)
844+
expect(toolCallPartialChunks[0]).toEqual({
845+
type: "tool_call_partial",
846+
index: 0,
826847
id: "call_1",
827848
name: "test_tool",
849+
arguments: "",
850+
})
851+
expect(toolCallPartialChunks[1]).toEqual({
852+
type: "tool_call_partial",
853+
index: 0,
854+
id: undefined,
855+
name: undefined,
828856
arguments: "{}",
829857
})
830858
})
@@ -870,11 +898,12 @@ describe("OpenAiHandler", () => {
870898
chunks.push(chunk)
871899
}
872900

873-
// Tool calls should still be yielded via the fallback mechanism
874-
const toolCallChunks = chunks.filter((chunk) => chunk.type === "tool_call")
875-
expect(toolCallChunks).toHaveLength(1)
876-
expect(toolCallChunks[0]).toEqual({
877-
type: "tool_call",
901+
// Provider now yields tool_call_partial chunks, NativeToolCallParser handles reassembly
902+
const toolCallPartialChunks = chunks.filter((chunk) => chunk.type === "tool_call_partial")
903+
expect(toolCallPartialChunks).toHaveLength(1)
904+
expect(toolCallPartialChunks[0]).toEqual({
905+
type: "tool_call_partial",
906+
index: 0,
878907
id: "call_o3_fallback",
879908
name: "o3_fallback_tool",
880909
arguments: '{"o3":"test"}',

0 commit comments

Comments
 (0)