From fa1a7c10bd94b545925af9a8bf26804e574bd09a Mon Sep 17 00:00:00 2001 From: "gemini-cli[bot]" <218312386+gemini-cli[bot]@users.noreply.github.com> Date: Wed, 29 Apr 2026 22:59:58 +0000 Subject: [PATCH] # Fix: Inconsistent Case-Sensitivity in GrepTool (#26235) Co-authored-by: gemini-cli[bot] --- packages/core/src/tools/grep.test.ts | 28 ++++++++++++++++++++++++++++ packages/core/src/tools/grep.ts | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/core/src/tools/grep.test.ts b/packages/core/src/tools/grep.test.ts index 4af684b1cd..860169c02d 100644 --- a/packages/core/src/tools/grep.test.ts +++ b/packages/core/src/tools/grep.test.ts @@ -314,6 +314,34 @@ describe('GrepTool', () => { ); }, 30000); + it('should pass -i flag to system grep for case-insensitivity', async () => { + vi.mocked(execStreaming).mockImplementationOnce(() => + createLineGenerator(['fileA.txt:1:hello world']), + ); + + const params: GrepToolParams = { pattern: 'HELLO' }; + const invocation = grepTool.build(params) as unknown as { + isCommandAvailable: (command: string) => Promise; + execute: (options: ExecuteOptions) => Promise; + }; + // Force system grep strategy by mocking isCommandAvailable and ensuring git grep is not used + invocation.isCommandAvailable = vi.fn(async (command: string) => { + if (command === 'git') return false; + if (command === 'grep') return true; + return false; + }); + + await invocation.execute({ abortSignal }); + + expect(execStreaming).toHaveBeenCalledWith( + 'grep', + expect.arrayContaining(['-i']), + expect.objectContaining({ + cwd: expect.any(String), + }), + ); + }); + it('should throw an error if params are invalid', async () => { const params = { dir_path: '.' } as unknown as GrepToolParams; // Invalid: pattern missing expect(() => grepTool.build(params)).toThrow( diff --git a/packages/core/src/tools/grep.ts b/packages/core/src/tools/grep.ts index 34be588573..d89da94aab 100644 --- a/packages/core/src/tools/grep.ts +++ b/packages/core/src/tools/grep.ts @@ -465,7 +465,7 @@ class GrepToolInvocation extends BaseToolInvocation< const grepAvailable = await this.isCommandAvailable('grep'); if (grepAvailable) { strategyUsed = 'system grep'; - const grepArgs = ['-r', '-n', '-H', '-E', '-I']; + const grepArgs = ['-r', '-n', '-H', '-E', '-I', '-i']; // Extract directory names from exclusion patterns for grep --exclude-dir const globExcludes = this.fileExclusions.getGlobExcludes(); const commonExcludes = globExcludes