889758605(v0.1.3981, coder_shaun on X asking for one-click import from relays' CC Switch links) made magpie claim ccswitch:// on every system: Info.plist on macOS, HKCU\Software\Classes\ccswitch on Windows, and magpie-ccswitch.desktop on Linux. That scheme is CC Switch's, and magpie claiming another app's links is not something it should do (asombrado_a on X: "Magpie为啥要注册 ccswitch://协议的深链"). From this version magpie registers magpie:// only: the ccswitch entry is out of Info.plist, and the Windows and Linux registration is back to what it was before889758605. A start doesn't touch what an older version wrote (the owner's call); uninstall still takes it out while it is magpie's, as before. The ccswitch:// parser (importccswitch.go, its test and CC Switch's example links) goes with it: with nothing registered, no link reaches it, and ParseImport, ImportLink and `magpie import` take magpie:// links only. The docs' "CC Switch links" paragraph is out in en, zh and ja, and llms-full.txt and the search indexes are regenerated. TestRegisterScheme now holds that registration never asks about or claims x-scheme-handler/ccswitch, and TestImportLink that a ccswitch:// argument is not taken as an import link. Run at this commit's tree (rebased on1318864d1), on mica (mote's load was 38): gofmt clean; go vet darwin, GOOS=windows (gui, uninstall, provider), GOOS=linux nogui (provider, uninstall); go test provider, gui, uninstall, cli ok; node --test site/*.test.mjs 135 pass. Linux (wsl-run, magpie-desktop, -tags gtk3), at the tree before the rebase (the scheme files are the same at this one): provider, uninstall ok; gui ok except TestClipboardReadBack/copies_after_a_read_back, which fails the same on origin/main3ec89c522(probe segfault, #7073); at this tree TestRegisterScheme*, TestImportLink and TestImportIsReadOnce ok. Pushed on3e66d25d8, which landed after the run and changes internal/agent only; not run again with it. Not tried: a real Windows or Linux desktop with an older magpie's ccswitch registration, which this leaves in place; macOS Launch Services dropping the scheme once the updated bundle replaces the old one.
76 lines
2.2 KiB
Go
76 lines
2.2 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestImportIsReadOnce(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("XDG_CONFIG_HOME", home)
|
|
mux := http.NewServeMux()
|
|
importRoutes(mux)
|
|
get := func(id string) (*httptest.ResponseRecorder, importJSON) {
|
|
rec := httptest.NewRecorder()
|
|
mux.ServeHTTP(rec, httptest.NewRequest("GET", "/api/import/"+id, nil))
|
|
var in importJSON
|
|
_ = json.Unmarshal(rec.Body.Bytes(), &in)
|
|
return rec, in
|
|
}
|
|
|
|
id := stashImport("magpie://import?preset=deepseek&key=sk-test")
|
|
rec, in := get(id)
|
|
if rec.Code != 200 || in.Provider.ID != "deepseek" || in.Provider.Key != "sk-test" || in.Error != "" {
|
|
t.Fatalf("%d %+v", rec.Code, in)
|
|
}
|
|
if rec, _ := get(id); rec.Code != 404 {
|
|
t.Fatalf("second read: %d", rec.Code)
|
|
}
|
|
if _, in := get(stashImport("magpie://import?name=x")); in.Error == "" {
|
|
t.Fatal("a bad link reported no error")
|
|
}
|
|
}
|
|
|
|
func TestImportIconRoute(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("XDG_CONFIG_HOME", home)
|
|
mux := http.NewServeMux()
|
|
importRoutes(mux)
|
|
post := func(url string) *httptest.ResponseRecorder {
|
|
rec := httptest.NewRecorder()
|
|
body := strings.NewReader(`{"url":"` + url + `"}`)
|
|
mux.ServeHTTP(rec, httptest.NewRequest("POST", "/api/import/icon", body))
|
|
return rec
|
|
}
|
|
// a loopback URL is refused before any request goes out
|
|
if rec := post("https://127.0.0.1/logo.png"); rec.Code == 200 {
|
|
t.Fatalf("loopback icon accepted: %s", rec.Body.String())
|
|
}
|
|
if rec := post("http://relay.example/logo.svg"); rec.Code == 200 {
|
|
t.Fatalf("plain http icon accepted: %s", rec.Body.String())
|
|
}
|
|
if rec := post("not a url"); rec.Code == 200 {
|
|
t.Fatalf("junk accepted: %s", rec.Body.String())
|
|
}
|
|
}
|
|
|
|
func TestImportLink(t *testing.T) {
|
|
if ImportLink([]string{"/usr/bin/magpie", "tray"}) != "" {
|
|
t.Fatal("found a link in plain args")
|
|
}
|
|
if ImportLink([]string{"MAGPIE://import?preset=x"}) == "" {
|
|
t.Fatal("missed an upper-case link")
|
|
}
|
|
// ccswitch:// is CC Switch's scheme, not magpie's
|
|
if ImportLink([]string{"ccswitch://v1/import?resource=provider&app=claude&name=x"}) != "" {
|
|
t.Fatal("took a CC Switch link")
|
|
}
|
|
}
|