Files
magpie/internal/usage/served_region_test.go
T
yetone e156fdd032 usage: a model's region deployment answered under its own name is not a swap (plugins#628)
WorkBuddy AI lists DeepSeek V4.1 Flash as deepseek-v4.1-flash-sg, its
paid id for the Singapore deployment. The plugin's product config names
it paidId to the free deepseek-v4.1-flash, with one window for both.
WorkBuddy answers under the model's own name, so the Routing page tagged
each request "请求 deepseek-v4.1-flash-sg · 实际 deepseek-v4.1-flash".
Old routes and kept usage rows kept the mark, so removing the model and
setting the provider up again didn't clear it (chansee97, plugins#628).

- RegionTail (internal/usage/served.go) covers a name that is the other
  with -sg, -us, -eu, -cn, -intl or -global after it. Such a pair is the
  same model, and Swapped excludes it.
- A region in both names, or a name that differs besides the region, is
  still a swap.
- Kept rows (request_page.go) and kept routes (gateway history.go's
  routedAgain) are judged again with it, so old marks go too.

Run on mote, at 5f0a84a00 plus this change:
- gofmt -l internal plugins: clean.
- go test -count=1 -timeout 45m on ./internal/usage, ./internal/usageapi,
  ./internal/budget, ./internal/davsync, ./internal/middleware,
  ./internal/otlp, ./internal/gui/..., ./internal/cli, ./internal/tui,
  ./internal/gateway/..., ./plugins/middleware/..., ./plugins/otel/... and
  ./internal/agent (every importer of internal/usage): all ok except four
  reds that are filed and don't touch swap marking:
  - internal/gui TestMainWindowCorners (#3949)
  - internal/cli TestEveryRouteHasACommandOrIsNamed (#4826)
  - internal/gateway TestCodexPoolSaysTheClientsVersion (#4807)
  - internal/gateway TestUnroutedRequestShownThenAnswered (#4200)
- GOOS=linux and GOOS=windows go vet ./internal/usage
  ./internal/gateway/...: ok.

After the rebase onto a32588528, which changed internal/usage's
request_page.go and match_chunks.go:
- ./internal/usage and ./internal/usageapi: ok.
- go test -run "RouteKept|Swap|Served|History" ./internal/gateway: ok.
- vet: ok.

Broken by hand, each red:
- RegionTail taken out of Swapped: TestSwappedRegionTail.
- The kept-row re-judge taken out: TestKeptRowRegionTailNotSwapped.
- The routedAgain re-judge taken out: TestRouteKeptRegionTailNotSwapped.

Not tried:
- A live WorkBuddy AI request to -sg, which would spend credits. That
  WorkBuddy answers -sg under the plain name rests on the report.
- The reporter's screen. This assumes the "实际" tag they saw is the
  Routing page's swap tag (or Usage's Served column, which is fixed by
  the same rule).
2026-11-02 19:26:26 +08:00

50 lines
1.9 KiB
Go

package usage
import "testing"
// WorkBuddy AI lists DeepSeek V4.1 Flash as deepseek-v4.1-flash-sg, its
// paid id for the Singapore deployment, and answers under the model's own
// name: the Routing page marked it "requested deepseek-v4.1-flash-sg ·
// served deepseek-v4.1-flash" (plugins#628, chansee97). A region after
// the name asked for, or after the name that answered, is the same model.
// Another model with a region after it is still a swap, as is one region
// answered as another.
func TestSwappedRegionTail(t *testing.T) {
for _, c := range [][2]string{
{"deepseek-v4.1-flash-sg", "deepseek-v4.1-flash"},
{"deepseek-v4.1-flash", "deepseek-v4.1-flash-sg"},
{"workbuddy-ai/deepseek-v4.1-flash-sg", "DeepSeek-V4.1-Flash"},
{"glm-5.1-intl", "glm-5.1"},
{"qwen3.8-plus_cn", "qwen3.8-plus"},
} {
if Swapped(c[0], c[1]) {
t.Errorf("%s answered as %s is the model asked for", c[0], c[1])
}
}
for _, c := range [][2]string{
{"deepseek-v4.1-flash-sg", "deepseek-v4.1-pro"},
{"deepseek-v4.1-pro-sg", "deepseek-v4.1-flash"},
{"deepseek-v4.1-flash-sg", "deepseek-chat"},
{"deepseek-v4.1-flash-sg", "deepseek-v4.1-flash-thinking"},
{"gpt-5-sg", "gpt-5-mini"},
{"sg", "us"},
} {
if !Swapped(c[0], c[1]) {
t.Errorf("%s answered as %s is another model", c[0], c[1])
}
}
}
// A row kept marked swapped before plugins#628 is read back as not
// swapped; a real swap stays one.
func TestKeptRowRegionTailNotSwapped(t *testing.T) {
c := &rowChunk{}
c.add(Row{Record: Record{Provider: "workbuddy-ai", Model: "deepseek-v4.1-flash-sg", Served: "deepseek-v4.1-flash"}, Swapped: true}, "", 0, false)
c.add(Row{Record: Record{Provider: "workbuddy-ai", Model: "deepseek-v4.1-flash-sg", Served: "deepseek-v4.1-pro"}, Swapped: true}, "", 1, false)
for _, chunk := range []*rowChunk{c, c.pack().unpack()} {
if chunk.row(0).Swapped || !chunk.row(1).Swapped {
t.Fatalf("region %v, other model %v", chunk.row(0).Swapped, chunk.row(1).Swapped)
}
}
}