MCPcopy Index your code
hub / github.com/docker/docker-agent / TestXMLToolCallFallback_WithPreamble

Function TestXMLToolCallFallback_WithPreamble

pkg/runtime/runtime_test.go:540–569  ·  view source on GitHub ↗

TestXMLToolCallFallback_WithPreamble verifies that preamble text before a block is emitted as AgentChoice while the XML is suppressed.

(t *testing.T)

Source from the content-addressed store, hash-verified

538// TestXMLToolCallFallback_WithPreamble verifies that preamble text before a
539// <tool_call> block is emitted as AgentChoice while the XML is suppressed.
540func 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
571func TestErrorEvent(t *testing.T) {
572 t.Parallel()

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
WithUserMessageFunction · 0.92
newStreamBuilderFunction · 0.85
runSessionFunction · 0.85
hasEventTypeFunction · 0.85
AddStopWithUsageMethod · 0.80
BuildMethod · 0.45
AddContentMethod · 0.45

Tested by

no test coverage detected