Skip to content

Commit d02a90a

Browse files
committed
code search fix
1 parent 5360734 commit d02a90a

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

npm-app/src/__tests__/tool-handlers.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,4 +387,45 @@ export interface TestInterface {
387387
expect(stdout).toContain('Global limit of 250 results reached')
388388
}
389389
})
390+
391+
test('handles glob pattern flags correctly without regex parse errors', async () => {
392+
// Create test files with different extensions
393+
await fs.promises.writeFile(
394+
path.join(testDataDir, 'typescript-file.ts'),
395+
`export const GLOB_TEST_TS = 'typescript file';`,
396+
)
397+
398+
await fs.promises.writeFile(
399+
path.join(testDataDir, 'javascript-file.js'),
400+
`export const GLOB_TEST_JS = 'javascript file';`,
401+
)
402+
403+
await fs.promises.writeFile(
404+
path.join(testDataDir, 'text-file.txt'),
405+
`GLOB_TEST_TXT in text file`,
406+
)
407+
408+
// Search with glob flags to only match .ts and .tsx files
409+
const parameters = {
410+
pattern: 'GLOB_TEST',
411+
flags: '-g *.ts -g *.tsx',
412+
cwd: 'src/__tests__/data',
413+
maxResults: 30,
414+
}
415+
416+
const result = await handleCodeSearch(parameters, 'test-id')
417+
418+
// Should not have a stderr with regex parse error
419+
expect((result[0].value as any).stderr).toBeUndefined()
420+
421+
const stdout = (result[0].value as any).stdout
422+
423+
// Should find the .ts file
424+
expect(stdout).toContain('typescript-file.ts')
425+
expect(stdout).toContain('GLOB_TEST_TS')
426+
427+
// Should not find the .js or .txt files
428+
expect(stdout).not.toContain('javascript-file.js')
429+
expect(stdout).not.toContain('text-file.txt')
430+
})
390431
})

npm-app/src/tool-handlers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ export const handleCodeSearch: ToolHandler<'code_search'> = async (
285285
searchCwd = requestedPath
286286
}
287287
// Always include -n flag to ensure line numbers are in output for parsing
288-
const args = ['-n', ...flags, pattern, '.']
288+
// Use "--" to prevent pattern from being misparsed as a flag (e.g., pattern starting with '-')
289+
const args = ['-n', ...flags, '--', pattern, '.']
289290

290291
console.log()
291292
console.log(

0 commit comments

Comments
 (0)