Files
magpie/internal/agent/thinks_export_test.go
T
yetone 9f8fe81aa2 models: a model that thinks with no levels magpie knows is marked reasoning for Pi and Command Code, as /v1/models says it (#2380)
Trae CN's kimi-k3 / kimi-k3-max / kimi-k3-auto think, and /v1/models
said reasoning: true, but Pi's models.json was written reasoning: false:
piModelJSON read the levels alone. Pi then offered off alone and
`magpie pi effort high` was clamped to off.

provider.Entry.Thinks() (Reasoning or levels) is now the one judgement:
/v1/models' modelObject and magpieModels, which every agent export
reads, both take it. Pi writes reasoning from it, with no
thinkingLevelMap when the levels aren't known, so Pi offers its own off
to high (getSupportedThinkingLevels, read in Pi's bundle) and the
gateway fits them (fitFor caps a switch-only model at high, #214).
Command Code is told reasoning alone for such a model, which its BYOK
reference takes for low/medium/high. OpenCode, Alma and Zed already
judged it so.

Left as they are: omp (pi-catalog's getSupportedEfforts gives a
reasoning model without thinking.efforts no levels, so the flag alone
buys nothing), jcode (how it reads reasoning with no effort not
verified), Crush (can_reason without levels sends no effort on its
openai type), cline/workbuddy/zcode (they write level lists only).

TestOpenCodeNoResellerLevelsForSwitchModel pinned Xiaomi's
mimo-v2.6-flash (a thinking switch alone) as reasoning: false in Pi; it
is now reasoning: true with no map, so Pi still offers no xhigh or max.

Run (worktree, sandbox HOME, -tags nogui -p 1):
- new TestThinkingWithoutLevelsReachesTheExports (trae-cn/kimi-k3-max):
  green; red with Pi's old line ("Pi offers [off]") and red with
  Command Code's case removed
- internal/agent -run 'Pi|CommandCode|CC|Cc|Thinking|Reason|OpenCode|
  Alma|Zed|Omp|JCode|Jcode|Crush|Route|MagpieModels': ok (382s)
- internal/gateway -run 'Model|Reason|Thinks': ok
- internal/provider -run 'Entry|Reason|Thinks|Catalog': ok
- gofmt -l clean; go vet -tags nogui darwin/linux/windows on agent,
  provider, gateway: clean
Not tried: a real Pi against a real Trae CN account; whether Xiaomi
takes Pi's "minimal" for mimo-v2.6-flash (the gateway passes a level
it has no list for as asked).

Full suite: SUITE_LINE
2026-10-15 23:08:04 +08:00

58 lines
2.0 KiB
Go

package agent
import (
"os"
"reflect"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
)
// #2380: Trae CN's kimi-k3-max thinks with no levels magpie knows, and
// /v1/models said reasoning: true for it, but Pi's models.json was written
// reasoning: false (the export read the levels alone), so Pi offered off
// alone and `magpie pi effort high` was clamped to off. Every export that
// writes a reasoning flag says what /v1/models says.
func TestThinkingWithoutLevelsReachesTheExports(t *testing.T) {
syncHome(t)
if err := os.WriteFile(catalog.CachePath(), []byte(`{
"moonshotai": {"models": {"kimi-k3-max": {"id":"kimi-k3-max","name":"Kimi-K3-Max","reasoning":true,"limit":{"context":262144}}}}
}`), 0o644); err != nil {
t.Fatal(err)
}
catalog.Reset()
if err := provider.Save(provider.Provider{ID: "trae-cn", Name: "Trae CN", Key: "k", Chat: "http://127.0.0.1:1/v1",
Catalog: "moonshotai", Models: []string{"kimi-k3-max"}}); err != nil {
t.Fatal(err)
}
const id = "trae-cn/kimi-k3-max"
shown, _ := provider.CatalogFor("pi")
var entry *provider.Entry
for i := range shown {
if shown[i].ID == id {
entry = &shown[i]
}
}
if entry == nil || !entry.Thinks() || len(entry.Efforts) != 0 {
t.Fatalf("the fixture is a model that thinks with no levels, as /v1/models says it: %+v", entry)
}
if got := piOffered("pi", "magpie/"+id); !reflect.DeepEqual(got, []string{"off", "minimal", "low", "medium", "high"}) {
t.Fatalf("Pi offers %v for %s, want its own off to high", got, id)
}
if got := piClamp("high", piOffered("pi", "magpie/"+id)); got != "high" {
t.Fatalf("magpie pi effort high runs at %q", got)
}
ms := ccProviderJSONAt("http://127.0.0.1:1/v1").(map[string]any)["models"].(map[string]any)
cc, _ := ms[id].(map[string]any)
if cc["reasoning"] != true {
t.Fatalf("Command Code's entry: %v", cc)
}
if _, set := cc["reasoningEfforts"]; set {
t.Fatalf("Command Code was told levels magpie doesn't know: %v", cc)
}
}