@@ -89,19 +89,19 @@ describe("QwenCodeHandler Native Tools", () => {
8989 } )
9090 await stream . next ( )
9191
92- expect ( mockCreate ) . toHaveBeenCalledWith (
93- expect . objectContaining ( {
94- tools : expect . arrayContaining ( [
95- expect . objectContaining ( {
96- type : "function" ,
97- function : expect . objectContaining ( {
98- name : "test_tool" ,
99- } ) ,
92+ const callArgs = mockCreate . mock . calls [ 0 ] [ 0 ]
93+ expect ( callArgs . tools ) . toEqual (
94+ expect . arrayContaining ( [
95+ expect . objectContaining ( {
96+ type : "function" ,
97+ function : expect . objectContaining ( {
98+ name : "test_tool" ,
10099 } ) ,
101- ] ) ,
102- parallel_tool_calls : true ,
103- } ) ,
100+ } ) ,
101+ ] ) ,
104102 )
103+ // DashScope does not support parallel_tool_calls
104+ expect ( callArgs ) . not . toHaveProperty ( "parallel_tool_calls" )
105105 } )
106106
107107 it ( "should include tool_choice when provided" , async ( ) => {
@@ -145,7 +145,8 @@ describe("QwenCodeHandler Native Tools", () => {
145145 const callArgs = mockCreate . mock . calls [ mockCreate . mock . calls . length - 1 ] [ 0 ]
146146 expect ( callArgs ) . toHaveProperty ( "tools" )
147147 expect ( callArgs ) . toHaveProperty ( "tool_choice" )
148- expect ( callArgs ) . toHaveProperty ( "parallel_tool_calls" , true )
148+ // DashScope does not support parallel_tool_calls
149+ expect ( callArgs ) . not . toHaveProperty ( "parallel_tool_calls" )
149150 } )
150151
151152 it ( "should yield tool_call_partial chunks during streaming" , async ( ) => {
@@ -215,7 +216,7 @@ describe("QwenCodeHandler Native Tools", () => {
215216 } )
216217 } )
217218
218- it ( "should set parallel_tool_calls based on metadata" , async ( ) => {
219+ it ( "should not include parallel_tool_calls even when metadata provides it (DashScope unsupported) " , async ( ) => {
219220 mockCreate . mockImplementationOnce ( ( ) => ( {
220221 [ Symbol . asyncIterator ] : async function * ( ) {
221222 yield {
@@ -231,11 +232,9 @@ describe("QwenCodeHandler Native Tools", () => {
231232 } )
232233 await stream . next ( )
233234
234- expect ( mockCreate ) . toHaveBeenCalledWith (
235- expect . objectContaining ( {
236- parallel_tool_calls : true ,
237- } ) ,
238- )
235+ const callArgs = mockCreate . mock . calls [ 0 ] [ 0 ]
236+ // DashScope does not support parallel_tool_calls - should never be sent
237+ expect ( callArgs ) . not . toHaveProperty ( "parallel_tool_calls" )
239238 } )
240239
241240 it ( "should yield tool_call_end events when finish_reason is tool_calls" , async ( ) => {
@@ -370,4 +369,98 @@ describe("QwenCodeHandler Native Tools", () => {
370369 expect ( endChunks ) . toHaveLength ( 1 )
371370 } )
372371 } )
372+
373+ describe ( "DashScope API Compatibility" , ( ) => {
374+ it ( "should use max_tokens instead of max_completion_tokens" , async ( ) => {
375+ mockCreate . mockImplementationOnce ( ( ) => ( {
376+ [ Symbol . asyncIterator ] : async function * ( ) {
377+ yield {
378+ choices : [ { delta : { content : "Test response" } } ] ,
379+ }
380+ } ,
381+ } ) )
382+
383+ const stream = handler . createMessage ( "test prompt" , [ ] , {
384+ taskId : "test-task-id" ,
385+ } )
386+ await stream . next ( )
387+
388+ const callArgs = mockCreate . mock . calls [ 0 ] [ 0 ]
389+ expect ( callArgs ) . toHaveProperty ( "max_tokens" )
390+ expect ( callArgs ) . not . toHaveProperty ( "max_completion_tokens" )
391+ } )
392+
393+ it ( "should not include stream_options" , async ( ) => {
394+ mockCreate . mockImplementationOnce ( ( ) => ( {
395+ [ Symbol . asyncIterator ] : async function * ( ) {
396+ yield {
397+ choices : [ { delta : { content : "Test response" } } ] ,
398+ }
399+ } ,
400+ } ) )
401+
402+ const stream = handler . createMessage ( "test prompt" , [ ] , {
403+ taskId : "test-task-id" ,
404+ } )
405+ await stream . next ( )
406+
407+ const callArgs = mockCreate . mock . calls [ 0 ] [ 0 ]
408+ expect ( callArgs ) . not . toHaveProperty ( "stream_options" )
409+ } )
410+
411+ it ( "should not include parallel_tool_calls" , async ( ) => {
412+ mockCreate . mockImplementationOnce ( ( ) => ( {
413+ [ Symbol . asyncIterator ] : async function * ( ) {
414+ yield {
415+ choices : [ { delta : { content : "Test response" } } ] ,
416+ }
417+ } ,
418+ } ) )
419+
420+ const stream = handler . createMessage ( "test prompt" , [ ] , {
421+ taskId : "test-task-id" ,
422+ tools : testTools ,
423+ } )
424+ await stream . next ( )
425+
426+ const callArgs = mockCreate . mock . calls [ 0 ] [ 0 ]
427+ expect ( callArgs ) . not . toHaveProperty ( "parallel_tool_calls" )
428+ } )
429+
430+ it ( "should not set strict: true on tool definitions" , async ( ) => {
431+ mockCreate . mockImplementationOnce ( ( ) => ( {
432+ [ Symbol . asyncIterator ] : async function * ( ) {
433+ yield {
434+ choices : [ { delta : { content : "Test response" } } ] ,
435+ }
436+ } ,
437+ } ) )
438+
439+ const stream = handler . createMessage ( "test prompt" , [ ] , {
440+ taskId : "test-task-id" ,
441+ tools : testTools ,
442+ } )
443+ await stream . next ( )
444+
445+ const callArgs = mockCreate . mock . calls [ 0 ] [ 0 ]
446+ const tools = callArgs . tools
447+ expect ( tools ) . toBeDefined ( )
448+ for ( const tool of tools ) {
449+ // DashScope does not support strict mode
450+ expect ( tool . function ) . not . toHaveProperty ( "strict" )
451+ }
452+ } )
453+
454+ it ( "should use max_tokens in completePrompt" , async ( ) => {
455+ mockCreate . mockImplementationOnce ( ( ) => ( {
456+ choices : [ { message : { content : "response" } } ] ,
457+ } ) )
458+
459+ await handler . completePrompt ( "test prompt" )
460+
461+ const callArgs = mockCreate . mock . calls [ 0 ] [ 0 ]
462+ expect ( callArgs ) . toHaveProperty ( "max_tokens" )
463+ expect ( callArgs ) . not . toHaveProperty ( "max_completion_tokens" )
464+ } )
465+ } )
373466} )
0 commit comments