@@ -14,10 +14,11 @@ func TestVSRHeadersAddedOnSuccessfulNonCachedResponse(t *testing.T) {
14
14
15
15
// Create request context with VSR decision information
16
16
ctx := & RequestContext {
17
- VSRSelectedCategory : "math" ,
18
- VSRReasoningMode : "on" ,
19
- VSRSelectedModel : "deepseek-v31" ,
20
- VSRCacheHit : false , // Not a cache hit
17
+ VSRSelectedCategory : "math" ,
18
+ VSRReasoningMode : "on" ,
19
+ VSRSelectedModel : "deepseek-v31" ,
20
+ VSRCacheHit : false , // Not a cache hit
21
+ VSRInjectedSystemPrompt : true , // System prompt was injected
21
22
}
22
23
23
24
// Create response headers with successful status (200)
@@ -48,7 +49,7 @@ func TestVSRHeadersAddedOnSuccessfulNonCachedResponse(t *testing.T) {
48
49
assert .NotNil (t , headerMutation , "HeaderMutation should not be nil for successful non-cached response" )
49
50
50
51
setHeaders := headerMutation .GetSetHeaders ()
51
- assert .Len (t , setHeaders , 3 , "Should have 3 VSR headers" )
52
+ assert .Len (t , setHeaders , 4 , "Should have 4 VSR headers" )
52
53
53
54
// Verify each header
54
55
headerMap := make (map [string ]string )
@@ -59,6 +60,7 @@ func TestVSRHeadersAddedOnSuccessfulNonCachedResponse(t *testing.T) {
59
60
assert .Equal (t , "math" , headerMap ["x-vsr-selected-category" ])
60
61
assert .Equal (t , "on" , headerMap ["x-vsr-selected-reasoning" ])
61
62
assert .Equal (t , "deepseek-v31" , headerMap ["x-vsr-selected-model" ])
63
+ assert .Equal (t , "true" , headerMap ["x-vsr-injected-system-prompt" ])
62
64
}
63
65
64
66
func TestVSRHeadersNotAddedOnCacheHit (t * testing.T ) {
@@ -139,10 +141,11 @@ func TestVSRHeadersPartialInformation(t *testing.T) {
139
141
140
142
// Create request context with partial VSR information
141
143
ctx := & RequestContext {
142
- VSRSelectedCategory : "math" ,
143
- VSRReasoningMode : "" , // Empty reasoning mode
144
- VSRSelectedModel : "deepseek-v31" ,
145
- VSRCacheHit : false ,
144
+ VSRSelectedCategory : "math" ,
145
+ VSRReasoningMode : "" , // Empty reasoning mode
146
+ VSRSelectedModel : "deepseek-v31" ,
147
+ VSRCacheHit : false ,
148
+ VSRInjectedSystemPrompt : false , // No system prompt injected
146
149
}
147
150
148
151
// Create response headers with successful status (200)
@@ -169,7 +172,7 @@ func TestVSRHeadersPartialInformation(t *testing.T) {
169
172
assert .NotNil (t , headerMutation )
170
173
171
174
setHeaders := headerMutation .GetSetHeaders ()
172
- assert .Len (t , setHeaders , 2 , "Should have 2 VSR headers (excluding empty reasoning mode)" )
175
+ assert .Len (t , setHeaders , 3 , "Should have 3 VSR headers (excluding empty reasoning mode, but including injected-system-prompt )" )
173
176
174
177
// Verify each header
175
178
headerMap := make (map [string ]string )
@@ -179,5 +182,80 @@ func TestVSRHeadersPartialInformation(t *testing.T) {
179
182
180
183
assert .Equal (t , "math" , headerMap ["x-vsr-selected-category" ])
181
184
assert .Equal (t , "deepseek-v31" , headerMap ["x-vsr-selected-model" ])
185
+ assert .Equal (t , "false" , headerMap ["x-vsr-injected-system-prompt" ])
182
186
assert .NotContains (t , headerMap , "x-vsr-selected-reasoning" , "Empty reasoning mode should not be added" )
183
187
}
188
+
189
+ func TestVSRInjectedSystemPromptHeader (t * testing.T ) {
190
+ router := & OpenAIRouter {}
191
+
192
+ // Test case 1: System prompt was injected
193
+ t .Run ("SystemPromptInjected" , func (t * testing.T ) {
194
+ ctx := & RequestContext {
195
+ VSRSelectedCategory : "coding" ,
196
+ VSRReasoningMode : "on" ,
197
+ VSRSelectedModel : "gpt-4" ,
198
+ VSRCacheHit : false ,
199
+ VSRInjectedSystemPrompt : true ,
200
+ }
201
+
202
+ responseHeaders := & ext_proc.ProcessingRequest_ResponseHeaders {
203
+ ResponseHeaders : & ext_proc.HttpHeaders {
204
+ Headers : & core.HeaderMap {
205
+ Headers : []* core.HeaderValue {
206
+ {Key : ":status" , Value : "200" },
207
+ },
208
+ },
209
+ },
210
+ }
211
+
212
+ response , err := router .handleResponseHeaders (responseHeaders , ctx )
213
+ assert .NoError (t , err )
214
+ assert .NotNil (t , response )
215
+
216
+ headerMutation := response .GetResponseHeaders ().GetResponse ().GetHeaderMutation ()
217
+ assert .NotNil (t , headerMutation )
218
+
219
+ headerMap := make (map [string ]string )
220
+ for _ , header := range headerMutation .GetSetHeaders () {
221
+ headerMap [header .Header .Key ] = string (header .Header .RawValue )
222
+ }
223
+
224
+ assert .Equal (t , "true" , headerMap ["x-vsr-injected-system-prompt" ])
225
+ })
226
+
227
+ // Test case 2: System prompt was not injected
228
+ t .Run ("SystemPromptNotInjected" , func (t * testing.T ) {
229
+ ctx := & RequestContext {
230
+ VSRSelectedCategory : "coding" ,
231
+ VSRReasoningMode : "on" ,
232
+ VSRSelectedModel : "gpt-4" ,
233
+ VSRCacheHit : false ,
234
+ VSRInjectedSystemPrompt : false ,
235
+ }
236
+
237
+ responseHeaders := & ext_proc.ProcessingRequest_ResponseHeaders {
238
+ ResponseHeaders : & ext_proc.HttpHeaders {
239
+ Headers : & core.HeaderMap {
240
+ Headers : []* core.HeaderValue {
241
+ {Key : ":status" , Value : "200" },
242
+ },
243
+ },
244
+ },
245
+ }
246
+
247
+ response , err := router .handleResponseHeaders (responseHeaders , ctx )
248
+ assert .NoError (t , err )
249
+ assert .NotNil (t , response )
250
+
251
+ headerMutation := response .GetResponseHeaders ().GetResponse ().GetHeaderMutation ()
252
+ assert .NotNil (t , headerMutation )
253
+
254
+ headerMap := make (map [string ]string )
255
+ for _ , header := range headerMutation .GetSetHeaders () {
256
+ headerMap [header .Header .Key ] = string (header .Header .RawValue )
257
+ }
258
+
259
+ assert .Equal (t , "false" , headerMap ["x-vsr-injected-system-prompt" ])
260
+ })
261
+ }
0 commit comments