Files
magpie/internal/usage/served_gemini_test.go
T
yetone 2f660ca86b sessions, usage: Antigravity's gemini-4-argon-d is gemini-4-argon, not a second unpriced model
oioio's Antigravity database names gemini-4-argon's generator
"gemini-4-argon-d". agAppModel took only "-n" off a gemini-* id (Google's
gemini-3.8-flash-n, b2432754e), so the Usage panel showed gemini-4-argon
twice and the -d one had no price. usage.GeminiServing had the same
"-n"-only rule, so the gateway's log would call gemini-4-argon answered
as gemini-4-argon-d a swap.

Both now ask sessions.GeminiDeployment: a gemini-* id with one lowercase
letter after its last hyphen is that model's deployment. Google's own
ids never end in a lone letter (-lite, -nano, -pro, -001, -exp), and
other makers' ids (gpt-5-d, claude-sonnet-4-5-n) stay as written. The
rule is by shape, not by the catalog: a catalog lookup at parse time
would freeze a "-d" into the kept parses whenever models.json wasn't
there yet. antigravity's parseVersions and callParseVersions go to 1,
so parses and call shards kept with gemini-4-argon-d are read again on
update; nothing else is reread.

Run (mote, at this tree):
- go test -tags nogui ./internal/sessions ./internal/usage: ok.
- go vet, GOOS=windows go vet, GOOS=linux go vet -tags nogui on both
  packages; gofmt -l prints nothing.
- Broken by hand: GeminiDeployment put back to the old -n-only rule.
  TestAntigravityAppDeploymentName failed ("gemini-4-argon-d":
  "gemini-4-argon-d", want "gemini-4-argon", fields 19, 21, 22) and
  TestSwappedGeminiServingName failed ("gemini-4-argon answered as
  gemini-4-argon-d is the model asked for"); both pass with the change.
- Full suite runs after the push (go test -tags nogui -timeout 45m ./...).

Not tried: oioio's own database (only the model name was posted), and
a real gateway request that Google answers as gemini-4-argon-d.

Reported-by: oioio (Discord)
2026-11-07 00:22:13 +08:00

113 lines
4.3 KiB
Go

package usage
import (
"os"
"path/filepath"
"testing"
"time"
"github.com/yetone/magpie/internal/catalog"
)
// Antigravity answers every level of gemini-3.8-flash with modelVersion
// gemini-3.8-flash-n (dumplings on Discord; seen on a real account for
// gemini-3.8-flash-low, -medium and -high, with and without a thinking
// level): Google's name for the deployment serving that model, not another
// model. Another vendor's swap, another Gemini model and another vendor's
// "-n" are still swaps.
func TestSwappedGeminiServingName(t *testing.T) {
for _, c := range [][2]string{
{"gemini-3.8-flash", "gemini-3.8-flash-n"},
{"antigravity/gemini-3.8-flash", "gemini-3.8-flash-n"},
{"gemini-3.8-flash-low", "gemini-3.8-flash-n"},
{"gemini-3.8-flash-medium", "gemini-3.8-flash-n"},
{"gemini-3.8-flash-high", "gemini-3.8-flash-n"},
{"gemini-3.8-flash", "models/gemini-3.8-flash-n"},
// oioio on Discord (11-06): Antigravity's name for gemini-4-argon
{"gemini-4-argon", "gemini-4-argon-d"},
{"antigravity/gemini-4-argon-high", "gemini-4-argon-d"},
} {
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{
{"gpt-5", "gpt-5-mini"},
{"openai/gpt-5", "gpt-5-mini-2025-08-07"},
{"gpt-5", "gpt-5-n"},
{"claude-sonnet-4-5", "claude-sonnet-4-5-n"},
{"gemini-3.8-flash", "gemini-3.8-flash-lite"},
{"gemini-3.8-flash", "gemini-3.8-flash-lite-n"},
{"gemini-3.8-flash", "gemini-3.7-flash-n"},
{"gemini-3.8-flash", "gemini-3.8-flash-nano"},
{"gemini-3.8-flash-high", "gemini-3.8-flash-low"},
{"gpt-5", "gpt-5-d"},
{"gemini-4-argon", "gemini-3.8-flash-d"},
{"gemini-4-argon", "gemini-4-argon-dx"},
} {
if !Swapped(c[0], c[1]) {
t.Errorf("%s answered as %s is another model", c[0], c[1])
}
}
}
// The requests log reads an Antigravity record of gemini-3.8-flash answered
// as gemini-3.8-flash-n as not swapped, at every level it went out at; a
// row of gpt-5 answered by gpt-5-mini is still marked.
func TestLedgerGeminiServingNameIsNoSwap(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
// Antigravity's own list on 2026-10-08 for the 3.8 Flash family
raw := []catalog.Model{
{ID: "gemini-3.8-flash-high", Name: "Gemini 3.8 Flash (High)"},
{ID: "gemini-3.8-flash-low", Name: "Gemini 3.8 Flash (Low)"},
{ID: "gemini-3.8-flash-medium", Name: "Gemini 3.8 Flash (Medium)"},
{ID: "gemini-3.8-flash-tiered"},
}
if err := catalog.SaveLive("antigravity", "", raw); err != nil {
t.Fatal(err)
}
catalog.Reset()
t.Cleanup(catalog.Reset)
os.MkdirAll(filepath.Dir(Path()), 0o755)
now := time.Now()
Append(Record{Time: now, Provider: "openai", Host: "api.openai.com", Model: "gpt-5",
Served: "gpt-5-mini-2025-08-07", Input: 10, Output: 1, Status: 200})
for i, effort := range []string{"", "low", "medium", "high"} {
Append(Record{Time: now.Add(time.Duration(i+1) * time.Minute), Provider: "antigravity",
Host: "daily-cloudcode-pa.googleapis.com", Model: "gemini-3.8-flash", Effort: effort,
Served: "gemini-3.8-flash-n", Input: 10, Output: 1, Status: 200})
}
rows, _, _ := Ledger(All, Filter{})
page := QueryPage(All, Filter{}, 0, 100)
for _, got := range [][]Row{rows, page.Rows} {
if len(got) != 5 {
t.Fatalf("rows %d: %+v", len(got), got)
}
for _, row := range got {
if row.Model == "gpt-5" && !row.Swapped {
t.Errorf("gpt-5 answered by gpt-5-mini is a swap: %+v", row)
}
if row.Model == "gemini-3.8-flash" && row.Swapped {
t.Errorf("gemini-3.8-flash at %q answered as %q is the model asked for: %+v", row.Effort, row.Served, row)
}
}
}
}
// A row kept marked swapped before is read back as not swapped when it was
// answered under Google's serving name; a real swap stays one.
func TestKeptRowGeminiServingNameNotSwapped(t *testing.T) {
c := &rowChunk{}
c.add(Row{Record: Record{Model: "gemini-3.8-flash", Served: "gemini-3.8-flash-n"}, Swapped: true}, "", 0, false)
c.add(Row{Record: Record{Model: "gpt-5", Served: "gpt-5-mini"}, Swapped: true}, "", 1, false)
for _, chunk := range []*rowChunk{c, c.pack().unpack()} {
if chunk.row(0).Swapped || !chunk.row(1).Swapped {
t.Fatalf("serving name %v, other model %v", chunk.row(0).Swapped, chunk.row(1).Swapped)
}
}
}