TestXMLToolCallFallback_WithPreamble verifies that preamble text before a block is emitted as AgentChoice while the XML is suppressed.
(t *testing.T)
| 538 | // TestXMLToolCallFallback_WithPreamble verifies that preamble text before a |
| 539 | // <tool_call> block is emitted as AgentChoice while the XML is suppressed. |
| 540 | func TestXMLToolCallFallback_WithPreamble(t *testing.T) { |
| 541 | t.Parallel() |
| 542 | |
| 543 | stream := newStreamBuilder(). |
| 544 | AddContent("I'll list the files for you.\n"). |
| 545 | AddContent(`<tool_call>{"name": "ls", "arguments": {"path": "/tmp"}}</tool_call>`). |
| 546 | AddStopWithUsage(12, 18). |
| 547 | Build() |
| 548 | |
| 549 | sess := session.New(session.WithUserMessage("list /tmp")) |
| 550 | events := runSession(t, sess, stream) |
| 551 | |
| 552 | // Preamble text must have been emitted as AgentChoice. |
| 553 | var choiceContents []string |
| 554 | for _, ev := range events { |
| 555 | if choice, ok := ev.(*AgentChoiceEvent); ok { |
| 556 | choiceContents = append(choiceContents, choice.Content) |
| 557 | } |
| 558 | } |
| 559 | require.NotEmpty(t, choiceContents, "Expected AgentChoice events for preamble") |
| 560 | require.Contains(t, strings.Join(choiceContents, ""), "I'll list the files for you.") |
| 561 | |
| 562 | // XML itself must not leak into AgentChoice. |
| 563 | for _, c := range choiceContents { |
| 564 | require.NotContains(t, c, "<tool_call>") |
| 565 | } |
| 566 | |
| 567 | // Tool must still be extracted. |
| 568 | require.True(t, hasEventType(t, events, &PartialToolCallEvent{})) |
| 569 | } |
| 570 | |
| 571 | func TestErrorEvent(t *testing.T) { |
| 572 | t.Parallel() |
nothing calls this directly
no test coverage detected