MCPcopy
hub / github.com/docker/docker-agent / TestCompaction

Function TestCompaction

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

Source from the content-addressed store, hash-verified

730}
731
732func TestCompaction(t *testing.T) {
733 t.Parallel()
734
735 // First stream: assistant issues a tool call and usage exceeds 90% threshold
736 mainStream := newStreamBuilder().
737 AddContent("Hello there").
738 AddStopWithUsage(101, 0). // Context limit will be 100
739 Build()
740
741 // Second stream: summary generation (simple content)
742 summaryStream := newStreamBuilder().
743 AddContent("summary").
744 AddStopWithUsage(1, 1).
745 Build()
746
747 prov := &queueProvider{id: "test/mock-model", streams: []chat.MessageStream{mainStream, summaryStream}}
748
749 root := agent.New("root", "You are a test agent", agent.WithModel(prov))
750 tm := team.New(team.WithAgents(root))
751
752 // Enable compaction and provide a model store with context limit = 100
753 rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(true), WithModelStore(mockModelStoreWithLimit{limit: 100}))
754 require.NoError(t, err)
755
756 sess := session.New(session.WithUserMessage("Start"))
757 e := rt.RunStream(t.Context(), sess)
758 for range e {
759 }
760 sess.AddMessage(session.UserMessage("Again"))
761 events := rt.RunStream(t.Context(), sess)
762
763 var seen []Event
764 for ev := range events {
765 seen = append(seen, ev)
766 }
767
768 compactionStartIdx := -1
769 for i, ev := range seen {
770 if e, ok := ev.(*SessionCompactionEvent); ok {
771 if e.Status == "started" && compactionStartIdx == -1 {
772 compactionStartIdx = i
773 }
774 }
775 }
776
777 require.NotEqual(t, -1, compactionStartIdx, "expected a SessionCompaction start event")
778}
779
780// errorProvider always returns the configured error from CreateChatCompletionStream.
781type errorProvider struct {

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected