Files
magpie/internal/library/dirlink_windows_test.go
T
yetone df2b819c67 library: Antigravity and Crush get copies of skills on Windows (#6610, #5107)
On Windows without the right to make a symlink, magpie links a skill with
a junction. Go 1.23+ lists a junction as ModeIrregular, neither a folder
nor a symlink, and Antigravity (the app and agy: customizations'
discoverInSubDirsFiltered) and Crush (internal/skills on fastwalk, which
follows only a ModeSymlink) keep only folders and symlinks, so a
junctioned skill never showed in them. dsh, pi and the other Node, Bun,
Rust and Python agents follow a junction.

Checked against the real apps on xiaomi-gpu (Windows 11) in a sandbox
USERPROFILE: Antigravity 2.30.0's language_server.exe (--standalone)
GetAllSkills lists a skill in a folder and one behind a symlink, not one
behind a junction. crush v0.101.0's `crush run` request to a local
capture server listed the folder and the symlink, not the junction. On
macOS agy 1.5.8 (ACP session/new, available_commands_update) takes a
symlink that leads out of ~/.gemini/config, so #6610's "confined to the
folder" filter doesn't touch magpie's links there.

- junctionBlind (agy, antigravity, crush) and skipsJunctions: on Windows
  these targets have Copy, so they get marked copies, made again when
  the library's changes, and the Library page shows "Only ever takes
  copies" for them. A junction an older magpie made becomes a copy.
- inShared: a link in ~/.agents/skills is no skill to them, so Crush,
  which reads that folder too, gets its own copy.
- A project's .agents/skills entry that one of them reads is a copy
  (syncFolder's per-entry flag); one no such agent reads is a link again.
- takeEdits takes an edit made in a project's copy into the library, as
  one in an agent's copy is, so a copy a user edits isn't undone by the
  next sync (Project.Copy's copies too, which were made again over an
  edit before).
- behind lists these agents' stale copies.

Run:
- go vet ./internal/library, GOOS=windows and GOOS=linux go vet, gofmt -l:
  clean (mote).
- go test -count=1 ./internal/library: ok on mote (macOS) 107.9s and on
  xiaomi-gpu (Windows 11) 440.0s, at this change on 0caa09b3d.
- go test -run JunctionBlind ./internal/library: ok on mote and on the
  Windows box (-v: all four new tests PASS, TestJunctionIsALink too).
- After rebasing on be7d22edd: go test ./internal/library on mote, ok.

Broken by hand:
- Without `t.Copy = skipsJunctions(a.ID)`, the inShared check and the
  project per-entry copy: TestJunctionBlindAgentsGetCopies,
  ...AgentSkipsSharedLink and ...ProjectCopies red on mote; on Windows
  TestJunctionBlindJunctionBecomesCopy red (both entries stay junctions,
  Lstat mode 2684354563 attrs, not a dir).
- Without the project loop in takeEdits: TestJunctionBlindProjectCopies
  red, the user's edit replaced by the library's.

Not tried: magpie's own binary syncing a real Antigravity on Windows end
to end (the apps were checked against a folder, a symlink and a junction
made by hand; magpie's copy is a plain folder, which the test checks a Go
ReadDir sees as one). Antigravity and Crush on Linux (symlinks there,
which both take). The full go test ./... suite.
2026-11-14 15:05:21 +08:00

92 lines
2.8 KiB
Go

//go:build windows
package library
import (
"os"
"path/filepath"
"testing"
)
// #973: a junction, what Windows links with when symlinks aren't allowed,
// is a link to the library's skill: magpie's own, and taking it away
// leaves the skill where it is.
func TestJunctionIsALink(t *testing.T) {
h := sandbox(t)
skill(t, skillDir("pdf"), "pdf", "Read PDFs")
p := filepath.Join(h, ".claude/skills/pdf")
os.MkdirAll(filepath.Dir(p), 0o755)
if err := junction(skillDir("pdf"), p); err != nil {
t.Fatal(err)
}
if to, ok := linkTarget(p); !ok || filepath.Clean(to) != filepath.Clean(skillDir("pdf")) {
t.Errorf("link target %q %v", to, ok)
}
if !ours(p, "pdf") {
t.Error("magpie's junction isn't its own")
}
if _, err := os.Stat(filepath.Join(p, "SKILL.md")); err != nil {
t.Errorf("the skill isn't read through the junction: %v", err)
}
if err := unlink(p); err != nil {
t.Fatal(err)
}
if _, err := os.Lstat(p); !os.IsNotExist(err) {
t.Errorf("the junction is still there: %v", err)
}
if _, err := os.Stat(filepath.Join(skillDir("pdf"), "SKILL.md")); err != nil {
t.Errorf("taking the junction away took the skill: %v", err)
}
// a junction can't point at a share; nothing is left behind
q := filepath.Join(h, "share")
if junction(`\\server\share\pdf`, q) == nil {
t.Error("a junction to a share")
}
if _, err := os.Lstat(q); !os.IsNotExist(err) {
t.Errorf("a failed junction left %s: %v", q, err)
}
}
// #6610: Antigravity skips a junction, so its junction from an older
// magpie is made a copy, a real folder (not ModeIrregular to a Go walk),
// in its own folder and in a project's .agents/skills.
func TestJunctionBlindJunctionBecomesCopy(t *testing.T) {
h, cfg := antigravity(t)
src := filepath.Join(h, "src/skills")
skill(t, filepath.Join(src, "pdf"), "pdf", "Read PDFs")
ok(t)(InstallSkills(src, []string{"pdf"}, []string{"agy"}))
proj := filepath.Join(t.TempDir(), "app")
write(t, filepath.Join(proj, ".git", "HEAD"), "ref: refs/heads/main\n")
ok(t)(AddProject(proj))
ok(t)(ProjectSkill(proj, "pdf", []string{"agy"}))
ps := []string{filepath.Join(cfg, "skills/pdf"), filepath.Join(proj, ".agents/skills/pdf")}
for _, p := range ps {
if err := os.RemoveAll(p); err != nil {
t.Fatal(err)
}
if err := junction(skillDir("pdf"), p); err != nil {
t.Fatal(err)
}
}
ok(t)(Sync())
for _, p := range ps {
fi, err := os.Lstat(p)
if err != nil || !fi.IsDir() || fi.Mode()&(os.ModeIrregular|os.ModeSymlink) != 0 || !ours(p, "pdf") {
t.Errorf("%s: %v %v", p, fi, err)
continue
}
es, err := os.ReadDir(filepath.Dir(p))
if err != nil {
t.Fatal(err)
}
for _, e := range es {
if e.Name() == "pdf" && !e.IsDir() {
t.Errorf("%s: a walk doesn't see a folder: %v", p, e.Type())
}
}
if _, err := os.Stat(filepath.Join(p, "SKILL.md")); err != nil {
t.Error(err)
}
}
}