Files
magpie/internal/catalog/catalog_test.go
T
yetone 2df2e0886d plugin, provider, gateway: a plugin's model is listed with every kind it takes and gives (audio, video, pdf), not image alone (#1595, tkhs101)
The plugin host read a model's capabilities.input only for "image", and
fromModelsDev hard-coded output to text, so /v1/models listed
opencode-zen-free's muse-spark-1.3-contributor-free (models.opencode.ai:
input text/image/audio/video/pdf) as ["text","image"] with no output.

- host.js: fromModelsDev and the config merge keep modalities.input and
  .output whole; the listing sends inputs/outputs, the kinds the
  capabilities object marks true, in OpenCode's order.
- plugin.Model gets Inputs/Outputs; pluginCatalog puts them on
  catalog.Model's new InputModalities/OutputModalities (input only where
  the plugin said what it takes, as ImageInput already is).
- catalog: models.dev entries and a vendor's live list (now reading
  modalities.output) fill the same fields; Decorate carries the catalog's
  when the live list says nothing, beside ImageInput.
- provider.Entry.Modalities() is what the gateway lists: the source's
  kinds, with "image" still decided by Images, so the user's own
  "takes images" override still wins and the other kinds stay.

Not changed: the 7 models the report lists as having lost their levels
have reasoning_options [] upstream (models.opencode.ai), so "reasoning,
no levels" is what they are; mimo-v2.6-flash turns away levels (#214).
DSH's model kinds and Muse's list still say text/image only.

Tests: TestPluginModelModalities (gateway) with the reporter's literal
metadata: muse-spark's config as opencode-zen-free 0.1.3's configModels
writes it, and mimo-v2.6-flash-free's capabilities as its models hook
lists them; a model said nothing of stays unlisted, and the image
override drops image only. TestFetchedModalitiesKeepEveryKind (catalog).
Broken by hand: host.js without inputs gives the report's [text image]
(red); Entry.Modalities without the Inputs branch (red); Decorate
without the fill (red). Run: go test catalog, plugin, provider, gateway;
gofmt -l; GOOS=linux and windows go vet on the four; go test ./...
green on 76db4c6c2+this; after rebasing on e9b16ca18 the four packages
again: catalog, plugin and gateway green; provider red once in a run of
all four together (the failing test's name was cut off by a tail), then
green 3 runs of 3, two of them concurrent.
2026-10-11 20:56:21 +08:00

290 lines
12 KiB
Go

package catalog
import (
"context"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
)
// writeCatalog puts a valid models.dev-shaped file where load() will find it;
// load() falls back to the machine's own caches, so a malformed file would
// silently read the developer's real catalog.
func writeCatalog(t *testing.T, body string) {
t.Helper()
dir := t.TempDir()
t.Setenv("XDG_CACHE_HOME", dir)
if err := os.MkdirAll(filepath.Join(dir, "magpie"), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(CachePath(), []byte(body), 0o644); err != nil {
t.Fatal(err)
}
Reset()
t.Cleanup(Reset)
}
func TestProviderReadsTemperatureCapability(t *testing.T) {
writeCatalog(t, `{
"openai": {
"models": {
"gpt-5.5": {"id":"gpt-5.5","name":"GPT-5.5","temperature":false,
"reasoning_options":[{"type":"effort","values":["low","high"]}]},
"gpt-4.1": {"id":"gpt-4.1","name":"GPT-4.1","temperature":true}
}
}
}`)
ms := Provider("openai")
if len(ms) != 2 {
t.Fatalf("models: %+v", ms)
}
byID := map[string]Model{}
for _, m := range ms {
byID[m.ID] = m
}
if p := byID["gpt-5.5"].Temperature; p == nil || *p {
t.Fatalf("gpt-5.5 temperature: %v", p)
}
if p := byID["gpt-4.1"].Temperature; p == nil || !*p {
t.Fatalf("gpt-4.1 temperature: %v", p)
}
if got := byID["gpt-5.5"].Efforts; len(got) != 2 || got[0] != "low" {
t.Fatalf("efforts: %v", got)
}
}
func TestDecorateCarriesTemperature(t *testing.T) {
no, yes := false, true
live := []Model{{ID: "new-model"}, {ID: "gpt-5.5"}}
known := []Model{
{ID: "gpt-5.5", Name: "GPT-5.5", Temperature: &no, Released: "2026-04-23"},
{ID: "old", Temperature: &yes},
}
out := Decorate(live, known)
if out[0].Temperature != nil {
t.Fatalf("an unknown model gained a capability: %v", *out[0].Temperature)
}
if out[1].Temperature == nil || *out[1].Temperature || out[1].Name != "GPT-5.5" {
t.Fatalf("decorated: %+v", out[1])
}
}
// A model takes images where models.dev says so; one listed by several
// providers takes them as most of those say, whatever a vendor prefixes.
func TestImages(t *testing.T) {
writeCatalog(t, `{
"a": {"models": {
"vision": {"id":"vision","name":"V","modalities":{"input":["text","image"],"output":["text"]}},
"text": {"id":"text","name":"T","modalities":{"input":["text"],"output":["text"]}}
}},
"b": {"models": {"text": {"id":"text","name":"T","modalities":{"input":["text"],"output":["text"]}}}},
"c": {"models": {"org/text": {"id":"org/text","name":"T","modalities":{"input":["text","image"],"output":["text"]}}}}
}`)
for _, m := range Provider("a") {
if m.Images != (m.ID == "vision") {
t.Errorf("%s: images %v", m.ID, m.Images)
}
}
if !SeesImages("z-ai/Vision") || SeesImages("text") || SeesImages("unknown") {
t.Error("SeesImages")
}
}
// A model's window is models.dev's input limit where it gives one (what a
// prompt may hold), else its context; looked up by bare id, it is the size
// most providers give, so a relay's model finds it too.
func TestContextOf(t *testing.T) {
writeCatalog(t, `{
"openai": {"models": {
"gpt-5.5": {"id":"gpt-5.5","limit":{"context":1050000,"input":922000,"output":128000}},
"gpt-4.1": {"id":"gpt-4.1","limit":{"context":1047576,"output":32768}}
}},
"zai": {"models": {"glm-4.6": {"id":"glm-4.6","limit":{"context":204800}}}},
"a": {"models": {"zai/glm-4.6": {"id":"zai/glm-4.6","limit":{"context":204800}}}},
"b": {"models": {"glm-4.6": {"id":"glm-4.6","limit":{"context":128000}}}}
}`)
for id, want := range map[string]int{
"gpt-5.5": 922000,
"openai/gpt-5.5": 922000,
"gpt-5.5(high)": 922000,
"gpt-4.1": 1047576,
"GLM-4.6": 204800,
"glm-4.6:free": 204800,
"unknown-model": 0,
} {
if got := ContextOf(id); got != want {
t.Errorf("ContextOf(%q) = %d, want %d", id, got, want)
}
}
for _, m := range Provider("openai") {
if m.ID == "gpt-5.5" && m.Context != 922000 {
t.Errorf("Provider: %+v", m)
}
}
if out := Decorate([]Model{{ID: "gpt-5.5"}}, Provider("openai")); out[0].Context != 922000 {
t.Errorf("Decorate: %+v", out[0])
}
}
// A Bedrock inference profile of a geography models.dev doesn't list the
// model in (apac.) takes the model id's window, output and levels.
func TestBedrockProfiles(t *testing.T) {
writeCatalog(t, `{
"amazon-bedrock": {"models": {
"anthropic.claude-opus-5-5": {"id":"anthropic.claude-opus-5-5","limit":{"context":1000000,"output":128000},"reasoning_options":[{"type":"effort","values":["low","high"]}]},
"global.anthropic.claude-opus-5-5": {"id":"global.anthropic.claude-opus-5-5","limit":{"context":1000000,"output":128000}}
}}
}`)
for _, id := range []string{"apac.anthropic.claude-opus-5-5", "us-gov.anthropic.claude-opus-5-5", "global.anthropic.claude-opus-5-5"} {
if ContextOf(id) != 1000000 || OutputOf(id) != 128000 {
t.Errorf("%s: %d %d", id, ContextOf(id), OutputOf(id))
}
}
if got := strings.Join(EffortsOf("apac.anthropic.claude-opus-5-5"), ","); got != "low,high" {
t.Errorf("efforts: %q", got)
}
// not a profile: a model named with a dot
if ContextOf("us.") != 0 || ContextOf("eu.unknown") != 0 {
t.Error("a bare geography taken for a profile")
}
}
// A vendor models.dev doesn't list takes the levels the providers serving
// the model give; one that gives none (a toggle, nothing) doesn't vote.
func TestEffortsOf(t *testing.T) {
writeCatalog(t, `{
"zai": {"models": {"glm-5.3-flash": {"id":"glm-5.3-flash","reasoning_options":[{"type":"effort","values":["low","high","max"]}]}}},
"a": {"models": {"z-ai/glm-5.3-flash": {"id":"z-ai/glm-5.3-flash","reasoning_options":[{"type":"effort","values":["low","high","max"]}]}}},
"b": {"models": {"glm-5.3-flash": {"id":"glm-5.3-flash","reasoning_options":[{"type":"effort","values":["none","low","medium","high"]}]},
"glm-5": {"id":"glm-5","reasoning_options":[{"type":"toggle"}]},
"deepseek-chat": {"id":"deepseek-chat"}}},
"c": {"models": {"glm-5.3-flash": {"id":"glm-5.3-flash","reasoning_options":[{"type":"toggle"}]}}}
}`)
for id, want := range map[string]string{
"glm-5.3-flash": "low,high,max",
"GLM-5.3-Flash": "low,high,max",
"volc/glm-5.3-flash": "low,high,max",
"glm-5.3-flash:free": "low,high,max",
"glm-5.3-flash(high)": "low,high,max",
"glm-5": "",
"deepseek-chat": "",
"unknown-model": "",
} {
if got := strings.Join(EffortsOf(id), ","); got != want {
t.Errorf("EffortsOf(%q) = %q, want %q", id, got, want)
}
}
}
// A gateway listing a model under each host it routes to votes once for
// the levels it gives: llmgateway's deepinfra/… and xiaomi/… made its
// none…max the levels of mimo-v2.6-flash over two others giving none, high
// (#214).
func TestEffortsOfOneVoteAProvider(t *testing.T) {
writeCatalog(t, `{
"llmgateway": {"models": {
"deepinfra/mimo-v2.6-flash": {"id":"deepinfra/mimo-v2.6-flash","reasoning_options":[{"type":"effort","values":["none","minimal","low","medium","high","xhigh","max"]}]},
"xiaomi/mimo-v2.6-flash": {"id":"xiaomi/mimo-v2.6-flash","reasoning_options":[{"type":"effort","values":["none","minimal","low","medium","high","xhigh","max"]}]},
"novita/mimo-v2.6-flash": {"id":"novita/mimo-v2.6-flash","reasoning_options":[{"type":"effort","values":["none","minimal","low","medium","high","xhigh","max"]}]}}},
"kilo": {"models": {"xiaomi/mimo-v2.6-flash": {"id":"xiaomi/mimo-v2.6-flash","reasoning_options":[{"type":"effort","values":["none","high"]}]}}},
"nano-gpt": {"models": {"xiaomi/mimo-v2.6-flash": {"id":"xiaomi/mimo-v2.6-flash","reasoning_options":[{"type":"effort","values":["none","high"]}]}}}
}`)
if got := strings.Join(EffortsOf("mimo-v2.6-flash"), ","); got != "none,high" {
t.Fatalf("EffortsOf = %q, want none,high", got)
}
}
// ListedBy is what the first of the providers named listing a model says of
// its levels: a thinking switch alone or nothing is none, a budget without
// levels says nothing, and a model none of them lists isn't theirs to say.
func TestListedBy(t *testing.T) {
writeCatalog(t, `{
"xiaomi": {"models": {"mimo-v2.6-flash": {"id":"mimo-v2.6-flash","reasoning_options":[{"type":"toggle"}]},
"mimo-v2-omni": {"id":"mimo-v2-omni"}}},
"anthropic": {"models": {"claude-sonnet-4-5": {"id":"claude-sonnet-4-5","reasoning_options":[{"type":"budget_tokens"}]}}},
"zai": {"models": {"glm-5.3-flash": {"id":"glm-5.3-flash","reasoning_options":[{"type":"effort","values":["low","high","max"]}]}}},
"relay": {"models": {"mimo-v2.6-flash": {"id":"mimo-v2.6-flash","reasoning_options":[{"type":"effort","values":["none","low","medium","high","max"]}]},
"claude-sonnet-4-5": {"id":"claude-sonnet-4-5","reasoning_options":[{"type":"effort","values":["low","medium","high","max"]}]}}}
}`)
makers := []string{"anthropic", "xiaomi", "zai"}
for _, c := range []struct {
id, want string
ok bool
}{
{"mimo-v2.6-flash", "", true},
{"xiaomi/MiMo-V2.6-Flash", "", true},
{"mimo-v2.6-flash:free", "", true},
{"mimo-v2-omni", "", true},
{"relay/glm-5.3-flash", "low,high,max", true},
{"claude-sonnet-4-5", "", false},
{"unknown-model", "", false},
} {
got, ok := ListedBy(makers, c.id)
if strings.Join(got, ",") != c.want || ok != c.ok {
t.Errorf("ListedBy(%q) = %v, %v; want %q, %v", c.id, got, ok, c.want, c.ok)
}
}
if got, ok := ListedBy([]string{"relay", "xiaomi"}, "mimo-v2.6-flash"); !ok || len(got) != 5 {
t.Errorf("the first provider listing it: %v %v", got, ok)
}
}
func TestFetchedImageCapabilityOverridesCatalog(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"data":[
{"id":"vision","modalities":{"input":["text","image"]}},
{"id":"text","modalities":{"input":["text"]}},
{"id":"unknown"}
]}`))
}))
defer server.Close()
live, err := Fetch(context.Background(), server.URL, "", false, nil)
if err != nil || len(live) != 3 {
t.Fatalf("fetched models: %+v, %v", live, err)
}
known := []Model{
{ID: "vision", Images: true, ImageInput: imageInput([]string{"text", "image"})},
{ID: "text", Images: true, ImageInput: imageInput([]string{"text", "image"})},
{ID: "unknown", Images: true, ImageInput: imageInput([]string{"text", "image"})},
}
got := Decorate(live, known)
if got[0].ImageInput == nil || !*got[0].ImageInput || !got[0].Images ||
got[1].ImageInput == nil || *got[1].ImageInput || got[1].Images ||
got[2].ImageInput == nil || !*got[2].ImageInput || !got[2].Images {
t.Fatalf("source precedence: %+v", got)
}
}
// A list's modalities keep every kind it names, input and output, not
// image alone; a model the list says nothing of takes the catalog's (#1595).
func TestFetchedModalitiesKeepEveryKind(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"data":[
{"id":"omni","modalities":{"input":["text","image","audio","video","pdf"],"output":["text","audio"]}},
{"id":"unknown"}
]}`))
}))
defer server.Close()
live, err := Fetch(context.Background(), server.URL, "", false, nil)
if err != nil || len(live) != 2 {
t.Fatalf("fetched models: %+v, %v", live, err)
}
known := []Model{{ID: "unknown", ImageInput: imageInput([]string{"text", "pdf"}), InputModalities: []string{"text", "pdf"}, OutputModalities: []string{"text"}}}
got := Decorate(live, known)
if !reflect.DeepEqual(got[0].InputModalities, []string{"text", "image", "audio", "video", "pdf"}) ||
!reflect.DeepEqual(got[0].OutputModalities, []string{"text", "audio"}) {
t.Errorf("omni: in %v out %v", got[0].InputModalities, got[0].OutputModalities)
}
if !reflect.DeepEqual(got[1].InputModalities, []string{"text", "pdf"}) ||
!reflect.DeepEqual(got[1].OutputModalities, []string{"text"}) {
t.Errorf("unknown: in %v out %v", got[1].InputModalities, got[1].OutputModalities)
}
}