From f895e32465f5f29b6bb7cce085a8eee6ea8d8358 Mon Sep 17 00:00:00 2001 From: zach Date: Wed, 6 May 2026 17:54:31 +0800 Subject: [PATCH] Create project temp dir before saving truncated output --- packages/core/src/utils/truncation.test.ts | 9 +++++++++ packages/core/src/utils/truncation.ts | 1 + 2 files changed, 10 insertions(+) diff --git a/packages/core/src/utils/truncation.test.ts b/packages/core/src/utils/truncation.test.ts index 4fb4bb99e90..9350f7844da 100644 --- a/packages/core/src/utils/truncation.test.ts +++ b/packages/core/src/utils/truncation.test.ts @@ -13,11 +13,13 @@ vi.mock('node:fs/promises'); describe('truncateAndSaveToFile', () => { const mockWriteFile = vi.mocked(fs.writeFile); + const mockMkdir = vi.mocked(fs.mkdir); const THRESHOLD = 40_000; const TRUNCATE_LINES = 1000; beforeEach(() => { vi.clearAllMocks(); + mockMkdir.mockResolvedValue(undefined); }); it('should return content unchanged if below both threshold and line limit', async () => { @@ -35,6 +37,7 @@ describe('truncateAndSaveToFile', () => { expect(result).toEqual({ content }); expect(mockWriteFile).not.toHaveBeenCalled(); + expect(mockMkdir).not.toHaveBeenCalled(); }); it('should truncate when line limit exceeded even if under character threshold', async () => { @@ -59,6 +62,9 @@ describe('truncateAndSaveToFile', () => { expect(result.outputFile).toBe( path.join(projectTempDir, `${fileName}.output`), ); + expect(mockMkdir).toHaveBeenCalledWith(projectTempDir, { + recursive: true, + }); const head = Math.floor(TRUNCATE_LINES / 5); const beginning = lines.slice(0, head); @@ -133,6 +139,9 @@ describe('truncateAndSaveToFile', () => { expect(result.outputFile).toBe( path.join(projectTempDir, `${fileName}.output`), ); + expect(mockMkdir).toHaveBeenCalledWith(projectTempDir, { + recursive: true, + }); expect(mockWriteFile).toHaveBeenCalledWith( path.join(projectTempDir, `${fileName}.output`), content, diff --git a/packages/core/src/utils/truncation.ts b/packages/core/src/utils/truncation.ts index 6672a1f83d1..35a11260736 100644 --- a/packages/core/src/utils/truncation.ts +++ b/packages/core/src/utils/truncation.ts @@ -85,6 +85,7 @@ export async function truncateAndSaveToFile( const safeFileName = `${path.basename(fileName)}.output`; const outputFile = path.join(projectTempDir, safeFileName); try { + await fs.mkdir(projectTempDir, { recursive: true }); await fs.writeFile(outputFile, content); return {