The "show the agent's own models" switch filtered magpie's pickers alone (agent.Picks, #1642): Claude Code's own /model rows stayed put, because nothing magpie wrote for Claude Code looked at the switch — while /model is fed by magpie all the same (modelPicker's rows are writePicker's). raclen traced the whole chain (#4548). writePicker now sets modelPicker.replaceBuiltInOptions (Claude Code's own key: with it the /model picker shows only the listed rows) while the switch is off, and drops the flag again when it is on, so the whole picker is written either way. The Default row stays under both settings: Claude Code keeps it as its own fallback. Tests: TestClaudePickerOwnModelsSwitch writes a settings.json and checks modelPicker carries the rows plus the flag with the switch off, and the flag without it with the switch on. Verification on the base5d955a4d4, macOS arm64: agent package -targets nogui; gofmt, vet on darwin/linux/windows and builds clean. Claude Code's reading of the key is per its documented modelPicker behavior (code.claude.com/docs, model-config); the Default-row fallback shape is per the reporter's capture, not re-run here. Generated-by: GLM-5.3-Flash (ZCode) Reviewed and run by yetone at the batch head overcac655c14(this commit, the four others from ggbdpq's #4495/#4548/#4512/#3260 patches and the #4548 follow-up), on mote: - gofmt -l clean; go vet ./... for darwin, linux (-tags nogui), windows; go build ./... for darwin and windows. - go test -tags nogui -count=1 -timeout 45m ./...: every package ok but internal/gui, with two filed reds: TestSettingsSaveKeepsWhatItDoesNotSend (#4514), red alone at origin/maincac655c14too, and TestColdTurnsTaken (#4510), red only in the full run. Rebased afterwards ontoe94fb18b8, a usage-page change that touches none of these files. - Windows (xiaomi-gpu): go test -run 'TestVSCode|TestClaudePicker' ./internal/agent ok. TestCopilotFolderFromAnIDEPluginIsNotTheCLI is red there atcac655c14too (#1827). - Broken by hand: the replaceBuiltInOptions line dropped -> TestClaudePickerOwnModelsSwitch red. Not tried: a real Claude Code /model with the switch flipped (2.1.316's handling of the flag was read from its binary).
71 lines
2.3 KiB
Go
71 lines
2.3 KiB
Go
package agent
|
|
|
|
import (
|
|
"encoding/json"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/edit"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// raclen (#4548): the "Show {agent}'s own models" switch left Claude Code's
|
|
// own rows in /model untouched: it filters magpie's pickers alone
|
|
// (agent.Picks, #1642), and nothing magpie writes for Claude Code looked at
|
|
// it. Claude Code's /model is fed by magpie all the same — modelPicker's
|
|
// rows are magpie's (writePicker) — and Claude Code drops its built-in
|
|
// lineup rows when a modelPicker says replaceBuiltInOptions, so writePicker
|
|
// sets that while the switch is off, and takes it back out when on. The
|
|
// Default row stays either way: Claude Code keeps it as its own fallback,
|
|
// it is no model of its lineup.
|
|
func TestClaudePickerOwnModelsSwitch(t *testing.T) {
|
|
home := syncHome(t)
|
|
path := filepath.Join(home, ".claude", "settings.json")
|
|
writeFile(t, path, `{"theme":"dark"}`)
|
|
|
|
flag := func() (hasPicker, replace bool) {
|
|
t.Helper()
|
|
raw, has := edit.GetJSON(path, "modelPicker")
|
|
if !has {
|
|
return false, false
|
|
}
|
|
var p struct {
|
|
Replace *bool `json:"replaceBuiltInOptions"`
|
|
}
|
|
if err := json.Unmarshal([]byte(raw), &p); err != nil {
|
|
t.Fatalf("modelPicker: %v\n%s", err, readFile(path))
|
|
}
|
|
return true, p.Replace != nil && *p.Replace
|
|
}
|
|
sync := func() {
|
|
t.Helper()
|
|
if err := claude(home).Apply("model", "relay/glm-4.6"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// the switch on: Claude Code's built-in lineup stays, nothing asked for
|
|
sync()
|
|
if has, replace := flag(); !has || replace {
|
|
t.Fatalf("with own models shown: picker has=%v, replaceBuiltInOptions=%v, want has, no flag\n%s", has, replace, readFile(path))
|
|
}
|
|
|
|
// the switch off: the picker says so, and /model's own rows go
|
|
if err := provider.SetOwnModelsHidden("claude", true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sync()
|
|
if has, replace := flag(); !has || !replace {
|
|
t.Fatalf("with own models hidden: picker has=%v, replaceBuiltInOptions=%v, want both\n%s", has, replace, readFile(path))
|
|
}
|
|
|
|
// the switch back on: the flag goes again
|
|
if err := provider.SetOwnModelsHidden("claude", false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sync()
|
|
if has, replace := flag(); !has || replace {
|
|
t.Fatalf("with own models shown again: picker has=%v, replaceBuiltInOptions=%v, want has, no flag\n%s", has, replace, readFile(path))
|
|
}
|
|
}
|