Files
magpie/internal/provider/group_test.go
T
herrkaefer b5d47ca5e7 gateway: an image sent to a model that can't see is dealt with before it goes out, and one a tool returned no longer ends the chat (#56)
A model's image input is taken from models.dev and the provider's own list, and a group's from its members: only a model known to be text-only is refused an image — one whose support is unknown still gets it, and Codex, OpenCode and Pi are told which models take images. An image the user attaches for a text-only model answers 400 in the client's own format before the upstream is asked; an image earlier in the chat, or one a tool returned (Claude Code's Read, Codex's view_image, a Chat tool message), becomes a short text note, so a chat that met a picture carries on after a switch to a text-only model. Thanks @herrkaefer.
2026-09-25 15:39:56 +08:00

69 lines
2.3 KiB
Go

package provider
import "testing"
// Vendors spell the same model differently; a group magpie finds joins
// them all.
func TestAutoGroupsSameModel(t *testing.T) {
for in, want := range map[string]string{
"claude-opus-5-5": "claude-opus-5-5",
"anthropic/claude-opus-5.5": "claude-opus-5-5",
"Claude-Opus-5.5": "claude-opus-5-5",
"claude-opus-5-5-20260801": "claude-opus-5-5",
"anthropic/claude-opus-5.5:batch": "claude-opus-5-5:batch",
"gpt-5.1-codex": "gpt-5-1-codex",
"v1.beta": "v1.beta",
} {
if got := sameModel(in); got != want {
t.Errorf("sameModel(%q) = %q, want %q", in, got, want)
}
}
e := func(p, m, name string) Entry {
return Entry{ID: p + "/" + m, Model: m, Name: name, Provider: Provider{ID: p}}
}
gs := autoGroups([]Entry{
e("openrouter", "anthropic/claude-opus-5.5", "anthropic/claude-opus-5.5"),
e("copilot", "claude-opus-5.5", "claude-opus-5.5"),
e("claude", "claude-opus-5-5", "Claude Opus 5.5"),
})
if len(gs) != 1 || gs[0].ID != "auto-claude-opus-5-5" || len(gs[0].Members) != 3 || gs[0].Name != "Claude Opus 5.5" {
t.Fatalf("groups: %+v", gs)
}
}
// A group takes images only when every member does: any of them may be
// the one that answers.
func TestGroupImages(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("XDG_CONFIG_HOME", "")
e := func(p, m string, images bool) Entry {
return Entry{ID: p + "/" + m, Model: m, Name: m, Provider: Provider{ID: p}, Images: images}
}
gs := groupEntries([]Entry{
e("a", "kimi-k3", true), e("b", "kimi-k3", true),
e("a", "glm-5.3", true), e("b", "glm-5.3", false),
})
got := map[string]bool{}
for _, g := range gs {
got[g.ID] = g.Images
}
if len(got) != 2 || !got[GroupPrefix+"auto-kimi-k3"] || got[GroupPrefix+"auto-glm-5-3"] {
t.Errorf("%v", got)
}
}
func TestGroupImagesKeepUnknownMemberUnknown(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("XDG_CONFIG_HOME", "")
yes := true
entries := []Entry{
{ID: "a/m", Model: "m", Provider: Provider{ID: "a"}, Images: true, ImageInput: &yes},
{ID: "b/m", Model: "m", Provider: Provider{ID: "b"}, Images: true},
}
groups := groupEntries(entries)
if len(groups) != 1 || !groups[0].Images || groups[0].ImageInput != nil {
t.Fatalf("group with inferred image support lost images: %+v", groups)
}
}