Measured in headless Chromium against the real transcript, scroll hook and CSS. - Status highlight: transform-only sweep (compositor) instead of background-position under background-clip:text, which repainted the label on the main thread every frame; labels share one sweep phase so a reworded step no longer restarts it. - Step timeline above the answer: folds to its summary line once the answer has text, and folds away over 180ms when the run ends instead of being dropped between two frames (the answer jumped up 164-260px); a half-written heading is no longer a step. - Streamed markdown: unclosed ** is bold as written, a table is held until its delimiter row, bare markers and the half-typed 判断依据 heading wait. - Answers render as memoised blocks, streaming and settled alike: a frame parses only the tail, settling does not rebuild the answer's DOM. - The report layer (from the first H2) is written out while streaming; it used to stay empty until the run ended. - Follow mode scrolls in the resize callback, before paint; each new line used to be painted once below its place. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
105 lines
6.2 KiB
TypeScript
105 lines
6.2 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import test from "node:test";
|
|
import { createElement } from "react";
|
|
import { renderToString } from "react-dom/server";
|
|
|
|
import { ConsultationRunTimeline, timelineSummaryLabel, visibleTimelineRows } from "../src/components/consultation-run-timeline.tsx";
|
|
import { latestAssistantView, type ChatMessage } from "../src/lib/chat-message-view.ts";
|
|
|
|
const read = (path: string) => readFileSync(new URL(`../${path}`, import.meta.url), "utf8");
|
|
const transcriptSource = read("src/components/chat-transcript.tsx");
|
|
const timelineSource = read("src/components/consultation-run-timeline.tsx");
|
|
const messageRowSource = read("src/components/chat-message-row.tsx");
|
|
const globalStyles = read("src/app/globals.css");
|
|
|
|
test("the trailing assistant reply keeps one view identity from first token to settlement", () => {
|
|
const history: ChatMessage[] = [{ role: "user", text: "问题" }];
|
|
const streaming = latestAssistantView(history, true, "完整答案");
|
|
const settled = latestAssistantView([...history, { role: "assistant", text: "完整答案" }], false, "");
|
|
assert.ok(streaming && settled);
|
|
assert.equal(streaming.view.renderKey, settled.view.renderKey);
|
|
assert.equal(streaming.view.state, "streaming");
|
|
assert.equal(settled.view.state, "settled");
|
|
assert.equal(streaming.views.length, 2);
|
|
assert.equal(settled.views.length, 2);
|
|
|
|
// A trailing user message means nothing is pending and nothing is latest.
|
|
assert.equal(latestAssistantView(history, false, ""), undefined);
|
|
// A settled reply still in the loading gap is rendered once, not duplicated.
|
|
const lagging = latestAssistantView([...history, { role: "assistant", text: "完整答案" }], true, "完整答案");
|
|
assert.equal(lagging?.view.state, "settled");
|
|
});
|
|
|
|
test("one component renders the latest reply in both states; nothing remounts on settle", () => {
|
|
assert.match(transcriptSource, /export const LatestAssistantEntry = memo\(/);
|
|
assert.match(transcriptSource, /<LatestAssistantEntry\s+key=\{latest\.view\.renderKey\}/);
|
|
assert.match(transcriptSource, /excludeLatestAssistant/);
|
|
assert.match(transcriptSource, /noteLatestEntryMount\(\)/);
|
|
assert.doesNotMatch(transcriptSource, /StreamingMessageEntry|SettledMessageEntry/);
|
|
// Exactly one place in the split transcript renders the trailing reply.
|
|
assert.equal(transcriptSource.match(/<LatestAssistantEntry\b/g)?.length, 1);
|
|
});
|
|
|
|
test("a message enters once, through GSAP at the documented 160ms, never twice", () => {
|
|
assert.match(messageRowSource, /duration: 0\.16/);
|
|
assert.doesNotMatch(globalStyles, /message-enter/);
|
|
const messageRule = globalStyles.match(/\n\.message \{[^}]*\}/)?.[0] ?? "";
|
|
assert.ok(messageRule, "the .message rule exists");
|
|
assert.doesNotMatch(messageRule, /animation/);
|
|
});
|
|
|
|
test("the timeline collapses in place with a 180ms height transition and honours the reader's toggle", () => {
|
|
assert.doesNotMatch(timelineSource, /key=\{live/);
|
|
// 原值: /const open = userOpen \?\? live/
|
|
// 新值: 回答开始有字以后,步骤收成一行摘要
|
|
// 原因: 2026-11-16 流式输出抖动——步骤在回答上方,每多一步整段回答下移一行
|
|
assert.match(timelineSource, /const open = userOpen \?\? \(live && !answering\)/);
|
|
assert.match(timelineSource, /aria-expanded=\{open\}/);
|
|
assert.match(timelineSource, /inert=\{open \? undefined : true\}/);
|
|
// 原值:className="consultation-run-timeline__summary"
|
|
// 新值:同一类名仍在,后面可以再接压掉按钮默认高度和换行的类
|
|
// 原因:K7 把这一行换成组件库 Button。类名、展开和 180ms 高度过渡不变
|
|
assert.match(timelineSource, /className="consultation-run-timeline__summary(?: [^"]*)?"/);
|
|
// 原值: timelineSource 里直接写 agent-activity-status__text
|
|
// 新值: 走 ShimmerText(同一个类名由它加)
|
|
// 原因: 2026-11-16 状态动画卡顿——高光改成只动 transform
|
|
assert.match(timelineSource, /<ShimmerText/);
|
|
assert.match(globalStyles, /\.consultation-run-timeline__body-wrap \{[^}]*grid-template-rows: 0fr/);
|
|
assert.match(globalStyles, /\.consultation-run-timeline__body-wrap \{[^}]*transition: grid-template-rows 180ms var\(--ease-out\)/);
|
|
assert.match(globalStyles, /\.consultation-run-timeline\.is-open > \.consultation-run-timeline__body-wrap \{[^}]*grid-template-rows: 1fr/);
|
|
assert.match(globalStyles, /\.consultation-run-timeline__summary-label \{[^}]*animation: agent-activity-status-in 120ms/);
|
|
assert.match(globalStyles, /@media \(prefers-reduced-motion: reduce\) \{\s*\.consultation-run-timeline__summary-label,\s*\.consultation-run-timeline__body-wrap,/);
|
|
|
|
assert.equal(timelineSummaryLabel([], true), "正在分析");
|
|
assert.equal(timelineSummaryLabel([{ id: "method", kind: "method", status: "done", label: "已加载方法" }], false), "已完成 1 步");
|
|
|
|
const live = renderToString(createElement(ConsultationRunTimeline, { rows: [], live: true }));
|
|
assert.match(live, /aria-expanded="true"/);
|
|
// 原值: /正在处理…/
|
|
// 新值: /收到,正在看你的问题…/
|
|
// 原因: TASK-consult-first-frame-and-pacing-20260928 D1 / BUG-1074:排队行从发送那一帧起可见,文案与服务端首帧一致
|
|
assert.match(live, /收到,正在看你的问题…/);
|
|
assert.doesNotMatch(live, /正在处理…/);
|
|
assert.match(live, /inline-spinner/);
|
|
const liveAfterTool = renderToString(createElement(ConsultationRunTimeline, {
|
|
rows: [{ id: "read", kind: "calculate", status: "done", label: "读取校正记录" }],
|
|
live: true,
|
|
}));
|
|
assert.match(liveAfterTool, /读取校正记录/);
|
|
assert.match(liveAfterTool, /正在分析…/);
|
|
assert.match(liveAfterTool, /inline-spinner/);
|
|
assert.deepEqual(
|
|
visibleTimelineRows([{ id: "read", kind: "calculate", status: "done", label: "读取校正记录" }], true).map((row) => row.status),
|
|
["done", "live"],
|
|
);
|
|
const settled = renderToString(createElement(ConsultationRunTimeline, {
|
|
rows: [{ id: "method", kind: "method", status: "done", label: "已加载方法" }],
|
|
live: false,
|
|
}));
|
|
assert.match(settled, /aria-expanded="false"/);
|
|
assert.match(settled, /inert=""/);
|
|
assert.match(settled, /已完成 1 步/);
|
|
assert.equal(renderToString(createElement(ConsultationRunTimeline, { rows: [], live: false })), "");
|
|
});
|