Files
magpie/internal/agent/claude_default_test.go
T
yetone b590edb5ef agent, gui: Claude Code taken off magpie by Default goes under Not set up and says Default (EZN7L2C3, #834 on v0.1.920) — picking Default and confirming Use default left the row up among the connected ones while it said Not connected, its model read Pick a model and its list had magpie's models alone. Default takes Claude Code's tiers and subagent model out with magpie's endpoint; Apply recorded only the field picked, so those read as changed outside magpie (replaced drift) and the drift kept the row up. Apply now records every field magpie set before that the change moves too. An agent not connected whose list has models of its own (Claude Code's, asked of Anthropic directly) now says what it is on, its Default or its own model, and lists everything as when connected: Default, its own models, magpie's. TestClaudeDefaultLeavesNoDrift (fails on the old code: drift replaced opus; a tier changed outside magpie is still said to be); claude-default-off.test.cjs (WebKit, en and zh: folded under Not set up, switch off, Default shown, Default current with the direct and via-magpie models listed, no scroll; fails on the old code: Pick a model / 选模型). agent-path-same, agent-leave-magpie, claude-picker-fold, claude-direct, agent-start-pick, model-rate, unlisted-models, agent-connect, agent-field-names, pi-default-note, click-scroll, desktop-model-menu, model-pick, favorite-star, agent-disconnect, agent-layout, gui-ja and gui-de pass on WebKit. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
2026-10-05 06:40:46 +08:00

65 lines
2.0 KiB
Go

package agent
import (
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/edit"
"github.com/yetone/magpie/internal/provider"
)
// Default picked for Claude Code on magpie takes out what magpie wrote, its
// tiers and subagent model too: magpie's own doing, not a change from
// outside, so no drift is left behind to keep the row up among the
// connected ones while it says Not connected (EZN7L2C3, #834).
func TestClaudeDefaultLeavesNoDrift(t *testing.T) {
home, _ := codexHome(t, "", "")
if err := provider.Save(provider.Provider{ID: "aaa", Name: "AAA", Chat: "https://a.example/v1", Key: "k", Models: []string{"first", "claude-opus-5-5"}}); err != nil {
t.Fatal(err)
}
path := filepath.Join(home, ".claude", "settings.json")
writeFile(t, path, `{"model": "opus"}`)
c := claude(home)
if err := c.Connect(); err != nil {
t.Fatal(err)
}
for _, k := range []string{"opus", "haiku", "subagent"} {
if err := c.Apply(k, "aaa/first"); err != nil {
t.Fatal(err)
}
}
if err := c.Apply("model", ""); err != nil {
t.Fatal(err)
}
if c.Wired() {
t.Fatalf("still connected:\n%s", readFile(path))
}
if d := c.Drift(); d != nil {
t.Fatalf("drift left: %+v", *d)
}
// a tier changed outside magpie before is still said to be
home2, _ := codexHome(t, "", "")
if err := provider.Save(provider.Provider{ID: "aaa", Name: "AAA", Chat: "https://a.example/v1", Key: "k", Models: []string{"first", "claude-opus-5-5"}}); err != nil {
t.Fatal(err)
}
path2 := filepath.Join(home2, ".claude", "settings.json")
writeFile(t, path2, `{"model": "opus"}`)
c2 := claude(home2)
if err := c2.Connect(); err != nil {
t.Fatal(err)
}
if err := c2.Apply("opus", "aaa/first"); err != nil {
t.Fatal(err)
}
if err := edit.SetJSON(path2, edit.KV{Path: "env.ANTHROPIC_DEFAULT_OPUS_MODEL", Value: "claude-opus-5-5"}); err != nil {
t.Fatal(err)
}
if err := c2.Apply("effort", "high"); err != nil {
t.Fatal(err)
}
if d := c2.Drift(); d == nil || d.Kind != "replaced" || d.Field != "opus" {
t.Fatalf("a change from outside isn't said: %+v", d)
}
}