Skip to content

Commit cc7f80c

Browse files
committed
Add test case for diff processor handling of multi-line replacements and fix hunk application logic
1 parent bed3830 commit cc7f80c

5 files changed

Lines changed: 80 additions & 8 deletions

File tree

apps/editor/src/commands/apply-chat-response-command/utils/edit-formats/diffs/diff-processor.spec.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ describe('diff-processor', () => {
5757
expect(result).toBe(expected)
5858
})
5959

60+
it('applies diff with failing test case correctly', async () => {
61+
const test_case = 'failing'
62+
const original = load_test_case_file('', test_case, 'original.txt')
63+
const diff = load_test_case_file('', test_case, 'diff.txt')
64+
65+
expect(() => {
66+
apply_diff({
67+
original_code: original,
68+
diff_patch: diff
69+
})
70+
}).toThrow(/Failed to apply \d+ hunk\(s\)/)
71+
})
72+
6073
it('applies diff with generic test case correctly', async () => {
6174
const test_case = 'generic-1'
6275
const original = load_test_case_file('', test_case, 'original.txt')
@@ -141,17 +154,18 @@ describe('diff-processor', () => {
141154
expect(result).toBe(expected)
142155
})
143156

144-
it('applies diff with failing test case correctly', async () => {
145-
const test_case = 'failing'
157+
it('applies diff with generic test case 7 correctly', async () => {
158+
const test_case = 'generic-7'
146159
const original = load_test_case_file('', test_case, 'original.txt')
147160
const diff = load_test_case_file('', test_case, 'diff.txt')
161+
const expected = load_test_case_file('', test_case, 'expected.txt')
148162

149-
expect(() => {
150-
apply_diff({
151-
original_code: original,
152-
diff_patch: diff
153-
})
154-
}).toThrow(/Failed to apply \d+ hunk\(s\)/)
163+
const result = apply_diff({
164+
original_code: original,
165+
diff_patch: diff
166+
})
167+
168+
expect(result).toBe(expected)
155169
})
156170
})
157171
})

apps/editor/src/commands/apply-chat-response-command/utils/edit-formats/diffs/diff-processor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ export const apply_diff = (params: {
134134
}
135135

136136
if (line.startsWith('-') || line.startsWith('~')) {
137+
if (inside_replace_block && line.startsWith('-')) {
138+
push_block()
139+
}
140+
137141
inside_replace_block = false
138142

139143
if (line.startsWith('-')) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--- a/apps/editor/src/views/i18n/settings.ts
2+
+++ b/apps/editor/src/views/i18n/settings.ts
3+
@@ -1116,13 +1116,13 @@
4+
- de: 'Integrieren Sie Änderungen aus fehlerhaften Antworten.',
5+
+ de: 'Integrieren Sie Änderungen aus fehlerhaft formatierten Antworten.',
6+
- es: 'Integra cambios de respuestas mal formateadas.',
7+
+ es: 'Integra los cambios de respuestas con formato incorrecto.',
8+
- fr: 'Intégrez les modifications à partir de réponses mal formatées.',
9+
+ fr: 'Intégrez les modifications des réponses mal formatées.',
10+
- ru: 'Интеграция изменений из некорректных ответов.',
11+
+ ru: 'Интегрируйте изменения из некорректно сформированных ответов.',
12+
- it: 'Integra modifiche da risposte mal formattate.',
13+
+ it: 'Integra le modifiche da risposte malformate.',
14+
@@ -1138,7 +1138,7 @@
15+
- hu: 'Hibás válaszokból származó változások integrálása.',
16+
+ hu: 'Hibásan formázott válaszokból származó változások integrálása.',
17+
- bg: 'Интегриране на промени от грешни отговори.'
18+
+ bg: 'Интегриране на промени от неправилно форматирани отговори.'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'settings.intelligent-update.subtitle': {
2+
en: 'Integrate changes from malformed responses.',
3+
pl: 'Integruj zmiany z nieprawidłowych bloków kodu.',
4+
'zh-cn': '集成格式错误响应中的更改。',
5+
ja: '不正な形式の応答からの変更を統合します。',
6+
'zh-tw': '整合格式錯誤回應中的變更。',
7+
de: 'Integrieren Sie Änderungen aus fehlerhaft formatierten Antworten.',
8+
es: 'Integra los cambios de respuestas con formato incorrecto.',
9+
fr: 'Intégrez les modifications des réponses mal formatées.',
10+
'pt-br': 'Integre alterações de respostas mal formatadas.',
11+
ru: 'Интегрируйте изменения из некорректно сформированных ответов.',
12+
ko: '잘못된 형식의 응답에서 변경 사항을 통합합니다.',
13+
it: 'Integra le modifiche da risposte malformate.',
14+
tr: 'Hatalı biçimlendirilmiş yanıtlardan gelen değişiklikleri entegre edin.',
15+
cs: 'Integrovat změny z chybně formátovaných odpovědí.',
16+
hu: 'Hibásan formázott válaszokból származó változások integrálása.',
17+
bg: 'Интегриране на промени от неправилно форматирани отговори.'
18+
},
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'settings.intelligent-update.subtitle': {
2+
en: 'Integrate changes from malformed responses.',
3+
pl: 'Integruj zmiany z nieprawidłowych bloków kodu.',
4+
'zh-cn': '集成格式错误响应中的更改。',
5+
ja: '不正な形式の応答からの変更を統合します。',
6+
'zh-tw': '整合格式錯誤回應中的變更。',
7+
de: 'Integrieren Sie Änderungen aus fehlerhaften Antworten.',
8+
es: 'Integra cambios de respuestas mal formateadas.',
9+
fr: 'Intégrez les modifications à partir de réponses mal formatées.',
10+
'pt-br': 'Integre alterações de respostas mal formatadas.',
11+
ru: 'Интеграция изменений из некорректных ответов.',
12+
ko: '잘못된 형식의 응답에서 변경 사항을 통합합니다.',
13+
it: 'Integra modifiche da risposte mal formattate.',
14+
tr: 'Hatalı biçimlendirilmiş yanıtlardan gelen değişiklikleri entegre edin.',
15+
cs: 'Integrovat změny z chybně formátovaných odpovědí.',
16+
hu: 'Hibás válaszokból származó változások integrálása.',
17+
bg: 'Интегриране на промени от грешни отговори.'
18+
},

0 commit comments

Comments
 (0)