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

Function TestCompactionOverflowDoesNotLoop

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

Source from the content-addressed store, hash-verified

794func (p *errorProvider) MaxTokens() int { return 0 }
795
796func TestCompactionOverflowDoesNotLoop(t *testing.T) {
797 t.Parallel()
798
799 // The model always returns a ContextOverflowError. Without the
800 // max-retry guard this would loop forever because compaction
801 // cannot fix the problem.
802 overflowErr := modelerrors.NewContextOverflowError(errors.New("prompt is too long"))
803 prov := &errorProvider{id: "test/overflow-model", err: overflowErr}
804
805 root := agent.New("root", "You are a test agent", agent.WithModel(prov))
806 tm := team.New(team.WithAgents(root))
807
808 rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(true), WithModelStore(mockModelStoreWithLimit{limit: 100}))
809 require.NoError(t, err)
810
811 sess := session.New(session.WithUserMessage("Hello"))
812 events := rt.RunStream(t.Context(), sess)
813
814 var compactionCount int
815 var sawError bool
816 for ev := range events {
817 if e, ok := ev.(*SessionCompactionEvent); ok && e.Status == "started" {
818 compactionCount++
819 }
820 if _, ok := ev.(*ErrorEvent); ok {
821 sawError = true
822 }
823 }
824
825 // Compaction should have been attempted at most once, then the loop
826 // must give up and surface an error instead of retrying indefinitely.
827 require.LessOrEqual(t, compactionCount, 1, "expected at most 1 compaction attempt, got %d", compactionCount)
828 require.True(t, sawError, "expected an ErrorEvent after exhausting compaction retries")
829}
830
831func TestSessionWithoutUserMessage(t *testing.T) {
832 t.Parallel()

Callers

nothing calls this directly

Calls 12

RunStreamMethod · 0.95
NewContextOverflowErrorFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
WithAgentsFunction · 0.92
NewFunction · 0.92
WithUserMessageFunction · 0.92
NewLocalRuntimeFunction · 0.85
WithSessionCompactionFunction · 0.85
WithModelStoreFunction · 0.85
ContextMethod · 0.80
NewMethod · 0.45

Tested by

no test coverage detected