Skip to content

Commit 5e4366b

Browse files
committed
Delete custom patch impl. Move change file to npm-app. Add 'diff' dependency for sdk.
1 parent 04ba7f2 commit 5e4366b

File tree

8 files changed

+28
-393
lines changed

8 files changed

+28
-393
lines changed

backend/src/__tests__/process-file-block.test.ts

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
mockModule,
55
} from '@codebuff/common/testing/mock-modules'
66
import { cleanMarkdownCodeBlock } from '@codebuff/common/util/file'
7-
import { applyPatch } from '@codebuff/common/util/patch'
7+
import { applyPatch } from 'diff'
88
import { afterAll, beforeAll, describe, expect, it } from 'bun:test'
99

1010
import { processFileBlock } from '../process-file-block'
@@ -164,87 +164,6 @@ describe('processFileBlockModule', () => {
164164
}
165165
})
166166

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-
248167
it('should preserve Windows line endings in patch and content', async () => {
249168
const oldContent = 'const x = 1;\r\nconst y = 2;\r\n'
250169
const newContent = 'const x = 1;\r\nconst z = 3;\r\n'

bun.lock

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)