返回 DeepSeek-Reasonix
add_dir_root_test.go
根目录 / internal / boot / add_dir_root_test.go
1 package boot
2
3 import (
4 "os"
5 "path/filepath"
6 "testing"
7 )
8
9 // TestAdditionalDirsResolveAgainstExplicitWorkspaceRoot pins the --dir/--add-dir
10 // contract that #6431 threads through cliBuildOverrides.WorkspaceRoot: when --dir
11 // points into a git repo, a relative --add-dir must resolve under that explicit
12 // root, not the repo's git root.
13 func TestAdditionalDirsResolveAgainstExplicitWorkspaceRoot(t *testing.T) {
14 repo := t.TempDir()
15 if err := os.Mkdir(filepath.Join(repo, ".git"), 0o755); err != nil {
16 t.Fatal(err)
17 }
18 // The --dir target: a subdirectory of the git repo, with a sibling to add.
19 proj := filepath.Join(repo, "packages", "app")
20 rel := filepath.Join(proj, "shared")
21 if err := os.MkdirAll(rel, 0o755); err != nil {
22 t.Fatal(err)
23 }
24
25 // An explicit workspace root (from --dir) pins resolution to proj, not the git root.
26 root := resolveWorkspaceRoot(proj)
27 if root != proj {
28 t.Fatalf("resolveWorkspaceRoot(%q) = %q, want the explicit --dir", proj, root)
29 }
30
31 // A relative --add-dir resolves against that explicit root (proj/shared), not
32 // repo/shared under the git root.
33 got, err := normalizeAdditionalDirs(root, []string{"shared"})
34 if err != nil {
35 t.Fatalf("normalizeAdditionalDirs: %v", err)
36 }
37 want, err := filepath.EvalSymlinks(rel)
38 if err != nil {
39 t.Fatal(err)
40 }
41 if len(got) != 1 || got[0] != want {
42 t.Fatalf("additional dirs = %v, want [%s] under --dir (not the git root)", got, want)
43 }
44 }
45
45 lines GO