huhuy72219405 on X: "能不能把不同设备的mcp区分一下,有些mcp属于本地的, 同步之后其他设备不应该读取到". A server in Library > MCP now has a "This computer only" switch in its editor (Server.Local; CLI `magpie library mcp add ... --local` and `magpie library mcp local <name> on|off`; the TUI keeps it on edit and marks the row). - Collect leaves local servers out (carriedServers), so neither a sync nor a backup file takes one to another computer. Turning a shared server local takes it out of what is carried, so the other computers drop it at their next sync; the flag itself is never carried. - Put (sync, join, Restore, Undo, backup file) keeps every local server, with its agents, and clears Local on what comes in. - Another computer's server by a local server's name goes to Library.Away: given to no agent, not in the hub, carried on as it came, so a push from here never removes it from the computers that have it. settleAway (every change) promotes it once the name is gone here, and drops it once the name is shared here again. - The hub serves local servers like any other (it runs here); subagents aren't carried, so one naming a local server keeps it. Docs: docs/subsystems/library.md, docs/subsystems/sync-backup.md. Run atf5dd4e142+ this change; after rebasing ond3898ca8d(gui/provider only, then2a1ef15ba, routing), vet, the five new Go tests, mcp-local-server and i18n-keys again, ok: - mote: gofmt -l clean; go vet of library/backup/davsync/cli/tui; GOOS=linux and GOOS=windows go vet -tags nogui of the same; go test of TestLocalServerNotCarried, TestPutKeepsLocalServer, TestPutSameNameAsLocal (library), TestRestoreKeepsLocalServer (backup), TestLocalServerThroughSync (davsync, two computers through the fake S3) ok. - mote GUI, Chromium and WebKit: mcp-local-server.test.cjs (new; every language, 1100 and 390 wide, switch saves local true/false, row tag, no sideways scroll), i18n-keys, mcp-editor-cancel, mcp-startup-timeout, every library-mcp-*, mcp-oauth-app, mcp-signin*, library-items, library-servers-bulk, library-subagents, library-pick-remove, library-env-refs, library-zed-mcp, library-loading: all pass (126 of 126 in the last batch). - Full Go suite, -tags nogui -timeout 45m, on the Linux box (wsl-run; mote had another session's full suite running): every package ok but internal/agent, whose TestInstalledVersion, TestGrokInstalled, TestOmpDetectedWithPiDir and TestZedAppPath fail the same at origin/main9b4d0bda8on that box; all four are #4033. - Real CLI in a sandbox HOME on mote: mcp add --local, local on/off, `magpie library` shows "this computer only", library.json has "local": true; an unknown name and a bad value are refused. Broken by hand: putServers not keeping local servers turned TestPutKeepsLocalServer, TestPutSameNameAsLocal, TestRestoreKeepsLocalServer and TestLocalServerThroughSync red; carriedServers carrying local servers turned TestLocalServerNotCarried, TestPutSameNameAsLocal, TestRestoreKeepsLocalServer and TestLocalServerThroughSync red. Not tried: a sync between two real computers; the real GUI app (the Playwright run fakes the API); the full Go suite on macOS or Windows.
116 lines
3.3 KiB
Go
116 lines
3.3 KiB
Go
package davsync
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/appdir"
|
|
"github.com/yetone/magpie/internal/library"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// A server kept to one computer (huhuy72219405 on X: "有些mcp属于本地的,
|
|
// 同步之后其他设备不应该读取到") goes nowhere through a real sync: the
|
|
// other computer never gets it, its own server by that name neither takes
|
|
// its place nor is taken from it, and syncs either way leave both as they
|
|
// are.
|
|
func TestLocalServerThroughSync(t *testing.T) {
|
|
f, srv := newFakeS3(t)
|
|
cfg := f.config(srv)
|
|
cfg.Keys, cfg.Agents = false, false
|
|
a, b := newComputer(t), newComputer(t)
|
|
use := func(c computer) {
|
|
t.Helper()
|
|
c.use(t)
|
|
appdir.UseExecutable("")
|
|
provider.ForgetAccounts()
|
|
p := filepath.Join(string(c), ".claude/settings.json")
|
|
os.MkdirAll(filepath.Dir(p), 0o755)
|
|
if _, err := os.Stat(p); err != nil {
|
|
os.WriteFile(p, nil, 0o644)
|
|
}
|
|
}
|
|
t.Cleanup(provider.ForgetAccounts)
|
|
now := func() {
|
|
t.Helper()
|
|
if err := Now(context.Background()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
ok := func(_ *library.Result, err error) {
|
|
t.Helper()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
server := func(name string) *library.Server {
|
|
t.Helper()
|
|
v, err := library.Read(nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, s := range v.Servers {
|
|
if s.Name == name {
|
|
return s.Server
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
// Claude Code's servers, under CLAUDE_CONFIG_DIR as use sets it
|
|
claude := func(c computer) string {
|
|
raw, _ := os.ReadFile(filepath.Join(string(c), ".claude", ".claude.json"))
|
|
return string(raw)
|
|
}
|
|
|
|
// A has gh to share and db kept to itself, and syncs first
|
|
use(a)
|
|
ok(library.SaveServer("", library.Server{Name: "gh", Transport: "stdio", Command: "gh-mcp", Agents: []string{"claude"}}))
|
|
ok(library.SaveServer("", library.Server{Name: "db", Transport: "stdio", Command: "/opt/a-db", Agents: []string{"claude"}, Local: true}))
|
|
if err := Configure(cfg); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
now()
|
|
|
|
// B joins: gh, and no db
|
|
use(b)
|
|
if err := Configure(cfg); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
now()
|
|
if server("gh") == nil || server("db") != nil || strings.Contains(claude(b), "/opt/a-db") || !strings.Contains(claude(b), "gh-mcp") {
|
|
t.Fatalf("B after joining: gh %v, db %+v; claude %s", server("gh"), server("db"), claude(b))
|
|
}
|
|
// B has a db of its own, shared, and syncs
|
|
ok(library.SaveServer("", library.Server{Name: "db", Transport: "stdio", Command: "b-db", Agents: []string{"claude"}}))
|
|
now()
|
|
|
|
// A syncs: its db stays its own, B's isn't given to Claude Code here
|
|
use(a)
|
|
now()
|
|
if s := server("db"); s == nil || !s.Local || s.Command != "/opt/a-db" {
|
|
t.Fatalf("A's db after B's came: %+v", s)
|
|
}
|
|
if c := claude(a); !strings.Contains(c, "/opt/a-db") || strings.Contains(c, "b-db") {
|
|
t.Fatalf("A's Claude Code: %s", c)
|
|
}
|
|
// A changes gh, which syncs up with B's db carried on
|
|
ok(library.ServerAgents("gh", []string{}))
|
|
now()
|
|
|
|
// B syncs: A's change came, and B's db wasn't taken away by it
|
|
use(b)
|
|
now()
|
|
if s := server("gh"); s == nil || len(s.Agents) != 0 {
|
|
t.Fatalf("A's gh change didn't reach B: %+v", s)
|
|
}
|
|
if s := server("db"); s == nil || s.Command != "b-db" || s.Local {
|
|
t.Fatalf("B's db after A's sync: %+v", s)
|
|
}
|
|
if strings.Contains(claude(b), "/opt/a-db") {
|
|
t.Fatalf("A's local db reached B: %s", claude(b))
|
|
}
|
|
}
|