Files
magpie/internal/provider/suffix_mode_test.go
T
yetone d35509b65b agents: a custom provider's picked API is the one its models are asked on, and a model named like a routing group stays plain (nb5p)
nb5p on Discord: (1) a custom provider set to Responses had its models
wired into dsh on magpie's Chat Completions route (`magpie`), so dsh sent
Chat and magpie translated; (2) in dsh's models, mygateway/gpt-6.1-sol was
"GPT-6.1 Sol" while mygateway/gpt-6.1-terra was "GPT-6.1 Terra · MyGateway".

Cause 1: Provider.Native never read BaseAPI, the API the user gave the
Base URL as. Detect fills in every API that answers, so a relay picked as
Responses also had a Chat URL, and Native returned Chat (out[0]). Native
now takes BaseAPI after the vendor rules (ResponsesFirst, MessagesFirst),
when the provider serves it. dsh supports it: dsh 0.2.1-rc.2 bundles
@earendil-works/pi-ai, whose KnownApi includes "openai-responses", and
magpie already has the `magpie-responses` route (dshKinds). Siblings
reading m.APIs from magpieModels move with it: dsh, Pi, omp, droid,
Grok Build.

Cause 2: provider.Labels counted collisions over models and routing
groups together. A model two providers serve gets an auto group with the
model's name, so the shown model collided with its own group and kept
"· Provider" (terra: served by a second provider too, hidden for dsh;
sol: one provider). Models and groups are counted apart now: a model
keeps its suffix only when another model reads the same, and a group
named like anything else keeps "· routing group". Labels feeds every
agent's list, so this holds for all of them.

Not changed: the gateway's usable() still orders a translated request
Chat first and doesn't read BaseAPI (#4508).

Tests (each red on the old code, broken by hand in a worktree on
origin/main: all new cases red; reverting only Native red on the route,
reverting only Labels red on terra's name; the old dsh output reproduced
the report exactly):
- internal/agent TestDshCustomResponsesProvider (new): both models on
  magpie-responses, none on magpie, named "GPT-6.1 Sol"/"GPT-6.1 Terra".
- internal/provider native_test: Responses picked beside Chat, Chat
  picked, Responses picked for a Claude where Messages is served, and
  Responses picked with no Responses URL.
- plainnames/plainown_groups/suffix_mode expectations updated to the rule.

Run on mote, at this change on 7fe191cec (the pushed head is the same
change rebased on a newer origin/main, 6f435677c; not re-run there):
go test -tags nogui -count=1 -timeout 45m ./internal/provider
./internal/agent ./internal/gateway ./internal/cli ./internal/gui:
provider ok 170s, agent ok 303s, gateway ok 797s, cli ok 53s; gui FAIL
TestColdTurnsTaken only (0.00s, a test race untouched by this change,
filed #4510). gofmt -l clean. Still running at push: TestColdTurnsTaken
-count=20 and GOOS=linux/windows go vet ./... on mote, and the test on
origin/main alone.

Not tried: a real dsh session against a real Responses relay; nb5p's
own providers.json (the second provider serving terra is inferred from
the suffix); the GUI suite (no GUI file changed); the full ./... suite.
2026-10-31 10:08:40 +08:00

87 lines
2.7 KiB
Go

package provider
import (
"slices"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/settings"
)
// Provider in model names has three ways (#92): on, as by default and as a
// settings.json from before has it, every name with its provider's after
// it, one the user gave too (#203); own, a name the user gave just as they
// wrote it, the vendor's with their provider's; off, none (#335), as an
// older plainNames: true still reads. Each change tells the agents; one to
// the way already set doesn't, and a way of no such name is refused.
func TestSuffixMode(t *testing.T) {
prefsHome(t)
touched := 0
catalog.Changed = func() { touched++ }
t.Cleanup(func() { catalog.Changed = nil })
if err := SetModelName("a/sol", "My Sol"); err != nil {
t.Fatal(err)
}
touched = 0
codex := func() []string {
var out []string
for _, m := range CodexListed() {
out = append(out, m.ID+"="+m.Name)
}
slices.Sort(out)
return out
}
if SuffixMode() != SuffixOn {
t.Fatalf("default %q", SuffixMode())
}
if got := codex(); !slices.Equal(got, []string{"a/sol=My Sol · A", "auto/sol=Sol · routing group", "b/sol=Sol · B"}) {
t.Fatalf("on: %q", got)
}
if err := SetSuffixMode(SuffixOwn); err != nil {
t.Fatal(err)
}
if s := settings.Load(); SuffixMode() != SuffixOwn || s.PlainNames || !s.PlainOwnNames || touched != 1 {
t.Fatalf("own: %q %+v, told %d", SuffixMode(), s, touched)
}
if got := codex(); !slices.Equal(got, []string{"a/sol=My Sol", "auto/sol=Sol · routing group", "b/sol=Sol · B"}) {
t.Fatalf("own: %q", got)
}
if err := SetSuffixMode(SuffixOwn); err != nil || touched != 1 {
t.Fatal(err, touched)
}
if err := SetSuffixMode(SuffixOff); err != nil {
t.Fatal(err)
}
if s := settings.Load(); SuffixMode() != SuffixOff || !s.PlainNames || s.PlainOwnNames || touched != 2 {
t.Fatalf("off: %q %+v, told %d", SuffixMode(), s, touched)
}
// b's sol and the group found for it would both read "Sol": the group
// keeps "· routing group", which tells them apart
if got := codex(); !slices.Equal(got, []string{"a/sol=My Sol", "auto/sol=Sol · routing group", "b/sol=Sol"}) {
t.Fatalf("off: %q", got)
}
// the two-way switch of before: off is plain, on is on again
if err := SetPlainNames(false); err != nil {
t.Fatal(err)
}
if SuffixMode() != SuffixOn || touched != 3 {
t.Fatalf("plain names off: %q, told %d", SuffixMode(), touched)
}
// a settings.json of before, plainNames: true, reads as off
s := settings.Load()
s.PlainNames = true
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
if SuffixMode() != SuffixOff {
t.Fatalf("plainNames: true reads %q", SuffixMode())
}
if err := SetSuffixMode("sometimes"); err == nil {
t.Fatal("took sometimes")
}
}