Files
magpie/internal/provider/grouplevels_unknown_test.go
T
yetone 8c5190a203 provider: a routing group keeps its thinking members' levels beside a member known not to think, so Codex shows its effort control (#2127, cnlove7777777-art)
#2127: with a routing group as its model, Codex showed an effort but no
control to change it, and new sessions and subagents ran at medium. A
group offers agents the levels its members have in common
(groupEntries), and a member magpie knows doesn't think (Entry.Quiet: its
vendor's list says no reasoning) counted as having none, so the
intersection came out empty. The group still reasons when one member
does, so Codex got its entry with reasoning but no
supported_reasoning_levels and no default_reasoning_level: no slider,
and Codex's own medium.

Since #950 the gateway sends such a member no reasoning ask at all
(withoutReasoningAsk, quiet.go), as it does a reasonless one (f074996d9)
and as it handles a member whose levels nothing knows (#597), so its
having no levels is no reason to take the others' away. groupEntries now
skips it like those two. The group's levels are those of its members
that think; Group.Levels and fixed-effort members are unchanged.

Tests: TestGroupQuietMemberKeepsCodexEffortControl builds the Codex
catalog (codexcat.Catalog(CodexListed())) for a group of a models.dev
reasoning:false model and one with levels, and wants the levels and
default (high, and max when config.toml asks max); TestGroupReasoningLevels
gains "quiet between". Both fail on the old group.go (levels [], default
""). TestGroupLevelsWithUnknownMember's "plain" group and
TestModelsListReasoning's group/auto-mixed encoded the old rule and now
want the thinking member's levels. docs/reference.md and
gateway-routing.md say the new rule.

Run (worktree on origin/main bda271999, private GOCACHE): gofmt -l clean;
go vet (darwin), GOOS=linux -tags nogui and GOOS=windows go vet of
internal/provider clean; go test -count=1 ./internal/provider
./internal/gateway ./internal/agent ./internal/codexcat ok.
Not tried: a real Codex session against the reporter's groups (their
config isn't known; a group with a non-thinking member is the case that
produces exactly what they describe).
2026-10-14 18:14:17 +08:00

86 lines
3.3 KiB
Go

package provider
import (
"os"
"path/filepath"
"slices"
"testing"
"github.com/yetone/magpie/internal/catalog"
)
// #597: a routing group of DeepSeek V4 Pro on Tencent's TokenHub and on its
// Token Plan (deepseek-v4-pro-202606, which nothing magpie reads knows)
// offered no reasoning levels, so Pi listed off alone for it and ran it
// without reasoning while magpie showed max. A model a provider serves that
// its vendor's list leaves out takes the levels the gateway fits an effort
// to (Provider.Efforts), and a member whose levels nothing knows takes
// whatever the agent asks rather than taking the others' away. Nor does a
// member known to have none, which the gateway sends no reasoning ask
// (#2127).
func TestGroupLevelsWithUnknownMember(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", t.TempDir())
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
cache := t.TempDir()
t.Setenv("XDG_CACHE_HOME", cache)
os.MkdirAll(filepath.Join(cache, "magpie"), 0o755)
if err := os.WriteFile(catalog.CachePath(), []byte(`{
"deepseek": {"models": {"deepseek-v4-pro": {"id":"deepseek-v4-pro","name":"DeepSeek V4 Pro","reasoning":true,
"reasoning_options":[{"type":"toggle"},{"type":"effort","values":["low","high","max"]}],"limit":{"context":1000000}}}},
"tencent-tokenhub": {"models": {"hy3": {"id":"hy3","reasoning":true,"reasoning_options":[{"type":"effort","values":["none","high"]}]}}},
"plaincat": {"models": {"plain-chat": {"id":"plain-chat","limit":{"context":128000}}}}
}`), 0o644); err != nil {
t.Fatal(err)
}
catalog.Reset()
t.Cleanup(catalog.Reset)
for _, p := range []Provider{
// TokenHub's models.dev list has its Hy models alone
{ID: "th", Name: "TokenHub", Key: "k", Chat: "http://127.0.0.1:1/v1", Catalog: "tencent-tokenhub", Models: []string{"deepseek-v4-pro"}},
{ID: "tp", Name: "Token Plan", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"deepseek-v4-pro-202606"}},
{ID: "pl", Name: "Plain", Key: "k", Chat: "http://127.0.0.1:1/v1", Catalog: "plaincat", Models: []string{"plain-chat"}},
} {
if err := Save(p); err != nil {
t.Fatal(err)
}
}
want := []string{"low", "high", "max"}
entry := func(id string) Entry {
t.Helper()
e, ok := EntryOf(id)
if !ok {
t.Fatalf("%s not listed", id)
}
return e
}
// the catalog and the gateway agree on the model's levels
p, _ := Find("th")
if got := p.Efforts("deepseek-v4-pro"); !slices.Equal(got, want) {
t.Fatalf("gateway's levels: %v", got)
}
if e := entry("th/deepseek-v4-pro"); !slices.Equal(e.Efforts, want) {
t.Fatalf("catalog's levels: %v", e.Efforts)
}
for name, members := range map[string][]string{
"ds": {"tp/deepseek-v4-pro-202606", "th/deepseek-v4-pro"},
"plain": {"th/deepseek-v4-pro", "pl/plain-chat"},
"tp": {"tp/deepseek-v4-pro-202606"},
} {
if err := SaveGroup(Group{Name: name, Members: members}); err != nil {
t.Fatal(err)
}
}
if e := entry("group/ds"); !slices.Equal(e.Efforts, want) || !e.Reasoning {
t.Fatalf("ds: levels %v, reasoning %v", e.Efforts, e.Reasoning)
}
// a member listed without levels doesn't take them away (#2127), and
// a group of models nothing knows offers none
if e := entry("group/plain"); !slices.Equal(e.Efforts, want) {
t.Fatalf("plain: levels %v", e.Efforts)
}
if e := entry("group/tp"); len(e.Efforts) != 0 {
t.Fatalf("tp: levels %v", e.Efforts)
}
}