test(changes-ops): 对齐空窗长轮询的契约断言(#885 收尾)
- tests/unbounded-caches.spec.ts:基线拉取不再传 0 而是不传游标(0 会丢掉 seq 0 的真实事件), 并断言 primed 之后第 4 参 wait=true、基线 false; - tests/changes-ops-route.spec.ts:用例名/注释英文,补一条 PTC 事件对穿透路由的断言,subCallId 用 ToolCallId; - api.ts / ChangesTab.tsx / ops-stream.ts 的说明改回英文行文(行为不变)。
This commit is contained in:
1 parent
172ca849dd
commit
6586c08bbc
2 files changed
+26
-13
No files matched your search
@@ -47,7 +47,14 @@ describe('changes.ops waiting form', () => {
|
||||
const session = runtime.sessions.create()
|
||||
const changesOps = createChangesOpsApi(runtime as Context)
|
||||
try {
|
||||
const at = () => ({ turn: 0, step: 0, rootCallId: ToolCallId('root'), parentCallId: ToolCallId('root'), subCallId: 'root:ptc:1', name: 'write' })
|
||||
const at = () => ({
|
||||
turn: 0,
|
||||
step: 0,
|
||||
rootCallId: ToolCallId('root'),
|
||||
parentCallId: ToolCallId('root'),
|
||||
subCallId: ToolCallId('root:ptc:1'),
|
||||
name: 'write',
|
||||
})
|
||||
session.append('tool/ptc-dispatch-start', { ...at(), arguments: { file_path: 'notes.txt', content: 'x' } })
|
||||
session.append('tool/ptc-dispatch', {
|
||||
...at(),
|
||||
|
||||
@@ -200,11 +200,13 @@ describe('ops-stream session records', () => {
|
||||
|
||||
it('keeps a parked session\'s cursor so the delta it missed is still published', async () => {
|
||||
vi.useFakeTimers()
|
||||
// `afterSeq` is the stream's own cursor: pull #1 is the BASELINE (an
|
||||
// unrelated, long-settled write, published to nobody), the pull after the
|
||||
// parked period carries the write the model did meanwhile.
|
||||
changesOps.mockImplementation(async (_scope: unknown, afterSeq: number) => (
|
||||
afterSeq === 0
|
||||
// The stream's own cursor rides `afterSeq`: pull #1 is the BASELINE (no
|
||||
// cursor yet — an absent `afterSeq` is what "from the very first event"
|
||||
// means, so a seq-0 event is not dropped; an unrelated, long-settled write
|
||||
// is published to nobody), and the pull after the parked period carries the
|
||||
// write the model did meanwhile.
|
||||
changesOps.mockImplementation(async (_scope: unknown, afterSeq?: number) => (
|
||||
afterSeq === undefined
|
||||
? {
|
||||
events: [call(1, 'write', 'w1', { file_path: '/w/old.ts', content: 'x' }), result(2, 'w1', 'wrote')],
|
||||
lastSeq: 2,
|
||||
@@ -214,6 +216,7 @@ describe('ops-stream session records', () => {
|
||||
|
||||
const parked = await mountProbe('rejoin')
|
||||
expect(changesOps).toHaveBeenCalledTimes(1)
|
||||
expect(changesOps.mock.calls.at(-1)?.[3]).toBe(false)
|
||||
// The baseline published nothing (the historical write is not a touch)…
|
||||
expect(latestStream?.revision).toBe(0)
|
||||
|
||||
@@ -224,10 +227,12 @@ describe('ops-stream session records', () => {
|
||||
expect(latestStream?.revision).toBe(0)
|
||||
|
||||
// Coming back resumes from the persisted cursor and folds what was missed:
|
||||
// the file the model rewrote while the tab was parked IS a touch.
|
||||
// the file the model rewrote while the tab was parked IS a touch, and the
|
||||
// primed stream asks the host to WAIT for the next event.
|
||||
parked.rerender(createElement(StreamProbe, { sessionId: 'rejoin', enabled: true }))
|
||||
await act(async () => { await Promise.resolve(); await Promise.resolve() })
|
||||
expect(changesOps.mock.calls.at(-1)?.[1]).toBe(2)
|
||||
expect(changesOps.mock.calls.at(-1)?.[3]).toBe(true)
|
||||
expect(latestStream?.revision).toBe(1)
|
||||
expect(latestStream?.touched.get('/w/missed.ts')?.kind).toBe('write')
|
||||
parked.unmount()
|
||||
@@ -235,8 +240,8 @@ describe('ops-stream session records', () => {
|
||||
|
||||
it('re-baselines a session evicted past the record cap', async () => {
|
||||
vi.useFakeTimers()
|
||||
changesOps.mockImplementation(async (_scope: unknown, afterSeq: number) => (
|
||||
afterSeq === 0
|
||||
changesOps.mockImplementation(async (_scope: unknown, afterSeq?: number) => (
|
||||
afterSeq === undefined
|
||||
? {
|
||||
events: [call(1, 'write', 'w1', { file_path: '/w/old.ts', content: 'x' }), result(2, 'w1', 'wrote')],
|
||||
lastSeq: 2,
|
||||
@@ -256,11 +261,12 @@ describe('ops-stream session records', () => {
|
||||
}
|
||||
|
||||
// The evicted session re-joins as a FRESH stream: its first pull is a
|
||||
// baseline again, so the delta it missed is deliberately not published —
|
||||
// the same state a page reload starts from. Inside the cap the same
|
||||
// scenario DOES publish (the case above).
|
||||
// baseline again (no cursor, no wait), so the delta it missed is
|
||||
// deliberately not published — the same state a page reload starts from.
|
||||
// Inside the cap the same scenario DOES publish (the case above).
|
||||
await mountProbe('cap-victim')
|
||||
expect(changesOps.mock.calls.at(-1)?.[1]).toBe(0)
|
||||
expect(changesOps.mock.calls.at(-1)?.[1]).toBeUndefined()
|
||||
expect(changesOps.mock.calls.at(-1)?.[3]).toBe(false)
|
||||
expect(latestStream?.revision).toBe(0)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user