Files
magpie/internal/library/found_skill_remove_test.go
T
yetone 56d1665251 library: a skill an agent has of its own is removed from every agent that has it, from its row under "In your agents" (trash) or with d twice in the TUI, without bringing it into the library first (#1303, sxwedo)
Until now the only action on such a row was Bring in: removing it meant
bringing it in and then removing it from the library. RemoveFoundSkill
(skills/remove-found) takes out of each agent that has it its folder, or
its copy of the very same files, and its links; its entry in the shared
~/.agents/skills, which agents read too, and a folder of it in the
library's own folder go as well. Nothing is deleted: folders go to the
backups (setAside), links are taken away, and a folder elsewhere that the
agents only linked to stays where it is. Another skill by that name
(Others) is a different skill and stays. The page asks first and says
which agents it leaves and what stays.

TestRemoveFoundSkill (library), TestLibraryPage's new part (TUI) and
remove-found-skill.test.cjs (GUI) fail without the change. The GUI test
fails 4 of 4 with library.js from before it, and passes in Chromium and
WebKit, in en, zh, ja and de, and at 440px wide.

Run: go test -tags nogui ./internal/library ./internal/tui ./internal/gui,
and go vet for linux, windows and darwin with -tags nogui, in Docker
(golang:1.26.8, a temporary HOME). The Mac's syspolicyd held test binaries
at launch. On the Mac, in Chromium and WebKit: remove-found-skill, gui-ja,
gui-de, i18n-keys, import-all-skills, own-skill, shared-skills,
library-own-folder, library-items, remove-all-skills,
library-desktop-skills, skill-name-many-agents and mobile-web, 133 of 133.
In one earlier run of that set at load ~40, mobile-web's WebKit "idle
scripts cannot scroll" failed once. It passed 3 of 3 alone with this
change, and passed in the full rerun. Not tried: the reporter's own agents,
and a WSL agent's folder.
2026-10-08 20:00:49 +08:00

68 lines
2.3 KiB
Go

package library
import (
"os"
"path/filepath"
"slices"
"testing"
)
// #1303 (sxwedo): a skill an agent has of its own could only be brought
// into the library, then removed from it. Removed where it is, it leaves
// every agent that has it, its copies and its shared entry with it, each
// kept with the backups; a folder the agents only linked to, and another
// skill by that name, stay.
func TestRemoveFoundSkill(t *testing.T) {
h := sandbox(t)
claude := filepath.Join(h, ".claude/skills")
skill(t, filepath.Join(claude, "notes"), "notes", "Mine")
skill(t, filepath.Join(h, ".codex/skills/notes"), "notes", "Mine") // a byte copy
gemini := filepath.Join(h, ".gemini/skills/notes")
skill(t, gemini, "notes", "Another")
// the shared folder is Goose's too: it goes with Goose's backups
shared := filepath.Join(h, ".agents/skills/pdf")
skill(t, shared, "pdf", "PDFs")
if err := os.Symlink(shared, filepath.Join(claude, "pdf")); err != nil {
t.Fatal(err)
}
dev := filepath.Join(h, "src/dev")
skill(t, dev, "dev", "Work in progress")
if err := os.Symlink(dev, filepath.Join(claude, "dev")); err != nil {
t.Fatal(err)
}
for _, name := range []string{"notes", "pdf", "dev"} {
ok(t)(RemoveFoundSkill(name))
}
for _, p := range []string{filepath.Join(claude, "notes"), filepath.Join(h, ".codex/skills/notes"), filepath.Join(claude, "pdf"), shared, filepath.Join(claude, "dev")} {
if _, err := os.Lstat(p); !os.IsNotExist(err) {
t.Errorf("%s is still there", p)
}
}
for _, g := range []string{"*/claude/skills/notes/SKILL.md", "*/codex/skills/notes/SKILL.md", "*/*/skills/pdf/SKILL.md"} {
if m, _ := filepath.Glob(filepath.Join(BackupDir(), g)); len(m) != 1 {
t.Errorf("%s isn't kept with the backups: %v", g, m)
}
}
if read(t, filepath.Join(dev, "SKILL.md")) == "" {
t.Error("the folder Claude Code linked to is gone")
}
if read(t, filepath.Join(gemini, "SKILL.md")) == "" {
t.Error("gemini's other notes was touched")
}
v, _ := Read(nil)
var names []string
for _, f := range v.FoundSkills {
names = append(names, f.Name+":"+f.Agents[0])
}
if !slices.Equal(names, []string{"notes:gemini"}) {
t.Errorf("found after: %v", names)
}
if _, err := RemoveFoundSkill("nothing"); err == nil {
t.Error("a skill no agent has was removed")
}
if len(v.Skills) != 0 {
t.Errorf("the library got skills: %+v", v.Skills)
}
}