mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-05 10:27:50 +08:00
fix context
This commit is contained in:
@@ -120,6 +120,35 @@ func TestCallLLMWithModelFallback_RetriesOnGateway524(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallLLMWithModelFallback_RetriesOnAuthUnavailable500(t *testing.T) {
|
||||
p := &fallbackTestProvider{
|
||||
byModel: map[string]fallbackResult{
|
||||
"gemini-3-flash": {err: fmt.Errorf(`API error (status 500, content-type "application/json"): {"error":{"message":"auth_unavailable: no auth available","type":"server_error","code":"internal_server_error"}}`)},
|
||||
"gpt-4o-mini": {resp: &providers.LLMResponse{Content: "ok"}},
|
||||
},
|
||||
}
|
||||
|
||||
al := &AgentLoop{
|
||||
provider: p,
|
||||
model: "gemini-3-flash",
|
||||
modelFallbacks: []string{"gpt-4o-mini"},
|
||||
}
|
||||
|
||||
resp, err := al.callLLMWithModelFallback(context.Background(), nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if resp == nil || resp.Content != "ok" {
|
||||
t.Fatalf("unexpected response: %+v", resp)
|
||||
}
|
||||
if len(p.called) != 2 {
|
||||
t.Fatalf("expected 2 model attempts, got %d (%v)", len(p.called), p.called)
|
||||
}
|
||||
if p.called[0] != "gemini-3-flash" || p.called[1] != "gpt-4o-mini" {
|
||||
t.Fatalf("unexpected model order: %v", p.called)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallLLMWithModelFallback_NoRetryOnNonRetryableError(t *testing.T) {
|
||||
p := &fallbackTestProvider{
|
||||
byModel: map[string]fallbackResult{
|
||||
@@ -162,3 +191,10 @@ func TestShouldRetryWithFallbackModel_Gateway524Error(t *testing.T) {
|
||||
t.Fatalf("expected 524 gateway timeout to trigger fallback retry")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldRetryWithFallbackModel_AuthUnavailableError(t *testing.T) {
|
||||
err := fmt.Errorf(`API error (status 500, content-type "application/json"): {"error":{"message":"auth_unavailable: no auth available","type":"server_error","code":"internal_server_error"}}`)
|
||||
if !shouldRetryWithFallbackModel(err) {
|
||||
t.Fatalf("expected auth_unavailable error to trigger fallback retry")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user