Files
magpie/internal/gateway/factory_think_off_test.go
T
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

79 lines
3.5 KiB
Go

package gateway
import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"time"
"github.com/yetone/magpie/internal/provider"
)
// Factory's DeepSeek V4.1 Flash and Kimi K3 (Fireworks) and GLM-5.2
// (Baseten) stop thinking at reasoning_effort "none", as droid sends for its
// "off" (#899); GLM-5.3 and GLM-5.3-Flash can't ("Reasoning is mandatory"),
// and are asked for low, their least. Whichever agent turns reasoning off
// — none on chat completions or Responses, Anthropic's thinking disabled —
// a model with none among its levels is asked for none, not low.
func TestFactoryThinkingOff(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
t.Setenv("XDG_DATA_HOME", filepath.Join(home, ".local", "share"))
f := &fake{t: t, code: http.StatusForbidden, ctype: "application/json", reply: `{"error":{"message":"no"}}`}
up := httptest.NewServer(f)
t.Cleanup(up.Close)
t.Cleanup(provider.FactoryBaseForTest(up.URL, up.URL+"/eu"))
auth, _ := json.Marshal(map[string]any{
"accessToken": "tok", "refreshToken": "r",
"expiresAt": time.Now().Add(time.Hour).UnixMilli(),
"orgId": "org_D", "activeOrganizationId": "fac_D", "email": "d@example.com",
})
dir := filepath.Dir(provider.Path())
if err := os.MkdirAll(dir, 0o755); err != nil {
t.Fatal(err)
}
raw, _ := json.Marshal([]map[string]any{{
"agent": "factory", "user": "d@example.com", "plan": "pro", "on": true, "auth": json.RawMessage(auth),
}})
if err := os.WriteFile(filepath.Join(dir, "logins.json"), raw, 0o600); err != nil {
t.Fatal(err)
}
for _, tt := range []struct {
name, path, body, want string
}{
{"chat none", "/v1/chat/completions", `{"model":"factory/deepseek-v4.1-flash","reasoning_effort":"none","messages":[{"role":"user","content":"hi"}]}`, "none"},
{"chat none kimi", "/v1/chat/completions", `{"model":"factory/kimi-k3","reasoning_effort":"none","messages":[{"role":"user","content":"hi"}]}`, "none"},
{"chat low", "/v1/chat/completions", `{"model":"factory/deepseek-v4.1-flash","reasoning_effort":"low","messages":[{"role":"user","content":"hi"}]}`, "low"},
{"responses none", "/v1/responses", `{"model":"factory/kimi-k3","reasoning":{"effort":"none"},"input":[{"role":"user","content":"hi"}]}`, "none"},
{"messages disabled", "/v1/messages", `{"model":"factory/deepseek-v4.1-flash","thinking":{"type":"disabled"},"messages":[{"role":"user","content":"hi"}],"max_tokens":8}`, "none"},
{"baseten none", "/v1/chat/completions", `{"model":"factory/glm-5.2","reasoning_effort":"none","messages":[{"role":"user","content":"hi"}]}`, "none"},
// reasoning is mandatory on these: low is the least
{"glm-5.3 none", "/v1/chat/completions", `{"model":"factory/glm-5.3","reasoning_effort":"none","messages":[{"role":"user","content":"hi"}]}`, "low"},
{"glm-5.3-flash none", "/v1/responses", `{"model":"factory/glm-5.3-flash","reasoning":{"effort":"none"},"input":[{"role":"user","content":"hi"}]}`, "low"},
} {
t.Run(tt.name, func(t *testing.T) {
f.got, f.path = nil, ""
post(t, tt.path, tt.body)
if f.path != "/api/llm/o/v1/chat/completions" {
t.Fatalf("went to %s: %s", f.path, f.got)
}
var m map[string]any
if json.Unmarshal(f.got, &m) != nil {
t.Fatalf("upstream %s", f.got)
}
if m["reasoning_effort"] != tt.want {
t.Errorf("reasoning_effort %v, want %s", m["reasoning_effort"], tt.want)
}
})
}
}