Files
magpie/internal/provider/quiet_test.go
T
如是 1b8c33b5e2 provider: a routing group reasons when any member does, not only when all of them do (#950)
* provider: a routing group reasons when any member does, not only when all of them do

groupEntries started a group at Reasoning: true and intersected it with
each member's (e.Reasoning = e.Reasoning && thinks), so one member that
doesn't think made the whole group 不支持推理. Pi reads that off /v1/models
and turns /thinking off for the model: a routing group of
deepseek-v4-flash-0731-max (a Trae plugin model magpie read as one that
doesn't reason) with a DeepSeek that does lost reasoning for both.

The group now reasons when any member does. Images already worked this way
(#756: a text-only member doesn't turn every image away), and the gateway
fits a request's effort to the member that gets it (fitFor), failing over
when a member refuses the level (failEffort). What the group offers as
levels is not changed: a member known to take none still leaves the group
none (#597), so such a group is Levelless — a shape magpie serves — rather
than one that doesn't reason.

group_reasoning_test.go (6 tests) fails without the change:
TestGroupReasoningFromAMemberThatThinks, TestGroupReasoningLevels and
TestGroupReasoningQuietMemberKeepsTheRest report reasoning off.
TestModelsListReasoning, the /v1/models contract test, fails the same way
and is updated to the new semantics. go vet, go build, GOOS=linux
GOARCH=amd64 go build -tags nogui and GOOS=windows go build pass; go test
-tags nogui ./internal/provider ./internal/plugin pass under a temp HOME.
internal/gateway passes except TestPluginStreamStalledClientKeepsOther
RequestsMoving, which fails on this machine with and without the change.

* gateway, provider: a group's member that can't think is sent no reasoning, rather than a 400

A routing group reasons when any member does (#950, 533887c2), so an agent
asks a group for reasoning that a member of it may not think at all. The
effort reached every member, and some vendors turn a reasoning ask away
with a 400 on a model that can't think — the review's second point: the
comment said the gateway routes a reasoning request to the members that
take it, and nothing did.

The gateway now sends such a member no reasoning ask, in the agent's own
protocol: Chat's reasoning_effort and reasoning, Responses' reasoning (with
reasoning_effort, which some relays take), Anthropic's thinking when it
asks to think — thinking disabled is no ask and stays — and output_config's
effort alone, the rest kept. Everything else goes as the agent sent it, the
Responses effort-update history is skipped for it, and the trace's Effort is
"" (nothing was sent) with Fixed kept, so the user's own pin is still read.
Which member goes first is unchanged: the group routes as it did, and only
the body changes.

provider.Entry.Quiet is the judgment: magpie has a word on the model — its
vendor's or its maker's list, or its provider's own account list — and that
word says no reasoning. A model nothing speaks for isn't quiet: it is sent
the effort the agent asked for, as #597 leaves it. Nor is one that takes
levels, which includes a model the user gave levels of their own: those
take the effort the gateway fits to them. Direct requests outside a group
are untouched, as TestPluginThinkingOff pins.

TestModelsReasoningWithoutLevels (thinks_test.go) still expected
group/mixed false; the review's first point. It is updated with a comment
saying why the #402 expectation changes, and a group of two quiet members
keeps the "none of them thinks" case.

TestGroupNonThinkingMemberNoEffort (group_reasoning_test.go) fails without
the change: with the withoutReasoningAsk call disabled it reports "B: the
quiet member was sent map[... reasoning_effort:high]". TestEntryQuiet
(provider) pins the judgment, and TestWithoutReasoningAsk the field set per
protocol.

go vet ./..., go build ./..., GOOS=linux go build -tags nogui ./... and
GOOS=windows go build ./... pass. go test ./internal/provider,
./internal/catalog and ./internal/plugin pass whole; internal/gateway
passes in three chunks covering every test (TestGroup|TestFixed|TestFast|
TestModels|TestPluginThink|TestWithout|TestMember, TestEffort|TestResponse|
TestReasoning|TestQuiet|TestTrace|TestRoute|TestRules|TestRule, and the
rest), 43s + 36s + 790s. The whole suite in one process times out on this
machine in an unrelated test (TestRuleDecidesAtTurnStartAndHolds here,
TestRequestBodyProgressRenewsIdleDeadline on another run) — the base commit
533887c2 times out the same way, at 800s — so the chunks are what was run.
The GUI is untouched, so no Playwright run.

* gateway, provider: a member the user fixed at an effort keeps it, quiet or not

The review's remaining point: Quiet() rests on magpie's catalog or an
account's own model list, and what this PR is about is that word being
wrong — the Trae plugin gave no capabilities, and magpie read a thinking
model as one that doesn't. A member the user fixed at an effort
("provider/model:high", #189) is the user saying this model does think, so
magpie's word doesn't override theirs: the gateway sends the fixed member
its effort and strips the reasoning ask from the others as before.

quiet := isGroup && c.effort == "" && quietTo(c.p.ID, c.model). c.effort is
only ever the member's own fixed effort (Member.Effort, planLevel), never
the agent's, a group's Group.Levels, the turn's pick or the Settings' — so
those are stripped as they were.

TestGroupNonThinkingMemberNoEffort's E is now the other way: the fixed quiet
member is sent reasoning_effort "high", and the trace's Effort is "high"
with Fixed "high". Dropping the c.effort == "" guard makes it fail with
"E: the fixed member was sent map[... model:plain]". quiet.go and
Entry.Quiet say why.

gofmt, go vet ./..., go build ./..., GOOS=linux go build -tags nogui ./...
and GOOS=windows go build ./... pass. The review's own set passes —
go test -count=1 -run 'TestGroup|TestWithoutReasoningAsk|TestEntryQuiet|
TestModelsReasoning|TestModelsListReasoning|Thinks|TestPluginThinking'
./internal/provider ./internal/gateway — and so does internal/provider whole
(208s). internal/gateway passes in chunks (Test[A-D] 340s, Test[S-Z] 216s,
Test[^A-DS-Z] split over TestEffort|TestResponse|TestReasoning|TestQuiet|
TestTrace|TestRoute|TestRules|TestRule|TestFixed|TestFast 38s and the rest
earlier): the whole suite in one process still hangs here on an unrelated
test (TestCodexBodyReadsPastOldLimit this time, TestRuleDecidesAtTurnStart
AndHolds and TestRequestBodyProgressRenewsIdleDeadline before), which the
base commit does too and which passes alone in 0.9s.
2026-10-08 13:47:13 +08:00

97 lines
3.8 KiB
Go

package provider
import (
"os"
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/catalog"
)
// Quiet is the model magpie has a word on that says no reasoning: its
// vendor's or its maker's list, or its provider's own account list. A model
// nothing speaks for isn't quiet — the gateway sends it the effort the
// agent asked for, as #597 leaves it — and neither is one that thinks.
func TestEntryQuiet(t *testing.T) {
isolate(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(`{
"xiaomi": {"models": {
"mimo-v2.6-flash": {"id":"mimo-v2.6-flash","reasoning":true,"reasoning_options":[{"type":"toggle"}]}}},
"opencode-go": {"models": {
"plain": {"id":"plain","reasoning":false},
"levelled": {"id":"levelled","reasoning":true,"reasoning_options":[{"type":"effort","values":["low","high"]}]}}}
}`), 0o644); err != nil {
t.Fatal(err)
}
catalog.Reset()
t.Cleanup(catalog.Reset)
for _, p := range []Provider{
// a vendor whose own catalog lists its models, with and without
// reasoning
{ID: "vendor", Name: "Vendor", Key: "k", Chat: "http://127.0.0.1:1/v1", Catalog: "opencode-go",
Models: []string{"plain", "levelled"}},
// a relay with no catalog of its own: its list, fetched from the
// vendor, gives ids alone, so nothing says whether it thinks
{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1",
Models: []string{"mimo-v2.6-flash", "plain", "levelled", "mystery"}},
} {
if err := Save(p); err != nil {
t.Fatal(err)
}
}
// the relay's own list, as its API answers: ids alone
if err := catalog.SaveLive("relay", "http://127.0.0.1:1/v1", []catalog.Model{
{ID: "mimo-v2.6-flash"}, {ID: "plain"}, {ID: "levelled"}, {ID: "mystery"}}); err != nil {
t.Fatal(err)
}
quiet := func(id string, want bool) {
t.Helper()
e, ok := ServedEntryOf(id)
if !ok {
t.Fatalf("%s not served", id)
}
if got := e.Quiet(); got != want {
t.Errorf("%s: Quiet %v, want %v (reasoning %v, levels %v)", id, got, want, e.Reasoning, e.Efforts)
}
}
// the vendor's own list says: plain doesn't think, levelled does
quiet("vendor/plain", true)
quiet("vendor/levelled", false)
// a relay's list says nothing of reasoning: #597's unknown, sent the
// effort as the agent asked, rather than treated as one that can't
// think — "plain" here is a model of another vendor's catalog, and
// nothing magpie reads speaks for the relay's
quiet("relay/plain", false)
quiet("relay/mystery", false)
// mimo-v2.6-flash thinks with a switch alone (Xiaomi's own list), so
// it isn't quiet: its effort goes as the agent asked, no more than high
quiet("relay/mimo-v2.6-flash", false)
quiet("relay/levelled", false)
// a provider signed in through a plugin: its own account list is a
// word on every model it serves, and says nothing of reasoning for
// this one — the shape the Trae plugin's model was read as (#950)
plugin := Entry{ID: "plugin/m", Model: "m", Provider: Provider{ID: "plugin",
Account: &Account{Agent: "plugin", models: func() []catalog.Model { return nil }}}}
if !plugin.Quiet() {
t.Errorf("a plugin's model with no reasoning: Quiet false (reasoning %v, levels %v)", plugin.Reasoning, plugin.Efforts)
}
thinks := plugin
thinks.Reasoning = true
if thinks.Quiet() {
t.Errorf("a plugin's model that thinks: Quiet true")
}
// the user gave the model levels of their own: they say it takes them,
// so it isn't quiet whatever its vendor's list says (SetModelEfforts,
// #295) — the gateway fits an effort to them
if err := SetModelEfforts("relay/mystery", []string{"low", "high"}); err != nil {
t.Fatal(err)
}
quiet("relay/mystery", false)
}