refactor(core): robust trimPreservingTrailingNewline and regression test (#18196)

This commit is contained in:
Adam Weidman
2026-02-03 10:51:09 -05:00
committed by GitHub
parent 19b1a74c99
commit dc37b190fa

View File

@@ -665,6 +665,30 @@ describe('editCorrector', () => {
expect(result.params.new_string).toBe('replaced\n\n');
expect(result.occurrences).toBe(1);
});
it('Test 7.2: should handle trailing newlines separated by spaces (regression fix)', async () => {
const currentContent = 'find me '; // Matches old_string initially
const originalParams = {
file_path: '/test/file.txt',
old_string: 'find me ', // Trailing space
new_string: 'replaced \n \n', // Trailing newlines with spaces
};
const result = await ensureCorrectEdit(
'/test/file.txt',
currentContent,
originalParams,
mockGeminiClientInstance,
mockBaseLlmClientInstance,
abortSignal,
false,
);
expect(result.params.old_string).toBe('find me');
// Should capture both newlines and join them, stripping the space between
expect(result.params.new_string).toBe('replaced\n\n');
expect(result.occurrences).toBe(1);
});
});
});