Skip to content

Commit 0fe3571

Browse files
committed
fix: move deduplicateReadFileHistory call from error handler to success path
- Deduplication now only triggers after successful read_file operations - Fixed test mocks to include deduplicateReadFileHistory method - All tests passing
1 parent e2db791 commit 0fe3571

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/core/tools/__tests__/readFileTool.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ describe("read_file tool with maxReadFileLine setting", () => {
126126

127127
mockCline.recordToolUsage = vi.fn().mockReturnValue(undefined)
128128
mockCline.recordToolError = vi.fn().mockReturnValue(undefined)
129+
mockCline.deduplicateReadFileHistory = vi.fn().mockResolvedValue(undefined)
129130

130131
toolResult = undefined
131132
})
@@ -382,6 +383,7 @@ describe("read_file tool XML output structure", () => {
382383
mockCline.recordToolUsage = vi.fn().mockReturnValue(undefined)
383384
mockCline.recordToolError = vi.fn().mockReturnValue(undefined)
384385
mockCline.didRejectTool = false
386+
mockCline.deduplicateReadFileHistory = vi.fn().mockResolvedValue(undefined)
385387

386388
toolResult = undefined
387389
})

src/core/tools/readFileTool.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ export async function readFileTool(
589589
// No status message, just push the files XML
590590
pushToolResult(filesXml)
591591
}
592+
593+
// Deduplicate read_file history after successful reads
594+
await cline.deduplicateReadFileHistory()
592595
} catch (error) {
593596
// Handle all errors using per-file format for consistency
594597
const relPath = fileEntries[0]?.path || "unknown"
@@ -609,8 +612,5 @@ export async function readFileTool(
609612
const xmlResults = fileResults.filter((result) => result.xmlContent).map((result) => result.xmlContent)
610613

611614
pushToolResult(`<files>\n${xmlResults.join("\n")}\n</files>`)
612-
613-
// Deduplicate read_file history after successful reads
614-
await cline.deduplicateReadFileHistory()
615615
}
616616
}

0 commit comments

Comments
 (0)