yyhhyyyyyy on Discord picked only a routing group's models for Claude Code
on the Agents page, and Claude Code's /model still listed a model they had
not picked. Real Claude Code 2.1.316 in a sandbox HOME, with the settings
magpie writes, lists: Default, the group (as Custom Opus), Claude Code's
built-in "Fable 5.1" row, then the group as Sonnet and Haiku, then
magpie's modelPicker rows. The Fable row is Claude Code's own lineup.
magpie leaves ANTHROPIC_DEFAULT_FABLE_MODEL unset for a main model that
isn't a Fable (#2090), so Claude Code shows its own Fable there. The
gateway's /v1/models already follows the picks (CatalogFor), and Claude
Code's gateway discovery is off unless
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY is set. Neither of those is
where the row comes from.
Claude Code's documented modelPicker.replaceBuiltInOptions hides the
lineup and leaves Default and magpie's rows. In the same sandbox, the
same settings with the flag set list exactly those rows. magpie already
set the flag while "Show Claude Code's own models" is off (#4548). It now
also sets it while Claude Code's list leaves out some of magpie's
catalog: only the picked models, some taken out one by one, or a
visibility of families (claudeNarrowed, CatalogFor's hidden list). A
change to the picks already rewrites settings.json through
catalog.Touched and Sync.
The user's own values:
- A user's ANTHROPIC_CUSTOM_MODEL_OPTION, in the settings env or the
shell, keeps the lineup. The flag would hide that row too.
- availableModels was not used. It also hid the Fable row in the
sandbox, but it is the user's key, it blocks --model, and it is meant
for enforcement.
Run at this head (rebased on origin/main 2503520f8), on mote:
- gofmt -l: clean.
- go vet ./..., GOOS=linux go vet -tags nogui ./... and
GOOS=windows go vet ./...: ok.
- go test -tags nogui -timeout 45m ./...: internal/agent ok, along with
84 packages. Three packages are red, all on main and filed:
- internal/settingsapi TestKeysAreWhatTheSaveWrites and
internal/cli TestSettingsCLISetsWhatTheWindowSaves (trayNoNumber,
#4793);
- internal/cli TestEveryRouteHasACommandOrIsNamed (/api/quit, #4794);
- internal/gui TestRestartHandsTheGatewayOver (#4167, #4107).
Broken by hand:
- On the old claude.go, TestClaudePickerNarrowedListReplacesLineup fails:
"glm-5 taken out: ... replaceBuiltInOptions=false".
- With the custom-option guard forced off, it fails on the user's
ANTHROPIC_CUSTOM_MODEL_OPTION step.
Not tried:
- A real magpie writing settings.json for the real Claude Code. The
sandbox used hand-written settings of the same shape, with the base URL
on an unused port and no sign-in.
- Claude Code in WSL. claude@wsl takes the same writePicker path.
No GUI file is touched, so no GUI run.
114 lines
4.1 KiB
Go
114 lines
4.1 KiB
Go
package agent
|
|
|
|
import (
|
|
"encoding/json"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/edit"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// yyhhyyyyyy on Discord: Claude Code's list in magpie narrowed to a routing
|
|
// group's models, and /model still listed others. Claude Code puts its
|
|
// built-in lineup above a modelPicker's rows unless the picker says
|
|
// replaceBuiltInOptions, and the lineup's Fable row (no tier names it while
|
|
// the main model is no Fable) named a model the user hadn't picked. A list
|
|
// narrowed in magpie, by picks or by models taken out, now says the flag as
|
|
// the own-models switch does; one that leaves nothing out doesn't, and a
|
|
// custom row of the user's own (ANTHROPIC_CUSTOM_MODEL_OPTION), which the
|
|
// flag hides too, keeps the lineup.
|
|
func TestClaudePickerNarrowedListReplacesLineup(t *testing.T) {
|
|
home := syncHome(t)
|
|
shell := claudeShellEnv
|
|
claudeShellEnv = func(string) string { return "" }
|
|
t.Cleanup(func() { claudeShellEnv = shell })
|
|
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"glm-4.6", "glm-5"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
path := filepath.Join(home, ".claude", "settings.json")
|
|
writeFile(t, path, `{"theme":"dark"}`)
|
|
|
|
picker := func() (models []string, replace bool) {
|
|
t.Helper()
|
|
raw, has := edit.GetJSON(path, "modelPicker")
|
|
if !has {
|
|
t.Fatalf("no modelPicker\n%s", readFile(path))
|
|
}
|
|
var p struct {
|
|
Options []struct {
|
|
Model string `json:"model"`
|
|
} `json:"options"`
|
|
Replace *bool `json:"replaceBuiltInOptions"`
|
|
}
|
|
if err := json.Unmarshal([]byte(raw), &p); err != nil {
|
|
t.Fatalf("modelPicker: %v\n%s", err, readFile(path))
|
|
}
|
|
for _, o := range p.Options {
|
|
models = append(models, o.Model)
|
|
}
|
|
return models, p.Replace != nil && *p.Replace
|
|
}
|
|
sync := func() {
|
|
t.Helper()
|
|
if err := claude(home).Apply("model", "relay/glm-4.6"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// every model listed: Claude Code's lineup stays
|
|
sync()
|
|
if ms, replace := picker(); replace || len(ms) != 2 {
|
|
t.Fatalf("nothing left out: rows %v, replaceBuiltInOptions=%v, want both rows and no flag", ms, replace)
|
|
}
|
|
|
|
// one taken out: the lineup goes, the row too
|
|
if err := provider.SetHiddenModels("claude", []string{"relay/glm-5"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sync()
|
|
if ms, replace := picker(); !replace || len(ms) != 1 || ms[0] != "relay/glm-4.6" {
|
|
t.Fatalf("glm-5 taken out: rows %v, replaceBuiltInOptions=%v, want [relay/glm-4.6] and the flag", ms, replace)
|
|
}
|
|
|
|
// only the picked ones, glm-5 not among them: the same
|
|
if err := provider.SetOnlyPicked("claude", true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sync()
|
|
if ms, replace := picker(); !replace || len(ms) != 1 {
|
|
t.Fatalf("only picks: rows %v, replaceBuiltInOptions=%v, want one row and the flag", ms, replace)
|
|
}
|
|
|
|
// a custom row of the user's own keeps the lineup it is shown in
|
|
if err := edit.SetJSON(path, edit.KV{Path: "env." + claudeCustomOptionEnv, Value: "my-model"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sync()
|
|
if _, replace := picker(); replace {
|
|
t.Fatalf("with the user's %s: replaceBuiltInOptions set, which hides their row\n%s", claudeCustomOptionEnv, readFile(path))
|
|
}
|
|
if v, _ := edit.GetJSON(path, "env."+claudeCustomOptionEnv); v != "my-model" {
|
|
t.Fatalf("the user's %s is %q now", claudeCustomOptionEnv, v)
|
|
}
|
|
// set in the login shell, the same
|
|
if err := edit.DelJSON(path, "env."+claudeCustomOptionEnv); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
claudeShellEnv = func(k string) string { return map[string]string{claudeCustomOptionEnv: "my-model"}[k] }
|
|
sync()
|
|
if _, replace := picker(); replace {
|
|
t.Fatalf("with the user's %s in the shell: replaceBuiltInOptions set", claudeCustomOptionEnv)
|
|
}
|
|
claudeShellEnv = func(string) string { return "" }
|
|
|
|
// every model picked again: the lineup is back
|
|
if err := provider.SetPickedModels("claude", []string{"relay/glm-4.6", "relay/glm-5"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sync()
|
|
if ms, replace := picker(); replace || len(ms) != 2 {
|
|
t.Fatalf("every model picked: rows %v, replaceBuiltInOptions=%v, want both rows and no flag", ms, replace)
|
|
}
|
|
}
|