test(editor): #855 收尾——补 read 与 opBaseline 两条判别性守护
独立验证节点列出的两处测试盲区,逐条补判别性用例(12 → 14 例): - **「只认 write/edit」这半个判据此前无守护**(变异:把命中判据放行 `kind === 'read'` 后原有 12 例全绿)。新增「B: 模型 read 本文件零重读」: 读出的是最近一次「模型读这个文件」的调用,字节没变,任何重读都是多余。 变异复验:放行 `read` → 仅该例红(`expected 2 to be 1`),其余 13 例绿。 - **`EditorHost` 的 `opBaseline` 守卫此前未被判别**(变异:放松守卫后原有 12 例全绿)。新增「I: 重新定向到刚被 touch 的路径不重复读」:同一 tab 切到刚被模型写过的路径时,它自己的加载就是那次写入的新鲜读数,不得再重读 重挂(否则滚动位置在字节相同时被丢掉)。变异复验:只留 `null` 判断、不再 按路径比对基线 → 仅该例红(`expected 2 to be 1`),其余 13 例(含原有 12 例)绿 → **保留守卫**,不是「只省一次多余重读」。 附注:把守卫连同消费行一起删掉是更狠的变异,会在这条例上变成重载自旋 (隔离运行 15s 超时),全量跑还会因该自旋污染后续用例——两个变异都只用于 取证,源码已逐字节还原(`git diff --exit-code` 干净)。
This commit is contained in:
1 parent
1748c7b0d4
commit
dc04efaabf
1 file changed
+74
@@ -78,6 +78,24 @@ function editPair(seq: number, path: string, callId = `e${seq}`): SidebarSession
|
||||
]
|
||||
}
|
||||
|
||||
/** One settled, successful `read` call pair (a READ touches no bytes). */
|
||||
function readPair(seq: number, path: string, callId = `r${seq}`): SidebarSessionEvent[] {
|
||||
return [
|
||||
{
|
||||
type: 'tool/call',
|
||||
seq,
|
||||
time: seq,
|
||||
data: { name: 'read', callId, arguments: JSON.stringify({ file_path: path }) },
|
||||
},
|
||||
{
|
||||
type: 'tool/result',
|
||||
seq: seq + 1,
|
||||
time: seq + 1,
|
||||
data: { message: { role: 'tool', source: { kind: 'tool', callId }, content: [{ type: 'text', text: 'ok' }] } },
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
/** The delta one poll answers with, and the cursor it reports. */
|
||||
function delta(events: SidebarSessionEvent[], lastSeq: number): { events: SidebarSessionEvent[]; lastSeq: number } {
|
||||
return { events, lastSeq }
|
||||
@@ -339,6 +357,28 @@ describe('editor preview auto-refresh (#855)', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('B: a settled READ of this very file refreshes nothing (a read changes no bytes)', async () => {
|
||||
const { ctx, tabOf } = harness('session-b-read')
|
||||
const view = mount(ctx, 'session-b-read', tabOf('/tmp/a.ts'))
|
||||
try {
|
||||
await settle()
|
||||
expect(reads()).toBe(1)
|
||||
|
||||
// The model reads the file it is already showing: the most common tool
|
||||
// call of a session, and one that leaves the bytes exactly as they were.
|
||||
// Only a mutation that lets `kind === 'read'` through the stream's filter
|
||||
// can make this reload (see the CHANGELOG's mutation list).
|
||||
changesOps.mockResolvedValue(delta(readPair(11, '/tmp/a.ts'), 12))
|
||||
await tick(3)
|
||||
|
||||
expect(reads()).toBe(1)
|
||||
expect(draftOf(view.container)).toBe('body-1')
|
||||
} finally {
|
||||
view.unmount()
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('C: a dirty draft is never overwritten by the model writing the file', async () => {
|
||||
const { ctx, tabOf } = harness('session-c')
|
||||
const view = mount(ctx, 'session-c', tabOf('/tmp/a.ts'))
|
||||
@@ -481,6 +521,40 @@ describe('editor preview auto-refresh (#855)', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('I: retargeting a tab onto a path touched a moment ago does not re-read it', async () => {
|
||||
const { ctx, tabOf } = harness('session-i')
|
||||
const tabA = tabOf('/tmp/a.ts')
|
||||
const tabB = tabOf('/tmp/b.ts')
|
||||
const view = mount(ctx, 'session-i', tabA)
|
||||
try {
|
||||
await settle()
|
||||
expect(readsOf('/tmp/a.ts')).toBe(1)
|
||||
|
||||
// The model writes B while this tab shows A. The touch is PUBLISHED now
|
||||
// (revision 1) and matches nothing yet.
|
||||
changesOps.mockResolvedValue(delta(writePair(11, '/tmp/b.ts'), 12))
|
||||
await tick(1)
|
||||
expect(readsOf('/tmp/b.ts')).toBe(0)
|
||||
|
||||
// The user retargets this very tab onto B (merged mode's in-place switch):
|
||||
// its own load reads the file ONCE, and that read is already the fresh
|
||||
// content of the write above...
|
||||
view.rerender(editorElement(ctx, 'session-i', tabB, true))
|
||||
await settle()
|
||||
expect(readsOf('/tmp/b.ts')).toBe(1)
|
||||
|
||||
// ...so the touch published BEFORE the retarget must not reload it again
|
||||
// (opBaseline's per-path revision: without it this is a second read and a
|
||||
// remount that throws away scroll position for identical bytes).
|
||||
await tick(3)
|
||||
expect(readsOf('/tmp/b.ts')).toBe(1)
|
||||
expect(draftOf(view.container)).toBe('body-2')
|
||||
} finally {
|
||||
view.unmount()
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it('G: an open edit session is left alone (its caret must not jump)', async () => {
|
||||
const store = createSidebarStore()
|
||||
const service = createBetterSidebarService(store)
|
||||
|
||||
Reference in new issue
Block a user