@@ -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,8 @@ describe('OpenAIResponsesModel', () => {
7474 } ) ;
7575 } ) ;
7676
77- it ( 'omits instructions when systemInstructions is empty or whitespace ' , async ( ) => {
78- withTrace ( 'test' , async ( ) => {
77+ it ( 'normalizes systemInstructions so empty strings are omitted ' , async ( ) => {
78+ await withTrace ( 'test' , async ( ) => {
7979 const fakeResponse = {
8080 id : 'res-empty-instructions' ,
8181 usage : {
@@ -85,15 +85,9 @@ describe('OpenAIResponsesModel', () => {
8585 } ,
8686 output : [ ] ,
8787 } ;
88- const createMock = vi . fn ( ) . mockResolvedValue ( fakeResponse ) ;
89- const fakeClient = {
90- responses : { create : createMock } ,
91- } as unknown as OpenAI ;
92- const model = new OpenAIResponsesModel ( fakeClient , 'gpt-empty' ) ;
93-
94- for ( const instructions of [ '' , ' ' ] ) {
88+ for ( const systemInstructions of [ '' , ' ' ] ) {
9589 const request = {
96- systemInstructions : instructions ,
90+ systemInstructions,
9791 input : 'hello' ,
9892 modelSettings : { } ,
9993 tools : [ ] ,
@@ -102,19 +96,45 @@ describe('OpenAIResponsesModel', () => {
10296 tracing : false ,
10397 signal : undefined ,
10498 } ;
105- await model . getResponse ( request as any ) ;
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 ) ;
106104
107105 expect ( createMock ) . toHaveBeenCalledTimes ( 1 ) ;
108106 const [ args ] = createMock . mock . calls [ 0 ] ;
109107 expect ( 'instructions' in args ) . toBe ( true ) ;
110108 expect ( args . instructions ) . toBeUndefined ( ) ;
111- 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 ) ;
112132 }
113133 } ) ;
114134 } ) ;
115135
116136 it ( 'merges top-level reasoning and text settings into provider data for Responses API' , async ( ) => {
117- withTrace ( 'test' , async ( ) => {
137+ await withTrace ( 'test' , async ( ) => {
118138 const fakeResponse = {
119139 id : 'res-settings' ,
120140 usage : {
@@ -173,7 +193,7 @@ describe('OpenAIResponsesModel', () => {
173193 } ) ;
174194
175195 it ( 'getStreamedResponse yields events and calls client with stream flag' , async ( ) => {
176- withTrace ( 'test' , async ( ) => {
196+ await withTrace ( 'test' , async ( ) => {
177197 const fakeResponse = { id : 'res2' , usage : { } , output : [ ] } ;
178198 const events : ResponseStreamEvent [ ] = [
179199 { type : 'response.created' , response : fakeResponse as any } ,
0 commit comments