Files
magpie/internal/provider/group_test.go
T
yetone 0407d69e84 provider: a group of Kimi models keeps always_thinking, dynamic tools and its default effort
jiabubu on Discord (#feedback): one Kimi Code model put in a routing group
so it lists first lost "always thinking" and "dynamic tool loading" in Kimi
Code, which the same model straight from its provider has. buildGroupEntries
never set AlwaysThinks, DynamicTools or DefaultEffort on a group (the Entry
comment said "a group has none of them"), so kimiModelTables wrote the
group's table without always_thinking and dynamically_loaded_tools, and
default_effort fell back to high.

groupSharedKimi now gives a group each of the three when every member's
entry says the same, and none of it when one member doesn't or has no
entry: a group request can reach any member (rule targets are members too,
ruledEntry's of()), so Kimi Code must not shape a request for a member that
can't take it. The capability words are Kimi Code 2.4.1's own
(catalog-runtime.ts capabilityFromDeclared), already written for direct
models; kimi-cli still gets neither.

Tests: TestGroupSharesKimiFacts (provider: all share, one without, efforts
differ) and TestKimiCodePlanCapabilities now writes a one-member group
"top" (the reporter's case: always_thinking, dynamically_loaded_tools,
default_effort max) and a group "mix" with a relay model (neither word).

Run on mote (mote-run, sandbox HOME):
- At 83a630d69 (on fbb1b36d1): gofmt -l internal/provider internal/agent
  clean; go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows
  go vet ./... ok; go test -tags nogui -count=1 -timeout 45m ./...: every
  package ok but internal/gui TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514) and internal/proc TestNoCommandBypassesProc (#4491). Both fail
  the same at origin/main 841326709, just fetched; neither touches this
  change.
- At the pushed head (rebased on 841326709): go test -count=1 -timeout 45m
  ./internal/provider ./internal/agent ./internal/catalog ok.

Broken by hand: without the groupSharedKimi call, both tests go red
(group/top loses always_thinking and dynamically_loaded_tools and gets
high). With "any member" instead of "every member", both go red
(group/mix and the mixed auto groups get the words).

Not tried: a real Kimi Code session picking the group (the words are the
ones real Kimi Code 2.4.1 already reads for direct models), Windows and
Linux test runs (vet only), nested groups.
2026-10-31 14:59:44 +08:00

141 lines
5.3 KiB
Go

package provider
import (
"maps"
"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"),
}, nil)
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 when one of its members does: the gateway gives an
// image to the members that see it (#756: an auto group of DeepSeek V4.1
// Flash with one text-only member turned every image away).
func TestGroupImages(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", t.TempDir())
t.Setenv("XDG_CONFIG_HOME", "")
no, yes := false, true
e := func(p, m string, images bool, in *bool) Entry {
return Entry{ID: p + "/" + m, Model: m, Name: m, Provider: Provider{ID: p}, Images: images, ImageInput: in}
}
gs := groupEntries([]Entry{
e("a", "kimi-k3", true, nil), e("b", "kimi-k3", true, nil),
e("a", "glm-5.3", true, nil), e("b", "glm-5.3", false, nil),
e("a", "deepseek-v4.1-flash", false, &no), e("b", "deepseek-v4.1-flash", true, &yes),
e("a", "glm-5.2", false, &no), e("b", "glm-5.2", false, &no),
})
got := map[string]bool{}
for _, g := range gs {
got[g.ID] = g.Images
}
want := map[string]bool{
AutoPrefix + "kimi-k3": true, AutoPrefix + "glm-5.3": true,
AutoPrefix + "deepseek-v4.1-flash": true, AutoPrefix + "glm-5.2": false,
}
if !maps.Equal(got, want) {
t.Errorf("%v", got)
}
}
func TestGroupImagesFromAMemberThatSees(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", 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 || !*groups[0].ImageInput {
t.Fatalf("group with a member that sees lost images: %+v", groups)
}
}
// A group whose first member is a ChatGPT account's model is still magpie's
// to list to a signed-in Codex: the backend lists the model, not the group.
func TestCodexListedKeepsGroups(t *testing.T) {
acct := Provider{ID: "codex-me", Account: &Account{Agent: "codex"}}
ms := codexListed([]Entry{
{ID: GroupPrefix + "fast", Model: "gpt-5.5", Name: "fast", Provider: acct, Group: "fast"},
{ID: "codex-me/gpt-5.5", Model: "gpt-5.5", Provider: acct},
{ID: "or/glm-5.3", Model: "glm-5.3", Provider: Provider{ID: "or"}},
}, func(id string) []Member {
return []Member{{Provider: Provider{ID: "or"}, Model: "glm-5.3"}, {Provider: acct, Model: "gpt-5.5"}}
}, false)
var ids []string
for _, m := range ms {
ids = append(ids, m.ID)
}
if len(ids) != 2 || ids[0] != GroupPrefix+"fast" || ids[1] != "or/glm-5.3" {
t.Errorf("listed %v", ids)
}
// Codex offers /fast on the group, a ChatGPT GPT model being in it
if !ms[0].Fast || ms[1].Fast {
t.Errorf("fast: group %v, model %v", ms[0].Fast, ms[1].Fast)
}
}
// A group keeps what Kimi Code's list says of its models (always thinks,
// loads tools mid-conversation, its default effort) when every member says
// it, and has none of it when one member doesn't (jiabubu on Discord: a Kimi
// model put in a group lost always_thinking and dynamically_loaded_tools in
// Kimi Code).
func TestGroupSharesKimiFacts(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", t.TempDir())
t.Setenv("XDG_CONFIG_HOME", "")
e := func(p, m string, always, dynamic bool, def string) Entry {
return Entry{ID: p + "/" + m, Model: m, Name: m, Provider: Provider{ID: p}, Reasoning: true,
Efforts: []string{"low", "medium", "high"}, AlwaysThinks: always, DynamicTools: dynamic, DefaultEffort: def}
}
type facts struct {
always, dynamic bool
def string
}
got := map[string]facts{}
for _, g := range groupEntries([]Entry{
e("kimi-code", "kimi-k3", true, true, "high"), e("kimi-code-cn", "kimi-k3", true, true, "high"),
e("kimi-code", "kimi-k2.7", true, true, "high"), e("or", "kimi-k2.7", false, false, ""),
e("kimi-code", "kimi-k2.8", true, false, "medium"), e("kimi-code-cn", "kimi-k2.8", true, true, "high"),
}) {
got[g.ID] = facts{g.AlwaysThinks, g.DynamicTools, g.DefaultEffort}
}
want := map[string]facts{
AutoPrefix + "kimi-k3": {true, true, "high"},
AutoPrefix + "kimi-k2.7": {},
AutoPrefix + "kimi-k2.8": {always: true},
}
if !maps.Equal(got, want) {
t.Errorf("got %+v, want %+v", got, want)
}
}