import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import { test } from 'vitest'; /** * The reader-in-chat wiring is mostly declarative (slot id, priority, child * seats, hidden official row), so the cheap regression guard is reading the * entry modules. Executable ledger behaviour lives in `chat-view-seat.test.ts`; * this file guards the two files' agreed contract. */ const source = await readFile(new URL('../src/client/reader-plugin.tsx', import.meta.url), 'utf8'); const seat = await readFile(new URL('../src/client/chat-view-seat.ts', import.meta.url), 'utf8'); const blocks = await readFile(new URL('../src/client/Blocks.tsx', import.meta.url), 'utf8'); const readerCss = await readFile(new URL('../src/client/Reader.module.css', import.meta.url), 'utf8'); const markdown = await readFile(new URL('../src/client/markdown/MarkdownText.tsx', import.meta.url), 'utf8'); test('the reader occupies the built-in 对话 View at a shadowing priority', () => { assert.match(source, /name: 'conversation\.view'/u); assert.match(source, /id: CHAT_VIEW_ID/u); assert.match(source, /priority: CHAT_VIEW_PRIORITY/u); assert.match(source, /label: \(\) => '对话'/u); assert.doesNotMatch(source, /id: 'reader'/u, 'the old 阅读 tab must not come back'); assert.doesNotMatch(source, /installReaderEntry/u, 'no forced View switch on open'); }); test('the official ChatView row stays live; only its tab id is hidden', () => { assert.match(source, /retireHostedChatView/u); assert.match(source, /yield retireHostedChatView\(/u); assert.match(source, /yield installOfficialSlots\(ctx\)/u); // The primary path only clears the View id; removing a live ledger row would // skip the official disposer's releaseEntry and leak conversation.chat.flow / // the Chat store on ui-chat teardown. The splice exists only as a bounded // runtime fallback for hosts where that id change does not hide the tab. assert.match(seat, /entry\.options\.id = undefined/u); assert.match(seat, /Runtime fallback/u); assert.match(seat, /rows\.splice\(index, 1\)/u); assert.match(seat, /row\.index = index/u); assert.match(seat, /ACTIVE\.set\(ledger, restore\)/u); }); test('the reader bubble keeps its fit-content width', () => { // The slot-row stretch rule must not match our own `.user` bubble, or short // messages render as a full-width band. assert.match(readerCss, /\.userCluster > \[data-slot\] > :not\(\.user\)/u); assert.doesNotMatch(readerCss, /\.userCluster > \[data-slot\] > \*/u); }); test('reasoning bodies render through compact Markdown', () => { assert.match(blocks, /data-reader-text-kind="reasoning"/u); assert.match(blocks, /variant="compact"/u); assert.match(markdown, /variant\?: 'body' \| 'compact'/u); });