返回 DeepSeek-Reasonix
path_access_test.go
根目录 / internal / config / path_access_test.go
1 package config
2
3 import (
4 "io/fs"
5 "os"
6 "path/filepath"
7 "strings"
8 "syscall"
9 "testing"
10
11 "reasonix/internal/pathidentity"
12 )
13
14 // refuseCanonicalizingUnder makes every path below mount fail to canonicalize
15 // the way a Box Drive subpath does on Windows, while the files stay readable.
16 func refuseCanonicalizingUnder(t *testing.T, mount string) {
17 t.Helper()
18 prev := resolvePathIdentity
19 t.Cleanup(func() { resolvePathIdentity = prev })
20 resolvePathIdentity = func(path string, options pathidentity.Options) (pathidentity.Identity, error) {
21 if strings.HasPrefix(path, mount+string(os.PathSeparator)) {
22 return pathidentity.Identity{}, &fs.PathError{Op: "GetFinalPathNameByHandle", Path: path, Err: syscall.ENOENT}
23 }
24 return prev(path, options)
25 }
26 }
27
28 func TestLoadForRootReadsProjectConfigUnderUncanonicalizableMount(t *testing.T) {
29 isolateUserConfigHome(t)
30 mount := t.TempDir()
31 root := filepath.Join(mount, "quant_research")
32 if err := os.MkdirAll(root, 0o755); err != nil {
33 t.Fatal(err)
34 }
35 if err := os.WriteFile(filepath.Join(root, "reasonix.toml"), []byte("[ui]\ncursor_shape = \"block\"\n"), 0o644); err != nil {
36 t.Fatal(err)
37 }
38 refuseCanonicalizingUnder(t, mount)
39
40 cfg, err := LoadForRoot(root)
41 if err != nil {
42 t.Fatalf("LoadForRoot(%q): %v", root, err)
43 }
44 if cfg.UI.CursorShape != "block" {
45 t.Fatalf("cursor_shape = %q, want the project file's block", cfg.UI.CursorShape)
46 }
47 }
48
49 func TestLoadForRootWithoutProjectConfigUnderUncanonicalizableMount(t *testing.T) {
50 isolateUserConfigHome(t)
51 mount := t.TempDir()
52 root := filepath.Join(mount, "Photos")
53 if err := os.MkdirAll(root, 0o755); err != nil {
54 t.Fatal(err)
55 }
56 refuseCanonicalizingUnder(t, mount)
57
58 if _, err := LoadForRoot(root); err != nil {
59 t.Fatalf("LoadForRoot(%q) with no reasonix.toml: %v", root, err)
60 }
61 }
62
63 func TestProjectConfigLinkUnderUncanonicalizableMountStillRefused(t *testing.T) {
64 mount := t.TempDir()
65 root := filepath.Join(mount, "repo")
66 if err := os.MkdirAll(root, 0o755); err != nil {
67 t.Fatal(err)
68 }
69 target := filepath.Join(root, "real.toml")
70 if err := os.WriteFile(target, []byte("\n"), 0o644); err != nil {
71 t.Fatal(err)
72 }
73 link := filepath.Join(root, "reasonix.toml")
74 if err := os.Symlink(target, link); err != nil {
75 t.Skipf("symlinks unavailable: %v", err)
76 }
77 refuseCanonicalizingUnder(t, mount)
78
79 if got, err := resolveConfigAccessPath(link, false); err == nil {
80 t.Fatalf("resolveConfigAccessPath(link) = %q, want the unresolvable link refused", got)
81 }
82 }
83
83 lines GO