@@ -182,7 +182,7 @@ func TestHandleNonStreamToolCallInterceptsReasonerModel(t *testing.T) {
182182 }
183183}
184184
185- func TestHandleNonStreamUnknownToolNotIntercepted (t * testing.T ) {
185+ func TestHandleNonStreamUnknownToolIntercepted (t * testing.T ) {
186186 h := & Handler {}
187187 resp := makeSSEHTTPResponse (
188188 `data: {"p":"response/content","v":"{\"tool_calls\":[{\"name\":\"not_in_schema\",\"input\":{\"q\":\"go\"}}]}"}` ,
@@ -198,16 +198,13 @@ func TestHandleNonStreamUnknownToolNotIntercepted(t *testing.T) {
198198 out := decodeJSONBody (t , rec .Body .String ())
199199 choices , _ := out ["choices" ].([]any )
200200 choice , _ := choices [0 ].(map [string ]any )
201- if choice ["finish_reason" ] != "stop " {
202- t .Fatalf ("expected finish_reason=stop , got %#v" , choice ["finish_reason" ])
201+ if choice ["finish_reason" ] != "tool_calls " {
202+ t .Fatalf ("expected finish_reason=tool_calls , got %#v" , choice ["finish_reason" ])
203203 }
204204 msg , _ := choice ["message" ].(map [string ]any )
205- if _ , ok := msg ["tool_calls" ]; ok {
206- t .Fatalf ("did not expect tool_calls for unknown schema name, got %#v" , msg ["tool_calls" ])
207- }
208- content , _ := msg ["content" ].(string )
209- if ! strings .Contains (content , `"tool_calls"` ) {
210- t .Fatalf ("expected unknown tool json to pass through as text, got %#v" , content )
205+ toolCalls , _ := msg ["tool_calls" ].([]any )
206+ if len (toolCalls ) != 1 {
207+ t .Fatalf ("expected tool_calls for unknown schema name, got %#v" , msg ["tool_calls" ])
211208 }
212209}
213210
@@ -413,7 +410,7 @@ func TestHandleStreamReasonerToolCallInterceptsWithoutRawContentLeak(t *testing.
413410 }
414411}
415412
416- func TestHandleStreamUnknownToolDoesNotLeakRawPayload (t * testing.T ) {
413+ func TestHandleStreamUnknownToolEmitsToolCall (t * testing.T ) {
417414 h := & Handler {}
418415 resp := makeSSEHTTPResponse (
419416 `data: {"p":"response/content","v":"{\"tool_calls\":[{\"name\":\"not_in_schema\",\"input\":{\"q\":\"go\"}}]}"}` ,
@@ -428,18 +425,18 @@ func TestHandleStreamUnknownToolDoesNotLeakRawPayload(t *testing.T) {
428425 if ! done {
429426 t .Fatalf ("expected [DONE], body=%s" , rec .Body .String ())
430427 }
431- if streamHasToolCallsDelta (frames ) {
432- t .Fatalf ("did not expect tool_calls delta for unknown schema name, body=%s" , rec .Body .String ())
428+ if ! streamHasToolCallsDelta (frames ) {
429+ t .Fatalf ("expected tool_calls delta for unknown schema name, body=%s" , rec .Body .String ())
433430 }
434431 if streamHasRawToolJSONContent (frames ) {
435432 t .Fatalf ("did not expect raw tool_calls json leak for unknown schema name: %s" , rec .Body .String ())
436433 }
437- if streamFinishReason (frames ) != "stop " {
438- t .Fatalf ("expected finish_reason=stop , body=%s" , rec .Body .String ())
434+ if streamFinishReason (frames ) != "tool_calls " {
435+ t .Fatalf ("expected finish_reason=tool_calls , body=%s" , rec .Body .String ())
439436 }
440437}
441438
442- func TestHandleStreamUnknownToolNoArgsDoesNotLeakRawPayload (t * testing.T ) {
439+ func TestHandleStreamUnknownToolNoArgsEmitsToolCall (t * testing.T ) {
443440 h := & Handler {}
444441 resp := makeSSEHTTPResponse (
445442 `data: {"p":"response/content","v":"{\"tool_calls\":[{\"name\":\"not_in_schema\"}]}"}` ,
@@ -454,14 +451,14 @@ func TestHandleStreamUnknownToolNoArgsDoesNotLeakRawPayload(t *testing.T) {
454451 if ! done {
455452 t .Fatalf ("expected [DONE], body=%s" , rec .Body .String ())
456453 }
457- if streamHasToolCallsDelta (frames ) {
458- t .Fatalf ("did not expect tool_calls delta for unknown schema name (no args), body=%s" , rec .Body .String ())
454+ if ! streamHasToolCallsDelta (frames ) {
455+ t .Fatalf ("expected tool_calls delta for unknown schema name (no args), body=%s" , rec .Body .String ())
459456 }
460457 if streamHasRawToolJSONContent (frames ) {
461458 t .Fatalf ("did not expect raw tool_calls json leak for unknown schema name (no args): %s" , rec .Body .String ())
462459 }
463- if streamFinishReason (frames ) != "stop " {
464- t .Fatalf ("expected finish_reason=stop , body=%s" , rec .Body .String ())
460+ if streamFinishReason (frames ) != "tool_calls " {
461+ t .Fatalf ("expected finish_reason=tool_calls , body=%s" , rec .Body .String ())
465462 }
466463}
467464
0 commit comments