Skip to content

Commit 7f84fa0

Browse files
committed
fix(read-file): cover boundaries and correct empty results
1 parent 8f09c9a commit 7f84fa0

6 files changed

Lines changed: 464 additions & 45 deletions

File tree

‎src/core/tools/file-reading/ReadFileTool.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class ReadFileTool extends BaseTool<"read_file"> {
8282
const fullPath = filePath ? path.resolve(task.cwd, filePath) : ""
8383
const message = JSON.stringify({
8484
tool: "readFile",
85-
path: getReadablePath(task.cwd, filePath),
85+
path: filePath ? getReadablePath(task.cwd, filePath) : "",
8686
isOutsideWorkspace: filePath ? isPathOutsideWorkspace(fullPath) : false,
8787
} satisfies ClineSayTool)
8888
try {

‎src/core/tools/file-reading/__tests__/readFileResultFormatter.spec.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,12 @@ describe("ReadFileResultFormatter", () => {
208208
{ type: "image", source: { type: "base64", media_type: "image/png", data: "aW1hZ2U=" } },
209209
])
210210
})
211+
212+
it("rejects an unrecognized runtime status instead of silently formatting a successful response", () => {
213+
const malformedResult: unknown = { path: "a", status: "unrecognized", nativeContent: "File: a" }
214+
// An injected JavaScript implementation can violate the TypeScript discriminator contract.
215+
expect(() => Reflect.apply(formatter.format, formatter, [malformedResult, false])).toThrow(
216+
"Unhandled read file status: unrecognized",
217+
)
218+
})
211219
})

‎src/core/tools/file-reading/__tests__/readFileTextProcessor.spec.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ describe("ReadFileTextProcessor", () => {
4444
expect(output).toMatch(/Included ranges:|IMPORTANT: File content truncated/)
4545
})
4646

47+
it("preserves indentation anchor errors without appending a range summary", () => {
48+
const output = processor.process("first\nsecond", {
49+
path: "a",
50+
mode: "indentation",
51+
indentation: { anchor_line: 50 },
52+
})
53+
expect(output).toBe("Error: anchor_line 50 is out of range (1-2)")
54+
})
55+
4756
it("detects long-line clipping only for returned lines", () => {
4857
const source = "short\n" + "x".repeat(3000)
4958
expect(processor.hasClippedLines(source, "1 | short")).toBe(false)

0 commit comments

Comments
 (0)