From 82f652fbac22205b1ae4960351d2d8c9d0931194 Mon Sep 17 00:00:00 2001 From: Anton Date: Sun, 15 Jun 2025 16:40:01 +0200 Subject: [PATCH 1/4] fixed code search where filePattern includes multiple values, e.g.: `*.ts|*.js|*.py|*.java|*.go` --- src/tools/search.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tools/search.ts b/src/tools/search.ts index 709584f..6d3cd4e 100644 --- a/src/tools/search.ts +++ b/src/tools/search.ts @@ -58,7 +58,8 @@ export async function searchCode(options: { } if (filePattern) { - args.push('-g', filePattern); + const patterns = filePattern.split('|'); + patterns.forEach(p => args.push('-g', p)); } // Add pattern and path @@ -116,6 +117,9 @@ export async function searchCode(options: { }); } } catch (error) { + + + const errorMessage = error instanceof Error ? error.message : String(error); capture('server_request_error', {error: `Error parsing ripgrep output: ${errorMessage}`}); console.error(`Error parsing ripgrep output: ${errorMessage}`); @@ -239,4 +243,4 @@ export async function searchTextInFiles(options: { excludeDirs: ['node_modules', '.git', 'dist'] }); } -} +} \ No newline at end of file From 4224388e7bdc21f55f9ab3c7ebf8c65f782bdd44 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 16 Jun 2025 13:10:49 +0200 Subject: [PATCH 2/4] coderabbit's suggestion --- src/tools/search.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tools/search.ts b/src/tools/search.ts index 6d3cd4e..f6d2639 100644 --- a/src/tools/search.ts +++ b/src/tools/search.ts @@ -58,7 +58,10 @@ export async function searchCode(options: { } if (filePattern) { - const patterns = filePattern.split('|'); + const patterns = filePattern + .split('|') + .map(p => p.trim()) // remove surrounding spaces + .filter(Boolean); // drop empty tokens patterns.forEach(p => args.push('-g', p)); } @@ -120,6 +123,9 @@ export async function searchCode(options: { + + + const errorMessage = error instanceof Error ? error.message : String(error); capture('server_request_error', {error: `Error parsing ripgrep output: ${errorMessage}`}); console.error(`Error parsing ripgrep output: ${errorMessage}`); From dfb8f5a445f8eb2516f663398d8b1742286af438 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 16 Jun 2025 13:12:22 +0200 Subject: [PATCH 3/4] added an actual test verifying search_code works with filePattern that contains multiple file extensions separated via `|` --- test/test-search-code-edge-cases.js | 62 +++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test/test-search-code-edge-cases.js b/test/test-search-code-edge-cases.js index c545657..ae45290 100644 --- a/test/test-search-code-edge-cases.js +++ b/test/test-search-code-edge-cases.js @@ -361,6 +361,68 @@ async function testManySmallFiles() { } } +/** + * Test filePattern with multiple values, including whitespace and empty tokens + */ +async function testFilePatternWithMultipleValues() { + console.log(`${colors.yellow}Testing filePattern with multiple values...${colors.reset}`); + + // Create test files + await fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file1.ts'), 'export const myTsVar = "patternTs";'); + await fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file2.js'), 'const myJsVar = "patternJs";'); + await fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file3.py'), 'my_py_var = "patternPy"'); + await fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file4.java'), 'String myJavaVar = "patternJava";'); + await fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file5.go'), 'var myGoVar = "patternGo"'); + await fs.writeFile(path.join(EDGE_CASE_TEST_DIR, 'file6.txt'), 'This is a text file.'); + + // Test with valid multiple patterns + let result = await handleSearchCode({ + path: EDGE_CASE_TEST_DIR, + pattern: 'pattern', + filePattern: '*.ts|*.js|*.py' + }); + let text = result.content[0].text; + assert(text.includes('file1.ts'), 'Should find match in file1.ts'); + assert(text.includes('file2.js'), 'Should find match in file2.js'); + assert(text.includes('file3.py'), 'Should find match in file3.py'); + assert(!text.includes('file4.java'), 'Should not find match in file4.java'); + assert(!text.includes('file5.go'), 'Should not find match in file5.go'); + + // Test with patterns including whitespace + result = await handleSearchCode({ + path: EDGE_CASE_TEST_DIR, + pattern: 'pattern', + filePattern: ' *.ts | *.js ' + }); + text = result.content[0].text; + assert(text.includes('file1.ts'), 'Should find match with whitespace-padded patterns (file1.ts)'); + assert(text.includes('file2.js'), 'Should find match with whitespace-padded patterns (file2.js)'); + assert(!text.includes('file3.py'), 'Should not find match with whitespace-padded patterns (file3.py)'); + + // Test with patterns including empty tokens (e.g., || or leading/trailing |) + result = await handleSearchCode({ + path: EDGE_CASE_TEST_DIR, + pattern: 'pattern', + filePattern: '|*.ts||*.py|' + }); + text = result.content[0].text; + assert(text.includes('file1.ts'), 'Should find match with empty tokens (file1.ts)'); + assert(text.includes('file3.py'), 'Should find match with empty tokens (file3.py)'); + assert(!text.includes('file2.js'), 'Should not find match with empty tokens (file2.js)'); + + // Test with only empty tokens + result = await handleSearchCode({ + path: EDGE_CASE_TEST_DIR, + pattern: 'pattern', + filePattern: '|||' + }); + text = result.content[0].text; + assert(!text.includes('file1.ts'), 'Should not find any matches with only empty patterns'); + assert(!text.includes('file2.js'), 'Should not find any matches with only empty patterns'); + + console.log(`${colors.green}✓ FilePattern with multiple values test passed${colors.reset}`); +} + /** * Main test runner for edge cases */ From f3721d03c72c16fa045693f4c30e649e7a07eff0 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 16 Jun 2025 14:21:23 +0200 Subject: [PATCH 4/4] 1 --- test/test-search-code-edge-cases.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test-search-code-edge-cases.js b/test/test-search-code-edge-cases.js index ae45290..3aedeb5 100644 --- a/test/test-search-code-edge-cases.js +++ b/test/test-search-code-edge-cases.js @@ -448,7 +448,8 @@ export async function testSearchCodeEdgeCases() { await testLargeContextLines(); await testPathTraversalSecurity(); await testManySmallFiles(); - + await testFilePatternWithMultipleValues(); + console.log(`${colors.green}✅ All handleSearchCode edge case tests passed!${colors.reset}`); return true;