6356d7b549
The rectification surface had its own activity pipeline: a trace panel with a 20px canvas orb clipped inside a 14px marker, a list that never collapsed, a second receipt disclosure under every reply, an inline failure banner and a staged label while regenerating. Its trace and receipt are now projected onto ConsultationTimelineRow so both surfaces render one ConsultationRunTimeline with one live marker and one settled summary; receipt methods become source chips on the last completed row. The unreachable sections-report/step-tree path, the trace panel, the receipt component and the thinking-orbs dependency are removed. The server-side drop of rectification thinking deltas is untouched. BUG-476 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JUei7K13cYxLHE3Axe4A45
93 lines
5.3 KiB
TypeScript
93 lines
5.3 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import test from "node:test";
|
|
|
|
import { plainParagraphs } from "../src/components/chat-message-paragraphs.ts";
|
|
|
|
const readProjectFile = (path: string) => readFileSync(new URL(`../${path}`, import.meta.url), "utf8");
|
|
const contentSource = readProjectFile("src/components/chat-message-content.tsx");
|
|
const markdownViewSource = readProjectFile("src/components/chat-markdown-view.tsx");
|
|
const messageRowSource = readProjectFile("src/components/chat-message-row.tsx");
|
|
const activitySource = readProjectFile("src/components/agent-activity-status.tsx");
|
|
const prefetchSource = readProjectFile("src/components/chat-chunk-prefetch.ts");
|
|
|
|
test("the markdown pipeline is split out of the initial chat bundle", () => {
|
|
// Given: the chat surface statically imports the message content component.
|
|
assert.doesNotMatch(contentSource, /^import .*"react-markdown"/m);
|
|
assert.doesNotMatch(contentSource, /^import .*"remark-gfm"/m);
|
|
|
|
// Then: the renderer only arrives through a dynamic import.
|
|
assert.match(contentSource, /import\("@\/components\/chat-markdown-view"\)/);
|
|
assert.match(contentSource, /markdownRenderer = module\.renderChatMarkdown/);
|
|
assert.match(markdownViewSource, /^import ReactMarkdown, \{ type Components \} from "react-markdown";$/m);
|
|
assert.match(markdownViewSource, /^import remarkGfm from "remark-gfm";$/m);
|
|
assert.match(markdownViewSource, /remarkPlugins=\{\[remarkGfm\]\}/);
|
|
assert.match(markdownViewSource, /skipHtml/);
|
|
});
|
|
|
|
test("the pre-markdown fallback renders prose but never raw markdown", () => {
|
|
// Given: a reply that carries markdown syntax.
|
|
assert.equal(plainParagraphs("**重点**在这里"), null);
|
|
assert.equal(plainParagraphs("## 阶段判断"), null);
|
|
assert.equal(plainParagraphs("- 第一点"), null);
|
|
assert.equal(plainParagraphs("1. 第一点"), null);
|
|
assert.equal(plainParagraphs("| 宫位 | 行星 |"), null);
|
|
assert.equal(plainParagraphs("`Vimshottari`"), null);
|
|
assert.equal(plainParagraphs("参见 https://example.com"), null);
|
|
assert.equal(plainParagraphs("> 引用"), null);
|
|
assert.equal(plainParagraphs("[链接](/x)"), null);
|
|
assert.equal(plainParagraphs("行尾软换行 \n下一行"), null);
|
|
|
|
// Then: only plain prose takes the fallback path, split exactly like CommonMark.
|
|
assert.deepEqual(plainParagraphs("第一段。\n\n第二段。"), ["第一段。", "第二段。"]);
|
|
assert.deepEqual(plainParagraphs("一行\n下一行"), ["一行\n下一行"]);
|
|
assert.deepEqual(plainParagraphs("只有一段。"), ["只有一段。"]);
|
|
|
|
// And: one stable wrapper serves both paths, so no styling or caret is lost on upgrade.
|
|
assert.equal(contentSource.match(/className="message-markdown"/g)?.length, 1);
|
|
assert.match(contentSource, /className="message-answer"/);
|
|
assert.match(contentSource, /TechniqueAuditDisclosure/);
|
|
assert.match(contentSource, /<p key=\{index\}>\{paragraph\}<\/p>/);
|
|
assert.match(contentSource, /plainParagraphs\(spoken\) \?\? \[\]/);
|
|
});
|
|
|
|
test("gsap loads on demand while keeping the reduced-motion gate", () => {
|
|
// Given: the animation engine is no longer part of the static import graph.
|
|
assert.doesNotMatch(messageRowSource, /^import .*from "gsap"/m);
|
|
assert.doesNotMatch(messageRowSource, /@gsap\/react/);
|
|
assert.match(messageRowSource, /import\("gsap"\)/);
|
|
|
|
// Then: reduced-motion users never request it, and the tween contract is unchanged.
|
|
assert.match(messageRowSource, /prefers-reduced-motion: reduce/);
|
|
assert.match(messageRowSource, /prefers-reduced-motion: no-preference/);
|
|
assert.match(messageRowSource, /gsap\.matchMedia\(\)/);
|
|
// Former value: `duration: 0\.18`. DESIGN.md §6 gives the message entrance 160ms and the CSS
|
|
// keyframe that used to run alongside was 160ms too; 0.18 was the GSAP copy drifting.
|
|
assert.match(messageRowSource, /duration: 0\.16/);
|
|
assert.match(messageRowSource, /clearProps: "opacity,transform,visibility"/);
|
|
|
|
// And: a row that mounts before the chunk lands renders unanimated instead of flashing.
|
|
assert.match(messageRowSource, /if \(!gsapCore\) \{/);
|
|
assert.match(messageRowSource, /useEntryEffect\(\(\) => \{/);
|
|
});
|
|
|
|
test("the live marker is the shared inline spinner, with no on-demand orb chunk", () => {
|
|
// Former test: "the thinking orb loads on demand behind a same-size placeholder". The canvas
|
|
// orb was a second live-marker vocabulary beside the timeline's InlineSpinner, undocumented in
|
|
// DESIGN.md §9, and clipped inside the rectification surface's 14px marker (BUG-476). Removed.
|
|
assert.doesNotMatch(activitySource, /thinking-orbs|ThinkingOrb|next\/dynamic/);
|
|
assert.match(activitySource, /<InlineSpinner size=\{12\} \/>/);
|
|
|
|
// And: the live region and the decorative marking survive.
|
|
assert.match(activitySource, /role="status"/);
|
|
assert.match(activitySource, /className="agent-thinking-marker is-live-marker" aria-hidden="true"/);
|
|
});
|
|
|
|
test("deferred chat chunks are requested during idle time after first paint", () => {
|
|
assert.match(prefetchSource, /if \(typeof window === "undefined"\) return;/);
|
|
assert.match(prefetchSource, /window\.requestIdleCallback\(request, \{ timeout: 2_000 \}\)/);
|
|
assert.match(prefetchSource, /window\.setTimeout\(request, 300\)/);
|
|
assert.match(contentSource, /prefetchOnIdle\(loadMarkdownRenderer\)/);
|
|
assert.match(messageRowSource, /if \(motionPreferred\(\)\) prefetchOnIdle\(loadGsap\)/);
|
|
});
|