Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { ClearedStreamTracker } from '../src/cleared-stream-tracker'
3import type { StreamChunk } from '@tanstack/ai/client'
4
5describe('ClearedStreamTracker', () => {
6 it.each([
7 { type: 'TEXT_MESSAGE_START', messageId: 'late-msg', role: 'assistant' },
8 { type: 'TEXT_MESSAGE_CHUNK', messageId: 'late-msg', delta: 'hi' },
9 { type: 'TOOL_CALL_CHUNK', toolCallId: 'tc-late', toolCallName: 'x' },
10 ])('ignores a runless $type from a run cleared mid-stream', (fields) => {
11 const tracker = new ClearedStreamTracker()
12 tracker.onRunStarted('run-1')
13 tracker.snapshotClear({
14 messages: [],
15 activeRunIds: new Set(['run-1']),
16 currentRunId: 'run-1',
17 })
18
19 expect(
20 tracker.shouldIgnoreChunk({
21 ...fields,
22 timestamp: Date.now(),
23 } as StreamChunk),
24 ).toBe(true)
25 })
26})