Files
magpie/internal/provider/claude_models_test.go
T
yetone 66f920e3a3 provider: a Claude account whose user picked every model is served Haiku 5.5 once models.dev lists it, beside the picks (wakaka)
9b51428e put Haiku 5.5 in the Claude account's list (Available), but
agents are served the user's picks (Exposed) when there are any. A user
who had picked every model (Select all, or the TUI's toggles) kept the
list as it was then. The owner's providers.json holds exactly that: all
16 Claude models up to Sonnet 5.5, not Haiku 5.5, which never reached
an agent; wakaka's file wasn't seen, so this is the likely cause there.

Save now keeps, beside new picks, the models listed when they were made
(PickedFrom); the same picks saved again keep it. withNewlyListed serves
a model listed since first beside picks that held every model listed
then; one listed then and left unpicked stays out, and picks that left
any out take nothing new. Picks saved before PickedFrom existed count as
"every model" when they hold every one released up to the newest of
them (models.dev's release_date), which is the owner's saved state. The
editor (providerJSON.Chosen) and the TUI start from Picks, so a later
Save keeps the new model picked rather than dropping it.

Run: TestClaudePicksOfEveryModelTakeOnesListedSince with the reporter's
16 picks and models.dev's Haiku 5.5 row (red with Exposed using the
picks alone); go test -tags nogui ./... under a temp HOME, all ok;
gofmt -l; go vet -tags nogui on darwin, GOOS=linux and GOOS=windows for
internal/provider, internal/gui, internal/tui.
2026-10-10 19:01:10 +08:00

192 lines
8.6 KiB
Go

package provider
import (
"context"
"os"
"path/filepath"
"slices"
"testing"
"time"
"github.com/yetone/magpie/internal/catalog"
)
// The models.dev catalog's anthropic rows, as models.dev served them on
// 2026-10-10: Opus 5.5, and Haiku 5.5, which it listed from 2026-10-07.
const (
mdOpus55 = `"claude-opus-5-5":{"id":"claude-opus-5-5","name":"Claude Opus 5.5","family":"claude-opus","attachment":true,"reasoning":true,"reasoning_options":[{"type":"effort","values":["low","medium","high","xhigh","max"]}],"tool_call":true,"structured_output":true,"temperature":false,"knowledge":"2026-06","release_date":"2026-09-22","last_updated":"2026-09-22","modalities":{"input":["text","image","pdf"],"output":["text"]},"open_weights":false,"limit":{"context":1000000,"output":128000},"cost":{"input":4,"output":20,"cache_read":0.2,"cache_write":5}}`
mdHaiku55 = `"claude-haiku-5-5":{"id":"claude-haiku-5-5","name":"Claude Haiku 5.5","family":"claude-haiku","attachment":true,"reasoning":true,"reasoning_options":[{"type":"toggle"},{"type":"effort","values":["low","medium","high","xhigh","max"]}],"tool_call":true,"structured_output":true,"temperature":false,"knowledge":"2026-06","release_date":"2026-10-07","last_updated":"2026-10-07","modalities":{"input":["text","image","pdf"],"output":["text"]},"open_weights":false,"limit":{"context":1000000,"output":128000},"cost":{"input":0.1,"output":0.5,"cache_read":0.01,"cache_write":0.125,"tiers":[{"input":0.5,"output":2.5,"cache_read":0.05,"cache_write":0.625,"tier":{"type":"context","size":100000}}]}}`
)
func writeAnthropicCatalog(t *testing.T, rows ...string) {
t.Helper()
body := `{"anthropic":{"id":"anthropic","name":"Anthropic","models":{`
for i, r := range rows {
if i > 0 {
body += ","
}
body += r
}
body += `}}}`
if err := os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(catalog.CachePath(), []byte(body), 0o644); err != nil {
t.Fatal(err)
}
catalog.Reset()
}
// A Claude model models.dev lists after the Claude account's list was
// last fetched is served at once, as the catalog has it: the copy a fetch
// keeps doesn't hold it out until the next Refresh (wakaka on Discord:
// Haiku 5.5 in Claude Code on the same account, not in magpie).
func TestClaudeAccountServesModelsListedSinceItsFetch(t *testing.T) {
home := claudeHome(t)
claudeSignIn(t, home, time.Now().Add(time.Hour))
t.Cleanup(catalog.Reset)
writeAnthropicCatalog(t, mdOpus55)
p, ok := find(All(), "claude")
if !ok || p.Account == nil {
t.Fatalf("claude: %+v %v", p, ok)
}
if _, err := p.Fetch(context.Background()); err != nil {
t.Fatal(err)
}
// models.dev lists Haiku 5.5 now; the hourly sync wrote it
writeAnthropicCatalog(t, mdOpus55, mdHaiku55)
p, _ = find(All(), "claude")
if _, ok := p.Fetched(); !ok {
t.Fatal("the fetch left no list")
}
i := slices.IndexFunc(p.Available(), func(m catalog.Model) bool { return m.ID == "claude-haiku-5-5" })
if i < 0 {
t.Fatalf("Haiku 5.5 not served on the Claude account: %v", modelIDs(p.Available()))
}
h := p.Available()[i]
if h.Name != "Claude Haiku 5.5" || h.Context != 1_000_000 || h.Output != 128_000 || !h.Reasoning ||
!slices.Equal(h.Efforts, []string{"low", "medium", "high", "xhigh", "max"}) {
t.Fatalf("Haiku 5.5: %+v", h)
}
if h.Price == nil || h.Price.Input != 0.1 || h.Price.Output != 0.5 {
t.Fatalf("Haiku 5.5's price: %+v", h.Price)
}
var listed []string
for _, e := range Catalog() {
listed = append(listed, e.ID)
}
if !slices.Contains(listed, "claude/claude-haiku-5-5") {
t.Fatalf("not among the models agents are offered: %v", listed)
}
if rp, model, ok := Resolve("claude/claude-haiku-5-5"); !ok || rp.ID != "claude" || model != "claude-haiku-5-5" {
t.Fatalf("resolve: %+v %q %v", rp, model, ok)
}
// and a model models.dev no longer lists leaves the account's list too
writeAnthropicCatalog(t, mdHaiku55)
p, _ = find(All(), "claude")
if got := modelIDs(p.Available()); !slices.Equal(got, []string{"claude-haiku-5-5"}) {
t.Fatalf("after Opus 5.5 left the catalog: %v", got)
}
}
// The picks wakaka's and the owner's Claude accounts had saved: every
// model listed then, newest first, with no PickedFrom kept beside them, as
// providers.json held them on 2026-10-10. Haiku 5.5, listed since, was
// never served: agents are given the picks alone.
var claudeAllPicked = []string{"claude-sonnet-5-5", "claude-opus-5-5", "claude-fable-5-1", "claude-opus-5", "claude-sonnet-5", "claude-fable-5", "claude-opus-4-8", "claude-opus-4-7", "claude-sonnet-4-6", "claude-opus-4-6", "claude-opus-4-5", "claude-opus-4-5-20251101", "claude-haiku-4-5", "claude-haiku-4-5-20251001", "claude-sonnet-4-5", "claude-sonnet-4-5-20250929"}
// mdOpus41 is an older row, for a model listed before the picks were
// saved and left unpicked.
const mdOpus41 = `"claude-opus-4-1":{"id":"claude-opus-4-1","name":"Claude Opus 4.1","family":"claude-opus","reasoning":true,"tool_call":true,"release_date":"2025-08-05","last_updated":"2025-08-05","limit":{"context":200000,"output":32000}}`
func claudeExposed(t *testing.T) []string {
t.Helper()
p, ok := find(All(), "claude")
if !ok || p.Account == nil {
t.Fatalf("claude: %+v %v", p, ok)
}
return modelIDs(p.Exposed())
}
// A model models.dev lists after the user picked every model the Claude
// account listed is served beside those picks (wakaka on Discord: Haiku
// 5.5 still missing after 9b51428e, whose list had it, as the picks held
// it out); one listed then and left unpicked stays out.
func TestClaudePicksOfEveryModelTakeOnesListedSince(t *testing.T) {
home := claudeHome(t)
claudeSignIn(t, home, time.Now().Add(time.Hour))
t.Cleanup(catalog.Reset)
writeAnthropicCatalog(t, mdOpus55, mdHaiku55)
// picks saved before PickedFrom was kept, as the reporter's are
if err := store(file{Providers: []Provider{{ID: "claude", Models: claudeAllPicked}}}); err != nil {
t.Fatal(err)
}
if got := claudeExposed(t); !slices.Contains(got, "claude-haiku-5-5") || !slices.Contains(got, "claude-sonnet-5-5") {
t.Fatalf("all picked before Haiku 5.5 was listed: %v", got)
}
if p, _ := find(All(), "claude"); !slices.Contains(p.Picks(), "claude-haiku-5-5") {
t.Fatalf("the editor's picks: %v", p.Picks())
}
// an older model the user left unpicked: the picks aren't all of them
writeAnthropicCatalog(t, mdOpus55, mdHaiku55, mdOpus41)
if got := claudeExposed(t); slices.Contains(got, "claude-haiku-5-5") || slices.Contains(got, "claude-opus-4-1") {
t.Fatalf("picks that left one out took more: %v", got)
}
// picks saved now keep what was listed: Haiku 5.5 unticked stays out
writeAnthropicCatalog(t, mdOpus55, mdHaiku55)
if err := SetModels("claude", []string{"claude-opus-5-5"}); err != nil {
t.Fatal(err)
}
if got := claudeExposed(t); !slices.Equal(got, []string{"claude-opus-5-5"}) {
t.Fatalf("Haiku 5.5 left unpicked: %v", got)
}
// and every model picked, before Haiku 5.5 was listed, takes it then
writeAnthropicCatalog(t, mdOpus55)
if err := SetModels("claude", []string{"claude-opus-5-5", "claude-sonnet-5-5"}); err != nil {
t.Fatal(err)
}
if p, _ := find(All(), "claude"); !slices.Equal(p.PickedFrom, []string{"claude-opus-5-5"}) {
t.Fatalf("listed with the picks: %v", p.PickedFrom)
}
writeAnthropicCatalog(t, mdOpus55, mdHaiku55)
if got := claudeExposed(t); !slices.Equal(got, []string{"claude-haiku-5-5", "claude-opus-5-5", "claude-sonnet-5-5"}) {
t.Fatalf("listed since every model was picked: %v", got)
}
// a Save of the same picks keeps the list they were picked from
if err := SetModels("claude", []string{"claude-opus-5-5", "claude-sonnet-5-5", " claude-opus-5-5"}); err != nil {
t.Fatal(err)
}
p, _ := find(All(), "claude")
if err := Save(p); err != nil {
t.Fatal(err)
}
if p, _ := find(All(), "claude"); !slices.Equal(p.PickedFrom, []string{"claude-opus-5-5"}) {
t.Fatalf("listed after a Save of the same picks: %v", p.PickedFrom)
}
}
// Factory's list is magpie's own too (droid's registry, compiled in): a
// model a newer magpie adds is served at once, not held out by the copy an
// older one's fetch kept.
func TestFactoryServesModelsAddedSinceItsFetch(t *testing.T) {
claudeHome(t)
p := factoryProvider(factoryLogin{Login: Login{User: "a@example.com"}})
if _, err := p.Fetch(context.Background()); err != nil {
t.Fatal(err)
}
old := factoryModels
t.Cleanup(func() { factoryModels = old })
factoryModels = append(slices.Clone(old), factoryModel{"claude-test-added", "Test Added", Anthropic, "anthropic", 200000, 64000, nil, true})
if _, ok := p.Fetched(); !ok {
t.Fatal("the fetch left no list")
}
if !slices.Contains(modelIDs(p.Available()), "claude-test-added") {
t.Fatalf("a model added since the fetch: %v", modelIDs(p.Available()))
}
}