MCPcopy Create free account
hub / github.com/docker/docker-agent / TestFallbackOrder

Function TestFallbackOrder

pkg/runtime/fallback_test.go:98–132  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

96}
97
98func TestFallbackOrder(t *testing.T) {
99 t.Parallel()
100
101 synctest.Test(t, func(t *testing.T) {
102 primary := &failingProvider{id: "primary/failing", err: errors.New("500 internal server error")}
103 fallback1 := &failingProvider{id: "fallback1/failing", err: errors.New("503 service unavailable")}
104 successStream := newStreamBuilder().
105 AddContent("Success from fallback2").
106 AddStopWithUsage(10, 5).
107 Build()
108 fallback2 := &mockProvider{id: "fallback2/success", stream: successStream}
109
110 root := agent.New("root", "test",
111 agent.WithModel(primary),
112 agent.WithFallbackModel(fallback1),
113 agent.WithFallbackModel(fallback2),
114 agent.WithFallbackRetries(0),
115 )
116
117 tm := team.New(team.WithAgents(root))
118 rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(false), WithModelStore(mockModelStore{}))
119 require.NoError(t, err)
120
121 sess := session.New(session.WithUserMessage("test"))
122 sess.Title = "Fallback Test"
123
124 var gotContent bool
125 for ev := range rt.RunStream(t.Context(), sess) {
126 if choice, ok := ev.(*AgentChoiceEvent); ok && choice.Content == "Success from fallback2" {
127 gotContent = true
128 }
129 }
130 assert.True(t, gotContent, "should receive content from fallback2")
131 })
132}
133
134func TestFallbackNoRetryOnNonRetryableError(t *testing.T) {
135 t.Parallel()

Callers

nothing calls this directly

Calls 15

RunStreamMethod · 0.95
NewFunction · 0.92
WithModelFunction · 0.92
WithFallbackModelFunction · 0.92
WithFallbackRetriesFunction · 0.92
NewFunction · 0.92
WithAgentsFunction · 0.92
NewFunction · 0.92
WithUserMessageFunction · 0.92
newStreamBuilderFunction · 0.85
NewLocalRuntimeFunction · 0.85
WithSessionCompactionFunction · 0.85

Tested by

no test coverage detected