feat(core): share file list patterns between glob and grep tools (#6359)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Arya Gummadi <aryagummadi@google.com>
This commit is contained in:
sangwook
2025-08-23 13:35:00 +09:00
committed by GitHub
parent f55b294570
commit 494a996ff8
13 changed files with 727 additions and 97 deletions

View File

@@ -4,11 +4,11 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { describe, it, expect, vi, beforeEach, afterEach, Mock } from 'vitest';
import * as os from 'os';
import * as path from 'path';
import { ShellTool, EditTool, WriteFileTool } from '@google/gemini-cli-core';
import { loadCliConfig, parseArguments } from './config.js';
import { loadCliConfig, parseArguments, CliArgs } from './config.js';
import { Settings } from './settings.js';
import { Extension } from './extension.js';
import * as ServerConfig from '@google/gemini-cli-core';
@@ -637,6 +637,7 @@ describe('Hierarchical Memory Loading (config.ts) - Placeholder Suite', () => {
const settings: Settings = {};
const extensions: Extension[] = [
{
path: '/path/to/ext1',
config: {
name: 'ext1',
version: '1.0.0',
@@ -644,6 +645,7 @@ describe('Hierarchical Memory Loading (config.ts) - Placeholder Suite', () => {
contextFiles: ['/path/to/ext1/GEMINI.md'],
},
{
path: '/path/to/ext2',
config: {
name: 'ext2',
version: '1.0.0',
@@ -651,6 +653,7 @@ describe('Hierarchical Memory Loading (config.ts) - Placeholder Suite', () => {
contextFiles: [],
},
{
path: '/path/to/ext3',
config: {
name: 'ext3',
version: '1.0.0',
@@ -716,6 +719,7 @@ describe('mergeMcpServers', () => {
};
const extensions: Extension[] = [
{
path: '/path/to/ext1',
config: {
name: 'ext1',
version: '1.0.0',
@@ -752,6 +756,7 @@ describe('mergeExcludeTools', () => {
const settings: Settings = { excludeTools: ['tool1', 'tool2'] };
const extensions: Extension[] = [
{
path: '/path/to/ext1',
config: {
name: 'ext1',
version: '1.0.0',
@@ -760,6 +765,7 @@ describe('mergeExcludeTools', () => {
contextFiles: [],
},
{
path: '/path/to/ext2',
config: {
name: 'ext2',
version: '1.0.0',
@@ -786,6 +792,7 @@ describe('mergeExcludeTools', () => {
const settings: Settings = { excludeTools: ['tool1', 'tool2'] };
const extensions: Extension[] = [
{
path: '/path/to/ext1',
config: {
name: 'ext1',
version: '1.0.0',
@@ -812,6 +819,7 @@ describe('mergeExcludeTools', () => {
const settings: Settings = { excludeTools: ['tool1'] };
const extensions: Extension[] = [
{
path: '/path/to/ext1',
config: {
name: 'ext1',
version: '1.0.0',
@@ -820,6 +828,7 @@ describe('mergeExcludeTools', () => {
contextFiles: [],
},
{
path: '/path/to/ext2',
config: {
name: 'ext2',
version: '1.0.0',
@@ -893,6 +902,7 @@ describe('mergeExcludeTools', () => {
const settings: Settings = {};
const extensions: Extension[] = [
{
path: '/path/to/ext',
config: {
name: 'ext1',
version: '1.0.0',
@@ -919,6 +929,7 @@ describe('mergeExcludeTools', () => {
const settings: Settings = { excludeTools: ['tool1'] };
const extensions: Extension[] = [
{
path: '/path/to/ext',
config: {
name: 'ext1',
version: '1.0.0',
@@ -1133,7 +1144,12 @@ describe('Approval mode tool exclusion logic', () => {
const extensions: Extension[] = [];
await expect(
loadCliConfig(settings, extensions, 'test-session', invalidArgv),
loadCliConfig(
settings,
extensions,
'test-session',
invalidArgv as CliArgs,
),
).rejects.toThrow(
'Invalid approval mode: invalid_mode. Valid values are: yolo, auto_edit, default',
);
@@ -1288,10 +1304,12 @@ describe('loadCliConfig with allowed-mcp-server-names', () => {
describe('loadCliConfig extensions', () => {
const mockExtensions: Extension[] = [
{
path: '/path/to/ext1',
config: { name: 'ext1', version: '1.0.0' },
contextFiles: ['/path/to/ext1.md'],
},
{
path: '/path/to/ext2',
config: { name: 'ext2', version: '1.0.0' },
contextFiles: ['/path/to/ext2.md'],
},
@@ -1894,14 +1912,12 @@ describe('loadCliConfig trustedFolder', () => {
description,
} of testCases) {
it(`should be correct for: ${description}`, async () => {
(isWorkspaceTrusted as vi.Mock).mockImplementation(
(settings: Settings) => {
const featureIsEnabled =
(settings.folderTrustFeature ?? false) &&
(settings.folderTrust ?? true);
return featureIsEnabled ? mockTrustValue : true;
},
);
(isWorkspaceTrusted as Mock).mockImplementation((settings: Settings) => {
const featureIsEnabled =
(settings.folderTrustFeature ?? false) &&
(settings.folderTrust ?? true);
return featureIsEnabled ? mockTrustValue : true;
});
const argv = await parseArguments();
const settings: Settings = { folderTrustFeature, folderTrust };
const config = await loadCliConfig(settings, [], 'test-session', argv);

View File

@@ -13,6 +13,8 @@ import {
ReadManyFilesTool,
StandardFileSystemService,
ToolRegistry,
COMMON_IGNORE_PATTERNS,
DEFAULT_FILE_EXCLUDES,
} from '@google/gemini-cli-core';
import * as os from 'os';
import { ToolCallStatus } from '../types.js';
@@ -69,6 +71,13 @@ describe('handleAtCommand', () => {
getPromptsByServer: () => [],
}),
getDebugMode: () => false,
getFileExclusions: () => ({
getCoreIgnorePatterns: () => COMMON_IGNORE_PATTERNS,
getDefaultExcludePatterns: () => DEFAULT_FILE_EXCLUDES,
getGlobExcludes: () => COMMON_IGNORE_PATTERNS,
buildExcludePatterns: () => DEFAULT_FILE_EXCLUDES,
getReadManyFilesExcludes: () => DEFAULT_FILE_EXCLUDES,
}),
getUsageStatisticsEnabled: () => false,
} as unknown as Config;