test(sourcewalk): cover Windows resolved roots (#673)

Windows temporary paths can use a spelling that differs from the path returned by filepath.EvalSymlinks. Canonicalize test roots before relativizing callback paths and restore internal/sourcewalk to the windows-test allow-list.
This commit is contained in:
star-nebula
2026-10-30 20:25:45 +08:00
committed by GitHub
parent 35a1e97783
commit 86f89bf242
3 changed files with 33 additions and 15 deletions
+1
View File
@@ -130,6 +130,7 @@ jobs:
./internal/search \
./internal/skill \
./internal/skillignore \
./internal/sourcewalk \
./internal/sync \
./internal/theme \
./internal/trash \
+3 -11
View File
@@ -44,6 +44,7 @@ func followFixture(t *testing.T) (root, checkout string) {
func walkEntries(t *testing.T, root string, opts Options, skip string) (walk, walkDir []string) {
t.Helper()
root = resolvedPath(t, root)
label := func(path string, dir bool, mode fs.FileMode) string {
rel, _ := filepath.Rel(root, path)
kind := "file"
@@ -144,7 +145,7 @@ func TestFollowThroughLinkedRoot(t *testing.T) {
symlink(t, root, alias)
var got []string
err := Walk(alias, Options{Follow: NewFollow(alias, nil)}, func(path string, info os.FileInfo, err error) error {
rel, _ := filepath.Rel(utilsResolve(t, root), path)
rel, _ := filepath.Rel(resolvedPath(t, root), path)
got = append(got, filepath.ToSlash(rel))
return err
})
@@ -156,15 +157,6 @@ func TestFollowThroughLinkedRoot(t *testing.T) {
}
}
func utilsResolve(t *testing.T, path string) string {
t.Helper()
resolved, err := filepath.EvalSymlinks(path)
if err != nil {
t.Fatal(err)
}
return resolved
}
func TestFollowGuards(t *testing.T) {
for _, tc := range []struct {
name string
@@ -264,7 +256,7 @@ func TestFollowWalkErrors(t *testing.T) {
for _, walker := range []string{"Walk", "WalkDir"} {
for _, failure := range []string{"unreadable-subdirectory", "missing-target", "vanished-child"} {
t.Run(walker+"/"+failure, func(t *testing.T) {
source, target := t.TempDir(), t.TempDir()
source, target := resolvedPath(t, t.TempDir()), resolvedPath(t, t.TempDir())
write(t, filepath.Join(source, "healthy", "SKILL.md"))
write(t, filepath.Join(target, "a", "SKILL.md"))
write(t, filepath.Join(target, "z", "SKILL.md"))
+29 -4
View File
@@ -27,6 +27,22 @@ func fixture(t *testing.T) string {
return root
}
func resolvedPath(t *testing.T, path string) string {
t.Helper()
resolved, err := filepath.EvalSymlinks(path)
if err != nil {
t.Fatal(err)
}
return resolved
}
// Walk reports paths under the resolved root, so tests must compare against
// that spelling rather than t.TempDir's possibly aliased one.
func resolvedFixture(t *testing.T) string {
t.Helper()
return resolvedPath(t, fixture(t))
}
func TestSkipTargetDotDir(t *testing.T) {
orig := TargetDotDirs
TargetDotDirs = map[string]bool{".claude": true, ".cursor": true, ".skillshare": true}
@@ -53,7 +69,7 @@ func TestSkipTargetDotDir(t *testing.T) {
}
func TestWalkParity(t *testing.T) {
root := fixture(t)
root := resolvedFixture(t)
for _, skip := range []string{"", "skip", "z", "."} {
t.Run("skip="+skip, func(t *testing.T) {
collect := func(paths *[]string) filepath.WalkFunc {
@@ -80,7 +96,7 @@ func TestWalkParity(t *testing.T) {
}
func TestWalkDirParity(t *testing.T) {
root := fixture(t)
root := resolvedFixture(t)
for _, skip := range []string{"", "skip", "z", "."} {
t.Run("skip="+skip, func(t *testing.T) {
collect := func(paths *[]string) fs.WalkDirFunc {
@@ -107,7 +123,7 @@ func TestWalkDirParity(t *testing.T) {
}
func TestSymlinkRoot(t *testing.T) {
root := fixture(t)
root := resolvedFixture(t)
link := filepath.Join(t.TempDir(), "source")
if err := os.Symlink(root, link); err != nil {
t.Fatal(err)
@@ -119,7 +135,16 @@ func TestSymlinkRoot(t *testing.T) {
if err := WalkDir(link, Options{}, func(path string, _ fs.DirEntry, err error) error { dirPaths = append(dirPaths, path); return err }); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(walkPaths, dirPaths) || len(walkPaths) != 7 || walkPaths[0] != root {
wantPaths := []string{
root,
filepath.Join(root, "a"),
filepath.Join(root, "a", "child"),
filepath.Join(root, "link"),
filepath.Join(root, "skip"),
filepath.Join(root, "skip", "child"),
filepath.Join(root, "z"),
}
if !reflect.DeepEqual(walkPaths, wantPaths) || !reflect.DeepEqual(dirPaths, wantPaths) {
t.Fatalf("unexpected paths: %v / %v", walkPaths, dirPaths)
}
got, err := ReadDir(link, Options{})