Skip to content

Commit ed102d1

Browse files
authored
Remove the strict line bounds check from the diff (RooCodeInc#2790)
1 parent 2205606 commit ed102d1

File tree

2 files changed

+79
-8
lines changed

2 files changed

+79
-8
lines changed

src/core/diff/strategies/__tests__/multi-search-replace.test.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,6 +2253,85 @@ function process() {
22532253
22542254
function two() {
22552255
return 2;
2256+
}`)
2257+
}
2258+
})
2259+
2260+
it("should fail when line range is far outside file bounds", async () => {
2261+
const originalContent = `
2262+
function one() {
2263+
return 1;
2264+
}
2265+
2266+
function two() {
2267+
return 2;
2268+
}
2269+
2270+
function three() {
2271+
return 3;
2272+
}
2273+
`.trim()
2274+
const diffContent = `test.ts
2275+
<<<<<<< SEARCH
2276+
:start_line:1000
2277+
-------
2278+
function three() {
2279+
return 3;
2280+
}
2281+
=======
2282+
function three() {
2283+
return "three";
2284+
}
2285+
>>>>>>> REPLACE`
2286+
2287+
// Line 1000 is way outside the bounds of the file (10 lines)
2288+
// and outside of any reasonable buffer range, so it should fail
2289+
const result = await strategy.applyDiff(originalContent, diffContent, 1000)
2290+
expect(result.success).toBe(false)
2291+
})
2292+
2293+
it("should find match when line range is slightly out of bounds but within buffer zone", async () => {
2294+
const originalContent = `
2295+
function one() {
2296+
return 1;
2297+
}
2298+
2299+
function two() {
2300+
return 2;
2301+
}
2302+
2303+
function three() {
2304+
return 3;
2305+
}
2306+
`.trim()
2307+
const diffContent = `test.ts
2308+
<<<<<<< SEARCH
2309+
:start_line:11
2310+
-------
2311+
function three() {
2312+
return 3;
2313+
}
2314+
=======
2315+
function three() {
2316+
return "three";
2317+
}
2318+
>>>>>>> REPLACE`
2319+
2320+
// File only has 10 lines, but we specify line 11
2321+
// It should still find the match since it's within the buffer zone (5 lines)
2322+
const result = await strategy.applyDiff(originalContent, diffContent, 11)
2323+
expect(result.success).toBe(true)
2324+
if (result.success) {
2325+
expect(result.content).toBe(`function one() {
2326+
return 1;
2327+
}
2328+
2329+
function two() {
2330+
return 2;
2331+
}
2332+
2333+
function three() {
2334+
return "three";
22562335
}`)
22572336
}
22582337
})

src/core/diff/strategies/multi-search-replace.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,14 +430,6 @@ Only use a single line of '=======' between search and replacement content, beca
430430
const searchLen = searchLines.length
431431
const exactEndIndex = exactStartIndex + searchLen - 1
432432

433-
if (exactStartIndex < 0 || exactEndIndex >= resultLines.length) {
434-
diffResults.push({
435-
success: false,
436-
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}`,
437-
})
438-
continue
439-
}
440-
441433
// Try exact match first
442434
const originalChunk = resultLines.slice(exactStartIndex, exactEndIndex + 1).join("\n")
443435
const similarity = getSimilarity(originalChunk, searchChunk)

0 commit comments

Comments
 (0)