summaryrefslogtreecommitdiff
path: root/packages/server/src/tools/write-file.test.ts
diff options
context:
space:
mode:
authorTaylor Mullen <[email protected]>2025-05-16 23:33:12 -0700
committerN. Taylor Mullen <[email protected]>2025-05-16 23:34:48 -0700
commit5dcdbe64ab6ef2ca2692e75b8600b8726ac72178 (patch)
treeecc774a5e10c5d2e6c65d11ba0008edf3c9cb09e /packages/server/src/tools/write-file.test.ts
parent58e02240612e0a0eddc1427a795f5003ee2b3d07 (diff)
refactor: Unify file modification confirmation state
- Modifies `EditTool` and `WriteFileTool` to share a single confirmation preference. - The "Always Proceed" choice for file modifications is now stored in `Config.alwaysSkipModificationConfirmation`. - This ensures that if a user chooses to always skip confirmation for one file modification tool, this preference is respected by the other. - `WriteFileTool` constructor now accepts `Config` instead of `targetDir` to facilitate this shared state. - Tests updated to reflect the new shared confirmation logic. Fixes https://b.corp.google.com/issues/415897960
Diffstat (limited to 'packages/server/src/tools/write-file.test.ts')
-rw-r--r--packages/server/src/tools/write-file.test.ts43
1 files changed, 39 insertions, 4 deletions
diff --git a/packages/server/src/tools/write-file.test.ts b/packages/server/src/tools/write-file.test.ts
index 25d1e998..fc2ca61b 100644
--- a/packages/server/src/tools/write-file.test.ts
+++ b/packages/server/src/tools/write-file.test.ts
@@ -4,18 +4,48 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { WriteFileTool } from './write-file.js';
import { FileDiff, ToolConfirmationOutcome } from './tools.js';
+import { Config } from '../config/config.js';
+import { ToolRegistry } from './tool-registry.js'; // Added import
import path from 'path';
import fs from 'fs';
import os from 'os';
+const rootDir = path.resolve(os.tmpdir(), 'gemini-cli-test-root');
+
+// Mock Config
+const mockConfigInternal = {
+ getTargetDir: () => rootDir,
+ getAlwaysSkipModificationConfirmation: vi.fn(() => false),
+ setAlwaysSkipModificationConfirmation: vi.fn(),
+ getApiKey: () => 'test-key',
+ getModel: () => 'test-model',
+ getSandbox: () => false,
+ getDebugMode: () => false,
+ getQuestion: () => undefined,
+ getFullContext: () => false,
+ getToolDiscoveryCommand: () => undefined,
+ getToolCallCommand: () => undefined,
+ getMcpServerCommand: () => undefined,
+ getMcpServers: () => undefined,
+ getUserAgent: () => 'test-agent',
+ getUserMemory: () => '',
+ setUserMemory: vi.fn(),
+ getGeminiMdFileCount: () => 0,
+ setGeminiMdFileCount: vi.fn(),
+ getToolRegistry: () =>
+ ({
+ registerTool: vi.fn(),
+ discoverTools: vi.fn(),
+ }) as unknown as ToolRegistry,
+};
+const mockConfig = mockConfigInternal as unknown as Config;
+
describe('WriteFileTool', () => {
let tool: WriteFileTool;
let tempDir: string;
- // Using a subdirectory within the OS temp directory for the root to avoid potential permission issues.
- const rootDir = path.resolve(os.tmpdir(), 'gemini-cli-test-root');
beforeEach(() => {
// Create a unique temporary directory for files created outside the root (for testing boundary conditions)
@@ -26,7 +56,12 @@ describe('WriteFileTool', () => {
if (!fs.existsSync(rootDir)) {
fs.mkdirSync(rootDir, { recursive: true });
}
- tool = new WriteFileTool(rootDir);
+ tool = new WriteFileTool(mockConfig);
+ // Reset mocks before each test that might use them for confirmation logic
+ mockConfigInternal.getAlwaysSkipModificationConfirmation.mockReturnValue(
+ false,
+ );
+ mockConfigInternal.setAlwaysSkipModificationConfirmation.mockClear();
});
afterEach(() => {