Files
skillshare/internal/install/source_write_linux_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

55 lines
1.6 KiB
Go

//go:build linux
package install
import (
"os"
"path/filepath"
"syscall"
"testing"
)
// TestSwapStagedIntoSourceCrossDevice stages on /dev/shm, a different
// filesystem from the test temp dir, so MoveIn's rename fails with EXDEV and
// the copy fallback runs through the source handle.
func TestSwapStagedIntoSourceCrossDevice(t *testing.T) {
source := t.TempDir()
staged, err := os.MkdirTemp("/dev/shm", "skillshare-stage-")
if err != nil {
t.Skip("/dev/shm not available:", err)
}
t.Cleanup(func() { os.RemoveAll(staged) })
if dev(t, source) == dev(t, staged) {
t.Skip("/dev/shm shares a filesystem with the temp dir")
}
if err := os.WriteFile(filepath.Join(staged, "SKILL.md"), []byte("staged"), 0o644); err != nil {
t.Fatal(err)
}
external := t.TempDir()
if err := os.Symlink(external, filepath.Join(source, "linked")); err != nil {
t.Fatal(err)
}
if err := swapStagedIntoSource(source, staged, filepath.Join(source, "plain")); err != nil {
t.Fatalf("cross-device swap: %v", err)
}
if data, _ := os.ReadFile(filepath.Join(source, "plain", "SKILL.md")); string(data) != "staged" {
t.Fatalf("plain skill = %q, want staged content", data)
}
if err := swapStagedIntoSource(source, staged, filepath.Join(source, "linked", "child")); err == nil {
t.Fatal("cross-device swap below a link must be refused")
}
if entries, _ := os.ReadDir(external); len(entries) != 0 {
t.Fatalf("external tree changed: %v", entries)
}
}
func dev(t *testing.T, path string) uint64 {
t.Helper()
var st syscall.Stat_t
if err := syscall.Stat(path, &st); err != nil {
t.Fatal(err)
}
return uint64(st.Dev)
}