Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
16 changes: 1 addition & 15 deletions src/internal/config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
30 changes: 22 additions & 8 deletions src/internal/config/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,15 @@ func TestFindLocalRuntimesFile_DirectoryWalking(t *testing.T) {
}
}

func TestFindLocalRuntimesFile_StopsAtGitRoot(t *testing.T) {
func TestFindLocalRuntimesFile_TraversesThroughGitRoot(t *testing.T) {
// Create structure:
// temp/
// └── outer/
// └── .dtvem/runtimes.json
// └── 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")
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/internal/download/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading