ZeroClover asked on X: Auto Group ids group/auto-<slug> can't be looked
up on models.dev. A found group is now listed and written as
auto/<model>, e.g. auto/claude-opus-5.5: /v1/models, the catalog, agent
configs, the GUI's Routing page and the CLI. Context and output limits
come from the model's metadata as before.
What stays the same:
- The internal id is still group/auto-<slug> (Group.Ref() gives the
public one). Every old form is still accepted as input forever:
provider.CanonicalRef turns auto/<model>[:level][[1m]] into it at the
gateway (validateModel), keys, stats, affinity and usage, so both ids
route to the same group and count as one.
- A key's model list allows a model by either id, group/* included
(allows() in key_models.go).
- Hand-made groups stay group/<id>.
- A provider whose stored id is "auto" keeps its models: while one
exists, found groups are listed by their old id (AutoRefsOn) and
auto/<x> means that provider's model. Documented in
docs/subsystems/gateway-routing.md.
Agent configs: SyncCatalog rewrites a field that holds a found group's
old id (renameFoundGroups), but only while the value is still what
applied.json says magpie wrote; a value the user set stays. A pick by
the old id written now is written as auto/<model> (Apply). Hidden,
picked and ordered model lists saved by the old id hold for the new one
(visible.go), and a bare model id still reaches its found group (bare.go).
Claude Code is given a dotted Claude version dashed (ClaudeSpelled), so
auto/claude-sonnet-4.5 sits in its settings as auto/claude-sonnet-4-5.
That routes to the same group, but with found groups off nothing reads
it back dotted, and Reseat took the field for changed and left the agent
on a group that was gone. Reseat now compares a group pick by its
canonical id (samePick). The old ids had no dots, so this is new with
auto/<model>.
Run at this tree (sandbox HOME, caches pinned):
- gofmt -l: clean. go vet ./...: clean on darwin, GOOS=linux -tags
nogui, GOOS=windows.
- go test -p 4 -timeout 45m ./...: every package ok except agent and
gateway, whose failures were the tests' expected ids (updated here)
and two regressions now fixed (bare ids; desktop models hiding groups
by prefix). Every failing test passes on rerun. Load average was
~210-290 from other sessions throughout.
- Reruns: provider, cli, codexcat ok. internal/gui: only
TestSetAnswersWhileDevinAndProvidersHang fails (set slow/slow-1 took
10.19s), and it fails the same in a git-archive export of 33dbdcc52.
- agent and gateway in full, -p 2 -timeout 120m: gateway ok (2996s).
agent failed four tests that still expected the old ids
(TestOmp/PiModelsAskedOnTheirNativeAPI, TestReseatFoundGroupsOff,
TestReseatKeepsAFoundGroupWithAProviderOff); updating them showed the
Reseat bug above. After the fix, go test -count=1 -timeout 120m
./internal/agent/: ok (1000s, load ~160-220).
- GUI files the change reaches, chromium and webkit: group-found-off and
the routing files pass, except routing-bodies, routing-model-rest,
routing-keys-fold and routing-request-metrics, which fail the same with
33dbdcc52's JS.
Broken by hand and watched red, then restored: CanonicalRef in
validateModel (both-ids routing test), allows() (key tests both ways),
the Save refusal and AutoRefsOn checks in Ref/CanonicalRef (provider
named auto), catalog.Lists' preference (models.dev lookup of the part
after auto/), renameFoundGroups' applied.json check and its SyncCatalog
call (user values kept), PublicRef in visible.go, the codexcat prefix,
samePick in Reseat (TestReseatFoundGroupsOff: opus left on the gone
group).
TestBareModelIDsShared was red before the bare.go fix.
Not verified: no real agent, vendor or models.dev client run; no run on
the Windows box. Settings pickers (vision, title model) holding a saved
group/auto-... value may show it as saved. codexcat can't tell a stored
"auto" provider apart, so its models lose the "text only" hint. The
pre-existing reds above are not filed.
308 lines
12 KiB
Go
308 lines
12 KiB
Go
package gateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http/httptest"
|
|
"regexp"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// Claude Desktop's model menu lists the models picked for it on the Agents
|
|
// page (蓝猫): /v1/models, asked with its key, holds those and no other,
|
|
// each named as the agents' lists name it — the Provider in model names
|
|
// setting, so the menu reads like Codex's (#1746) — and two of one name
|
|
// stay apart.
|
|
func TestClaudeDesktopPickedModels(t *testing.T) {
|
|
setup(t, provider.Anthropic, &fake{})
|
|
for _, p := range []provider.Provider{
|
|
{ID: "opencode-go", Name: "OpenCode Go", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"deepseek-v4.1-flash", "glm-5"}},
|
|
{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"deepseek-v4.1-flash"}},
|
|
{ID: "grok-2", Name: "Grok", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"grok-4.6"}},
|
|
} {
|
|
if err := provider.Save(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
for ref, name := range map[string]string{"opencode-go/deepseek-v4.1-flash": "DeepSeek V4.1 Flash", "relay/deepseek-v4.1-flash": "DeepSeek V4.1 Flash", "grok-2/grok-4.6": "grok-4.6"} {
|
|
if err := provider.SetModelName(ref, name); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
list := func() map[string]desktopRow {
|
|
t.Helper()
|
|
req := httptest.NewRequest("GET", "/v1/models?limit=1000", nil)
|
|
req.Header.Set("x-api-key", TokenFor("claude-desktop"))
|
|
rec := httptest.NewRecorder()
|
|
New().Handler().ServeHTTP(rec, req)
|
|
var out struct {
|
|
Data []desktopRow `json:"data"`
|
|
}
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := map[string]desktopRow{}
|
|
for _, d := range out.Data {
|
|
if d.Description != "" {
|
|
t.Errorf("%s has a description: %q", d.DisplayName, d.Description)
|
|
}
|
|
got[DesktopCatalogID(d.ID)] = d
|
|
}
|
|
return got
|
|
}
|
|
keys := func(m map[string]desktopRow) []string {
|
|
var out []string
|
|
for k := range m {
|
|
out = append(out, k)
|
|
}
|
|
slices.Sort(out)
|
|
return out
|
|
}
|
|
|
|
// both DeepSeeks shown: each with its provider's after it; grok-4.6, a
|
|
// name the user gave that already says its provider's, without it
|
|
all := list()
|
|
if all["opencode-go/deepseek-v4.1-flash"].DisplayName != "DeepSeek V4.1 Flash · OpenCode Go" ||
|
|
all["relay/deepseek-v4.1-flash"].DisplayName != "DeepSeek V4.1 Flash · Relay" || all["grok-2/grok-4.6"].DisplayName != "grok-4.6" {
|
|
t.Fatalf("both shown: %v", all)
|
|
}
|
|
|
|
// three picked, the other DeepSeek, the routing group magpie found for
|
|
// the two and GLM left out: only those three, the DeepSeek still with
|
|
// its provider after it
|
|
hide := []string{"relay/deepseek-v4.1-flash", "opencode-go/glm-5"}
|
|
for id := range all {
|
|
if provider.IsGroupRef(id) {
|
|
hide = append(hide, id)
|
|
}
|
|
}
|
|
if err := provider.SetHiddenModels("claude-desktop", hide); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { provider.SetHiddenModels("claude-desktop", nil) })
|
|
got := list()
|
|
if want := []string{"fake/m1", "grok-2/grok-4.6", "opencode-go/deepseek-v4.1-flash"}; !slices.Equal(keys(got), want) {
|
|
t.Fatalf("Desktop lists %v, want %v", keys(got), want)
|
|
}
|
|
if n := got["opencode-go/deepseek-v4.1-flash"].DisplayName; n != "DeepSeek V4.1 Flash · OpenCode Go" {
|
|
t.Fatalf("named %q, want the name with its provider after it", n)
|
|
}
|
|
// another agent's list is its own
|
|
rec := httptest.NewRecorder()
|
|
New().Handler().ServeHTTP(rec, httptest.NewRequest("GET", "/v1/models", nil))
|
|
var other struct{ Data []struct{ ID string } }
|
|
json.Unmarshal(rec.Body.Bytes(), &other)
|
|
if len(other.Data) != len(all) {
|
|
t.Fatalf("another agent's list: %s", rec.Body)
|
|
}
|
|
}
|
|
|
|
// Claude Desktop's menu names a model as every agent's list does, by the
|
|
// Provider in model names setting (#1746, marsxxl): on, the name with its
|
|
// provider's after it, as Codex's list has it; own, a name the user gave
|
|
// as they wrote it and a vendor's with its provider's; off, plain names —
|
|
// and two of one name keep their provider's, two that still read the same
|
|
// (one provider's, named alike twice) the whole id.
|
|
func TestClaudeDesktopNamesFollowSuffixMode(t *testing.T) {
|
|
fresh(t)
|
|
for _, p := range []provider.Provider{
|
|
{ID: "opencode-go", Name: "OpenCode Go", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"deepseek-v4.1-flash"}},
|
|
{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"deepseek-v4.1-flash"}},
|
|
{ID: "grok-2", Name: "Grok", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"grok-4.6"}},
|
|
{ID: "kimi", Name: "Kimi", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"kimi-k3"}},
|
|
{ID: "twin", Name: "Twinco", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"x", "x2"}},
|
|
} {
|
|
if err := provider.Save(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
for ref, name := range map[string]string{
|
|
"opencode-go/deepseek-v4.1-flash": "DeepSeek V4.1 Flash",
|
|
"relay/deepseek-v4.1-flash": "DeepSeek V4.1 Flash",
|
|
"kimi/kimi-k3": "Nightly",
|
|
"twin/x": "Twin",
|
|
"twin/x2": "Twin",
|
|
} {
|
|
if err := provider.SetModelName(ref, name); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
list := func() map[string]string {
|
|
t.Helper()
|
|
req := httptest.NewRequest("GET", "/v1/models", nil)
|
|
req.Header.Set("x-api-key", TokenFor("claude-desktop"))
|
|
rec := httptest.NewRecorder()
|
|
New().Handler().ServeHTTP(rec, req)
|
|
var out struct {
|
|
Data []desktopRow `json:"data"`
|
|
}
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := map[string]string{}
|
|
for _, d := range out.Data {
|
|
got[DesktopCatalogID(d.ID)] = d.DisplayName
|
|
}
|
|
return got
|
|
}
|
|
for _, c := range []struct {
|
|
mode string
|
|
want map[string]string
|
|
}{
|
|
{provider.SuffixOn, map[string]string{
|
|
"opencode-go/deepseek-v4.1-flash": "DeepSeek V4.1 Flash · OpenCode Go",
|
|
"relay/deepseek-v4.1-flash": "DeepSeek V4.1 Flash · Relay",
|
|
"grok-2/grok-4.6": "grok-4.6 · Grok",
|
|
"kimi/kimi-k3": "Nightly · Kimi",
|
|
"twin/x": "Twin · Twinco (twin/x)",
|
|
"twin/x2": "Twin · Twinco (twin/x2)",
|
|
}},
|
|
{provider.SuffixOwn, map[string]string{
|
|
"opencode-go/deepseek-v4.1-flash": "DeepSeek V4.1 Flash · OpenCode Go",
|
|
"relay/deepseek-v4.1-flash": "DeepSeek V4.1 Flash · Relay",
|
|
"grok-2/grok-4.6": "grok-4.6 · Grok",
|
|
"kimi/kimi-k3": "Nightly",
|
|
"twin/x": "Twin · Twinco (twin/x)",
|
|
"twin/x2": "Twin · Twinco (twin/x2)",
|
|
}},
|
|
{provider.SuffixOff, map[string]string{
|
|
"opencode-go/deepseek-v4.1-flash": "DeepSeek V4.1 Flash · OpenCode Go",
|
|
"relay/deepseek-v4.1-flash": "DeepSeek V4.1 Flash · Relay",
|
|
"grok-2/grok-4.6": "grok-4.6",
|
|
"kimi/kimi-k3": "Nightly",
|
|
"twin/x": "Twin · Twinco (twin/x)",
|
|
"twin/x2": "Twin · Twinco (twin/x2)",
|
|
}},
|
|
} {
|
|
if err := provider.SetSuffixMode(c.mode); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := list()
|
|
for id, want := range c.want {
|
|
if got[id] != want {
|
|
t.Fatalf("%s: %s named %q, want %q (all: %v)", c.mode, id, got[id], want, got)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// A Claude Desktop build that has no mythos word (the Store's 1.6608.2,
|
|
// sublatesublate-design) keeps a gateway model only when its id reads as a
|
|
// sonnet|opus|haiku tier or has claude, sonnet, opus, haiku or anthropic in
|
|
// it, so every reasoning-level model listed by mythos-magpie-<n> vanished
|
|
// from its menu. To a build whose User-Agent names no 2.x, a
|
|
// reasoning-level model is listed by its plain alias, which every build
|
|
// keeps; one that says 2.x keeps the picker alias.
|
|
func TestClaudeDesktopOldBuildModels(t *testing.T) {
|
|
setup(t, provider.Anthropic, &fake{})
|
|
if err := provider.Save(provider.Provider{ID: "opencode-go", Name: "OpenCode Go", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"deepseek-v4.1-flash"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := provider.SetModelEfforts("opencode-go/deepseek-v4.1-flash", []string{"low", "medium", "high"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// an old build's own filter (its app.asar, 1.6608.2)
|
|
oldBuildKeeps := func(id string) bool {
|
|
l := strings.ToLower(id)
|
|
if regexp.MustCompile(`^(sonnet|opus|haiku)(-[\d.]+)?$`).MatchString(l) {
|
|
return true
|
|
}
|
|
for _, w := range []string{"claude", "sonnet", "opus", "haiku", "anthropic"} {
|
|
if strings.Contains(l, w) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
list := func(ua string) map[string]string {
|
|
t.Helper()
|
|
req := httptest.NewRequest("GET", "/v1/models", nil)
|
|
req.Header.Set("x-api-key", TokenFor("claude-desktop"))
|
|
if ua != "" {
|
|
req.Header.Set("User-Agent", ua)
|
|
}
|
|
rec := httptest.NewRecorder()
|
|
New().Handler().ServeHTTP(rec, req)
|
|
var out struct {
|
|
Data []desktopRow `json:"data"`
|
|
}
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := map[string]string{}
|
|
for _, d := range out.Data {
|
|
got[DesktopCatalogID(d.ID)] = d.ID
|
|
}
|
|
return got
|
|
}
|
|
const oldUA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Claude/1.6608.2 Chrome/140.0.0.0 Electron/37.2.0 Safari/537.36"
|
|
|
|
// the old build keeps every model it is shown
|
|
for _, ua := range []string{oldUA} {
|
|
for catalog, id := range list(ua) {
|
|
if !oldBuildKeeps(id) {
|
|
t.Errorf("User-Agent %q: %s is listed as %s, which the build drops", ua, catalog, id)
|
|
}
|
|
}
|
|
}
|
|
|
|
// a 2.x build is still offered the effort picker, and so is a request
|
|
// that names no build (the Code tab's Claude Code, known by its key)
|
|
for _, ua := range []string{"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Claude/2.7032.0 Chrome/140.0.0.0 Electron/37.2.0 Safari/537.36", "claude-cli/2.1.295 (external, claude-desktop)", ""} {
|
|
if id := list(ua)["opencode-go/deepseek-v4.1-flash"]; !regexp.MustCompile(`^mythos-magpie-\d{10}$`).MatchString(id) {
|
|
t.Errorf("User-Agent %q: deepseek-v4.1-flash is listed as %q, want the mythos picker alias", ua, id)
|
|
}
|
|
}
|
|
}
|
|
|
|
// desktopKnowsMythos, by the version a User-Agent names: 2.x takes the
|
|
// mythos effort alias, an older one does not, and a request naming no
|
|
// build is listed as before.
|
|
func TestDesktopKnowsMythos(t *testing.T) {
|
|
for _, c := range []struct {
|
|
ua string
|
|
want bool
|
|
}{
|
|
{"Mozilla/5.0 … Claude/2.7032.0 Chrome/… Safari/537.36", true},
|
|
{"Mozilla/5.0 … Claude/2 Chrome/…", true},
|
|
{"Mozilla/5.0 … Claude/1.6608.2 Chrome/… Safari/537.36", false},
|
|
{"Mozilla/5.0 … Claude/3.0.0 Chrome/… Safari/537.36", true},
|
|
// no build named (the Code tab's Claude Code, known by its key):
|
|
// listed as before, by the picker alias
|
|
{"claude-cli/2.1.295 (external, claude-desktop)", true},
|
|
{"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", true},
|
|
{"", true},
|
|
} {
|
|
if got := desktopKnowsMythos(c.ua); got != c.want {
|
|
t.Errorf("desktopKnowsMythos(%q) = %v, want %v", c.ua, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// desktopNames: the agents' list naming (provider.Labels, the Provider in
|
|
// model names setting) with the whole catalog id after two entries that
|
|
// still read the same — Desktop's menu shows the name alone, so two models
|
|
// of one provider named alike stay apart there.
|
|
func TestDesktopNames(t *testing.T) {
|
|
fresh(t)
|
|
es := []provider.Entry{
|
|
{ID: "a/x", Name: "X", Provider: provider.Provider{ID: "a", Name: "A"}},
|
|
{ID: "b/x", Name: "x", Provider: provider.Provider{ID: "b", Name: "B"}},
|
|
{ID: "c/y", Name: "Y", Provider: provider.Provider{ID: "c", Name: "C"}},
|
|
{ID: "d/z", Name: "Z", Provider: provider.Provider{ID: "d", Name: "D"}},
|
|
{ID: "d/z2", Name: "Z", Provider: provider.Provider{ID: "d", Name: "D"}},
|
|
}
|
|
if got, want := desktopNames(es), []string{"X · A", "x · B", "Y · C", "Z · D (d/z)", "Z · D (d/z2)"}; !slices.Equal(got, want) {
|
|
t.Fatalf("desktopNames = %q, want %q", got, want)
|
|
}
|
|
if err := provider.SetSuffixMode(provider.SuffixOff); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got, want := desktopNames(es), []string{"X · A", "x · B", "Y", "Z · D (d/z)", "Z · D (d/z2)"}; !slices.Equal(got, want) {
|
|
t.Fatalf("desktopNames (names plain) = %q, want %q", got, want)
|
|
}
|
|
}
|