GitHub sync and backups carried the skills a Claude plugin brought into
magpie's library, but not the plugins installed in Claude Code itself
through its /plugin marketplaces, so a second computer had none of them.
The library bundle now carries ClaudePlugins: each marketplace's source
(from plugins/known_marketplaces.json and settings.json's
extraKnownMarketplaces, only `source` and `autoUpdate` kept) and the
plugin ids enabledPlugins has on, under CLAUDE_CONFIG_DIR when set.
installLocation, installPath and plugins/{marketplaces,cache} stay, as
Claude Code fetches them again. A marketplace from a local folder or
file, or with a user/token in a URL or request headers, is not carried,
and neither are its plugins. claude-plugins-official itself is not
carried (Claude Code adds it), its plugins are.
On the other computer they are added to settings.json's
extraKnownMarketplaces and enabledPlugins, which Claude Code installs
from at its next interactive start: tried with Claude Code 2.1.319 in a
sandbox CLAUDE_CONFIG_DIR, commit-commands@claude-code-plugins was
cloned and installed from those two settings alone. settings.json is
patched in place (comments and other keys kept), written to a temp file
and renamed in, and the old file is kept with the backups. Claude Code's
own known_marketplaces.json and installed_plugins.json are never
written. Only adding: a marketplace known here under that name, and a
plugin with any value here (false too), stay as they are. An unreadable
settings.json is neither carried as "none" nor written over. A computer
with no such plugins carries nil, so its library hash is as before. The
davsync library part counts it as the user's (not unset, #5642), and the
preview lists each marketplace and plugin.
Run (mote):
- go test -tags nogui ./... -timeout 45m -count=1 at 5d12d65dc (on
origin/main 442964d70): ok, 101 packages, no FAIL
- rebased on becc1ef15 (bili path change in internal/library), then at
this head: go test ./internal/library ./internal/davsync
./internal/backup . -count=1: ok
- go vet ./internal/library ./internal/davsync ./internal/backup, and
GOOS=linux / GOOS=windows go vet of library and davsync: ok
- gofmt -l: clean
Broken by hand: carriedClaudePlugins and putClaudePlugins returning nil,
the unset clause and the preview branch removed: TestClaudePluginsCollected,
TestClaudePluginsPut, TestClaudePluginsInLibraryPart and
TestClaudePluginsInPreview red. A first version added x@evil for a
carried marketplace that wasn't portable; TestClaudePluginsPut caught it.
The first full run was red only on TestNoEagerPackageRegexps (a
package-level regexp); now lazyre.New.
Not tried: a real two-computer GitHub sync with a real marketplace;
`claude -p` and `claude plugin list` do not install declared plugins,
only an interactive start does. Not yet: a plugin removed or turned off
on one computer is not removed on the others (add-only). GUI sync labels
unchanged (the preview shows each item by name), so no GUI run.
59 lines
2.0 KiB
Go
59 lines
2.0 KiB
Go
package davsync
|
|
|
|
import (
|
|
"encoding/json"
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/backup"
|
|
"github.com/yetone/magpie/internal/library"
|
|
)
|
|
|
|
// A library that holds only Claude Code's plugins is the user's, not an
|
|
// unset part a joining computer's library would be taken over by
|
|
// (#5642), and adding a plugin changes the library's hash.
|
|
func TestClaudePluginsInLibraryPart(t *testing.T) {
|
|
empty := func() backup.Bundle {
|
|
return backup.Bundle{Library: &library.Bundle{MCP: []*library.Server{}, Skills: []*library.CarriedSkill{}}}
|
|
}
|
|
with := empty()
|
|
with.Library.ClaudePlugins = &library.ClaudePlugins{Enabled: []string{"frontend-design@claude-plugins-official"}}
|
|
if unset(with, "library") {
|
|
t.Error("a library with Claude Code's plugins said unset")
|
|
}
|
|
if hashes(with)["library"] == hashes(empty())["library"] {
|
|
t.Error("Claude Code's plugins didn't change the library's hash")
|
|
}
|
|
}
|
|
|
|
// The sync's preview names each marketplace and plugin it would add.
|
|
func TestClaudePluginsInPreview(t *testing.T) {
|
|
at := func(cp *library.ClaudePlugins) backup.Bundle {
|
|
return backup.Bundle{Library: &library.Bundle{MCP: []*library.Server{}, Skills: []*library.CarriedSkill{}, ClaudePlugins: cp}}
|
|
}
|
|
to := &library.ClaudePlugins{
|
|
Marketplaces: map[string]json.RawMessage{"claude-code-plugins": json.RawMessage(`{"source":{"source":"github","repo":"anthropics/claude-code"}}`)},
|
|
Enabled: []string{"commit-commands@claude-code-plugins"},
|
|
}
|
|
got := diffItems(itemsOf(at(nil), "library"), itemsOf(at(to), "library"))
|
|
want := []Item{
|
|
{Kind: "claudeMarketplace", Name: "claude-code-plugins", Change: "added"},
|
|
{Kind: "claudePlugin", Name: "commit-commands@claude-code-plugins", Change: "added"},
|
|
}
|
|
slices.SortFunc(got, func(a, b Item) int {
|
|
if a.Kind < b.Kind {
|
|
return -1
|
|
}
|
|
if a.Kind > b.Kind {
|
|
return 1
|
|
}
|
|
return 0
|
|
})
|
|
if !slices.Equal(got, want) {
|
|
t.Errorf("preview: %+v", got)
|
|
}
|
|
if got := diffItems(itemsOf(at(to), "library"), itemsOf(at(to), "library")); len(got) != 0 {
|
|
t.Errorf("the same plugins: %+v", got)
|
|
}
|
|
}
|