Files
Agent-System-Frontend/test/send.test.ts
weichenandCursor e4ca2acfa6 Show a run as active as soon as the send returns
Why: Stamping the user message with the run id made the live bubble look settled, and the composer stayed on 发送 until the next reconcile.
Evidence: npx tsc -b passed. vitest 75, including hasSettledReply and mergeStartedRun. On a mock server the button became 停止/排队 within 250ms and the reply grew while the run was open.
Impact: Composer, live bubble, and agent tracker only. A stored user message no longer hides the stream. Reopening replays from resumeSeq when the server sends it.
Refs: Dev fix/live-run-visibility
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-03 15:21:28 +00:00

38 lines
1.4 KiB
TypeScript

// 发送后的运行态投影:把刚启动的 run 合进列表,并用事件上的服务端时间。
import { describe, expect, it } from 'vitest'
import type { Run } from '../src/contracts'
import { activeRun, eventTime, mergeStartedRun } from '../src/store'
function run(id: string, status: Run['status'], over: Partial<Run> = {}): Run {
return {
id, conversationId: 'c', projectId: 'p', kind: 'conversation', status,
createdAt: '2026-10-03T00:00:00Z', ...over,
}
}
describe('mergeStartedRun', () => {
it('adds a pending run so the composer treats the conversation as active', () => {
const merged = mergeStartedRun([], run('r1', 'pending'))
expect(activeRun(merged)?.id).toBe('r1')
})
it('keeps an existing record when the same id arrives again', () => {
const settled = run('r1', 'completed', { phase: 'done' })
const merged = mergeStartedRun([settled], run('r1', 'pending'))
expect(merged).toHaveLength(1)
expect(merged[0].status).toBe('completed')
expect(activeRun(merged)).toBeUndefined()
})
})
describe('eventTime', () => {
it('parses the server timestamp', () => {
expect(eventTime({ ts: '2026-10-03T14:50:25.073Z' }, 0)).toBe(Date.parse('2026-10-03T14:50:25.073Z'))
})
it('falls back when the timestamp is missing or unparseable', () => {
expect(eventTime({}, 42)).toBe(42)
expect(eventTime({ ts: 'not-a-time' }, 42)).toBe(42)
})
})