diff --git a/CLAUDE.md b/CLAUDE.md index 221bec7..9cdfa8a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -223,7 +223,7 @@ The shim mappings are automatically registered via `Shims()`. ## Version Resolution **Priority order:** -1. **Local**: Walk up from `pwd` looking for `.dtvem/runtimes.json` (stops at git root) +1. **Local**: Walk up from `pwd` looking for `.dtvem/runtimes.json` (stops at filesystem root) 2. **Global**: `~/.dtvem/config/runtimes.json` 3. **Error**: No version configured @@ -282,7 +282,7 @@ cd src && go test -cover ./... # With coverage ### Test Coverage -- `internal/config/` - Paths, version resolution, git root detection +- `internal/config/` - Paths, version resolution, directory traversal - `internal/runtime/` - Registry, provider test harness - `internal/shim/` - Shim mapping, cache, file operations - `internal/ui/` - Output formatting functions diff --git a/src/internal/config/version.go b/src/internal/config/version.go index baea2ff..f82eea9 100644 --- a/src/internal/config/version.go +++ b/src/internal/config/version.go @@ -33,7 +33,7 @@ func ResolveVersion(runtimeName string) (string, error) { } // findLocalVersion walks up the directory tree looking for .dtvem/runtimes.json file -// Stops at git repository root or filesystem root +// Stops at filesystem root func findLocalVersion(runtimeName string) (string, error) { // Start from current working directory currentDir, err := os.Getwd() @@ -54,13 +54,6 @@ func findLocalVersion(runtimeName string) (string, error) { } } - // Check if this directory contains a .git directory (repository root) - gitDir := filepath.Join(currentDir, ".git") - if _, err := os.Stat(gitDir); err == nil { - // We've reached the git repository root, stop here - break - } - // Move up one directory parent := filepath.Dir(currentDir) @@ -130,13 +123,6 @@ func FindLocalRuntimesFile() (string, error) { return versionFile, nil } - // Check if this directory contains a .git directory (repository root) - gitDir := filepath.Join(currentDir, ".git") - if _, err := os.Stat(gitDir); err == nil { - // We've reached the git repository root, stop here - break - } - // Move up one directory parent := filepath.Dir(currentDir) diff --git a/src/internal/config/version_test.go b/src/internal/config/version_test.go index 8122731..57314f6 100644 --- a/src/internal/config/version_test.go +++ b/src/internal/config/version_test.go @@ -269,7 +269,7 @@ func TestFindLocalRuntimesFile_DirectoryWalking(t *testing.T) { } } -func TestFindLocalRuntimesFile_StopsAtGitRoot(t *testing.T) { +func TestFindLocalRuntimesFile_TraversesThroughGitRoot(t *testing.T) { // Create structure: // temp/ // └── outer/ @@ -277,7 +277,7 @@ func TestFindLocalRuntimesFile_StopsAtGitRoot(t *testing.T) { // └── repo/ // └── .git/ // └── subdir/ - // (run from here - should NOT find outer config) + // (run from here - SHOULD find outer config) tmpRoot := t.TempDir() outerDir := filepath.Join(tmpRoot, "outer") repoDir := filepath.Join(outerDir, "repo") @@ -287,7 +287,7 @@ func TestFindLocalRuntimesFile_StopsAtGitRoot(t *testing.T) { t.Fatalf("Failed to create directory structure: %v", err) } - // Create outer config (should NOT be found) + // Create outer config (SHOULD be found) outerConfigDir := filepath.Join(outerDir, ".dtvem") if err := os.MkdirAll(outerConfigDir, 0755); err != nil { t.Fatalf("Failed to create outer .dtvem: %v", err) @@ -297,7 +297,7 @@ func TestFindLocalRuntimesFile_StopsAtGitRoot(t *testing.T) { t.Fatalf("Failed to write outer config: %v", err) } - // Create .git directory at repo level (marks git root) + // Create .git directory at repo level (should NOT stop traversal) gitDir := filepath.Join(repoDir, ".git") if err := os.MkdirAll(gitDir, 0755); err != nil { t.Fatalf("Failed to create .git directory: %v", err) @@ -311,10 +311,24 @@ func TestFindLocalRuntimesFile_StopsAtGitRoot(t *testing.T) { t.Fatalf("Failed to change directory: %v", err) } - // Should NOT find the outer config (stopped at git root) - _, err := FindLocalRuntimesFile() - if err == nil { - t.Error("FindLocalRuntimesFile() should not find config outside git root") + // SHOULD find the outer config (traverses through git root) + foundPath, err := FindLocalRuntimesFile() + if err != nil { + t.Fatalf("FindLocalRuntimesFile() error: %v", err) + } + + // Resolve symlinks for comparison (macOS uses /var -> /private/var symlink) + foundPathResolved, err := filepath.EvalSymlinks(foundPath) + if err != nil { + t.Fatalf("Failed to resolve symlinks in found path: %v", err) + } + outerConfigPathResolved, err := filepath.EvalSymlinks(outerConfigPath) + if err != nil { + t.Fatalf("Failed to resolve symlinks in outer config path: %v", err) + } + + if foundPathResolved != outerConfigPathResolved { + t.Errorf("FindLocalRuntimesFile() = %q, want %q", foundPathResolved, outerConfigPathResolved) } } diff --git a/src/internal/download/extract.go b/src/internal/download/extract.go index 8c998b9..b37034c 100644 --- a/src/internal/download/extract.go +++ b/src/internal/download/extract.go @@ -10,8 +10,8 @@ import ( "path/filepath" "strings" - "github.com/bodgit/sevenzip" "github.com/CodingWithCalvin/dtvem.cli/src/internal/ui" + "github.com/bodgit/sevenzip" ) // archiveFile is an interface for files within an archive (zip or 7z)