Files
magpie/internal/gateway/plugin_think_off_test.go
yetone 9e13f18fb9 gateway, provider: a request turning reasoning off stops Factory's DeepSeek V4.1 Flash, Kimi K3 and GLM-5.2 thinking (#899, tedestar) — they offered only low/high/max (GLM-5.2 high/max), so an agent's none (or Claude Code's thinking disabled) was asked for low, or nothing, and Fireworks thought anyway. droid 0.231.0 lists off for them and sends reasoning_effort "none"; through OpenRouter pinned to Fireworks, none came back with 0 reasoning tokens on DeepSeek V4.1 Flash (2 completion tokens; 19 at the default, 16 reasoning at low) and Kimi K3 (8; 71 at the default), and on Baseten's GLM-5.2 (2; 114 at the default), while GLM-5.3 and GLM-5.3-Flash turn none away ("Reasoning is mandatory for this endpoint and cannot be disabled") and stay at low, their least (Qwen3.8 Max and MiniMax have no off in droid either). The three now have none among their levels, in the built-in and in @magpie-community/opencode-factory-auth 0.1.17, which the mover's min is raised to; and a translated request that turned reasoning off (Effort reads it as low) is asked for none on a model with none among its levels, whatever the provider, else as before (a refusal still falls back to the lowest level on). No Factory account was at hand to send through Factory itself. TestFactoryThinkingOff (the built-in: chat, Responses and Anthropic's disabled; GLM-5.3 still low) and TestPluginThinkingOff (the plugin host, a model whose variants have none and one without) are new and fail without the change. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass (TestSavedButSignedOutClaudeServed timed out once under load and passes alone).
2026-10-05 20:09:00 +08:00

51 lines
2.0 KiB
Go

package gateway
import (
"encoding/json"
"io"
"net/http"
"sync"
"testing"
)
// Factory's plugin, as the built-in (TestFactoryThinkingOff): a model whose
// variants have none is asked for none when an agent turns reasoning off,
// and one whose least is low is asked for low (#899).
func TestPluginThinkingOff(t *testing.T) {
t.Setenv("FAKE_OFF", "1")
var mu sync.Mutex
var sent []any
pid := besideFake(t, "factory", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var q map[string]any
b, _ := io.ReadAll(r.Body)
json.Unmarshal(b, &q)
mu.Lock()
sent = append(sent, q["reasoning_effort"])
mu.Unlock()
w.Header().Set("Content-Type", "text/event-stream")
io.WriteString(w, sse(`data: {"id":"c1","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":"hi"},"finish_reason":"stop"}]}`, `data: [DONE]`))
}))
for _, tt := range []struct {
name, path, body string
want any
}{
{"chat none", "/v1/chat/completions", `{"model":"` + pid + `/fake-off","reasoning_effort":"none","messages":[{"role":"user","content":"hi"}]}`, "none"},
{"responses none", "/v1/responses", `{"model":"` + pid + `/fake-off","reasoning":{"effort":"none"},"input":[{"role":"user","content":"hi"}]}`, "none"},
{"messages disabled", "/v1/messages", `{"model":"` + pid + `/fake-off","thinking":{"type":"disabled"},"messages":[{"role":"user","content":"hi"}],"max_tokens":8}`, "none"},
{"chat low", "/v1/chat/completions", `{"model":"` + pid + `/fake-off","reasoning_effort":"low","messages":[{"role":"user","content":"hi"}]}`, "low"},
{"no off", "/v1/responses", `{"model":"` + pid + `/fake-on","reasoning":{"effort":"none"},"input":[{"role":"user","content":"hi"}]}`, "low"},
} {
t.Run(tt.name, func(t *testing.T) {
mu.Lock()
sent = nil
mu.Unlock()
postProto(t, New(), tt.path, tt.body)
mu.Lock()
defer mu.Unlock()
if len(sent) != 1 || sent[0] != tt.want {
t.Errorf("reasoning_effort sent %v, want %v", sent, tt.want)
}
})
}
}