Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/core/src/utils/truncation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/truncation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading