Files
magpie/internal/gateway/cline_client_test.go
T
yetone fbddf45a86 providers: ClinePass lists Cline's real free models and asks for them as Cline's desktop app (lml and ARNO on Discord: the free models didn't match Cline's) — a3962602 listed the Cline API's OpenRouter-style ":free" ids (qwen/qwen3.8-27b:free…), which are not what Cline offers free: Cline's clients take their picker from GET /api/v1/ai/cline/recommended-models (cline/cline sdk/packages/llms/src/catalog/catalog-cline-recommended.ts), whose free bucket is the desktop's FREE section ("Try with limited usage, separate from ClinePass quota": cline-free/deepseek-v4.1-flash, stealth/space-bunny-alpha, cline-free/mimo-v2.6-flash, cline-free/muse-spark-1.3-contributor) and whose clinePass bucket is the plan's. ClinePass now fetches that feed, asked as Cline's desktop app and with no key, as Cline asks it (pi-freeflow measured that X-CLIENT-TYPE cline-desktop is what the feed keys its free list on); the plan's models are its clinePass ones, the free ones are marked Free (the FREE badge) and priced at nothing, and its recommended paid models are left out, as before. When the feed can't be had the API's list is asked as before, and the free models are the desktop's list of today (from Cline's generated fallback, cline-recommended.generated.ts); the ":free" ids are dropped with FreeTag, as Cline's own clients never offer them as free and their cost on a Cline key was never shown. Requests to the Cline API (the gateway's and the Test button's) carry the desktop's headers — HTTP-Referer https://cline.bot, X-Title Cline, X-IS-MULTIROOT false, X-CLIENT-TYPE cline-desktop, X-CLIENT-VERSION 3.5.54, User-Agent Cline/3.5.54 — since the cline-free/ models answer 403 "only available via Cline product surfaces" without them (pi-freeflow, measured live); the key goes as before. ListPrice prices a model free by its cline-free/ id, by the fetched list or by the fallback at zero. No request was made to Cline and nothing was tried with a real Cline key. TestClineFeed (the feed asked as the desktop with no key; plan, free and no paid models listed; a free model the feed alone names priced at zero), TestClineClientHeaders (the headers on a cline-free request to api.cline.bot and on no other provider's) and the updated TestPlanModels fail without the change. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./internal/provider/ ./internal/gateway/ pass (TestClaudeSignInOverStaleCredentials failed once under the full run, passes alone and on the rerun; Cline untouched by it).
2026-10-02 13:07:03 +08:00

68 lines
2.5 KiB
Go

package gateway
import (
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// Cline's free models (cline-free/…) answer 403 "only available via Cline
// product surfaces" unless the request says it is Cline's: requests to the
// Cline API carry its desktop app's headers, with the user's key, and those
// to anyone else don't (lml and ARNO on Discord).
func TestClineClientHeaders(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
cline, err := provider.FromPreset("clinepass")
if err != nil {
t.Fatal(err)
}
cline.ID, cline.Key, cline.Models = "cline", "clp_key", []string{"cline-free/deepseek-v4.1-flash"}
for _, p := range []provider.Provider{cline,
{ID: "other", Name: "Other", Key: "k", Chat: "https://other.test/v1", Models: []string{"cline-free/deepseek-v4.1-flash"}},
} {
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
}
got := map[string]http.Header{}
s := New()
s.client = &http.Client{Transport: countTransport(func(r *http.Request) (*http.Response, error) {
got[r.URL.Host] = r.Header.Clone()
return &http.Response{StatusCode: 200, Header: http.Header{"Content-Type": {"application/json"}},
Body: io.NopCloser(strings.NewReader(`{"id":"c","object":"chat.completion","model":"m","choices":[{"index":0,"message":{"role":"assistant","content":"pong"},"finish_reason":"stop"}]}`))}, nil
})}
for _, id := range []string{"cline", "other"} {
req := httptest.NewRequest("POST", "/v1/chat/completions", strings.NewReader(`{"model":"`+id+`/cline-free/deepseek-v4.1-flash","messages":[{"role":"user","content":"Say pong"}]}`))
req.Header.Set("User-Agent", "some-agent/1.0")
rec := httptest.NewRecorder()
s.Handler().ServeHTTP(rec, req)
if rec.Code != 200 {
t.Fatalf("%s: %d %s", id, rec.Code, rec.Body)
}
}
h, o := got["api.cline.bot"], got["other.test"]
if h == nil || o == nil {
t.Fatalf("requests: %v", got)
}
want := map[string]string{
"HTTP-Referer": "https://cline.bot", "X-Title": "Cline", "X-IS-MULTIROOT": "false",
"X-CLIENT-TYPE": "cline-desktop", "X-CLIENT-VERSION": provider.ClineVersion,
"User-Agent": "Cline/" + provider.ClineVersion, "Authorization": "Bearer clp_key",
}
for k, v := range want {
if h.Get(k) != v {
t.Errorf("cline: %s %q, want %q", k, h.Get(k), v)
}
}
for _, k := range []string{"X-CLIENT-TYPE", "X-Title", "X-IS-MULTIROOT"} {
if o.Get(k) != "" {
t.Errorf("other provider got %s", k)
}
}
}