Files
magpie/internal/gateway/minimax_effort_test.go
T
yetone 226551d0d8 gateway: MiniMax M3.1-Flash is sent its effort in output_config (shin4 on plugins#316)
An OpenAI client's reasoning effort (Responses' reasoning.effort, Chat's
reasoning_effort) for MiniMax Code's MiniMax-M3.1-Flash or -Preview, built
into an Anthropic body for the minimax plugin, went as a thinking budget
alone. Under the reporter's 8192 cap medium, high, xhigh and max were all
budget_tokens 7168, so the level was lost before the plugin saw it.

The two models join GLM-5.2/5.3 in effortInOutputConfig: buildAnthropic
sends output_config.effort next to the budget, and an Anthropic client's
budget gets its nearest level there too (withOutputEffort, passthrough).
MiniMax Code's catalog marks M3.1-Flash forced_on at low..max. The budget
stays as it was (the owner's plan on plugins#317); dropping thinking for
the managed-login route, as MiniMax Code 3.1.4 does, stays the plugin's
call. Nothing goes into prompt text. Claude, MiniMax-M3 and other vendors'
models keep the budget alone. MiniMax's public Anthropic API doesn't list
M3.1-Flash (platform.minimax.io text-anthropic-api), so the rule reaches
MiniMax Code's subscription and any relay serving those two models.

Tests (internal/gateway/minimax_effort_test.go, fake plugin $FAKE_MINIMAX):
- TestMiniMaxPluginGetsTheNativeEffort: the reporter's Responses request
  and its Chat form, low..max, both models, on minimax-code and
  minimax-code-global through the plugin host (bun), plus an Anthropic
  client's budget 10000 -> medium; MiniMax-M3 keeps no output_config.
- TestNativeEffortLeavesOthersAlone: claude-sonnet-4-5, kimi-k3 and
  MiniMax-M3 on an Anthropic relay get budget 7168 and no output_config.

Run at e31e3699a + this change, sandbox HOME, pinned caches:
- with the regex change reverted, TestMiniMaxPluginGetsTheNativeEffort
  fails with the reporter's table ("/v1/responses MiniMax-M3.1-Flash
  medium: output_config <nil>, thinking map[budget_tokens:7168
  type:enabled]"); restored, passes.
- the regex widened by hand to minimax|claude|kimi: TestNativeEffort-
  LeavesOthersAlone fails for all three models; restored, passes.
- go test ./internal/gateway -run 'Effort|Adaptive|Think|GLM|MiniMax|
  Budget|Reasoning|Level': ok. go test ./internal/plugin/...: ok.
- gofmt -l: clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok.

Not run before this push: the full suite (the machine is at load ~210
with several sessions queued for it; it runs after, in turn). Not tried:
a real MiniMax Code account. Whether MiniMax's subscription endpoint
honours output_config.effort beside a budget (rather than with thinking
left out, as shin4's live run sent it) is not verified.
2026-10-22 19:36:50 +08:00

85 lines
4.1 KiB
Go

package gateway
import (
"encoding/json"
"net/http/httptest"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// shin4 on plugins#316: an OpenAI client's effort for MiniMax Code's
// M3.1-Flash reached the plugin as a thinking budget alone, and under an
// 8192 cap medium to max were all budget 7168, so the level was lost. It
// goes in output_config.effort too, from Responses, Chat and an Anthropic
// client's budget, on both MiniMax Code providers. The requests are the
// reporter's, with the effort and the model's provider swapped in.
func TestMiniMaxPluginGetsTheNativeEffort(t *testing.T) {
t.Setenv("FAKE_MINIMAX", "1")
for _, id := range []string{"minimax-code", "minimax-code-global"} {
t.Run(id, func(t *testing.T) {
up := &adaptiveVendor{}
pid := besideFake(t, id, up)
for _, model := range []string{"MiniMax-M3.1-Flash", "MiniMax-M3.1-Flash-Preview"} {
for _, c := range []struct {
effort string
budget float64
}{{"low", 4096}, {"medium", 7168}, {"high", 7168}, {"xhigh", 7168}, {"max", 7168}} {
for _, ask := range []struct{ path, body string }{
{"/v1/responses", `{"model":"` + pid + `/` + model + `","input":"Reply exactly OK.","reasoning":{"effort":"` + c.effort + `"},"max_output_tokens":8192,"stream":false}`},
{"/v1/chat/completions", `{"model":"` + pid + `/` + model + `","messages":[{"role":"user","content":"Reply exactly OK."}],"reasoning_effort":"` + c.effort + `","max_tokens":8192,"stream":false}`},
} {
postProto(t, New(), ask.path, ask.body)
got := up.last()
oc, _ := got["output_config"].(map[string]any)
th, _ := got["thinking"].(map[string]any)
if oc["effort"] != c.effort {
t.Errorf("%s %s %s: output_config %v, thinking %v", ask.path, model, c.effort, got["output_config"], th)
}
if th["type"] != "enabled" || th["budget_tokens"] != c.budget {
t.Errorf("%s %s %s: thinking %v, want a budget of %v beside the effort", ask.path, model, c.effort, th, c.budget)
}
}
}
}
// an Anthropic client's budget, as Claude Code sends medium
postProto(t, New(), "/v1/messages", `{"model":"`+pid+`/MiniMax-M3.1-Flash","max_tokens":32000,"thinking":{"type":"enabled","budget_tokens":10000},"messages":[{"role":"user","content":"Reply exactly OK."}]}`)
if oc, _ := up.last()["output_config"].(map[string]any); oc["effort"] != "medium" {
t.Errorf("/v1/messages budget 10000: output_config %v", up.last()["output_config"])
}
// M3, which thinks or doesn't and has no levels of its own,
// keeps the budget alone
postProto(t, New(), "/v1/responses", `{"model":"`+pid+`/MiniMax-M3","input":"Reply exactly OK.","reasoning":{"effort":"high"},"max_output_tokens":8192,"stream":false}`)
if got := up.last(); got["output_config"] != nil {
t.Errorf("MiniMax-M3 asked output_config %v", got["output_config"])
}
})
}
}
// What goes to a Claude and to another vendor's model on an Anthropic
// endpoint is as before: the budget alone, no output_config.
func TestNativeEffortLeavesOthersAlone(t *testing.T) {
fresh(t)
up := &adaptiveVendor{}
srv := httptest.NewServer(up)
t.Cleanup(srv.Close)
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Anthropic: srv.URL,
Models: []string{"claude-sonnet-4-5", "kimi-k3", "MiniMax-M3"}}); err != nil {
t.Fatal(err)
}
for _, model := range []string{"claude-sonnet-4-5", "kimi-k3", "MiniMax-M3"} {
for _, ask := range []struct{ path, body string }{
{"/v1/responses", `{"model":"relay/` + model + `","input":"Reply exactly OK.","reasoning":{"effort":"high"},"max_output_tokens":8192,"stream":false}`},
{"/v1/chat/completions", `{"model":"relay/` + model + `","messages":[{"role":"user","content":"Reply exactly OK."}],"reasoning_effort":"high","max_tokens":8192,"stream":false}`},
} {
postProto(t, New(), ask.path, ask.body)
got := up.last()
b, _ := json.Marshal(map[string]any{"thinking": got["thinking"], "output_config": got["output_config"]})
if want := `{"output_config":null,"thinking":{"budget_tokens":7168,"type":"enabled"}}`; string(b) != want {
t.Errorf("%s %s: %s", ask.path, model, b)
}
}
}
}