Skip to content

Commit fb6c47d

Browse files
maxbeizerCopilot
andcommitted
fix: normalize paths in ProjectByPath and add tilde expansion tests
ProjectByPath now expands both the input path and configured paths, preventing silent mismatches when one side uses ~ and the other uses an absolute path. Added test cases exercising tilde expansion in both directions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5dbb7fc commit fb6c47d

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

internal/config/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,11 @@ func (c *Config) ExpandedProviderPath(provider string) string {
567567
}
568568

569569
// ProjectByPath returns the ProjectConfig for the given path, or nil if not found.
570+
// Both the input path and configured paths are expanded to handle tilde notation.
570571
func (c *Config) ProjectByPath(path string) *ProjectConfig {
572+
normalized := expandPath(path)
571573
for i := range c.Projects {
572-
if expandPath(c.Projects[i].Path) == path {
574+
if expandPath(c.Projects[i].Path) == normalized {
573575
return &c.Projects[i]
574576
}
575577
}

internal/config/config_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,16 @@ func TestValidate_CustomTaskDuplicateType(t *testing.T) {
604604
}
605605

606606
func TestProjectByPath(t *testing.T) {
607+
home, err := os.UserHomeDir()
608+
if err != nil {
609+
t.Fatalf("failed to get home dir: %v", err)
610+
}
611+
607612
cfg := &Config{
608613
Projects: []ProjectConfig{
609614
{Path: "/home/user/project-a", DraftPR: true},
610615
{Path: "/home/user/project-b", DraftPR: false},
616+
{Path: "~/project-c", DraftPR: true},
611617
},
612618
}
613619

@@ -631,4 +637,19 @@ func TestProjectByPath(t *testing.T) {
631637
if pc != nil {
632638
t.Error("expected nil for nonexistent path")
633639
}
640+
641+
// Tilde expansion: lookup with expanded path should match ~/project-c
642+
pc = cfg.ProjectByPath(home + "/project-c")
643+
if pc == nil {
644+
t.Fatal("expected to find project-c via expanded path")
645+
}
646+
if !pc.DraftPR {
647+
t.Error("expected DraftPR to be true for project-c")
648+
}
649+
650+
// Tilde expansion: lookup with tilde should also match
651+
pc = cfg.ProjectByPath("~/project-c")
652+
if pc == nil {
653+
t.Fatal("expected to find project-c via tilde path")
654+
}
634655
}

0 commit comments

Comments
 (0)