test: remove duplicate diff cases and repair audit fixtures (#33503)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-10-25 03:42:35 -07:00
committed by GitHub
co-authored by OrcaWin
parent 751591f911
commit a5e948dc3d
4 changed files with 18 additions and 51 deletions
@@ -27,10 +27,14 @@ async function load(source, sourcefile = 'src/shared/native-chat-tool-fold.ts')
setup(builder) {
builder.onResolve({ filter: /^\./ }, (args) => {
const target = path.resolve(args.resolveDir, args.path)
for (const name of ['native-chat-tool-pairs', 'native-chat-folded-tool-results']) {
for (const [name, directory] of [
['native-chat-tool-pairs', 'src/shared/native-chat/tools'],
['native-chat-folded-tool-results', 'src/shared/native-chat/tools'],
['native-chat-provider-frame-summary', 'src/shared/native-chat']
]) {
const previous = path.join(root, 'src/shared', name)
if (target === previous || target === `${previous}.ts`) {
return { path: path.join(root, 'src/shared/native-chat/tools', `${name}.ts`) }
return { path: path.join(root, directory, `${name}.ts`) }
}
}
return undefined
@@ -76,7 +76,7 @@ describe('pairToolBlocks', () => {
expect(pairs[1]).toEqual({ call: call2, result: result2 })
})
it('retains the last result while bounding rendered pairs', () => {
it('keeps the first completed pairs at the rendering limit', () => {
const blocks = Array.from({ length: 20 }, (_unused, index) => [
{ type: 'tool-call' as const, name: 'Bash', input: { index } },
{ type: 'tool-result' as const, output: String(index) }
@@ -1,54 +1,7 @@
import { describe, expect, it } from 'vitest'
import {
diffFromText,
diffFromToolCall
} from '../../../src/shared/native-chat/tools/native-chat-diff'
describe('diffFromToolCall', () => {
it('builds del/add lines from an Edit tool call', () => {
const lines = diffFromToolCall('Edit', {
file_path: 'src/a.ts',
old_string: 'const a = 1\nconst b = 2',
new_string: 'const a = 10'
})
expect(lines).toEqual([
{ kind: 'meta', text: 'src/a.ts' },
{ kind: 'del', text: 'const a = 1' },
{ kind: 'del', text: 'const b = 2' },
{ kind: 'add', text: 'const a = 10' }
])
})
it('returns null for non-edit tools', () => {
expect(diffFromToolCall('Bash', { command: 'ls' })).toBeNull()
})
})
import { diffFromText } from '../../../src/shared/native-chat/tools/native-chat-diff'
describe('diffFromText', () => {
it('parses unified diff lines with colours', () => {
const lines = diffFromText('@@ -1,2 +1,2 @@\n context\n-old\n+new')
expect(lines).toEqual([
{ kind: 'meta', text: '@@ -1,2 +1,2 @@' },
{ kind: 'context', text: ' context' },
{ kind: 'del', text: 'old' },
{ kind: 'add', text: 'new' }
])
})
it('does not treat ordinary prose as a diff', () => {
expect(diffFromText('Here is a list:\n- one bullet\nthat is all')).toBeNull()
})
it('counts a removed -- comment line despite the --- prefix collision', () => {
const lines = diffFromText('@@ -1,2 +1,2 @@\n ctx\n---sql comment\n+new')
expect(lines).toEqual([
{ kind: 'meta', text: '@@ -1,2 +1,2 @@' },
{ kind: 'context', text: ' ctx' },
{ kind: 'del', text: '--sql comment' },
{ kind: 'add', text: 'new' }
])
})
it('caps large diffs before creating render rows', () => {
const text = Array.from(
{ length: 1_000 },
@@ -90,7 +90,16 @@ vi.stubGlobal(
}
)
const mountedRenderers = new Set<ReactTestRenderer>()
afterEach(() => {
act(() => {
for (const renderer of mountedRenderers) {
renderer.unmount()
}
})
mountedRenderers.clear()
scrollable.node = null
vi.useRealTimers()
vi.restoreAllMocks()
})
@@ -285,6 +294,7 @@ function mount(
let renderer!: ReactTestRenderer
act(() => {
renderer = create(h('div'))
mountedRenderers.add(renderer)
})
const scroller = page(() => renderer.toJSON())
scrollable.node = scroller