mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
fix(read_file): empty files should not report hasMoreBefore: true in indentation mode
When totalLinesInFile is 0, there are no lines before the anchor point, so hasMoreBefore must be false regardless of the offset/anchorLine value.
This commit is contained in:
parent
c903656abc
commit
e072ffc91f
2 changed files with 27 additions and 2 deletions
|
|
@ -214,7 +214,7 @@ describe("read-file-content", () => {
|
|||
const codeWithComment = `# This is a comment header
|
||||
# describing the function
|
||||
def my_function():
|
||||
return 42`
|
||||
return 42`
|
||||
await withTempFile("indent-header-test.py", codeWithComment, async (filepath) => {
|
||||
const result = await readIndentationBlock(filepath, 3, 100, {
|
||||
anchorLine: 3,
|
||||
|
|
@ -224,6 +224,31 @@ def my_function():
|
|||
expect(result.content).toContain("# This is a comment header")
|
||||
})
|
||||
})
|
||||
|
||||
it("should report hasMoreBefore as false for empty files", async () => {
|
||||
await withTempFile("indent-empty-test.txt", "", async (filepath) => {
|
||||
const result = await readIndentationBlock(filepath, 1, 100)
|
||||
expect(result.content).toBe("")
|
||||
expect(result.lineCount).toBe(0)
|
||||
expect(result.totalLines).toBe(0)
|
||||
expect(result.metadata.totalLinesInFile).toBe(0)
|
||||
expect(result.metadata.hasMoreBefore).toBe(false)
|
||||
expect(result.metadata.hasMoreAfter).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
it("should report hasMoreBefore as false for empty files even with offset > 1", async () => {
|
||||
await withTempFile("indent-empty-offset-test.txt", "", async (filepath) => {
|
||||
const result = await readIndentationBlock(filepath, 5, 100)
|
||||
expect(result.content).toBe("")
|
||||
expect(result.lineCount).toBe(0)
|
||||
expect(result.totalLines).toBe(0)
|
||||
expect(result.metadata.totalLinesInFile).toBe(0)
|
||||
// Even though offset > 1, there are no lines in an empty file
|
||||
expect(result.metadata.hasMoreBefore).toBe(false)
|
||||
expect(result.metadata.hasMoreAfter).toBe(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("readFileContent", () => {
|
||||
|
|
|
|||
|
|
@ -382,7 +382,7 @@ export async function readIndentationBlock(
|
|||
linesReturned: 0,
|
||||
startLine: anchorLine,
|
||||
endLine: anchorLine,
|
||||
hasMoreBefore: anchorLine > 1,
|
||||
hasMoreBefore: false, // Empty file has no lines before
|
||||
hasMoreAfter: false,
|
||||
linesBeforeStart: 0,
|
||||
linesAfterEnd: 0,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue