Files
skillshare/internal/sourcewalk/resolve_test.go
T
Willie 04ee235277 feat(sourcewalk): expose Follow.Resolve for writes through followed links
Operations that write or scan below a followed first-level link need the
real location of a logical path (<source>/_dev-skills/foo). Resolve maps
such a path onto the link's canonical target, reusing the same guards as
traversal, so sourcefs, group walks, trash, and audit roots can share one
answer instead of each re-deriving link identity.

Refs #274
2026-10-05 14:28:00 +08:00

60 lines
1.7 KiB
Go

package sourcewalk
import (
"os"
"path/filepath"
"runtime"
"testing"
)
func TestFollowResolve(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("symlink creation needs privileges on windows")
}
source := filepath.Join(t.TempDir(), "skills")
checkout := t.TempDir()
if err := os.MkdirAll(filepath.Join(source, "plain"), 0o755); err != nil {
t.Fatal(err)
}
if err := os.Symlink(checkout, filepath.Join(source, "_dev")); err != nil {
t.Fatal(err)
}
if err := os.Symlink(filepath.Join(t.TempDir(), "gone"), filepath.Join(source, "_missing")); err != nil {
t.Fatal(err)
}
// An alias of the source root: callers may spell paths through it.
alias := filepath.Join(t.TempDir(), "alias")
if err := os.Symlink(source, alias); err != nil {
t.Fatal(err)
}
f := NewFollow(source, nil)
cases := []struct {
in string
want string
ok bool
}{
{filepath.Join(source, "_dev", "foo"), filepath.Join(checkout, "foo"), true},
{filepath.Join(source, "_dev"), checkout, true},
{filepath.Join(alias, "_dev", "foo", "SKILL.md"), filepath.Join(checkout, "foo", "SKILL.md"), true},
{filepath.Join(source, "plain", "foo"), "", false},
{filepath.Join(source, "_missing", "foo"), "", false},
{source, "", false},
{filepath.Dir(source), "", false},
}
for _, c := range cases {
got, ok := f.Resolve(c.in)
if ok != c.ok || got != c.want {
t.Errorf("Resolve(%q) = %q, %v; want %q, %v", c.in, got, ok, c.want, c.ok)
}
}
if !f.Incomplete() {
t.Error("missing link target should mark the policy incomplete")
}
var nilFollow *Follow
if _, ok := nilFollow.Resolve(filepath.Join(source, "_dev")); ok {
t.Error("nil policy must resolve nothing")
}
}