Files
magpie/internal/library/skill_dangling_windows_test.go
T
yetone 0a37c93682 library: a skill linked in from ~/.agents/skills whose folder is gone is shown as gone and given to no agent (#7226)
"Bring in all" links a skill of the skills CLI's folder into the library.
After `npx skills remove` its folder is gone: the library entry stayed
listed and every sync linked each ticked agent to the dead link.

markDangling (skill_dangling.go, each read and sync) finds a linked-in skill
whose folder is absent or has no SKILL.md, marks it Gone (the page already
offers to take such a skill out; RemoveGoneSkills only removes the link) and
sets Skill.Dangling, which gives() reads, so no agent, project or shared
folder is given it and magpie's own links to it are taken away. It is cleared
when the source returns. A stat error other than not-exist is unknown and keeps
the entry. Nothing the user owns is deleted. The library's own folders are
never judged.

Run (sandbox HOME, tests only):
- New TestLinkedInSkillWhoseSourceIsGone and TestSourceGoneKinds: red on the
  old code (no Gone, agents keep the link), green after (mica-run).
- Windows junction case TestJunctionToARemovedFolderIsGone, plus the two
  above, via win-run on xiaomi-gpu: ok.
- gofmt -l clean; go vet -tags nogui ./internal/library for GOOS=linux and
  windows: clean.
- Full `go test -tags nogui -timeout 45m ./...` on mote at this head was
  still running when pushed (the first 39 packages ok, no red); shipped
  on the coordinator's word with these targeted runs. No reds named.
Not tried: a real `npx skills remove`, the GUI (no GUI files changed, so the
GUI suite was not run).
2026-11-19 23:44:48 +08:00

35 lines
981 B
Go

//go:build windows
package library
import (
"os"
"path/filepath"
"testing"
)
// #7226 on Windows, where the library's link into ~/.agents/skills is a
// junction: its folder removed, the skill is gone, and taking the junction
// away leaves the user's other folders as they are.
func TestJunctionToARemovedFolderIsGone(t *testing.T) {
h := sandbox(t)
shared := filepath.Join(h, ".agents", "skills")
skill(t, filepath.Join(shared, "pdf"), "pdf", "Read PDFs")
os.MkdirAll(filepath.Dir(skillDir("pdf")), 0o755)
if err := junction(filepath.Join(shared, "pdf"), skillDir("pdf")); err != nil {
t.Fatal(err)
}
if sourceGone("pdf") {
t.Fatal("a junction to a folder that is there is gone")
}
if err := os.RemoveAll(filepath.Join(shared, "pdf")); err != nil {
t.Fatal(err)
}
if !sourceGone("pdf") {
t.Error("a junction to a removed folder isn't gone")
}
if _, err := os.Lstat(skillDir("pdf")); err != nil {
t.Errorf("the junction was taken away: %v", err)
}
}