@@ -10,6 +10,7 @@ vi.mock("node:fs", () => ({
1010
1111const mockCreate = vi . fn ( )
1212import { asyncStreamFrom , collectStream } from "../../../test-utils/stream"
13+ import { collectStreamAndParseToolCalls } from "../../../test-utils/native-tool-call-stream"
1314import { clearAllMocks } from "../../../test-utils/reset"
1415vi . mock ( "openai" , ( ) => {
1516 return {
@@ -373,35 +374,11 @@ describe("QwenCodeHandler Native Tools", () => {
373374 ] )
374375 mockCreate . mockImplementationOnce ( ( ) => firstStream ( ) ) . mockImplementationOnce ( ( ) => secondStream )
375376
376- const collectAndTrack = async ( stream : ReturnType < QwenCodeHandler [ "createMessage" ] > ) => {
377- const chunks = [ ]
378- const parserEvents = [ ]
379- const parserScope = NativeToolCallParser . createScope ( )
380- for await ( const chunk of stream ) {
381- if ( chunk . type === "tool_call_partial" ) {
382- parserEvents . push (
383- ...NativeToolCallParser . processRawChunk (
384- {
385- index : chunk . index ,
386- id : chunk . id ,
387- name : chunk . name ,
388- arguments : chunk . arguments ,
389- } ,
390- parserScope ,
391- ) ,
392- )
393- }
394- chunks . push ( chunk )
395- }
396- NativeToolCallParser . clearRawChunkState ( parserScope )
397- return { chunks, parserEvents }
398- }
399-
400- const firstChunksPromise = collectAndTrack (
377+ const firstChunksPromise = collectStreamAndParseToolCalls (
401378 handler . createMessage ( "first" , [ ] , { taskId : "task-a" , tools : testTools } ) ,
402379 )
403380 await firstStreamPaused
404- const secondChunks = await collectAndTrack (
381+ const secondChunks = await collectStreamAndParseToolCalls (
405382 handler . createMessage ( "second" , [ ] , { taskId : "task-b" , tools : testTools } ) ,
406383 )
407384 releaseFirstStream ?.( )
0 commit comments