|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +// |
| 3 | +// Consumer-side guarantee: with the partial-markdown version chat depends on, a |
| 4 | +// streaming table header renders as a `table` immediately — before the delimiter |
| 5 | +// row and while it is buffered awaiting the delimiter — instead of blanking out. |
| 6 | +// Guards against a dependency downgrade reintroducing the table blank/flash. |
| 7 | +import { describe, it, expect } from 'vitest'; |
| 8 | +import { createPartialMarkdownParser, materialize } from '@cacheplane/partial-markdown'; |
| 9 | + |
| 10 | +function topType(p: ReturnType<typeof createPartialMarkdownParser>): string | null { |
| 11 | + const doc = materialize(p.root) as { children?: Array<{ type: string }> } | null; |
| 12 | + return doc?.children?.[0]?.type ?? null; |
| 13 | +} |
| 14 | + |
| 15 | +describe('libs/chat consumes streaming table headers', () => { |
| 16 | + it('shows a table header immediately, before and during the delimiter wait', () => { |
| 17 | + const p = createPartialMarkdownParser(); |
| 18 | + p.push('| Name | Age |'); // first row, still on the open line (no newline) |
| 19 | + expect(topType(p)).toBe('table'); // pre-0.5.2: null (header buffered/blank) |
| 20 | + p.push('\n'); // header committed; delimiter not yet streamed |
| 21 | + expect(topType(p)).toBe('table'); // pre-0.5.2: null (the blank gap) |
| 22 | + p.push('| --- | --- |\n| Ada | 36 |\n'); // delimiter + body commit |
| 23 | + const doc = materialize(p.root) as any; |
| 24 | + expect(doc.children).toHaveLength(1); |
| 25 | + expect(doc.children[0].type).toBe('table'); |
| 26 | + expect(doc.children[0].children.length).toBeGreaterThanOrEqual(2); // header + body |
| 27 | + }); |
| 28 | +}); |
0 commit comments