(t *testing.T)
| 96 | } |
| 97 | |
| 98 | func 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 | |
| 134 | func TestFallbackNoRetryOnNonRetryableError(t *testing.T) { |
| 135 | t.Parallel() |
nothing calls this directly
no test coverage detected