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

Function TestContextCancellation

pkg/runtime/runtime_test.go:605–639  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

603}
604
605func TestContextCancellation(t *testing.T) {
606 t.Parallel()
607
608 stream := newStreamBuilder().
609 AddContent("This should not complete").
610 AddStopWithUsage(10, 5).
611 Build()
612
613 prov := &mockProvider{id: "test/mock-model", stream: stream}
614 root := agent.New("root", "You are a test agent", agent.WithModel(prov))
615 tm := team.New(team.WithAgents(root))
616
617 rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(false), WithModelStore(mockModelStore{}))
618 require.NoError(t, err)
619
620 sess := session.New(session.WithUserMessage("Hi"))
621 sess.Title = "Unit Test"
622
623 ctx, cancel := context.WithCancel(t.Context())
624 evCh := rt.RunStream(ctx, sess)
625
626 cancel()
627
628 var events []Event
629 for ev := range evCh {
630 events = append(events, ev)
631 }
632
633 require.GreaterOrEqual(t, len(events), 4)
634 require.IsType(t, &TeamInfoEvent{}, events[0])
635 require.IsType(t, &ToolsetInfoEvent{}, events[1])
636 require.IsType(t, &UserMessageEvent{}, events[2])
637 require.IsType(t, &StreamStartedEvent{}, events[3])
638 require.IsType(t, &StreamStoppedEvent{}, events[len(events)-1])
639}
640
641func TestToolCallVariations(t *testing.T) {
642 t.Parallel()

Callers

nothing calls this directly

Calls 14

RunStreamMethod · 0.95
NewFunction · 0.92
NewFunction · 0.92
WithAgentsFunction · 0.92
NewFunction · 0.92
WithUserMessageFunction · 0.92
newStreamBuilderFunction · 0.85
NewLocalRuntimeFunction · 0.85
WithSessionCompactionFunction · 0.85
WithModelStoreFunction · 0.85
AddStopWithUsageMethod · 0.80
ContextMethod · 0.80

Tested by

no test coverage detected