diff options
| author | Keith Ballinger <[email protected]> | 2025-06-03 21:40:46 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-04 04:40:46 +0000 |
| commit | c313762ba06ab1324dccd4c7663038cb56d24e53 (patch) | |
| tree | dbec46c12a06047ec1b79bfdfe6c8a5dd90a97be /packages/cli/src/config/config.integration.test.ts | |
| parent | d85f09ac5129227932d3d6cf76b6dac36a325655 (diff) | |
Ignore folders files (#651)
# Add .gitignore-Aware File Filtering to gemini-cli
This pull request introduces .gitignore-based file filtering to the gemini-cli, ensuring that git-ignored files are automatically excluded from file-related operations and suggestions throughout the CLI. The update enhances usability, reduces noise from build artifacts and dependencies, and provides new configuration options for fine-tuning file discovery.
Key Improvements
.gitignore File Filtering
All @ (at) commands, file completions, and core discovery tools now honor .gitignore patterns by default.
Git-ignored files (such as node_modules/, dist/, .env, and .git) are excluded from results unless explicitly overridden.
The behavior can be customized via a new fileFiltering section in settings.json, including options for:
Turning .gitignore respect on/off.
Adding custom ignore patterns.
Allowing or excluding build artifacts.
Configuration & Documentation Updates
settings.json schema extended with fileFiltering options.
Documentation updated to explain new filtering controls and usage patterns.
Testing
New and updated integration/unit tests for file filtering logic, configuration merging, and edge cases.
Test coverage ensures .gitignore filtering works as intended across different workflows.
Internal Refactoring
Core file discovery logic refactored for maintainability and extensibility.
Underlying tools (ls, glob, read-many-files) now support git-aware filtering out of the box.
Co-authored-by: N. Taylor Mullen <[email protected]>
Diffstat (limited to 'packages/cli/src/config/config.integration.test.ts')
| -rw-r--r-- | packages/cli/src/config/config.integration.test.ts | 213 |
1 files changed, 213 insertions, 0 deletions
diff --git a/packages/cli/src/config/config.integration.test.ts b/packages/cli/src/config/config.integration.test.ts new file mode 100644 index 00000000..6a995296 --- /dev/null +++ b/packages/cli/src/config/config.integration.test.ts @@ -0,0 +1,213 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'; +import * as fs from 'fs'; +import * as path from 'path'; +import { tmpdir } from 'os'; +import { Config, ConfigParameters } from '@gemini-code/core'; + +// Mock file discovery service and tool registry +vi.mock('@gemini-code/core', async () => { + const actual = await vi.importActual('@gemini-code/core'); + return { + ...actual, + FileDiscoveryService: vi.fn().mockImplementation(() => ({ + initialize: vi.fn(), + })), + createToolRegistry: vi.fn().mockResolvedValue({}), + }; +}); + +describe('Configuration Integration Tests', () => { + let tempDir: string; + let originalEnv: NodeJS.ProcessEnv; + + beforeEach(() => { + tempDir = fs.mkdtempSync(path.join(tmpdir(), 'gemini-cli-test-')); + originalEnv = { ...process.env }; + process.env.GEMINI_API_KEY = 'test-api-key'; + vi.clearAllMocks(); + }); + + afterEach(() => { + process.env = originalEnv; + if (fs.existsSync(tempDir)) { + fs.rmSync(tempDir, { recursive: true }); + } + }); + + describe('File Filtering Configuration', () => { + it('should load default file filtering settings', async () => { + const configParams: ConfigParameters = { + apiKey: 'test-key', + model: 'test-model', + sandbox: false, + targetDir: tempDir, + debugMode: false, + userAgent: 'test-agent', + fileFilteringRespectGitIgnore: undefined, // Should default to true + fileFilteringAllowBuildArtifacts: undefined, // Should default to false + }; + + const config = new Config(configParams); + + expect(config.getFileFilteringRespectGitIgnore()).toBe(true); + expect(config.getFileFilteringAllowBuildArtifacts()).toBe(false); + }); + + it('should load custom file filtering settings from configuration', async () => { + const configParams: ConfigParameters = { + apiKey: 'test-key', + model: 'test-model', + sandbox: false, + targetDir: tempDir, + debugMode: false, + userAgent: 'test-agent', + fileFilteringRespectGitIgnore: false, + fileFilteringAllowBuildArtifacts: true, + }; + + const config = new Config(configParams); + + expect(config.getFileFilteringRespectGitIgnore()).toBe(false); + expect(config.getFileFilteringAllowBuildArtifacts()).toBe(true); + }); + + it('should merge user and workspace file filtering settings', async () => { + const configParams: ConfigParameters = { + apiKey: 'test-key', + model: 'test-model', + sandbox: false, + targetDir: tempDir, + debugMode: false, + userAgent: 'test-agent', + fileFilteringRespectGitIgnore: true, + fileFilteringAllowBuildArtifacts: true, + }; + + const config = new Config(configParams); + + expect(config.getFileFilteringAllowBuildArtifacts()).toBe(true); + expect(config.getFileFilteringRespectGitIgnore()).toBe(true); + }); + }); + + describe('Configuration Integration', () => { + it('should handle partial configuration objects gracefully', async () => { + const configParams: ConfigParameters = { + apiKey: 'test-key', + model: 'test-model', + sandbox: false, + targetDir: tempDir, + debugMode: false, + userAgent: 'test-agent', + fileFilteringRespectGitIgnore: false, + fileFilteringAllowBuildArtifacts: undefined, // Should default to false + }; + + const config = new Config(configParams); + + // Specified settings should be applied + expect(config.getFileFilteringRespectGitIgnore()).toBe(false); + + // Missing settings should use defaults + expect(config.getFileFilteringAllowBuildArtifacts()).toBe(false); + }); + + it('should handle empty configuration objects gracefully', async () => { + const configParams: ConfigParameters = { + apiKey: 'test-key', + model: 'test-model', + sandbox: false, + targetDir: tempDir, + debugMode: false, + userAgent: 'test-agent', + fileFilteringRespectGitIgnore: undefined, + fileFilteringAllowBuildArtifacts: undefined, + }; + + const config = new Config(configParams); + + // All settings should use defaults + expect(config.getFileFilteringRespectGitIgnore()).toBe(true); + expect(config.getFileFilteringAllowBuildArtifacts()).toBe(false); + }); + + it('should handle missing configuration sections gracefully', async () => { + const configParams: ConfigParameters = { + apiKey: 'test-key', + model: 'test-model', + sandbox: false, + targetDir: tempDir, + debugMode: false, + userAgent: 'test-agent', + // Missing fileFiltering configuration + }; + + const config = new Config(configParams); + + // All git-aware settings should use defaults + expect(config.getFileFilteringRespectGitIgnore()).toBe(true); + expect(config.getFileFilteringAllowBuildArtifacts()).toBe(false); + }); + }); + + describe('Real-world Configuration Scenarios', () => { + it('should handle a security-focused configuration', async () => { + const configParams: ConfigParameters = { + apiKey: 'test-key', + model: 'test-model', + sandbox: false, + targetDir: tempDir, + debugMode: false, + userAgent: 'test-agent', + fileFilteringRespectGitIgnore: true, + fileFilteringAllowBuildArtifacts: false, + }; + + const config = new Config(configParams); + + expect(config.getFileFilteringRespectGitIgnore()).toBe(true); + expect(config.getFileFilteringAllowBuildArtifacts()).toBe(false); + }); + + it('should handle a development-focused configuration', async () => { + const configParams: ConfigParameters = { + apiKey: 'test-key', + model: 'test-model', + sandbox: false, + targetDir: tempDir, + debugMode: false, + userAgent: 'test-agent', + fileFilteringRespectGitIgnore: true, + fileFilteringAllowBuildArtifacts: true, + }; + + const config = new Config(configParams); + + expect(config.getFileFilteringAllowBuildArtifacts()).toBe(true); + }); + + it('should handle a CI/CD environment configuration', async () => { + const configParams: ConfigParameters = { + apiKey: 'test-key', + model: 'test-model', + sandbox: false, + targetDir: tempDir, + debugMode: false, + userAgent: 'test-agent', + fileFilteringRespectGitIgnore: false, // CI might need to see all files + fileFilteringAllowBuildArtifacts: true, + }; + + const config = new Config(configParams); + + expect(config.getFileFilteringRespectGitIgnore()).toBe(false); + expect(config.getFileFilteringAllowBuildArtifacts()).toBe(true); + }); + }); +}); |
