|
4 | 4 | mockModule, |
5 | 5 | } from '@codebuff/common/testing/mock-modules' |
6 | 6 | import { cleanMarkdownCodeBlock } from '@codebuff/common/util/file' |
7 | | -import { applyPatch } from '@codebuff/common/util/patch' |
| 7 | +import { applyPatch } from 'diff' |
8 | 8 | import { afterAll, beforeAll, describe, expect, it } from 'bun:test' |
9 | 9 |
|
10 | 10 | import { processFileBlock } from '../process-file-block' |
@@ -164,87 +164,6 @@ describe('processFileBlockModule', () => { |
164 | 164 | } |
165 | 165 | }) |
166 | 166 |
|
167 | | - it('should handle multiple diff blocks in a single file', async () => { |
168 | | - const oldContent = ` |
169 | | -function add(a: number, b: number) { |
170 | | - return a + b; |
171 | | -} |
172 | | -
|
173 | | -function multiply(a: number, b: number) { |
174 | | - return a * b; |
175 | | -} |
176 | | -
|
177 | | -function divide(a: number, b: number) { |
178 | | - return a / b; |
179 | | -} |
180 | | -`.trim() |
181 | | - |
182 | | - const newContent = |
183 | | - `<<<<<<< SEARCH |
184 | | -function add(a: number, b: number) { |
185 | | - return a + b; |
186 | | -} |
187 | | -======= |
188 | | -function add(a: number, b: number) { |
189 | | - if (typeof a !== 'number' || typeof b !== 'number') { |
190 | | - throw new Error('Invalid arguments'); |
191 | | - } |
192 | | - return a + b; |
193 | | -} |
194 | | ->>>>>>> REPLACE` + |
195 | | - ` |
196 | | - |
197 | | -` + |
198 | | - `<<<<<<< SEARCH |
199 | | -function multiply(a: number, b: number) { |
200 | | - return a * b; |
201 | | -} |
202 | | -======= |
203 | | -function multiply(a: number, b: number) { |
204 | | - if (typeof a !== 'number' || typeof b !== 'number') { |
205 | | - throw new Error('Invalid arguments'); |
206 | | - } |
207 | | - return a * b; |
208 | | -} |
209 | | ->>>>>>> REPLACE |
210 | | -
|
211 | | -function divide(a: number, b: number) { |
212 | | - return a / b; |
213 | | -}` |
214 | | - |
215 | | - const result = await processFileBlock( |
216 | | - 'test.ts', |
217 | | - undefined, |
218 | | - Promise.resolve(oldContent), |
219 | | - newContent, |
220 | | - [], |
221 | | - '', |
222 | | - undefined, |
223 | | - 'clientSessionId', |
224 | | - 'fingerprintId', |
225 | | - 'userInputId', |
226 | | - TEST_USER_ID, |
227 | | - ) |
228 | | - |
229 | | - expect(result).not.toBeNull() |
230 | | - if ('error' in result) { |
231 | | - throw new Error(`Expected success but got error: ${result.error}`) |
232 | | - } |
233 | | - expect(result.path).toBe('test.ts') |
234 | | - expect(result.patch).toBeDefined() |
235 | | - if (result.patch) { |
236 | | - const updatedContent = applyPatch(oldContent, result.patch) |
237 | | - expect(updatedContent).toContain( |
238 | | - "if (typeof a !== 'number' || typeof b !== 'number')", |
239 | | - ) |
240 | | - expect( |
241 | | - updatedContent.match( |
242 | | - /if \(typeof a !== 'number' \|\| typeof b !== 'number'\)/g, |
243 | | - )?.length, |
244 | | - ).toBe(2) |
245 | | - } |
246 | | - }) |
247 | | - |
248 | 167 | it('should preserve Windows line endings in patch and content', async () => { |
249 | 168 | const oldContent = 'const x = 1;\r\nconst y = 2;\r\n' |
250 | 169 | const newContent = 'const x = 1;\r\nconst z = 3;\r\n' |
|
0 commit comments