Files
magpie/internal/agent/claudedesktop_models_test.go
T
yetone 9335e23d3b claude-desktop: every inferenceModels entry carries its /v1/models name (chengming0v0)
chengming0v0 on Discord (v0.1.2806, Claude Desktop): the models of an
API-key provider read "mythos-magpie-0167851852", "mythos-magpie-3494120245"
and the like in Desktop's model menu, beside rows named properly
("DeepSeek V4.1 Flash 1017 · 寄吧鲁东", "GPT-6.1 Sol · ag:zdgit").

Cause: since ae060550b (v0.1.2770), while a model is picked for one of
Desktop's tiers, magpie writes its profile's inferenceModels so Claude
Code gets behavesAs. Desktop 4.4212 skips /v1/models discovery while that
list has no bare tier word as a name (adminListObviatesDiscovery in
index.chunk-m4oMImJ-.js, discoveryEnabled unset), and pzn then names each
entry labelOverride ?? catalog name ?? discovered name ?? ypn(id), which
for mythos-magpie-<n> and anthropic/magpie-<n> is the id itself. Only the
rows listed by their [1m] id (DesktopLongest) got a labelOverride, which is
why the user's 1M models kept their names, and why one GPT model of theirs
showed its name once its window was set from 400K to 1M.

Change: DesktopInferenceModels gives every entry the display_name
/v1/models gives its row as labelOverride, a catalog-named Claude model
(magpie-<n>.anthropic.<model>) too, whose description naming the provider
is lost with discovery. A list magpie wrote before is rewritten on the next
Sync (its hash is magpie's); Desktop reads it as it starts, so it needs a
restart (the Agents row offers one). agent-wiring.md updated.

Reproduced with the reporter's shape: an API-key provider whose models
have reasoning levels (listed as mythos-magpie-<n>), a GPT model at 400K
and one at 1M under DesktopLongest, one picked for a tier, in the tests'
sandbox HOME. TestDesktopInferenceModelsNamed (new) is red on the old
desktop_list.go for every entry but the 1M one ("mythos-magpie-3254679763
is labelled <nil>, /v1/models names it \"gpt-6.1-sol · 寄吧鲁东\"", 5
entries), and
TestClaudeDesktopModelsList's new check, on the profile magpie writes, is
red on it ("named by its id: … name:anthropic/magpie-4604110569"); both
green with the change.

Run on mote, rebased on 3e3196222: gofmt -l clean; GOOS=linux and
GOOS=windows go vet ./internal/gateway ./internal/agent ok; go test
-count=1 -timeout 45m ./internal/gateway ./internal/agent ./internal/gui:
gateway ok, agent ok, gui red on TestMainWindowCorners/macOS_26_SDK only
(#3949, open, unrelated). After that run the new test gained the 400K/1M
pair; -run 'TestDesktopInferenceModels|TestClaudeDesktop' over gateway and
agent ok at the pushed tree.
Not tried: a real Claude Desktop 4.4212 with the written profile (read
from its app.asar only); the reporter's own Desktop version is unknown.
2026-11-03 14:37:00 +08:00

160 lines
4.6 KiB
Go

package agent
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"time"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/edit"
"github.com/yetone/magpie/internal/gateway"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// moer2831 on Discord: a model picked for a Claude Desktop tier ran in its
// Code tab on Claude Code's generic prompt. While a tier is picked,
// magpie's profile lists Desktop's models in inferenceModels, the pick's
// with behavesAs, and Claude Code is told the pick's window, since it
// would take the behavesAs model's. The list follows the picks and the
// catalog, is written only when it changes, goes when nothing is picked,
// and a list the user wrote is theirs. Picks that can't be read leave it
// as it is.
func TestClaudeDesktopModelsList(t *testing.T) {
home, p := desktopSandbox(t)
if err := provider.Save(provider.Provider{ID: "v", Name: "V", Chat: "http://127.0.0.1:1/v1", Key: "k", Models: []string{"a", "b"}}); err != nil {
t.Fatal(err)
}
if err := catalog.SaveLive("v", "http://127.0.0.1:1/v1", []catalog.Model{{ID: "a", Context: 272000}, {ID: "b", Context: 128000}}); err != nil {
t.Fatal(err)
}
cc := filepath.Join(home, ".claude", "settings.json")
writeFile(t, cc, `{"theme":"dark"}`)
d := claudeDesktop(home)
set := func(key, v string) {
t.Helper()
if err := d.Field(key).Set(v); err != nil {
t.Fatal(err)
}
}
id := func(ref string) string {
for _, e := range provider.Catalog() {
if e.ID == ref {
return gateway.DesktopID(e)
}
}
t.Fatalf("%s not in the catalog", ref)
return ""
}
list := func() []map[string]any {
t.Helper()
raw, ok := edit.GetJSONRaw(p.prof, "inferenceModels")
if !ok {
return nil
}
var out []map[string]any
if err := json.Unmarshal([]byte(raw), &out); err != nil {
t.Fatalf("%v: %s", err, raw)
}
return out
}
entry := func(ref string) map[string]any {
t.Helper()
for _, e := range list() {
if e["name"] == id(ref) {
return e
}
}
t.Fatalf("%s not listed: %v", ref, list())
return nil
}
set("provider", "magpie")
if l := list(); l != nil {
t.Fatalf("nothing picked: %v", l)
}
// a's pick for sonnet: the list, a as Sonnet 5.5, and its window told
set("sonnet", "v/a")
if l := list(); len(l) != 2 {
t.Fatalf("a for sonnet: %v", l)
}
if e := entry("v/a"); e["behavesAs"] != "claude-sonnet-5-5" || e["anthropicFamilyTier"] != "sonnet" {
t.Fatalf("a: %v", e)
}
if e := entry("v/b"); e["behavesAs"] != nil {
t.Fatalf("b unpicked: %v", e)
}
// Desktop reads no /v1/models beside such a list: each entry is
// named in it, not by its id (chengming0v0 on Discord)
for _, e := range list() {
if l, _ := e["labelOverride"].(string); l == "" || l == e["name"] {
t.Fatalf("named by its id: %v", e)
}
}
if v, _ := edit.GetJSON(cc, budgetPath(id("v/a"))); v != "272000" {
t.Fatalf("a's window in Claude Code's settings: %q\n%s", v, readFile(cc))
}
// unchanged: not written again
st, _ := os.Stat(p.prof)
old := st.ModTime().Add(-2 * time.Second)
os.Chtimes(p.prof, old, old)
if err := d.Sync(); err != nil {
t.Fatal(err)
}
if st, _ := os.Stat(p.prof); !st.ModTime().Equal(old) {
t.Fatal("the profile was written with nothing changed")
}
// a model added reaches the list with the catalog
if err := provider.Save(provider.Provider{ID: "w", Name: "W", Chat: "http://127.0.0.1:1/v1", Key: "k", Models: []string{"c"}}); err != nil {
t.Fatal(err)
}
if err := d.Sync(); err != nil {
t.Fatal(err)
}
if l := list(); len(l) != 3 {
t.Fatalf("after w/c: %v", l)
}
// picks that can't be read: the list stays
tiers := filepath.Join(settings.Dir(), "claude-desktop.tiers.json")
good, err := os.ReadFile(tiers)
if err != nil {
t.Fatal(err)
}
writeFile(t, tiers, `{"sonnet":`)
if err := d.Sync(); err != nil {
t.Fatal(err)
}
if l := list(); len(l) != 3 {
t.Fatalf("unreadable picks: %v", l)
}
writeFile(t, tiers, string(good))
// nothing picked: the list goes
set("sonnet", "")
if l := list(); l != nil {
t.Fatalf("pick cleared: %v", l)
}
if _, ok := edit.GetJSONRaw(p.prof, "inferenceGatewayBaseUrl"); !ok {
t.Fatal("the rest of the profile went with the list")
}
// the user's own list is theirs, through a pick and its clearing
set("haiku", "v/b")
if err := edit.SetJSON(p.prof, edit.KV{Path: "inferenceModels", Value: []any{map[string]any{"name": "mine"}}}); err != nil {
t.Fatal(err)
}
mine, _ := edit.GetJSONRaw(p.prof, "inferenceModels")
set("sonnet", "v/a")
set("haiku", "")
set("sonnet", "")
if now, _ := edit.GetJSONRaw(p.prof, "inferenceModels"); now != mine {
t.Fatalf("the user's list: %s, was %s", now, mine)
}
}