Files
magpie/internal/gateway/plugin_cline_pin_test.go
T
yetone dad4b98729 gateway, gui: the Cline plugin's provider has ClinePass's Upstream tick too (ARNO on Discord: 这个功能可以也加到cline的插件里面吗) — "DeepSeek models only from DeepSeek's own API" was the built-in ClinePass's alone: the Cline plugin's provider (@magpie-community/opencode-cline-auth) is an account, whose editor had no such tick, whose save didn't keep pinUpstream and whose requests clinePin didn't touch. Now ClinePinnable is ClinePass, a cline.bot provider or the Cline plugin's; its editor shows the Upstream tick (one upstreamField for both editors), its save posts pinUpstream, the account keeps it (Save, allProviders), and a DeepSeek model's request reaches the plugin with "providerOptions":{"gateway":{"only":["deepseek"]}} on Chat and Anthropic Messages, as ClinePass's does. The plugin 0.1.3 has the same as an option of its own for OpenCode. TestClinePluginPinsDeepSeek (the fake plugin as cline, with a deepseek-v4-pro): unticked nothing is pinned; ticked and saved, the tick is kept and both DeepSeek requests are pinned, fake-1's not; it fails on the old code (not pinnable; the tick not kept). clinepass-pin.test.cjs: the plugin's editor shows the tick as saved and Save posts it off when unticked (WebKit, en and zh); it fails on the old app.js. model-first-pick, plugin-moved-signin, click-scroll, gui-ja and gui-de pass on WebKit. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
2026-10-05 12:59:32 +08:00

86 lines
2.9 KiB
Go

package gateway
import (
"encoding/json"
"io"
"net/http"
"sync"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// The Cline plugin's provider has ClinePass's Upstream tick too (ARNO on
// Discord): saved on it, a DeepSeek model's request reaches the plugin
// pinned to DeepSeek's own API, on Chat and Anthropic Messages alike, and
// its other models' requests go as sent.
func TestClinePluginPinsDeepSeek(t *testing.T) {
t.Setenv("FAKE_DEEPSEEK", "1")
var mu sync.Mutex
var sent []map[string]any
pid := besideFake(t, "cline", 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)
mu.Unlock()
if q["stream"] == true {
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]`))
return
}
w.Header().Set("Content-Type", "application/json")
io.WriteString(w, `{"id":"c1","object":"chat.completion","choices":[{"index":0,"message":{"role":"assistant","content":"hi"},"finish_reason":"stop"}],"usage":{"prompt_tokens":3,"completion_tokens":1}}`)
}))
p, err := provider.Find(pid)
if err != nil {
t.Fatal(err)
}
if !p.ClinePinnable() || p.ClinePin("deepseek-v4-pro") != "" {
t.Fatalf("the Cline plugin's provider: pinnable %v, pinned unasked %q", p.ClinePinnable(), p.ClinePin("deepseek-v4-pro"))
}
ask := func() []map[string]any {
mu.Lock()
sent = nil
mu.Unlock()
for _, req := range []struct{ path, body string }{
{"/v1/chat/completions", `{"model":"` + pid + `/deepseek-v4-pro","messages":[{"role":"user","content":"hi"}]}`},
{"/v1/messages", `{"model":"` + pid + `/deepseek-v4-pro","max_tokens":10,"messages":[{"role":"user","content":"hi"}]}`},
{"/v1/chat/completions", `{"model":"` + pid + `/fake-1","messages":[{"role":"user","content":"hi"}]}`},
} {
postProto(t, New(), req.path, req.body)
}
mu.Lock()
defer mu.Unlock()
if len(sent) != 3 {
t.Fatalf("the plugin sent %d requests", len(sent))
}
return append([]map[string]any(nil), sent...)
}
for i, q := range ask() {
if q["providerOptions"] != nil {
t.Fatalf("request %d pinned with the tick off: %v", i, q["providerOptions"])
}
}
// the tick, saved as the editor saves it, is kept on the account
p.PinUpstream = true
if err := provider.Save(*p); err != nil {
t.Fatal(err)
}
if p, err = provider.Find(pid); err != nil || !p.PinUpstream {
t.Fatalf("the tick wasn't kept: %+v, %v", p, err)
}
got := ask()
for i, q := range got[:2] {
po, _ := json.Marshal(q["providerOptions"])
if string(po) != `{"gateway":{"only":["deepseek"]}}` {
t.Fatalf("request %d (DeepSeek) reached the plugin with providerOptions %s", i, po)
}
}
if got[2]["providerOptions"] != nil {
t.Fatalf("fake-1 pinned: %v", got[2]["providerOptions"])
}
}