From 29e019ec663fecb8512c61ad740a98eeb4b39aa8 Mon Sep 17 00:00:00 2001 From: danmobot Date: Mon, 22 Jun 2026 23:01:20 +0100 Subject: [PATCH] test: cover sandbox fs Windows path handling --- pkg/tools/fs/filesystem_windows_path_test.go | 57 ++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 pkg/tools/fs/filesystem_windows_path_test.go diff --git a/pkg/tools/fs/filesystem_windows_path_test.go b/pkg/tools/fs/filesystem_windows_path_test.go new file mode 100644 index 00000000..1061f9ff --- /dev/null +++ b/pkg/tools/fs/filesystem_windows_path_test.go @@ -0,0 +1,57 @@ +package fstools + +import ( + "io" + "os" + "path/filepath" + "testing" +) + +func TestSandboxFsReadDirAcceptsOSSpecificRelativePaths(t *testing.T) { + workspace := t.TempDir() + if err := os.MkdirAll(filepath.Join(workspace, "aaa", "bbb", "ccc"), 0o755); err != nil { + t.Fatalf("create nested directory: %v", err) + } + if err := os.WriteFile(filepath.Join(workspace, "aaa", "bbb", "file.txt"), []byte("hello"), 0o600); err != nil { + t.Fatalf("create nested file: %v", err) + } + + fsys := &sandboxFs{workspace: workspace} + entries, err := fsys.ReadDir(filepath.Join("aaa", "bbb")) + if err != nil { + t.Fatalf("ReadDir with OS-specific relative path returned error: %v", err) + } + + seen := map[string]bool{} + for _, entry := range entries { + seen[entry.Name()] = true + } + if !seen["ccc"] || !seen["file.txt"] { + t.Fatalf("ReadDir entries = %v, want ccc and file.txt", seen) + } +} + +func TestSandboxFsOpenAcceptsOSSpecificRelativePaths(t *testing.T) { + workspace := t.TempDir() + if err := os.MkdirAll(filepath.Join(workspace, "aaa", "bbb"), 0o755); err != nil { + t.Fatalf("create nested directory: %v", err) + } + if err := os.WriteFile(filepath.Join(workspace, "aaa", "bbb", "file.txt"), []byte("hello"), 0o600); err != nil { + t.Fatalf("create nested file: %v", err) + } + + fsys := &sandboxFs{workspace: workspace} + file, err := fsys.Open(filepath.Join("aaa", "bbb", "file.txt")) + if err != nil { + t.Fatalf("Open with OS-specific relative path returned error: %v", err) + } + defer file.Close() + + data, err := io.ReadAll(file) + if err != nil { + t.Fatalf("read opened file: %v", err) + } + if string(data) != "hello" { + t.Fatalf("file content = %q, want %q", string(data), "hello") + } +}