@@ -13,7 +13,7 @@ describe('OpenAIResponsesModel', () => {
13
13
setTracingDisabled ( true ) ;
14
14
} ) ;
15
15
it ( 'getResponse returns correct ModelResponse and calls client with right parameters' , async ( ) => {
16
- withTrace ( 'test' , async ( ) => {
16
+ await withTrace ( 'test' , async ( ) => {
17
17
const fakeResponse = {
18
18
id : 'res1' ,
19
19
usage : {
@@ -74,8 +74,67 @@ describe('OpenAIResponsesModel', () => {
74
74
} ) ;
75
75
} ) ;
76
76
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
+
77
136
it ( 'merges top-level reasoning and text settings into provider data for Responses API' , async ( ) => {
78
- withTrace ( 'test' , async ( ) => {
137
+ await withTrace ( 'test' , async ( ) => {
79
138
const fakeResponse = {
80
139
id : 'res-settings' ,
81
140
usage : {
@@ -134,7 +193,7 @@ describe('OpenAIResponsesModel', () => {
134
193
} ) ;
135
194
136
195
it ( 'getStreamedResponse yields events and calls client with stream flag' , async ( ) => {
137
- withTrace ( 'test' , async ( ) => {
196
+ await withTrace ( 'test' , async ( ) => {
138
197
const fakeResponse = { id : 'res2' , usage : { } , output : [ ] } ;
139
198
const events : ResponseStreamEvent [ ] = [
140
199
{ type : 'response.created' , response : fakeResponse as any } ,
0 commit comments