Files
magpie/internal/catalog/labs_test.go
T
yetone f51ab771f6 catalog, provider: a model only models.dev's lab lists is known, and a Claude account lists the gated models Anthropic told its Claude Code of (iebb on Discord)
iebb on Discord (10-27): his account has Claude Mythos 5.1, magpie
doesn't list it. models.dev took the gated Mythos 5.1 out of
anthropic's provider list (models.dev #11327) and kept only its lab
file, models/anthropic/claude-mythos-5-1.toml (#11328).

Cause. magpie read only models.dev's api.json (providers -> models).
The Claude subscription's list was exactly catalog.Provider("anthropic"),
so Mythos 5.1 left it with that PR. And a vendor list that still
returns it (an Anthropic key's /v1/models) got no window, reply limit,
name or thinking for it, since nothing read the lab catalog.

Fix.
- catalog: Sync also keeps models.dev's lab catalog (models.json) as
  labs.json beside the cache, through temp+rename; a failed fetch
  keeps the last one, and a cache without it is Stale once a process.
  A model only a lab lists votes into the same tables as a listed one
  (ContextOf, OutputOf, NameOf, Thinks, SeesImages); a model a
  provider lists keeps what providers say. A thinking lab-only model
  with no levels takes those of the newest of its family a provider
  gives (labKinEfforts: Mythos 5.1 takes Mythos 5's). catalog.Describe
  builds a Model from an id for lists that name ids alone.
- provider: the Claude account's list is models.dev's anthropic list
  plus what Anthropic told the account's Claude Code beyond it, read
  from .claude.json's additionalModelOptionsCache / modelAccessCache /
  additionalModelCostsCache (Claude Code's own sign-in and each saved
  account's directory). Account.Lists honours modelAccessCache's
  entitled per account, ListPrice falls back to Anthropic's price
  from additionalModelCostsCache, and the agent's own Claude Code
  picker (claudeOwn) offers the signed-in account's extras. WSL keeps
  the catalog list. magpie still asks Anthropic nothing with a Claude
  sign-in; nothing is sent differently, no Claude Code mimicry change.
- docs/subsystems/providers-accounts.md: two rows, the lab catalog
  and a Claude account's models.

Testdata: models.dev's api.json and models.json as served on 10-27,
cut to the anthropic and azure providers' Claude models and the
anthropic lab. Tests never reach the network.

Run:
- TestLabOnlyModelIsKnown, TestLabsLeaveListedModels, TestSyncKeepsLabs,
  TestClaudeAccountListsGatedModels, TestAnthropicKeyGatedModelDescribed:
  pass.
- go test -count=1 -timeout 45m ./internal/catalog/ ./internal/provider/
  ./internal/agent/ ./internal/gateway/ at 2e165fe9d + this change:
  catalog, agent (362s), gateway (557s) ok; provider crashed in
  TestUnreadLoginsWriteErrorsKeepCredentials ("close of synctest
  channel from outside bubble" in filememo.Forget). It crashes the
  same alone on a fresh origin/main 19dc5b925 and is #3632, open.
- rebased onto origin/main 2afacd7d1 (this commit's parent): catalog
  and provider again with -skip TestUnreadLoginsWriteErrorsKeepCredentials,
  both ok. agent and gateway were not run again after the rebase.
- gofmt -l internal/: nothing. go vet for darwin, linux and windows on
  catalog, provider, agent, gateway at the rebased head: ok.
- Real use: magpie built from this tree (linux, nogui) in a golang:1.26.8
  container with a sandbox HOME, so the Mac's Keychain and ~/.claude are
  never read. `magpie sync` fetched models.dev's real catalogs today
  (api.json's anthropic has no claude-mythos-5-1; labs.json has it).
  With a fake Claude sign-in and a .claude.json whose bootstrap caches
  name claude-mythos-5-1, `magpie models` lists claude/claude-mythos-5-1
  "Mythos 5.1" low/medium/high/xhigh; `magpie model spec` gives 1M,
  128k, vision on; `magpie model price` gives $25/$125, cache read
  $2.5, write $31.25 / $50 (1h). A custom Anthropic-protocol provider
  against a fake /v1/models returning claude-mythos-5-1 lists
  fakeanth/claude-mythos-5-1 "Claude Mythos 5.1" with 1M / 128k /
  low..xhigh.

Broken by hand, each red:
- lab reading off in loadGen: every lab assertion in the catalog tests
  and the provider tests (no window, no levels, the API-key entry's
  context 0).
- syncLabs off: TestSyncKeepsLabs.
- labKinEfforts off: the efforts assertions.
- the Claude list back to catalog.Provider("anthropic"): "Claude
  account's list has no Mythos 5.1".
- claudeLists / claudeCodePrice off: the entitlement and price
  assertions.

Not tried:
- a real account with Mythos 5.1: none here. The .claude.json keys and
  shapes were read from Claude Code 2.1.311's own binary, not a real
  account's file.
- a custom Anthropic-protocol provider without catalog=anthropic gets
  no price for a lab-only model (labs carry none).
- the plugin host's mdev() (host.js) reads api.json only; Gemini CLI's
  own picker stays catalog-only; a saved Claude account whose Claude
  Code never ran has no .claude.json, so its gated models show once it
  has run there.
2026-10-27 12:16:33 +08:00

170 lines
4.9 KiB
Go

package catalog
import (
"context"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"slices"
"testing"
)
// The catalogs as models.dev serves them on 10-27, cut to Claude: its
// anthropic and azure providers (api.json) and the anthropic lab
// (models.json). models.dev took the gated Claude Mythos 5.1 out of
// anthropic's provider list (#11327) and kept its lab file (#11328).
const (
claudeAPI10_27 = "testdata/models.dev-2026-10-27-claude.json"
claudeLabs10_27 = "testdata/models.dev-labs-2026-10-27-anthropic.json"
)
func useCatalogs(t *testing.T, api, labs string) {
t.Helper()
t.Setenv("XDG_CACHE_HOME", t.TempDir())
t.Cleanup(Reset)
for src, dst := range map[string]string{api: CachePath(), labs: LabsPath()} {
if src == "" {
continue
}
b, err := os.ReadFile(src)
if err != nil {
t.Fatal(err)
}
os.MkdirAll(filepath.Dir(dst), 0o755)
if err := os.WriteFile(dst, b, 0o644); err != nil {
t.Fatal(err)
}
}
Reset()
}
// A model models.dev keeps under its lab alone is still known: an account
// or a vendor's list that has Claude Mythos 5.1 gets its name, 1M window,
// reply limit, thinking and images from the lab file, and Mythos 5's
// levels, the newest of its family any provider gives (iebb on Discord).
func TestLabOnlyModelIsKnown(t *testing.T) {
useCatalogs(t, claudeAPI10_27, claudeLabs10_27)
for _, m := range Provider("anthropic") {
if m.ID == "claude-mythos-5-1" {
t.Fatal("fixture: models.dev's anthropic list has Mythos 5.1 again")
}
}
const id = "claude-mythos-5-1"
if got := NameOf(id); got != "Claude Mythos 5.1" {
t.Errorf("NameOf = %q", got)
}
if got := ContextOf(id); got != 1_000_000 {
t.Errorf("ContextOf = %d", got)
}
if got := OutputOf(id); got != 128_000 {
t.Errorf("OutputOf = %d", got)
}
if !Thinks(id) || !SeesImages(id) {
t.Errorf("Thinks %v, SeesImages %v", Thinks(id), SeesImages(id))
}
want := EffortsOf("claude-mythos-5")
if len(want) == 0 {
t.Fatal("fixture: Mythos 5 has no levels")
}
if got := EffortsOf(id); !slices.Equal(got, want) {
t.Errorf("EffortsOf = %v, want Mythos 5's %v", got, want)
}
// a vendor prefix and Claude Code's [1m] reach it as they reach any
for _, as := range []string{"anthropic/claude-mythos-5-1", "claude-mythos-5-1[1m]"} {
if got := ContextOf(as); got != 1_000_000 {
t.Errorf("ContextOf(%q) = %d", as, got)
}
}
d := Describe(id, "")
if d.Name != "Claude Mythos 5.1" || d.Context != 1_000_000 || d.Output != 128_000 ||
!d.Reasoning || !slices.Equal(d.Efforts, want) || !d.Images || d.Released != "2026-09-01" ||
d.Temperature == nil || *d.Temperature || d.Price != nil {
t.Errorf("Describe = %+v", d)
}
if d := Describe(id, "Mythos (account)"); d.Name != "Mythos (account)" {
t.Errorf("Describe kept no list name: %q", d.Name)
}
}
// A model a provider lists keeps what providers say of it: its lab file
// adds nothing to it, and without a lab catalog the catalog answers as
// before.
func TestLabsLeaveListedModels(t *testing.T) {
useCatalogs(t, claudeAPI10_27, "")
want := map[string]int{}
for _, m := range Provider("anthropic") {
want[m.ID] = ContextOf(m.ID)
}
if ContextOf("claude-mythos-5-1") != 0 {
t.Fatal("Mythos 5.1 known without a lab catalog")
}
useCatalogs(t, claudeAPI10_27, claudeLabs10_27)
for id, w := range want {
if got := ContextOf(id); got != w {
t.Errorf("%s: window %d with labs, %d without", id, got, w)
}
}
}
// Sync keeps models.dev's lab catalog beside its provider catalog, and a
// lab fetch that fails keeps the one it had.
func TestSyncKeepsLabs(t *testing.T) {
api, _ := os.ReadFile(claudeAPI10_27)
labs, _ := os.ReadFile(claudeLabs10_27)
labsDown := false
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/api.json":
w.Write(api)
case "/models.json":
if labsDown {
http.Error(w, "down", http.StatusBadGateway)
return
}
w.Write(labs)
default:
http.NotFound(w, r)
}
}))
defer srv.Close()
useCatalogs(t, "", "")
was := modelsDevURL
modelsDevURL = srv.URL + "/api.json"
t.Cleanup(func() { modelsDevURL = was; labsTried.Store(false) })
labsTried.Store(false)
if err := Sync(context.Background()); err != nil {
t.Fatal(err)
}
if got := ContextOf("claude-mythos-5-1"); got != 1_000_000 {
t.Fatalf("after Sync, Mythos 5.1's window = %d", got)
}
if Stale() {
t.Error("a catalog just synced with its labs is stale")
}
labsDown = true
if err := Sync(context.Background()); err != nil {
t.Fatal("a lab fetch failing failed Sync:", err)
}
if got := ContextOf("claude-mythos-5-1"); got != 1_000_000 {
t.Errorf("a failed lab fetch lost the kept labs: window %d", got)
}
// a cache kept before magpie read labs is fetched again at once
os.Remove(LabsPath())
labsTried.Store(false)
if !Stale() {
t.Error("a catalog without its labs isn't stale")
}
labsDown = false
if err := Sync(context.Background()); err != nil {
t.Fatal(err)
}
if Stale() {
t.Error("stale after the labs came")
}
}