Repository navigation
Expand file tree
/
Copy pathfile-panel-utils.test.ts
More file actions
40 lines (33 loc) · 1.76 KB
/
Copy pathfile-panel-utils.test.ts
File metadata and controls
40 lines (33 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { expect, test } from 'bun:test'
import { computeOptimisticUpdatePreview, findActiveFileStream } from './file-panel-utils'
function makeToolHandles(toolHandles: Record<string, any>) {
return toolHandles
}
test('findActiveFileStream returns latest active stream for matching fileWrite path', () => {
const toolHandles = makeToolHandles({
older: { toolKey: 'fileWrite', state: { phase: 'streaming', path: 'a.ts', body: 'one', charCount: 3, lineCount: 1 } },
newer: { toolKey: 'fileWrite', state: { phase: 'executing', path: 'a.ts', body: 'two', charCount: 3, lineCount: 1 } },
other: { toolKey: 'fileWrite', state: { phase: 'streaming', path: 'b.ts', body: 'three', charCount: 5, lineCount: 1 } },
})
const match = findActiveFileStream(toolHandles, 'a.ts')
expect(match?.toolCallId).toBe('newer')
expect(match?.state).toMatchObject({ body: 'two' })
})
test('findActiveFileStream matches fileEdit streaming for exact path only', () => {
const toolHandles = makeToolHandles({
wrongPath: { toolKey: 'fileEdit', state: { phase: 'streaming', path: 'src/a.ts', oldText: '', newText: '', replaceAll: false, diffs: [] } },
rightPath: { toolKey: 'fileEdit', state: { phase: 'streaming', path: '/tmp/work/src/a.ts', oldText: '', newText: '', replaceAll: false, diffs: [] } },
})
expect(findActiveFileStream(toolHandles, 'src/a.ts')?.toolCallId).toBe('wrongPath')
expect(findActiveFileStream(toolHandles, '/tmp/work/src/a.ts')?.toolCallId).toBe('rightPath')
})
test('computeOptimisticUpdatePreview applies replaceAll edits for live edit preview', () => {
const preview = computeOptimisticUpdatePreview(
'hello x\nhello x\n',
'hello',
'hi',
true,
)
expect(preview?.content).toBe('hi x\nhi x\n')
expect(preview?.changedRanges.length).toBe(2)
})