BeiWeiji on X (v0.1.4322, zh): a skill imported from "Agent 中已有"
had no way back, only off or Remove, and removed it was gone from the
agents and from "Agent 中已有" too: Remove sent the folder that had been
moved into the library to magpie's backups and took the agents' links
and marked copies away.
ImportSkill now records where the skill was (Skill.Home, this
computer's own; Put keeps it for the same source, a sync never carries
it): the folder moved in (Home.Dir; handOver points it at the shared
~/.agents/skills place) and each agent's entry, a link with its own
text or a byte copy. RemoveSkill/RemoveSkills put it back (putBack):
the library's folder moves back to Home.Dir with what was changed in
the library, or the library's link goes; each agent's link is made
again as it was and each copy copied back. It is in "In your agents"
again and nothing goes to the backups. An entry the user replaced since
is left alone; when Home.Dir is taken the skill is removed as before,
its folder to the backups. This covers every agent with a skills folder
(the record is per agent entry, links and copies alike).
The page: SkillView.back lists those agents, and such a row has Put
back in the trash's place ("放回 {agents}"), whose sheet says where it
goes and sends skills/remove. Other skills keep the trash.
Old imports: a skill brought in before this has no Home record.
Removed, its folder goes to magpie's backups as before, where it can
be moved back by hand (the reporter's already-removed skill is there).
Run (at this change on acc358f07, then rebased on a75a1fffc and on
d67ccbd3c; the commits between touch no library code):
- go test -tags nogui ./internal/library ./internal/gui on mote at
this head (d67ccbd3c base): ok; go build ./...: ok.
- Full go test -timeout 45m ./... on mica at the acc358f07 base: exit 0,
every package ok. Not run again after the rebases.
- GOOS=windows go vet and GOOS=linux go vet -tags nogui: ok (whole tree
at acc358f07; internal/library and internal/gui at this head).
- gofmt -l internal/: clean.
- GUI: skill-put-back.test.cjs (new) in chromium and webkit, en, zh,
zh-TW, ja, de at 980px and 400px: ok; remove-found-skill ok;
i18n-keys: only #6877 (", with an image"), red the same at a fresh
origin/main copy.
- Whole GUI suite (make test-ui) on mica at the acc358f07 base, beside
another session's suite (load to 200): 28548 tests, 1060 red in 128
files. Each red file was run at a fresh origin/main a75a1fffc copy:
118 files (1039 tests) red there too, filed as #6975 (108 already in
#6934, the rest with their own issues). The other 10 (editor-advanced-
align, group-new-head, ledger-swipe, library-problems-hide,
nav-sub-fold, routing-pulse-composited, search-mcp-library,
signin-closes-sheet, readable-focus, library-env) pass at this change
run alone on mote, 150 of 150.
Broken by hand: canPutBack forced false; TestRemoveSkills,
TestRemovedImportGoesBackToTheAgents and TestRemovedLinkedImportGoesBack
went red (TestPutBackLeavesTheUsersNewFolder guards the fallback and
passes either way).
Not tried: a real magpie with real agents (tests run in a sandbox
HOME); Windows junctions and WSL-distro links (a WSL distro agent's own
entry is recorded like any other but not tried there); the link tests are skipped on Windows.
136 lines
4.8 KiB
Go
136 lines
4.8 KiB
Go
package library
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
// BeiWeiji on X: a skill brought into the library from "In your agents"
|
|
// had no way back, and removed from the library it was gone from the
|
|
// agents too, and from "In your agents". Removed now, it goes back to the
|
|
// agents as they had it: the folder moved in goes back where it was, with
|
|
// what was changed in the library, each agent's own link to it is made
|
|
// again and a copy of the very same files copied back. It is in "In your
|
|
// agents" again, and the library's folder isn't left with the backups.
|
|
func TestRemovedImportGoesBackToTheAgents(t *testing.T) {
|
|
if runtime.GOOS == "windows" {
|
|
t.Skip("links need Developer Mode on Windows")
|
|
}
|
|
h := sandbox(t)
|
|
claude := filepath.Join(h, ".claude/skills/notes")
|
|
skill(t, claude, "notes", "Mine")
|
|
codex := filepath.Join(h, ".codex/skills/notes")
|
|
if err := os.MkdirAll(filepath.Dir(codex), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Symlink("../../.claude/skills/notes", codex); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
gemini := filepath.Join(h, ".gemini/skills/notes")
|
|
skill(t, gemini, "notes", "Mine") // a byte copy
|
|
|
|
ok(t)(ImportSkill("notes"))
|
|
v, _ := Read(nil)
|
|
if len(v.Skills) != 1 || !slices.Equal(v.Skills[0].Back, []string{"claude", "codex", "gemini"}) {
|
|
t.Fatalf("skills: %+v", v.Skills)
|
|
}
|
|
if !ours(claude, "notes") || !ours(gemini, "notes") {
|
|
t.Fatal("the agents weren't given the library's")
|
|
}
|
|
// changed in the library while it was there: the change goes back too
|
|
write(t, filepath.Join(skillDir("notes"), "more.md"), "added in the library\n")
|
|
|
|
ok(t)(RemoveSkill("notes"))
|
|
if fi, err := os.Lstat(claude); err != nil || linkEntry(fi) {
|
|
t.Fatalf("claude's folder isn't back: %v", err)
|
|
}
|
|
if read(t, filepath.Join(claude, "more.md")) == "" || read(t, filepath.Join(claude, "scripts/run.sh")) == "" {
|
|
t.Error("claude's folder came back without its files")
|
|
}
|
|
if to, err := os.Readlink(codex); err != nil || to != "../../.claude/skills/notes" {
|
|
t.Errorf("codex's link is %q, %v", to, err)
|
|
}
|
|
if fi, err := os.Lstat(gemini); err != nil || linkEntry(fi) || ours(gemini, "notes") || read(t, filepath.Join(gemini, "SKILL.md")) == "" {
|
|
t.Errorf("gemini's copy isn't back: %v", err)
|
|
}
|
|
if _, err := os.Lstat(skillDir("notes")); !os.IsNotExist(err) {
|
|
t.Error("the library still has its folder")
|
|
}
|
|
if m, _ := filepath.Glob(filepath.Join(BackupDir(), "*/skills/notes")); len(m) != 0 {
|
|
t.Errorf("its folder went to the backups: %v", m)
|
|
}
|
|
v, _ = Read(nil)
|
|
if len(v.Skills) != 0 || len(v.FoundSkills) != 1 || v.FoundSkills[0].Name != "notes" ||
|
|
!slices.Equal(v.FoundSkills[0].Agents, []string{"claude", "codex"}) || !slices.Equal(v.FoundSkills[0].Copies, []string{"gemini"}) {
|
|
t.Fatalf("after: skills %+v, found %+v", v.Skills, v.FoundSkills)
|
|
}
|
|
// and it can be brought in again
|
|
ok(t)(ImportSkill("notes"))
|
|
}
|
|
|
|
// One an agent only linked to, in a folder elsewhere: the library linked
|
|
// to it there, and removed, the agent's link is made again. The folder
|
|
// itself never moved.
|
|
func TestRemovedLinkedImportGoesBack(t *testing.T) {
|
|
if runtime.GOOS == "windows" {
|
|
t.Skip("links need Developer Mode on Windows")
|
|
}
|
|
h := sandbox(t)
|
|
dev := filepath.Join(h, "src/dev")
|
|
skill(t, dev, "dev", "Work in progress")
|
|
entry := filepath.Join(h, ".claude/skills/dev")
|
|
if err := os.MkdirAll(filepath.Dir(entry), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Symlink(dev, entry); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ok(t)(ImportSkill("dev"))
|
|
if !ours(entry, "dev") {
|
|
t.Fatal("claude wasn't given the library's")
|
|
}
|
|
ok(t)(RemoveSkill("dev"))
|
|
if to, err := os.Readlink(entry); err != nil || to != dev {
|
|
t.Errorf("claude's link is %q, %v", to, err)
|
|
}
|
|
if read(t, filepath.Join(dev, "SKILL.md")) == "" {
|
|
t.Error("the folder elsewhere is gone")
|
|
}
|
|
v, _ := Read(nil)
|
|
if len(v.FoundSkills) != 1 || !slices.Equal(v.FoundSkills[0].Agents, []string{"claude"}) {
|
|
t.Fatalf("found: %+v", v.FoundSkills)
|
|
}
|
|
}
|
|
|
|
// Something of the user's put where the folder was, while the library had
|
|
// it: it stays as it is, and the skill is removed as one that came from
|
|
// anywhere else is, its folder kept with the backups.
|
|
func TestPutBackLeavesTheUsersNewFolder(t *testing.T) {
|
|
h := sandbox(t)
|
|
claude := filepath.Join(h, ".claude/skills/notes")
|
|
skill(t, claude, "notes", "Mine")
|
|
ok(t)(ImportSkill("notes"))
|
|
if err := unlink(claude); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
skill(t, claude, "notes", "Another")
|
|
if _, err := RemoveSkill("notes"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if m := readMetaOf(t, claude); m != "Another" {
|
|
t.Errorf("the user's folder was touched: %q", m)
|
|
}
|
|
if m, _ := filepath.Glob(filepath.Join(BackupDir(), "*/skills/notes/SKILL.md")); len(m) != 1 {
|
|
t.Errorf("the library's folder isn't with the backups: %v", m)
|
|
}
|
|
}
|
|
|
|
func readMetaOf(t *testing.T, p string) string {
|
|
t.Helper()
|
|
m, _ := readMeta(p)
|
|
return m.Description
|
|
}
|