From 7cef2fe0a4481ecfee13b62c3aa24b6829b3fc67 Mon Sep 17 00:00:00 2001 From: "A.K.M. Adib" Date: Thu, 19 Mar 2026 10:34:07 -0400 Subject: [PATCH] add test to test isPlanMode true behavior --- packages/core/src/tools/edit.test.ts | 41 +++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/core/src/tools/edit.test.ts b/packages/core/src/tools/edit.test.ts index 2530ed9ba0..66111aed9d 100644 --- a/packages/core/src/tools/edit.test.ts +++ b/packages/core/src/tools/edit.test.ts @@ -131,9 +131,10 @@ describe('EditTool', () => { isInteractive: () => false, getDisableLLMCorrection: vi.fn(() => true), getExperiments: () => {}, - isPlanMode: () => false, + isPlanMode: vi.fn(() => false), storage: { getProjectTempDir: vi.fn().mockReturnValue('/tmp/project'), + getPlansDir: vi.fn().mockReturnValue('/tmp/plans'), }, isPathAllowed(this: Config, absolutePath: string): boolean { const workspaceContext = this.getWorkspaceContext(); @@ -1300,4 +1301,42 @@ function doIt() { ); }); }); + + describe('plan mode', () => { + it('should allow edits to plans directory when isPlanMode is true', async () => { + const mockProjectTempDir = path.join(tempDir, 'project'); + fs.mkdirSync(mockProjectTempDir); + vi.mocked(mockConfig.storage.getProjectTempDir).mockReturnValue( + mockProjectTempDir, + ); + + const plansDir = path.join(mockProjectTempDir, 'plans'); + fs.mkdirSync(plansDir); + + vi.mocked(mockConfig.isPlanMode).mockReturnValue(true); + vi.mocked(mockConfig.storage.getPlansDir).mockReturnValue(plansDir); + + const filePath = path.join(rootDir, 'test-file.txt'); + const planFilePath = path.join(plansDir, 'test-file.txt'); + const initialContent = 'some initial content'; + fs.writeFileSync(planFilePath, initialContent, 'utf8'); + + const params: EditToolParams = { + file_path: filePath, + instruction: 'Replace initial with new', + old_string: 'initial', + new_string: 'new', + }; + + const invocation = tool.build(params); + const result = await invocation.execute(new AbortController().signal); + + expect(result.llmContent).toMatch(/Successfully modified file/); + + // Verify plan file is written with new content + expect(fs.readFileSync(planFilePath, 'utf8')).toBe('some new content'); + + fs.rmSync(plansDir, { recursive: true, force: true }); + }); + }); });