diff options
| author | Taylor Mullen <[email protected]> | 2025-05-16 23:33:12 -0700 |
|---|---|---|
| committer | N. Taylor Mullen <[email protected]> | 2025-05-16 23:34:48 -0700 |
| commit | 5dcdbe64ab6ef2ca2692e75b8600b8726ac72178 (patch) | |
| tree | ecc774a5e10c5d2e6c65d11ba0008edf3c9cb09e /packages/server/src/tools/edit.test.ts | |
| parent | 58e02240612e0a0eddc1427a795f5003ee2b3d07 (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/edit.test.ts')
| -rw-r--r-- | packages/server/src/tools/edit.test.ts | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/packages/server/src/tools/edit.test.ts b/packages/server/src/tools/edit.test.ts index f0650d70..a552cf53 100644 --- a/packages/server/src/tools/edit.test.ts +++ b/packages/server/src/tools/edit.test.ts @@ -6,7 +6,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; +import { describe, it, expect, beforeEach, afterEach, vi, Mock } from 'vitest'; import { EditTool, EditToolParams } from './edit.js'; import { FileDiff } from './tools.js'; import path from 'path'; @@ -38,10 +38,37 @@ describe('EditTool', () => { mockConfig = { getTargetDir: () => rootDir, - getGeminiConfig: () => ({ apiKey: 'test-api-key' }), + getAlwaysSkipModificationConfirmation: vi.fn(() => false), + setAlwaysSkipModificationConfirmation: vi.fn(), + // getGeminiConfig: () => ({ apiKey: 'test-api-key' }), // This was not a real Config method // Add other properties/methods of Config if EditTool uses them + // Minimal other methods to satisfy Config type if needed by EditTool constructor or other direct uses: + getApiKey: () => 'test-api-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: () => ({}) as any, // Minimal mock for ToolRegistry } as unknown as Config; + // Reset mocks before each test + (mockConfig.getAlwaysSkipModificationConfirmation as Mock).mockClear(); + (mockConfig.setAlwaysSkipModificationConfirmation as Mock).mockClear(); + // Default to not skipping confirmation + (mockConfig.getAlwaysSkipModificationConfirmation as Mock).mockReturnValue( + false, + ); + // Reset mocks and set default implementation for ensureCorrectEdit mockEnsureCorrectEdit.mockReset(); mockEnsureCorrectEdit.mockImplementation(async (currentContent, params) => { @@ -290,9 +317,10 @@ describe('EditTool', () => { new_string: fileContent, }; - (tool as any).shouldAlwaysEdit = true; + ( + mockConfig.getAlwaysSkipModificationConfirmation as Mock + ).mockReturnValueOnce(true); const result = await tool.execute(params, new AbortController().signal); - (tool as any).shouldAlwaysEdit = false; expect(result.llmContent).toMatch(/Created new file/); expect(fs.existsSync(newFilePath)).toBe(true); |
