Files
magpie/internal/gui/providers_systemone_test.go
T
yetone 919ceb3a68 provider: Bailian's decision model as a routing preset, and System One for custom providers (#647, Aimer779: Alibaba Cloud Bailian's decision-model-preview speaks TypeSafe's System One at POST <root>/systemone, and magpie only took it from TypeSafe's Jev) — a new preset, Bailian Decision Model (qwen icon, decide-only like TypeSafe Jev), asks decision-model-preview at its plan's root: Workspace · Beijing / Workspace · Singapore (https://{WorkspaceId}.<region>.maas.aliyuncs.com/compatible-mode/v1, the editor asks for the workspace ID and fills it in) or Token Plan · Beijing (token-plan.cn-beijing…, sk-sp- keys). Saving with the workspace still unfilled is refused, both in the editor and in provider.Add. A Bailian host has no /models for it, so its list is the one model, checked by a System One ask. A custom provider can now be a System One API: the CLI's decide=<root> (with models=… named anything, not only jev-*), workspace= and region=/plan= for a preset's plan; the editor's API seg has a fourth option, System One, whose Detect APIs posts a test question to <root>/systemone with the model typed, and a decide-only custom provider passes the "base URL is needed" check. A decide-only provider's first model is what it is asked as (Jev() no longer assumes jev-*), and its models stay routing groups' classifiers, never agents'. TestBailianDecisionPreset, TestCustomSystemOne, TestProviderSystemOne and TestProviderDecidePairs fail on the old code (undefined BailianDecision / DetectDecide, unknown decide=); internal/gui/tests/system-one.test.cjs (webkit, en/zh) covers the workspace, the Singapore and Token Plan plans, TypeSafe's unchanged editor and a custom System One detected and added. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass but TestProvidersAnswerWhileListsComeIn, a timing test that passes alone. Not tried against a real Bailian key.
2026-10-03 15:21:15 +08:00

60 lines
2.5 KiB
Go

package gui
import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// The editor's System One: a custom provider's decision API is probed at
// POST …/systemone and saved with any model name, and Bailian's preset
// takes the workspace's host (#647).
func TestProviderSystemOne(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", os.Getenv("HOME"))
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
vendor := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" || r.URL.Path != "/v1/systemone" || r.Header.Get("Authorization") != "Bearer sk-1" {
http.Error(w, `{"error":{"message":"no"}}`, http.StatusNotFound)
return
}
w.Write([]byte(`{"answers":{"ok":{"type":"noul","noul":0.9}}}`))
}))
defer vendor.Close()
mux := http.NewServeMux()
providerRoutes(mux, nil)
post := func(action, body string) *httptest.ResponseRecorder {
t.Helper()
w := httptest.NewRecorder()
mux.ServeHTTP(w, httptest.NewRequest("POST", "/api/provider/"+action, strings.NewReader(body)))
return w
}
w := post("detect", `{"typed":true,"key":"sk-1","decide":"`+vendor.URL+`/v1","base":"`+vendor.URL+`/v1","model":"my-decider"}`)
var got struct{ Results []provider.Detection }
json.Unmarshal(w.Body.Bytes(), &got)
if w.Code != 200 || len(got.Results) != 1 || !got.Results[0].OK || got.Results[0].Protocol != "decide" || got.Results[0].Model != "my-decider" {
t.Fatalf("detect: %d %s", w.Code, w.Body)
}
if w := post("save", `{"name":"Decider","decide":"`+vendor.URL+`/v1","key":"sk-1","models":["my-decider"],"new":true}`); w.Code != 200 {
t.Fatalf("save: %d %s", w.Code, w.Body)
}
if p, err := provider.Find("decider"); err != nil || !p.DecideOnly() || p.Jev() != "my-decider" {
t.Fatalf("saved: %+v %v", p, err)
}
if w := post("save", `{"preset":"bailian-decision","key":"sk-2","new":true}`); w.Code == 200 {
t.Fatalf("Bailian saved with no workspace: %s", w.Body)
}
if w := post("save", `{"preset":"bailian-decision","key":"sk-2","decide":"https://ws-9.cn-beijing.maas.aliyuncs.com/compatible-mode/v1","new":true}`); w.Code != 200 {
t.Fatalf("Bailian: %d %s", w.Code, w.Body)
}
if p, err := provider.Find("bailian-decision"); err != nil || p.Decide != "https://ws-9.cn-beijing.maas.aliyuncs.com/compatible-mode/v1" || p.Jev() != provider.BailianDecision {
t.Fatalf("Bailian saved: %+v %v", p, err)
}
}