(t *testing.T)
| 132 | } |
| 133 | |
| 134 | func TestFallbackNoRetryOnNonRetryableError(t *testing.T) { |
| 135 | t.Parallel() |
| 136 | |
| 137 | synctest.Test(t, func(t *testing.T) { |
| 138 | primary := &failingProvider{id: "primary/auth-fail", err: errors.New("401 unauthorized")} |
| 139 | successStream := newStreamBuilder(). |
| 140 | AddContent("Should not see this"). |
| 141 | AddStopWithUsage(10, 5). |
| 142 | Build() |
| 143 | fallback := &mockProvider{id: "fallback/success", stream: successStream} |
| 144 | |
| 145 | root := agent.New("root", "test", |
| 146 | agent.WithModel(primary), |
| 147 | agent.WithFallbackModel(fallback), |
| 148 | ) |
| 149 | |
| 150 | tm := team.New(team.WithAgents(root)) |
| 151 | rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(false), WithModelStore(mockModelStore{})) |
| 152 | require.NoError(t, err) |
| 153 | |
| 154 | sess := session.New(session.WithUserMessage("test")) |
| 155 | sess.Title = "Non-Retryable Test" |
| 156 | |
| 157 | var gotError, gotFallbackContent bool |
| 158 | for ev := range rt.RunStream(t.Context(), sess) { |
| 159 | if _, ok := ev.(*ErrorEvent); ok { |
| 160 | gotError = true |
| 161 | } |
| 162 | if choice, ok := ev.(*AgentChoiceEvent); ok && choice.Content == "Should not see this" { |
| 163 | gotFallbackContent = true |
| 164 | } |
| 165 | } |
| 166 | assert.True(t, gotFallbackContent || gotError, "should either get fallback content or error") |
| 167 | }) |
| 168 | } |
| 169 | |
| 170 | func TestFallbackRetriesWithBackoff(t *testing.T) { |
| 171 | t.Parallel() |
nothing calls this directly
no test coverage detected