@@ -3,6 +3,7 @@ package scope
33import (
44 "os"
55 "path/filepath"
6+ "strings"
67 "testing"
78
89 "github.com/sethdeckard/loadout/internal/config"
@@ -136,6 +137,44 @@ func TestResolve_ExplicitPath(t *testing.T) {
136137 }
137138}
138139
140+ func TestResolve_ExplicitPath_NoSymlinks (t * testing.T ) {
141+ // A real directory that is not a symlink should resolve without error.
142+ dir := resolveSymlinks (t , t .TempDir ())
143+ gitDir := filepath .Join (dir , ".git" )
144+ claudeDir := filepath .Join (dir , ".claude" )
145+ if err := os .MkdirAll (gitDir , 0o755 ); err != nil {
146+ t .Fatalf ("setup .git: %v" , err )
147+ }
148+ if err := os .MkdirAll (claudeDir , 0o755 ); err != nil {
149+ t .Fatalf ("setup .claude: %v" , err )
150+ }
151+
152+ sc , err := Resolve (dir )
153+ if err != nil {
154+ t .Fatalf ("Resolve(%q) error = %v" , dir , err )
155+ }
156+ if sc .Project != dir {
157+ t .Errorf ("Project = %q, want %q" , sc .Project , dir )
158+ }
159+ }
160+
161+ func TestResolve_ExplicitPath_NonexistentFallsBackToAbs (t * testing.T ) {
162+ // When the explicit path does not exist, EvalSymlinks returns
163+ // os.ErrNotExist and Resolve should fall back to the absolute path
164+ // rather than returning an error.
165+ missing := filepath .Join (t .TempDir (), "does-not-exist" )
166+ _ , err := Resolve (missing )
167+ // The path doesn't contain .git so DetectProjectRoot will fail,
168+ // but the important thing is we get past the EvalSymlinks step.
169+ if err == nil {
170+ t .Fatal ("expected error from DetectProjectRoot, got nil" )
171+ }
172+ // Should NOT be a "resolve symlinks" error.
173+ if strings .Contains (err .Error (), "resolve symlinks" ) {
174+ t .Errorf ("error = %q, should not fail at symlink resolution for missing path" , err )
175+ }
176+ }
177+
139178func TestResolve_ExplicitPath_Invalid (t * testing.T ) {
140179 dir := t .TempDir ()
141180 // No .git
@@ -146,37 +185,40 @@ func TestResolve_ExplicitPath_Invalid(t *testing.T) {
146185}
147186
148187func TestTargetRoot_User (t * testing.T ) {
188+ claudePath := filepath .Join (os .TempDir (), "user" , ".claude" , "skills" )
189+ codexPath := filepath .Join (os .TempDir (), "user" , ".codex" , "skills" )
149190 sc := Scope {Project : "" }
150191 paths := config.TargetPaths {
151- Claude : config.TargetConfig {Enabled : true , Path : "/home/user/.claude/skills" },
152- Codex : config.TargetConfig {Enabled : true , Path : "/home/user/.codex/skills" },
192+ Claude : config.TargetConfig {Enabled : true , Path : claudePath },
193+ Codex : config.TargetConfig {Enabled : true , Path : codexPath },
153194 }
154195
155196 got := sc .TargetRoot (domain .TargetClaude , paths )
156- if got != "/home/user/.claude/skills" {
197+ if got != claudePath {
157198 t .Errorf ("TargetRoot(claude) = %q, want user path" , got )
158199 }
159200 got = sc .TargetRoot (domain .TargetCodex , paths )
160- if got != "/home/user/.codex/skills" {
201+ if got != codexPath {
161202 t .Errorf ("TargetRoot(codex) = %q, want user path" , got )
162203 }
163204}
164205
165206func TestTargetRoot_Project (t * testing.T ) {
166- sc := Scope {Project : "/projects/my-app" }
207+ projectDir := filepath .Join (os .TempDir (), "projects" , "my-app" )
208+ sc := Scope {Project : projectDir }
167209 paths := config.TargetPaths {
168- Claude : config.TargetConfig {Enabled : true , Path : "/home/ user/ .claude/ skills" },
169- Codex : config.TargetConfig {Enabled : true , Path : "/home/ user/ .codex/ skills" },
210+ Claude : config.TargetConfig {Enabled : true , Path : filepath . Join ( os . TempDir (), " user" , " .claude" , " skills") },
211+ Codex : config.TargetConfig {Enabled : true , Path : filepath . Join ( os . TempDir (), " user" , " .codex" , " skills") },
170212 }
171213
172214 got := sc .TargetRoot (domain .TargetClaude , paths )
173- want := filepath .Join ("/projects/my-app" , ".claude" , "skills" )
215+ want := filepath .Join (projectDir , ".claude" , "skills" )
174216 if got != want {
175217 t .Errorf ("TargetRoot(claude) = %q, want %q" , got , want )
176218 }
177219
178220 got = sc .TargetRoot (domain .TargetCodex , paths )
179- want = filepath .Join ("/projects/my-app" , ".codex" , "skills" )
221+ want = filepath .Join (projectDir , ".codex" , "skills" )
180222 if got != want {
181223 t .Errorf ("TargetRoot(codex) = %q, want %q" , got , want )
182224 }
0 commit comments