@@ -329,7 +329,28 @@ describe("provider-specific reasoning effort mapping", () => {
329329 expect ( body ) . not . toHaveProperty ( "tool_choice" ) ;
330330 } ) ;
331331
332- test ( "OpenAI-compatible chat keeps tool_choice when tools are present" , ( ) => {
332+ test ( "OpenAI-compatible chat omits tools and tool_choice when tool_choice is none" , ( ) => {
333+ const provider : OcxProviderConfig = {
334+ adapter : "openai-chat" ,
335+ baseUrl : "https://api.neuralwatt.com/v1" ,
336+ } ;
337+
338+ const req = createOpenAIChatAdapter ( provider ) . buildRequest ( {
339+ modelId : "glm-5.2" ,
340+ context : {
341+ messages : [ { role : "user" , content : "hello" , timestamp : 0 } ] ,
342+ tools : [ { name : "read_secret" , description : "Read" , parameters : { type : "object" } } ] ,
343+ } ,
344+ stream : false ,
345+ options : { toolChoice : "none" } ,
346+ } ) ;
347+ const body = JSON . parse ( req . body as string ) as Record < string , unknown > ;
348+
349+ expect ( body ) . not . toHaveProperty ( "tools" ) ;
350+ expect ( body ) . not . toHaveProperty ( "tool_choice" ) ;
351+ } ) ;
352+
353+ test ( "OpenAI-compatible chat advertises only the named tool when the provider downgrades the selector" , ( ) => {
333354 const provider : OcxProviderConfig = {
334355 adapter : "openai-chat" ,
335356 baseUrl : "https://api.moonshot.ai/v1" ,
@@ -340,14 +361,20 @@ describe("provider-specific reasoning effort mapping", () => {
340361 modelId : "kimi-k2.7-code" ,
341362 context : {
342363 messages : [ { role : "user" , content : "hello" , timestamp : 0 } ] ,
343- tools : [ { name : "run_tests" , description : "Run tests" , parameters : { type : "object" , properties : { } } } ] ,
364+ tools : [
365+ { name : "run_tests" , description : "Run tests" , parameters : { type : "object" , properties : { } } } ,
366+ { name : "read_secret" , description : "Read" , parameters : { type : "object" , properties : { } } } ,
367+ ] ,
344368 } ,
345369 stream : false ,
346370 options : { toolChoice : { name : "run_tests" } } ,
347371 } ) ;
348- const body = JSON . parse ( req . body as string ) as Record < string , unknown > ;
372+ const body = JSON . parse ( req . body as string ) as {
373+ tools : Array < { function : { name : string } } > ;
374+ tool_choice : string ;
375+ } ;
349376
350- expect ( body ) . toHaveProperty ( "tools" ) ;
377+ expect ( body . tools . map ( tool => tool . function . name ) ) . toEqual ( [ "run_tests" ] ) ;
351378 expect ( body . tool_choice ) . toBe ( "auto" ) ;
352379 } ) ;
353380
@@ -411,18 +438,30 @@ describe("provider-specific reasoning effort mapping", () => {
411438 modelId : "umans-kimi-k2.7" ,
412439 context : {
413440 messages : [ { role : "user" , content : "run it" , timestamp : 0 } ] ,
414- tools : [ {
415- namespace : "functions" ,
416- name : "exec_command" ,
417- description : "Run a command" ,
418- parameters : { type : "object" , properties : { cmd : { type : "string" } } , required : [ "cmd" ] } ,
419- } ] ,
441+ tools : [
442+ {
443+ namespace : "functions" ,
444+ name : "exec_command" ,
445+ description : "Run a command" ,
446+ parameters : { type : "object" , properties : { cmd : { type : "string" } } , required : [ "cmd" ] } ,
447+ } ,
448+ {
449+ namespace : "mcp__secrets" ,
450+ name : "read_secret" ,
451+ description : "Read" ,
452+ parameters : { type : "object" } ,
453+ } ,
454+ ] ,
420455 } ,
421456 stream : false ,
422457 options : { toolChoice : { name : "functions.exec_command" } } ,
423458 } ) ;
424- const body = JSON . parse ( req . body as string ) as { tool_choice : { function : { name : string } } } ;
459+ const body = JSON . parse ( req . body as string ) as {
460+ tools : Array < { function : { name : string } } > ;
461+ tool_choice : { function : { name : string } } ;
462+ } ;
425463
464+ expect ( body . tools . map ( tool => tool . function . name ) ) . toEqual ( [ "functions__exec_command" ] ) ;
426465 expect ( body . tool_choice . function . name ) . toBe ( "functions__exec_command" ) ;
427466 } ) ;
428467
0 commit comments