Files
magpie/internal/provider/plainnames_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

98 lines
3.2 KiB
Go

package provider
import (
"slices"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/settings"
)
// With PlainNames (#335: 希望 Codex 模型列表里的显示名可以不带 · routing group
// / · 提供商 后缀) the lists agents get name each model by its name alone —
// Codex's catalog and the other agents' files alike — but two a list would
// call the same keep their provider's, so a picker never shows one name
// twice; taking one of them out of the agent's list leaves the other plain.
// Off, as by default, every name has its provider's after it as before, and
// switching it tells the agents.
func TestPlainNames(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
}
other := func() []string {
shown, _ := CatalogFor("opencode")
out := Labels(shown)
slices.Sort(out)
return out
}
full := []string{"a/sol=My Sol · A", "auto/sol=Sol · routing group", "b/sol=Sol · B"}
if got := codex(); !slices.Equal(got, full) {
t.Fatalf("by default: %q", got)
}
if err := SetPlainNames(true); err != nil {
t.Fatal(err)
}
if touched != 1 || !settings.Load().PlainNames {
t.Fatalf("agents told %d times, setting %v", touched, settings.Load().PlainNames)
}
// the group found for sol and b's sol are both "Sol": the group is
// told apart by its "· routing group", and b's model stays plain as
// a/sol does (nb5p on Discord: a relay's GPT-6.1 Terra kept
// "· MyGateway" beside its group while its GPT-6.1 Sol had none)
want := []string{"a/sol=My Sol", "auto/sol=Sol · routing group", "b/sol=Sol"}
if got := codex(); !slices.Equal(got, want) {
t.Fatalf("plain: %q", got)
}
if got := other(); !slices.Equal(got, []string{"My Sol", "Sol", "Sol · routing group"}) {
t.Fatalf("plain, another agent: %q", got)
}
// b's taken out of Codex's list: the group is the one Sol there, and
// named so; another agent still has both
s := settings.Load()
s.HiddenModels = map[string][]string{"codex": {"b/sol"}}
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
if got := codex(); !slices.Equal(got, []string{"a/sol=My Sol", "auto/sol=Sol"}) {
t.Fatalf("plain, b hidden: %q", got)
}
if got := other(); !slices.Equal(got, []string{"My Sol", "Sol", "Sol · routing group"}) {
t.Fatalf("plain, another agent: %q", got)
}
// two models a list would call the same still keep their providers'
if err := SetModelName("b/sol", "My Sol"); err != nil {
t.Fatal(err)
}
if got := other(); !slices.Equal(got, []string{"My Sol · A", "My Sol · B", "Sol"}) {
t.Fatalf("plain, two models named alike: %q", got)
}
if err := SetModelName("b/sol", ""); err != nil {
t.Fatal(err)
}
touched = 1
if err := SetPlainNames(false); err != nil {
t.Fatal(err)
}
if got := codex(); !slices.Equal(got, []string{"a/sol=My Sol · A", "auto/sol=Sol · routing group"}) || touched != 2 {
t.Fatalf("off again: %q, told %d", got, touched)
}
}