Files
magpie/internal/gateway/history_gemini_test.go
T
yetone 24f24abde3 usage: a ClinePass contributor-fallbacks route still shows as a swap (plugins#351)
woyin's Routing rows show cline-pass/deepseek-v4.1-flash-1017 served as
vmc/deepseek-v4p1-flash-1017-contributor-fallbacks. Third-party Cline Pass
tools record that name as a private contributor deployment
(finalProvider "openai-compatible-private"), not DeepSeek's own API. So
the row has to keep saying it was served elsewhere. 6db5e9d59's
ClineServing already does this, because only the exact model maps. This
commit is tests only: they hold the rule, so a looser match (a prefix,
say) can't hide the route later.

- TestSwappedClineServingName: -contributor-fallbacks (with and without
  the -1017 date), -contributor and -fallbacks are swaps.
- TestRouteKeptClineServingNameNotSwapped: a kept row served as
  ...-contributor-fallbacks stays swapped when it is read again.

Run at 616c87256's tree:
- go test ./internal/usage: ok.
- go test ./internal/gateway -run 'Clin|Swap|Served|routedAgain|History': ok.
- go vet on darwin, linux and windows: ok. gofmt -l: clean.

Broken by hand: ClineServing changed to a prefix match. Three usage cases
and the history case went red. Restored afterwards.

Not run: the full suite (tests only, in two packages).
2026-10-24 17:07:35 +08:00

61 lines
2.8 KiB
Go

package gateway
import "testing"
// A route kept with a try marked swapped for Antigravity's
// gemini-3.8-flash answered as gemini-3.8-flash-n (Google's name for the
// deployment serving it, dumplings on Discord) is read as not swapped;
// gpt-5 answered by gpt-5-mini stays swapped.
func TestRouteKeptGeminiServingNameNotSwapped(t *testing.T) {
r := &Route{Swapped: true, Served: "gemini-3.8-flash-n", Tries: []Try{{Model: "gemini-3.8-flash", Served: "gemini-3.8-flash-n", Swapped: true}}}
r.routedAgain()
if r.Swapped || r.Tries[0].Swapped {
t.Fatalf("still swapped: %+v", r)
}
r = &Route{Swapped: true, Served: "gpt-5-mini", Tries: []Try{{Model: "gpt-5", Served: "gpt-5-mini", Swapped: true}}}
r.routedAgain()
if !r.Swapped || !r.Tries[0].Swapped {
t.Fatalf("a real swap was cleared: %+v", r)
}
}
// A route kept with a try marked swapped for grok-4.7 answered as
// grok-4.7-build (xAI's name for the build serving it, #1455) is read as
// not swapped; grok-4.7 answered by grok-4.7-build-fast stays swapped.
func TestRouteKeptGrokServingNameNotSwapped(t *testing.T) {
r := &Route{Swapped: true, Served: "grok-4.7-build", Tries: []Try{{Model: "grok-4.7", Served: "grok-4.7-build", Swapped: true}}}
r.routedAgain()
if r.Swapped || r.Tries[0].Swapped {
t.Fatalf("still swapped: %+v", r)
}
r = &Route{Swapped: true, Served: "grok-4.7-build-fast", Tries: []Try{{Model: "grok-4.7", Served: "grok-4.7-build-fast", Swapped: true}}}
r.routedAgain()
if !r.Swapped || !r.Tries[0].Swapped {
t.Fatalf("a real swap was cleared: %+v", r)
}
}
// A route kept with a try marked swapped for ClinePass's
// cline-pass/deepseek-v4.1-flash-1017 answered as
// vmc/deepseek-v4p1-flash-1017 (its virtual model config's name, zRain on
// Discord) is read as not swapped; deepseek-v4-pro answered by
// vmc/deepseek-v4p1-flash stays swapped.
func TestRouteKeptClineServingNameNotSwapped(t *testing.T) {
r := &Route{Swapped: true, Served: "vmc/deepseek-v4p1-flash-1017", Tries: []Try{{Model: "cline-pass/deepseek-v4.1-flash-1017", Served: "vmc/deepseek-v4p1-flash-1017", Swapped: true, Upstream: "deepseek"}}}
r.routedAgain()
if r.Swapped || r.Tries[0].Swapped {
t.Fatalf("still swapped: %+v", r)
}
r = &Route{Swapped: true, Served: "vmc/deepseek-v4p1-flash", Tries: []Try{{Model: "cline-pass/deepseek-v4-pro", Served: "vmc/deepseek-v4p1-flash", Swapped: true}}}
r.routedAgain()
if !r.Swapped || !r.Tries[0].Swapped {
t.Fatalf("a real swap was cleared: %+v", r)
}
// a contributor-fallbacks config is another deployment (plugins#351)
r = &Route{Swapped: true, Served: "vmc/deepseek-v4p1-flash-1017-contributor-fallbacks", Tries: []Try{{Model: "cline-pass/deepseek-v4.1-flash-1017", Served: "vmc/deepseek-v4p1-flash-1017-contributor-fallbacks", Swapped: true}}}
r.routedAgain()
if !r.Swapped || !r.Tries[0].Swapped {
t.Fatalf("a contributor-fallbacks route was cleared: %+v", r)
}
}