A plugin installed from Library > Claude plugins didn't reach the other
computer by sync: the bundle carried its parts as plain items, with
${CLAUDE_PLUGIN_ROOT} already resolved to the first computer's
<library>/plugins/<name>, and neither the plugin record nor its folder.
Hooks there pointed at a path that doesn't exist, Windows' too.
Now Bundle.Plugins carries each plugin's record (name, version, source,
pick, agents, Off, parts taken out by hand) and never its parts:
- A GitHub or git link goes as its source. The receiving computer
installs it from there, as UpdatePlugin does, after the library's lock
is let go. Re-installing from the source was chosen because the files
stay the vendor's and an update keeps working there; a fetch that
fails keeps the plugin Pending (shown on its row, "Update tries again")
with a problem, and the next sync or Update tries again.
- A plugin from a local folder, or from a link holding a token (whose
link must not be synced), goes with its files on the skills' budget,
executables kept executable, and is installed from them.
- Either way the parts are read again there, so every hook, server and
skill names that computer's own plugin folder. A plugin the bundle no
longer has is removed with its folder; Off spreads.
- A bundle from an older magpie has no plugins list: this computer's
plugins keep their parts over the same-named items it carries.
- An empty list hashes as before, so computers without plugins don't
see a change; the preview names each plugin, its files as one digest.
- Sibling: a plugin installed from a marketplace under a name other
than its manifest's named the manifest's folder in its parts.
- The sync settings' text says Claude plugins go with the Library (en,
zh, zh-TW, ja, de); "Claude plugins" moved into the core i18n.js since
the core now says it.
Run at this head (54e682dc5's tree on f1b0663f1, mote):
- go test -tags nogui -timeout 45m ./internal/library ./internal/davsync
./internal/backup: ok
- gofmt -l: empty; go vet GOOS=darwin (library, davsync, backup, gui),
GOOS=linux -tags nogui ./..., GOOS=windows ./...: clean
- Windows (win-run, xiaomi-gpu): go test ./internal/library -run
TestPlugin and ./internal/davsync -run Plugin: ok. The hook there names
B's C:\...\plugins\kit/bin/done (TestSyncLibraryPlugins first failed
on Windows for the test's own path form; fixed in the test).
- GUI, Chromium and WebKit, every language the files test:
library-plugins, library-items, agent-plugin-agents, i18n-keys,
i18n-en-no-cjk, old-webkit, every sync-*, github-sync, s3-sync,
auto-backup: 337 pass, 1 fail: webkit en "S3 sync settings", red the
same at origin/main f1b0663f1 (#2448, #3413, open).
Broken by hand, each red, then restored:
- parts not skipped and Plugins not set in Collect:
TestPluginCarriedWhole, TestPluginCarriedBySource,
TestSyncLibraryPlugins
- held.without dropped: TestPluginOldBundleKeepsPlugins
- fetchPlugins dropped: TestPluginCarriedBySource
- marketplace name fix reverted: TestPluginMarketplaceNameIsItsFolder
- empty list not hashed as none: TestNoPluginsHashAsBefore
- TestPluginFromFilesEitherOS guards that a Mac path is files on
Windows and C:\ on a Mac; it passed without a new check (such paths
are no git source), so none was added.
Not tried:
- a real two-computer sync through the GUI, Mac to Windows;
- a local marketplace entry's own fields (strict: false) aren't carried,
so there it is read from its files alone;
- a private git source over ssh on the receiving computer.
Reported by JJasonsun on Discord; issue by JJasonSun (#6685).
112 lines
4.0 KiB
Go
112 lines
4.0 KiB
Go
package davsync
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/backup"
|
|
"github.com/yetone/magpie/internal/library"
|
|
)
|
|
|
|
// #6685: a plugin installed through the Library on one computer is on the
|
|
// other after its next sync, whole, with its hook naming that computer's
|
|
// folder for it; the second computer pushes nothing back, and a plugin
|
|
// taken out on the first goes from the second.
|
|
func TestSyncLibraryPlugins(t *testing.T) {
|
|
fake := &fakeDAV{files: map[string][]byte{}, etags: map[string]string{}, dirs: map[string]bool{"/dav": true}}
|
|
srv := httptest.NewServer(fake)
|
|
defer srv.Close()
|
|
ctx := context.Background()
|
|
cfg := Config{URL: srv.URL + "/dav/", User: "me", Password: "pw", Passphrase: "correct horse", Keys: true, Agents: true}
|
|
now := func(t *testing.T) {
|
|
t.Helper()
|
|
if err := Now(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v := Status(); v.Error != "" {
|
|
t.Fatalf("sync: %+v", v)
|
|
}
|
|
}
|
|
write := func(p, s string) {
|
|
os.MkdirAll(filepath.Dir(p), 0o755)
|
|
if err := os.WriteFile(p, []byte(s), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
a, b := newComputer(t), newComputer(t)
|
|
a.use(t)
|
|
write(filepath.Join(string(a), ".claude", "settings.json"), "{}\n")
|
|
src := filepath.Join(string(a), "work", "kit")
|
|
write(filepath.Join(src, ".claude-plugin", "plugin.json"), `{"name":"kit","version":"1.0.0"}`)
|
|
write(filepath.Join(src, "hooks", "hooks.json"), `{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"${CLAUDE_PLUGIN_ROOT}/bin/done"}]}]}}`)
|
|
write(filepath.Join(src, "bin", "done"), "#!/bin/sh\n")
|
|
if _, err := library.InstallPlugins(src, nil, []string{"claude"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
Configure(cfg)
|
|
now(t)
|
|
|
|
b.use(t)
|
|
write(filepath.Join(string(b), ".claude", "settings.json"), "{}\n")
|
|
Configure(cfg)
|
|
now(t)
|
|
v, err := library.Read(nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(v.Plugins) != 1 || v.Plugins[0].Name != "kit" {
|
|
t.Fatalf("b's plugins: %+v", v.Plugins)
|
|
}
|
|
// as the plugin wrote it: ${CLAUDE_PLUGIN_ROOT}/bin/done, on Windows too
|
|
inJSON := func(s string) string { j, _ := json.Marshal(s); return strings.Trim(string(j), `"`) }
|
|
want := inJSON(v.Plugins[0].Dir + "/bin/done")
|
|
s, _ := os.ReadFile(filepath.Join(string(b), ".claude", "settings.json"))
|
|
if !strings.Contains(string(s), want) || strings.Contains(string(s), inJSON(string(a))) {
|
|
t.Fatalf("b's Claude Code hook doesn't name b's folder for the plugin %s: %s", want, s)
|
|
}
|
|
puts := fake.puts
|
|
now(t)
|
|
if fake.puts != puts {
|
|
t.Fatalf("b pushed back the plugin it brought in (%d puts)", fake.puts-puts)
|
|
}
|
|
|
|
a.use(t)
|
|
if _, err := library.RemovePlugin("kit"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
now(t)
|
|
b.use(t)
|
|
now(t)
|
|
if v, _ := library.Read(nil); len(v.Plugins) != 0 || len(v.Hooks) != 0 {
|
|
t.Errorf("the plugin stays on b after a took it out: %+v", v.Plugins)
|
|
}
|
|
if s, _ := os.ReadFile(filepath.Join(string(b), ".claude", "settings.json")); strings.Contains(string(s), "bin/done") {
|
|
t.Errorf("the hook stays in b's Claude Code: %s", s)
|
|
}
|
|
}
|
|
|
|
// A library with no plugins hashes as it did before they were carried, so
|
|
// a magpie that starts carrying them doesn't see a change to sync.
|
|
func TestNoPluginsHashAsBefore(t *testing.T) {
|
|
none := []*library.CarriedPlugin{}
|
|
with := backup.Bundle{Library: &library.Bundle{MCP: []*library.Server{}, Skills: []*library.CarriedSkill{}, Plugins: &none}}
|
|
before := backup.Bundle{Library: &library.Bundle{MCP: []*library.Server{}, Skills: []*library.CarriedSkill{}}}
|
|
if hashes(with)["library"] != hashes(before)["library"] {
|
|
t.Error("an empty list of plugins changed the library's hash")
|
|
}
|
|
one := []*library.CarriedPlugin{{Name: "kit", Source: "https://github.com/acme/kit", Agents: []string{"claude"}}}
|
|
with.Library.Plugins = &one
|
|
if hashes(with)["library"] == hashes(before)["library"] {
|
|
t.Error("a plugin didn't change the library's hash")
|
|
}
|
|
items := itemsOf(with, "library")
|
|
if it, ok := items["plugin\x00kit"]; !ok || it.Name != "kit" {
|
|
t.Errorf("the plugin as the preview lists it: %+v", items)
|
|
}
|
|
}
|