Files
magpie/internal/agent/pi_test.go
T
yetone de290249bb pi: a model that always thinks has off hidden on the Messages API, and its Chinese refusal of thinking off is asked again (#699, liuweifeng: 走 Anthropic Messages API 的 always-thinks 模型被删掉 thinkingLevelMap 的 off,Pi 仍提供 off 导致上游 400) — piThinkingLevels left off out of thinkingLevelMap for every model on anthropic-messages, which is right for Claude (Pi offers a level left out, and Claude takes thinking disabled whatever its levels) but had Pi offer off for ZCode's GLM-5.3-Flash too, whose levels are low/high/max and which answers thinking disabled with 400 "该模型始终支持思考,不可关闭". Now off is left out only for a model that thinks only when asked: gateway.ThinksOnlyWhenAsked, the gateway's own anthropicModel (the test that decides it leaves a Claude's request as sent and turns another vendor's thinking off unless asked), plus a relay's opus-5.5 spelling. Another vendor's model there gets "off": null unless none is among its levels (GLM-5.2's none still maps off to it), as on Chat and Responses. The gateway's alwaysThinks, which asks a refused thinking-off request again with thinking left to the model, didn't know the Chinese wording, so the 400 reached Pi (and any agent whose request the gateway turned off); it now matches 始终…思考 / 思考…不可关闭. OpenCode's variants, dsh's levels and omp's efforts name only the model's own levels, off only for none, so they don't offer a level the model refuses; omp can't hide its off, and the gateway's retry now covers it. TestPiOffOnMessagesAPI (GLM-5.3-Flash off null and not offered; GLM-5.2 off=none; Claude and opus-5.5 off left out) and TestAnthropicPassthroughAlwaysThinksInChinese (asked again once without thinking) fail on the old code and pass. Pi's models.json generated in a temp HOME with PI_CODING_AGENT_DIR in it: zc/GLM-5.3-Flash has "off": null, low/high/max; claude-sonnet-5 has no off key. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass but TestDevinSignedInOnlyInMagpie, a timing test that passes alone. Not tried with a real ZCode account.
2026-10-03 23:36:50 +08:00

77 lines
3.4 KiB
Go

package agent
import (
"reflect"
"testing"
"github.com/yetone/magpie/internal/catalog"
)
// Every one of Pi's levels is in the map, the model's own mapped and the
// rest null, so Pi's /thinking offers the model's levels alone (#243); off
// is the model's none, and left for Pi to offer on Anthropic's Messages
// API, where it turns thinking off. A model with no known levels gets none.
func TestPiThinkingLevels(t *testing.T) {
for _, c := range []struct {
efforts []string
anthropic bool
want map[string]any
}{
{[]string{"low", "high", "max"}, false, map[string]any{
"off": nil, "minimal": nil, "low": "low", "medium": nil, "high": "high", "xhigh": nil, "max": "max"}},
{[]string{"low", "medium", "high", "xhigh"}, false, map[string]any{
"off": nil, "minimal": nil, "low": "low", "medium": "medium", "high": "high", "xhigh": "xhigh", "max": nil}},
{[]string{"none", "low", "high", "xhigh", "max"}, false, map[string]any{
"off": "none", "minimal": nil, "low": "low", "medium": nil, "high": "high", "xhigh": "xhigh", "max": "max"}},
{[]string{"none", "minimal", "low", "medium", "high"}, false, map[string]any{
"off": "none", "minimal": "minimal", "low": "low", "medium": "medium", "high": "high", "xhigh": nil, "max": nil}},
// Claude keeps off (thinking disabled) and its xhigh and max
{[]string{"low", "medium", "high", "xhigh", "max"}, true, map[string]any{
"minimal": nil, "low": "low", "medium": "medium", "high": "high", "xhigh": "xhigh", "max": "max"}},
{[]string{"none", "high"}, true, map[string]any{
"off": "none", "minimal": nil, "low": nil, "medium": nil, "high": "high", "xhigh": nil, "max": nil}},
{nil, false, nil},
{nil, true, nil},
} {
if got := piThinkingLevels(c.efforts, c.anthropic); !reflect.DeepEqual(got, c.want) {
t.Errorf("%v (anthropic %v): got %v, want %v", c.efforts, c.anthropic, got, c.want)
}
}
}
// #699: ZCode's GLM-5.3-Flash, on Anthropic's Messages API, always thinks
// (its levels low, high and max, no none) and turns thinking disabled away
// ("该模型始终支持思考,不可关闭"); its entry left off out, which Pi offers,
// so off is null for it. A Claude there still has off left for Pi to offer,
// and a vendor's model that takes none maps off to it.
func TestPiOffOnMessagesAPI(t *testing.T) {
for _, c := range []struct {
id string
efforts []string
off any // the map's off; "left out" when it has none
offered []string
}{
{"zcode/GLM-5.3-Flash", []string{"low", "high", "max"}, nil, []string{"low", "high", "max"}},
{"zcode/GLM-5.2", []string{"none", "high", "max"}, "none", []string{"off", "high", "max"}},
{"anth/claude-sonnet-5", []string{"low", "medium", "high", "xhigh", "max"}, "left out", []string{"off", "low", "medium", "high", "xhigh", "max"}},
{"relay/opus-5.5", []string{"low", "high", "max"}, "left out", []string{"off", "low", "high", "max"}},
} {
m := catalog.Model{ID: c.id, Name: c.id, Efforts: c.efforts, APIs: []string{"anthropic"}}
e := piModelJSON(m, "http://127.0.0.1:1", true)
if e["api"] != "anthropic-messages" {
t.Fatalf("%s on %v", c.id, e["api"])
}
levels := e["thinkingLevelMap"].(map[string]any)
off, set := levels["off"]
if !set {
off = "left out"
}
if off != c.off {
t.Errorf("%s: off is %v, want %v", c.id, off, c.off)
}
if got := piSupported(e); !reflect.DeepEqual(got, c.offered) {
t.Errorf("%s: Pi offers %v, want %v", c.id, got, c.offered)
}
}
}