diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.go index 345fd443..ba95d8e2 100644 --- a/app/cli/lib/context_load.go +++ b/app/cli/lib/context_load.go @@ -12,6 +12,7 @@ import ( "plandex/term" "plandex/types" "plandex/url" + "plandex/utils" "strings" "sync" @@ -87,6 +88,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) { resource = resource[2:] } + resource = utils.EnsureValidPath(resource) inputFilePaths = append(inputFilePaths, resource) } } diff --git a/app/cli/utils/utils.go b/app/cli/utils/utils.go index 346500bb..9e6f1bb1 100644 --- a/app/cli/utils/utils.go +++ b/app/cli/utils/utils.go @@ -10,3 +10,12 @@ func EnsureMinDuration(start time.Time, minDuration time.Duration) { time.Sleep(minDuration - elapsed) } } + +func EnsureValidPath(path string) string { + // Remove trailing slash if it's not the root path + if len(path) > 1 && path[len(path)-1] == '/' { + path = path[:len(path)-1] + } + + return path +} diff --git a/app/cli/utils/utils_test.go b/app/cli/utils/utils_test.go new file mode 100644 index 00000000..a5127f31 --- /dev/null +++ b/app/cli/utils/utils_test.go @@ -0,0 +1,25 @@ +package utils + +import ( + "testing" +) + +func TestEnsureValidPath(t *testing.T) { + tests := []struct { + input string + expected string + }{ + {"/home/user/", "/home/user"}, + {"/", "/"}, + } + + for _, test := range tests { + t.Run("Path: "+test.input, func(t *testing.T) { + output := EnsureValidPath(test.input) + // t.Logf(output) + if output != test.expected { + t.Errorf("EnsureValidPath(%q) = %q; want %q", test.input, output, test.expected) + } + }) + } +}