Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ describe('processStrReplace', () => {
}
})

it('says why when the old and new strings are identical', async () => {
it('does not rewrite CRLF when the old and new strings are identical', async () => {
const line = 'import kotlinx.coroutines.flow.Flow'
const result = await processStrReplace({
path: 'test.kt',
replacements: [{ oldString: line, newString: line, allowMultiple: false }],
initialContentPromise: Promise.resolve(`${line}\n`),
initialContentPromise: Promise.resolve(`${line}\r\n`),
logger,
})

Expand Down
11 changes: 7 additions & 4 deletions packages/agent-runtime/src/process-str-replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ export async function processStrReplace(params: {
)
}

currentContent = currentContent.replaceAll('\n', lineEnding)

// If no successful replacements occurred, return error
if (initialContent === currentContent) {
// Line-ending normalization alone is not a successful replacement.
if (
normalizeLineEndings({ str: initialContent }) ===
normalizeLineEndings({ str: currentContent })
) {
logger.debug(
{
path,
Expand All @@ -117,6 +118,8 @@ export async function processStrReplace(params: {
}
}

currentContent = currentContent.replaceAll('\n', lineEnding)

let patch = createBoundedPatch(path, initialContent, currentContent)
const lines = patch.split('\n')
const hunkStartIndex = lines.findIndex((line) => line.startsWith('@@'))
Expand Down
Loading