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
This commit is contained in:
Roo Code 2025-07-27 21:26:09 +00:00
parent e2db79160e
commit 0fe3571cde
2 changed files with 5 additions and 3 deletions

View file

@ -126,6 +126,7 @@ describe("read_file tool with maxReadFileLine setting", () => {
mockCline.recordToolUsage = vi.fn().mockReturnValue(undefined)
mockCline.recordToolError = vi.fn().mockReturnValue(undefined)
mockCline.deduplicateReadFileHistory = vi.fn().mockResolvedValue(undefined)
toolResult = undefined
})
@ -382,6 +383,7 @@ describe("read_file tool XML output structure", () => {
mockCline.recordToolUsage = vi.fn().mockReturnValue(undefined)
mockCline.recordToolError = vi.fn().mockReturnValue(undefined)
mockCline.didRejectTool = false
mockCline.deduplicateReadFileHistory = vi.fn().mockResolvedValue(undefined)
toolResult = undefined
})

View file

@ -589,6 +589,9 @@ export async function readFileTool(
// No status message, just push the files XML
pushToolResult(filesXml)
}
// Deduplicate read_file history after successful reads
await cline.deduplicateReadFileHistory()
} catch (error) {
// Handle all errors using per-file format for consistency
const relPath = fileEntries[0]?.path || "unknown"
@ -609,8 +612,5 @@ export async function readFileTool(
const xmlResults = fileResults.filter((result) => result.xmlContent).map((result) => result.xmlContent)
pushToolResult(`<files>\n${xmlResults.join("\n")}\n</files>`)
// Deduplicate read_file history after successful reads
await cline.deduplicateReadFileHistory()
}
}