Files
Agent-System-Frontend/test/send.test.ts
T
agent-exec-transport b496c4476d
governance / governance (pull_request) Successful in 22s
ci / test-and-build (pull_request) Successful in 43s
agent-exec transport 5cc70be566de95cb35d2d8bdfb05b392/b0fcba7575e5
2026-10-20 03:54:20 +00:00

44 lines
1.7 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 normal ISO server timestamps', () => {
const iso = '2026-10-03T14:50:25.073Z'
expect(eventTime({ ts: iso }, 0)).toBe(Date.parse(iso))
expect(eventTime({ ts: iso }, 42)).toBe(Date.parse(iso))
})
it('falls back to now when timestamp is missing, invalid or zero-time 0001-01-01T00:00:00Z', () => {
expect(eventTime({}, 42)).toBe(42)
expect(eventTime({ ts: undefined }, 42)).toBe(42)
expect(eventTime({ ts: '' }, 42)).toBe(42)
expect(eventTime({ ts: 'not-a-time' }, 42)).toBe(42)
expect(eventTime({ ts: '0001-01-01T00:00:00Z' }, 42)).toBe(42)
expect(eventTime({ ts: '1970-01-01T00:00:00Z' }, 42)).toBe(42)
})
})