mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-07 08:26:51 +00:00
Remove the strict line bounds check from the diff (#2790)
This commit is contained in:
parent
2205606118
commit
ed102d1850
2 changed files with 79 additions and 8 deletions
|
|
@ -2253,6 +2253,85 @@ function process() {
|
|||
|
||||
function two() {
|
||||
return 2;
|
||||
}`)
|
||||
}
|
||||
})
|
||||
|
||||
it("should fail when line range is far outside file bounds", async () => {
|
||||
const originalContent = `
|
||||
function one() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
function two() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
function three() {
|
||||
return 3;
|
||||
}
|
||||
`.trim()
|
||||
const diffContent = `test.ts
|
||||
<<<<<<< SEARCH
|
||||
:start_line:1000
|
||||
-------
|
||||
function three() {
|
||||
return 3;
|
||||
}
|
||||
=======
|
||||
function three() {
|
||||
return "three";
|
||||
}
|
||||
>>>>>>> REPLACE`
|
||||
|
||||
// Line 1000 is way outside the bounds of the file (10 lines)
|
||||
// and outside of any reasonable buffer range, so it should fail
|
||||
const result = await strategy.applyDiff(originalContent, diffContent, 1000)
|
||||
expect(result.success).toBe(false)
|
||||
})
|
||||
|
||||
it("should find match when line range is slightly out of bounds but within buffer zone", async () => {
|
||||
const originalContent = `
|
||||
function one() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
function two() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
function three() {
|
||||
return 3;
|
||||
}
|
||||
`.trim()
|
||||
const diffContent = `test.ts
|
||||
<<<<<<< SEARCH
|
||||
:start_line:11
|
||||
-------
|
||||
function three() {
|
||||
return 3;
|
||||
}
|
||||
=======
|
||||
function three() {
|
||||
return "three";
|
||||
}
|
||||
>>>>>>> REPLACE`
|
||||
|
||||
// File only has 10 lines, but we specify line 11
|
||||
// It should still find the match since it's within the buffer zone (5 lines)
|
||||
const result = await strategy.applyDiff(originalContent, diffContent, 11)
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.content).toBe(`function one() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
function two() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
function three() {
|
||||
return "three";
|
||||
}`)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -430,14 +430,6 @@ Only use a single line of '=======' between search and replacement content, beca
|
|||
const searchLen = searchLines.length
|
||||
const exactEndIndex = exactStartIndex + searchLen - 1
|
||||
|
||||
if (exactStartIndex < 0 || exactEndIndex >= resultLines.length) {
|
||||
diffResults.push({
|
||||
success: false,
|
||||
error: `Line range ${startLine}-${startLine + searchLen - 1} is invalid (file has ${resultLines.length} lines)\n\nDebug Info:\n- Requested Range: lines ${startLine}-${startLine + searchLen - 1}\n- File Bounds: lines 1-${resultLines.length}`,
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
// Try exact match first
|
||||
const originalChunk = resultLines.slice(exactStartIndex, exactEndIndex + 1).join("\n")
|
||||
const similarity = getSimilarity(originalChunk, searchChunk)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue