Skip to content

Commit 1bb074e

Browse files
test(readFileTool): comprehensive coverage; align legacy failure flag with native path (#222)
Add unit coverage for ReadFileTool: input validation, rooignore blocking, directory/binary/image handling, image memory limits, approval flow, slice and indentation modes, output structure, and the legacy multi-file format. Source changes: - Drop the temporary "[read_file] Legacy format detected" debug console.warn. - Mirror the native path in the legacy read path: set didToolFailInCurrentTurn on rooignore blocks, directory reads, and read errors so a failed legacy read fails the tool turn consistently. - Recognize re-hydrated bare-`files` calls in isLegacyReadFileParams (history persisted before the _legacyFormat flag existed). Co-authored-by: Armando Vaquera <263793884+proyectoauraorg@users.noreply.github.com>
1 parent d1e7e8c commit 1bb074e

3 files changed

Lines changed: 770 additions & 4 deletions

File tree

packages/types/src/tool-params.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ export type ReadFileToolParams = ReadFileParams | LegacyReadFileParams
8989
* Type guard to check if params are in legacy format.
9090
*/
9191
export function isLegacyReadFileParams(params: ReadFileToolParams): params is LegacyReadFileParams {
92-
return "_legacyFormat" in params && params._legacyFormat === true
92+
// `NativeToolCallParser` always tags freshly parsed legacy calls with `_legacyFormat: true`.
93+
// The bare-`files` fallback only matters for chat history persisted before that flag was
94+
// introduced (commit cc86049f1) and re-hydrated on a later run. Note that params matched via
95+
// that fallback narrow to `LegacyReadFileParams` but leave `_legacyFormat` `undefined`, so
96+
// callers should branch on the presence of `files`, not on `_legacyFormat === true`.
97+
const hasLegacyFlag = "_legacyFormat" in params && params._legacyFormat === true
98+
const hasFilesArray = "files" in params && Array.isArray((params as unknown as Record<string, unknown>).files)
99+
return hasLegacyFlag || hasFilesArray
93100
}
94101

95102
export interface Coordinate {

src/core/tools/ReadFileTool.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,6 @@ export class ReadFileTool extends BaseTool<"read_file"> {
668668
const { pushToolResult } = callbacks
669669
const modelInfo = task.api.getModel().info
670670

671-
// Temporary indicator for testing legacy format detection
672-
console.warn("[read_file] Legacy format detected - using backward compatibility path")
673-
674671
if (!fileEntries || fileEntries.length === 0) {
675672
task.consecutiveMistakeCount++
676673
task.recordToolError("read_file")
@@ -694,6 +691,8 @@ export class ReadFileTool extends BaseTool<"read_file"> {
694691
await task.say("rooignore_error", relPath)
695692
const errorMsg = formatResponse.rooIgnoreError(relPath)
696693
results.push(`File: ${relPath}\nError: ${errorMsg}`)
694+
// Mirror the native path: a blocked file marks the tool turn as failed.
695+
task.didToolFailInCurrentTurn = true
697696
continue
698697
}
699698

@@ -731,6 +730,8 @@ export class ReadFileTool extends BaseTool<"read_file"> {
731730
const errorMsg = `Cannot read '${relPath}' because it is a directory.`
732731
results.push(`File: ${relPath}\nError: ${errorMsg}`)
733732
await task.say("error", `Error reading file ${relPath}: ${errorMsg}`)
733+
// Mirror the native path: a failed read marks the tool turn as failed.
734+
task.didToolFailInCurrentTurn = true
734735
continue
735736
}
736737

@@ -802,6 +803,8 @@ export class ReadFileTool extends BaseTool<"read_file"> {
802803
const errorMsg = error instanceof Error ? error.message : String(error)
803804
results.push(`File: ${relPath}\nError: ${errorMsg}`)
804805
await task.say("error", `Error reading file ${relPath}: ${errorMsg}`)
806+
// Mirror the native path: a failed read marks the tool turn as failed.
807+
task.didToolFailInCurrentTurn = true
805808
}
806809
}
807810

0 commit comments

Comments
 (0)