@@ -13,7 +13,7 @@ describe('OpenAIResponsesModel', () => {
1313 setTracingDisabled ( true ) ;
1414 } ) ;
1515 it ( 'getResponse returns correct ModelResponse and calls client with right parameters' , async ( ) => {
16- withTrace ( 'test' , async ( ) => {
16+ await withTrace ( 'test' , async ( ) => {
1717 const fakeResponse = {
1818 id : 'res1' ,
1919 usage : {
@@ -74,8 +74,67 @@ describe('OpenAIResponsesModel', () => {
7474 } ) ;
7575 } ) ;
7676
77+ it ( 'normalizes systemInstructions so empty strings are omitted' , async ( ) => {
78+ await withTrace ( 'test' , async ( ) => {
79+ const fakeResponse = {
80+ id : 'res-empty-instructions' ,
81+ usage : {
82+ input_tokens : 0 ,
83+ output_tokens : 0 ,
84+ total_tokens : 0 ,
85+ } ,
86+ output : [ ] ,
87+ } ;
88+ for ( const systemInstructions of [ '' , ' ' ] ) {
89+ const request = {
90+ systemInstructions,
91+ input : 'hello' ,
92+ modelSettings : { } ,
93+ tools : [ ] ,
94+ outputType : 'text' ,
95+ handoffs : [ ] ,
96+ tracing : false ,
97+ signal : undefined ,
98+ } ;
99+ const createMock = vi . fn ( ) . mockResolvedValue ( fakeResponse ) ;
100+ await new OpenAIResponsesModel (
101+ { responses : { create : createMock } } as unknown as OpenAI ,
102+ 'gpt-test' ,
103+ ) . getResponse ( request as any ) ;
104+
105+ expect ( createMock ) . toHaveBeenCalledTimes ( 1 ) ;
106+ const [ args ] = createMock . mock . calls [ 0 ] ;
107+ expect ( 'instructions' in args ) . toBe ( true ) ;
108+ expect ( args . instructions ) . toBeUndefined ( ) ;
109+ }
110+
111+ for ( const systemInstructions of [ ' a ' , 'foo' ] ) {
112+ const request = {
113+ systemInstructions,
114+ input : 'hello' ,
115+ modelSettings : { } ,
116+ tools : [ ] ,
117+ outputType : 'text' ,
118+ handoffs : [ ] ,
119+ tracing : false ,
120+ signal : undefined ,
121+ } ;
122+ const createMock = vi . fn ( ) . mockResolvedValue ( fakeResponse ) ;
123+ await new OpenAIResponsesModel (
124+ { responses : { create : createMock } } as unknown as OpenAI ,
125+ 'gpt-test' ,
126+ ) . getResponse ( request as any ) ;
127+
128+ expect ( createMock ) . toHaveBeenCalledTimes ( 1 ) ;
129+ const [ args ] = createMock . mock . calls [ 0 ] ;
130+ expect ( 'instructions' in args ) . toBe ( true ) ;
131+ expect ( args . instructions ) . toBe ( systemInstructions ) ;
132+ }
133+ } ) ;
134+ } ) ;
135+
77136 it ( 'merges top-level reasoning and text settings into provider data for Responses API' , async ( ) => {
78- withTrace ( 'test' , async ( ) => {
137+ await withTrace ( 'test' , async ( ) => {
79138 const fakeResponse = {
80139 id : 'res-settings' ,
81140 usage : {
@@ -134,7 +193,7 @@ describe('OpenAIResponsesModel', () => {
134193 } ) ;
135194
136195 it ( 'getStreamedResponse yields events and calls client with stream flag' , async ( ) => {
137- withTrace ( 'test' , async ( ) => {
196+ await withTrace ( 'test' , async ( ) => {
138197 const fakeResponse = { id : 'res2' , usage : { } , output : [ ] } ;
139198 const events : ResponseStreamEvent [ ] = [
140199 { type : 'response.created' , response : fakeResponse as any } ,
0 commit comments