From f6d6ffdc01bd72c1682a5f79cafbd17be89f040e Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Thu, 10 Jul 2025 18:24:18 -0700 Subject: [PATCH] fixup suggestions from copilot --- internal/llm/prompt/prompt.go | 29 +++++++++++++++-------------- internal/llm/prompt/prompt_test.go | 8 +++++++- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/internal/llm/prompt/prompt.go b/internal/llm/prompt/prompt.go index 7f1f58d6f7dcb163a7a9c64bf0fac8f3e63455b3..4a2661bb9f663d9f93cf0371ac5d71dd513392c7 100644 --- a/internal/llm/prompt/prompt.go +++ b/internal/llm/prompt/prompt.go @@ -85,13 +85,20 @@ func processContextPaths(workDir string, paths []string) string { // Expand ~ and environment variables before processing p = expandPath(p) - if strings.HasSuffix(p, "/") { - // Use absolute path if provided, otherwise join with workDir - dirPath := p - if !filepath.IsAbs(p) { - dirPath = filepath.Join(workDir, p) - } - filepath.WalkDir(dirPath, func(path string, d os.DirEntry, err error) error { + // Use absolute path if provided, otherwise join with workDir + fullPath := p + if !filepath.IsAbs(p) { + fullPath = filepath.Join(workDir, p) + } + + // Check if the path is a directory using os.Stat + info, err := os.Stat(fullPath) + if err != nil { + return // Skip if path doesn't exist or can't be accessed + } + + if info.IsDir() { + filepath.WalkDir(fullPath, func(path string, d os.DirEntry, err error) error { if err != nil { return err } @@ -115,13 +122,7 @@ func processContextPaths(workDir string, paths []string) string { return nil }) } else { - // Expand ~ and environment variables before processing - // Use absolute path if provided, otherwise join with workDir - fullPath := p - if !filepath.IsAbs(p) { - fullPath = filepath.Join(workDir, p) - } - + // It's a file, process it directly // Check if we've already processed this file (case-insensitive) lowerPath := strings.ToLower(fullPath) diff --git a/internal/llm/prompt/prompt_test.go b/internal/llm/prompt/prompt_test.go index 2087ca149a372209e8cd8c8cdb56aaf8cbc4d68e..3f87c435a18daf251bbe6745ff73085b195cf718 100644 --- a/internal/llm/prompt/prompt_test.go +++ b/internal/llm/prompt/prompt_test.go @@ -80,7 +80,7 @@ func TestProcessContextPaths(t *testing.T) { t.Fatalf("Failed to create test file: %v", err) } - // Test with absolute path + // Test with absolute path to file result := processContextPaths("", []string{testFile}) expected := "# From:" + testFile + "\n" + testContent @@ -88,6 +88,12 @@ func TestProcessContextPaths(t *testing.T) { t.Errorf("processContextPaths with absolute path failed.\nGot: %q\nWant: %q", result, expected) } + // Test with directory path (should process all files in directory) + result = processContextPaths("", []string{tmpDir}) + if !strings.Contains(result, testContent) { + t.Errorf("processContextPaths with directory path failed to include file content") + } + // Test with tilde expansion (if we can create a file in home directory) tmpDir := t.TempDir() t.Setenv("HOME", tmpDir)