Files
skillshare/internal/install/source_write_test.go
T
Willie 8c60f51b9f feat(source): add the sourcewalk walker and sourcefs write boundary for proposal 274 (#385)
Implements rollout steps 1 and 2 of proposals/274-skillfollow.md. Nothing follows a link or parses .skillfollow yet.

Step 1: doctor reports first-level symlinks and junctions in the skills source as info, in text and JSON, without following them.

Step 2a: internal/sourcewalk owns traversal of the skills source. Thirteen raw walks move onto it with identical behavior, and a go/parser ratchet fails the tests on any new unclassified walk.

Step 2b: internal/sourcefs wraps an os.Root opened at the skills source and refuses any write whose path has a link component. The six write sites the proposal found in review move onto it, including the cross-device copy fallback, and a second ratchet covers raw os write calls. The only behavior change is that an explicit path crossing a link inside the source is refused instead of written through.

Refs #274

Release-As: 0.24.3
2026-10-04 15:15:43 +08:00

57 lines
1.6 KiB
Go

package install
import (
"errors"
"os"
"path/filepath"
"testing"
"skillshare/internal/sourcefs"
)
func TestSwapStagedIntoSource(t *testing.T) {
source := t.TempDir()
external := t.TempDir()
if err := os.WriteFile(filepath.Join(external, "SKILL.md"), []byte("external"), 0o644); err != nil {
t.Fatal(err)
}
if err := os.Symlink(external, filepath.Join(source, "linked")); err != nil {
t.Fatal(err)
}
if err := os.MkdirAll(filepath.Join(source, "plain"), 0o755); err != nil {
t.Fatal(err)
}
stage := func() string {
dir := filepath.Join(t.TempDir(), "skill")
if err := os.MkdirAll(dir, 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "SKILL.md"), []byte("staged"), 0o644); err != nil {
t.Fatal(err)
}
return dir
}
for _, dest := range []string{
filepath.Join(source, "linked"), // the skill is a link
filepath.Join(source, "linked", "child"), // the skill is below one
} {
if err := swapStagedIntoSource(source, stage(), dest); !errors.Is(err, sourcefs.ErrLink) {
t.Errorf("swap into %s: got %v, want ErrLink", dest, err)
}
}
if data, _ := os.ReadFile(filepath.Join(external, "SKILL.md")); string(data) != "external" {
t.Fatalf("external skill changed: %q", data)
}
if entries, _ := os.ReadDir(external); len(entries) != 1 {
t.Fatalf("external tree changed: %v", entries)
}
if err := swapStagedIntoSource(source, stage(), filepath.Join(source, "plain")); err != nil {
t.Fatalf("swap into a real directory: %v", err)
}
if data, _ := os.ReadFile(filepath.Join(source, "plain", "SKILL.md")); string(data) != "staged" {
t.Fatalf("plain skill = %q, want staged content", data)
}
}