@@ -467,8 +467,8 @@ test("responsesSseToChatCompletionsSse delivers the first frame before a macrota
467467 await reader . cancel ( ) ;
468468} ) ;
469469
470- test ( "POST /v1/chat/completions rejects response_format for routed openai-chat" , async ( ) => {
471- const upstream = mockChatUpstream ( ) ;
470+ test ( "POST /v1/chat/completions forwards response_format to routed openai-chat" , async ( ) => {
471+ const { server : upstream , captured } = mockChatUpstreamCapturing ( ) ;
472472 saveConfig ( mockConfig ( `${ upstream . url . toString ( ) . replace ( / \/ $ / , "" ) } /v1` ) ) ;
473473 const server = startServer ( 0 ) ;
474474 try {
@@ -477,15 +477,47 @@ test("POST /v1/chat/completions rejects response_format for routed openai-chat",
477477 headers : { "content-type" : "application/json" } ,
478478 body : JSON . stringify ( {
479479 model : "mock/test-model" ,
480- stream : false ,
480+ stream : true ,
481481 messages : [ { role : "user" , content : "hi" } ] ,
482- response_format : { type : "json_object" } ,
482+ response_format : { type : "json_schema" , json_schema : { name : "answer" , schema : { type : "object" } , strict : true } } ,
483483 } ) ,
484484 } ) ;
485- expect ( response . status ) . toBe ( 400 ) ;
486- const json = await response . json ( ) as { error : { message : string ; type : string } } ;
487- expect ( json . error . message ) . toContain ( "response_format" ) ;
488- expect ( json . error . type ) . toBe ( "invalid_request_error" ) ;
485+ expect ( response . status ) . toBe ( 200 ) ;
486+ await response . text ( ) ;
487+ // Round trip: chat nested -> internal flat text.format -> re-nested on the wire, byte-identical.
488+ expect ( captured . length ) . toBe ( 1 ) ;
489+ expect ( captured [ 0 ] ! . response_format ) . toEqual ( {
490+ type : "json_schema" ,
491+ json_schema : { name : "answer" , schema : { type : "object" } , strict : true } ,
492+ } ) ;
493+ } finally {
494+ await server . stop ( true ) ;
495+ upstream . stop ( true ) ;
496+ }
497+ } ) ;
498+
499+ test ( "POST /v1/responses carries text.format onto the routed chat wire" , async ( ) => {
500+ const { server : upstream , captured } = mockChatUpstreamCapturing ( ) ;
501+ saveConfig ( mockConfig ( `${ upstream . url . toString ( ) . replace ( / \/ $ / , "" ) } /v1` ) ) ;
502+ const server = startServer ( 0 ) ;
503+ try {
504+ const response = await fetch ( new URL ( "/v1/responses" , server . url ) , {
505+ method : "POST" ,
506+ headers : { "content-type" : "application/json" } ,
507+ body : JSON . stringify ( {
508+ model : "mock/test-model" ,
509+ stream : true ,
510+ input : [ { type : "message" , role : "user" , content : [ { type : "input_text" , text : "hi" } ] } ] ,
511+ text : { format : { type : "json_schema" , name : "answer" , schema : { type : "object" } , strict : true } } ,
512+ } ) ,
513+ } ) ;
514+ expect ( response . status ) . toBe ( 200 ) ;
515+ await response . text ( ) ;
516+ expect ( captured . length ) . toBe ( 1 ) ;
517+ expect ( captured [ 0 ] ! . response_format ) . toEqual ( {
518+ type : "json_schema" ,
519+ json_schema : { name : "answer" , schema : { type : "object" } , strict : true } ,
520+ } ) ;
489521 } finally {
490522 await server . stop ( true ) ;
491523 upstream . stop ( true ) ;
0 commit comments