Files
magpie/internal/gateway/fallback_unpicked_test.go
T
yetoneandtimonwong 25fc92d59a fallback: a model unchecked in its provider's list is not a fallback to go to (#3911)
The sibling of the group fix before this: a provider's Fallback list
resolved each entry with Resolve, so a fallback the user unchecked in
its own provider's list was still sent to, while the fallback editor
says "No provider serves {id} now; it is skipped". plan's fallbacks,
and the places that read the same list (carefulOf, native compaction's
carrier check, unredactedRoute, codexFallsBack), now resolve through
provider.ResolveRoute, which skips it. ResolveRoute scans the entries
once for the one model rather than building a map per request.

Test: fallback_unpicked_test.go, plan/m answering 429 with fallbacks
a/x (unchecked) and b/x goes to b and never to a.

Run (mote): red on the previous commit's tree ("from ka", a tried
[ka]); green with this one. Full suite as recorded in the previous
commit, which ran at this tree: 76 packages ok, internal/plugin's
TestGatewayHookMixedPiPackage red at load ~134 (#2865), passing alone.
go vet darwin/linux/windows clean.

Not tried: a real provider with a fallback in the app.

Co-authored-by: timonwong <timon86.wang@gmail.com>
2026-10-28 17:34:16 +08:00

32 lines
1.2 KiB
Go

package gateway
import (
"net/http/httptest"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// A provider's fallback the user unchecked in its own provider's list is
// skipped as a group's member is (#3911): the fallback editor says "No
// provider serves it now; it is skipped", and the gateway did send there.
func TestFallbackSkipsModelRemovedFromProviderPicks(t *testing.T) {
fresh(t)
plan, a, b := &keyed{fail: map[string]int{"kp": 429}}, &keyed{}, &keyed{}
serveOn(t, "a", "ka", []string{"x", "y"}, a)
serveOn(t, "b", "kb", []string{"x"}, b)
up := httptest.NewServer(plan)
t.Cleanup(up.Close)
if err := provider.Save(provider.Provider{ID: "plan", Name: "Plan", Key: "kp", Models: []string{"m"}, Chat: up.URL + "/v1", Fallback: []string{"a/x", "b/x"}}); err != nil {
t.Fatal(err)
}
if err := provider.SetModels("a", []string{"y"}); err != nil {
t.Fatal(err)
}
code, body := postAs(t, New(), "", `{"model":"plan/m","messages":[{"role":"user","content":"hi"}]}`)
if code != 200 || !strings.Contains(body, "from kb") || len(a.tried) != 0 || len(plan.tried) != 1 {
t.Fatalf("plan/m, its fallback a/x unchecked: %d %s, plan tried %v, a tried %v, b tried %v", code, body, plan.tried, a.tried, b.tried)
}
}