(t *testing.T)
| 639 | } |
| 640 | |
| 641 | func TestToolCallVariations(t *testing.T) { |
| 642 | t.Parallel() |
| 643 | |
| 644 | tests := []struct { |
| 645 | name string |
| 646 | streamBuilder func() *streamBuilder |
| 647 | description string |
| 648 | }{ |
| 649 | { |
| 650 | name: "tool_call_with_empty_args", |
| 651 | streamBuilder: func() *streamBuilder { |
| 652 | return newStreamBuilder(). |
| 653 | AddToolCallName("call_1", "empty_tool"). |
| 654 | AddToolCallArguments("call_1", "{}"). |
| 655 | AddStopWithUsage(3, 5) |
| 656 | }, |
| 657 | description: "Tool call with empty JSON arguments", |
| 658 | }, |
| 659 | { |
| 660 | name: "multiple_tool_calls", |
| 661 | streamBuilder: func() *streamBuilder { |
| 662 | return newStreamBuilder(). |
| 663 | AddToolCallName("call_1", "tool_one"). |
| 664 | AddToolCallArguments("call_1", `{"param":"value1"}`). |
| 665 | AddToolCallName("call_2", "tool_two"). |
| 666 | AddToolCallArguments("call_2", `{"param":"value2"}`). |
| 667 | AddStopWithUsage(8, 12) |
| 668 | }, |
| 669 | description: "Multiple tool calls in sequence", |
| 670 | }, |
| 671 | { |
| 672 | name: "tool_call_with_fragmented_args", |
| 673 | streamBuilder: func() *streamBuilder { |
| 674 | return newStreamBuilder(). |
| 675 | AddToolCallName("call_1", "fragmented_tool"). |
| 676 | AddToolCallArguments("call_1", `{"long`). |
| 677 | AddToolCallArguments("call_1", `_param": "`). |
| 678 | AddToolCallArguments("call_1", `some_value"}`). |
| 679 | AddStopWithUsage(5, 8) |
| 680 | }, |
| 681 | description: "Tool call with arguments streamed in fragments", |
| 682 | }, |
| 683 | } |
| 684 | |
| 685 | for _, tt := range tests { |
| 686 | t.Run(tt.name, func(t *testing.T) { |
| 687 | stream := tt.streamBuilder().Build() |
| 688 | sess := session.New(session.WithUserMessage("Use tools")) |
| 689 | events := runSession(t, sess, stream) |
| 690 | |
| 691 | require.True(t, hasEventType(t, events, &PartialToolCallEvent{}), "Expected PartialToolCallEvent for %s", tt.description) |
| 692 | require.True(t, hasEventType(t, events, &StreamStartedEvent{}), "Expected StreamStartedEvent") |
| 693 | require.True(t, hasEventType(t, events, &StreamStoppedEvent{}), "Expected StreamStoppedEvent") |
| 694 | }) |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | // queueProvider returns a different stream on each CreateChatCompletionStream call. |
nothing calls this directly
no test coverage detected