VincentChan on Discord (v0.1.3005) said part of the Library doesn't reach his other computer through sync. Checked kind by kind what the library part of a bundle carries: instructions (each set's text, a linked set's file text, the agents ticked, each agent's own addition), MCP servers, skills and subagents all go. Hooks didn't: library.Bundle had no field for them, so a hook made on one computer never reached the other, by WebDAV/S3/GitHub sync or a backup file. - library.Bundle.Hooks (*[]*Hook): name, description, event, matcher, command, timeout, agents ticked. Collect always sets it, empty too. Applied.Hooks (the entries magpie wrote into each agent here) stays out: each computer writes them on the sync Put runs, beside the user's own hooks, and records its own entries, so an entry the user edited there stays theirs. - Put replaces the hooks with the bundle's, so one taken out on one computer goes from the others. A nil list (a bundle from a magpie before this) keeps this computer's. - check refuses a hook with no name, no command, or named twice. The event and agents are carried as they come: an event a newer magpie knows is a problem on the agent here, not a refused library. - davsync: an empty list hashes as before the field, so upgrading with no hooks syncs nothing. - The CLI's backup line counts hooks; the GUI's sync/export/import ticks say "instructions, MCP servers, skills, hooks and subagents" in every language. - library.md and sync-backup.md updated, and they now name what stays this computer's own: projects, skill groups, CopySkills/SkillHow, SharedSkills, MCPHub. Instructions: two sandbox computers through the fake DAV server carried a named set and a change to it, a set linked to ~/.agents/AGENTS.md and a hand edit of that file, both computers having their own text first, an agent's own addition, and an agent installed after the first sync. All reached the second computer's CLAUDE.md/AGENTS.md (exploration tests, not kept). So no instructions change here; what VincentChan saw is not reproduced yet. Run (worktree at 0e55a7593; origin/main bf60ea596's two commits touch none of these files): - mote: go test -tags nogui ./internal/backup ./internal/davsync ./internal/cli ./internal/library ok; go vet -tags nogui for darwin, GOOS=linux and GOOS=windows on the four packages ok; gofmt -l clean; go test ./internal/gui -run 'TestCoreScriptBudget|Words|I18n|Builtins' ok - GUI (wsl-run, Linux): i18n-keys, github-sync, s3-sync, sync-*, webdav-settings-refresh, library-backups-top, gui-de, gui-ja, gui-zh-tw: 187/187 Broken by hand: with Collect not setting Hooks, Put ignoring them and the hash not dropping an empty list (the old code), TestCarryHooks, TestCarryOldBundleKeepsHooks, TestCarryNewerHooks, TestBackupFileCarriesHooks, TestSyncHooks and TestNoHooksHashAsBefore went red. Not tried: a real WebDAV/S3/GitHub remote between two real computers; Windows and Linux runs of the Go packages.
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package backup
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/library"
|
|
)
|
|
|
|
// A backup file carries the library's hooks, and restoring it on another
|
|
// computer puts them in its library; an older file, made before hooks were
|
|
// carried, leaves the ones there.
|
|
func TestBackupFileCarriesHooks(t *testing.T) {
|
|
home(t)
|
|
if _, err := library.SaveHook("", library.Hook{Name: "done", Event: "turn-end", Command: "echo done", Agents: []string{"claude"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, err := Collect(false, "test")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
data, _ := Seal(b, "pw")
|
|
old := b
|
|
lib := *b.Library
|
|
lib.Hooks = nil // as a magpie before them sealed it
|
|
old.Library = &lib
|
|
older, _ := Seal(old, "pw")
|
|
|
|
home(t)
|
|
if _, err := library.SaveHook("", library.Hook{Name: "mine", Event: "prompt", Command: "echo mine", Agents: []string{}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, _ := Open(older, "pw")
|
|
if _, err := Restore(got, All); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
names := func() []string {
|
|
l, _ := library.Collect()
|
|
var n []string
|
|
for _, h := range *l.Hooks {
|
|
n = append(n, h.Name)
|
|
}
|
|
return n
|
|
}
|
|
if n := names(); len(n) != 1 || n[0] != "mine" {
|
|
t.Fatalf("an older file changed the hooks: %v", n)
|
|
}
|
|
got, _ = Open(data, "pw")
|
|
if r, err := Restore(got, All); err != nil || !r.Library {
|
|
t.Fatalf("restore: %+v %v", r, err)
|
|
}
|
|
l, _ := library.Collect()
|
|
if h := *l.Hooks; len(h) != 1 || h[0].Name != "done" || h[0].Command != "echo done" || len(h[0].Agents) != 1 || h[0].Agents[0] != "claude" {
|
|
t.Fatalf("hooks restored: %+v", h)
|
|
}
|
|
}
|