feat: preserve assistant progress previews

This commit is contained in:
inman
2026-09-01 11:46:04 +08:00
parent 38f85f6b5e
commit 8d878ebd14
4 changed files with 150 additions and 41 deletions

View File

@@ -303,8 +303,8 @@ describe('CodingConversationTimeline', () => {
expect(within(process).getByText('处理中')).toBeVisible();
const thinking = screen.getByLabelText('思考过程');
const thinkingPreview = within(thinking).getByTestId('process-progress-preview');
expect(thinkingPreview).toHaveTextContent('最后确认本轮只读取、不修改项目内容。');
expect(thinkingPreview).toHaveAttribute('data-progress-tail', 'true');
expect(thinkingPreview).toHaveTextContent('先确认 project.json 项目边界,再读取配置。');
expect(thinkingPreview).toHaveAttribute('data-progress-origin', 'head');
expect(thinkingPreview).toHaveAttribute('data-progress-alignment', 'left');
expect(thinkingPreview).toHaveAttribute('data-progress-update-motion', 'none');
expect(thinkingPreview).not.toHaveAttribute('data-roll-revision');
@@ -315,7 +315,7 @@ describe('CodingConversationTimeline', () => {
expect(thinkingPreview).toHaveClass('text-left');
expect(thinkingPreview.firstElementChild).toHaveClass('inline-flex');
expect(thinkingPreview.firstElementChild).not.toHaveClass('absolute', 'right-0');
expect(thinking).not.toHaveTextContent('先确认 project.json 项目边界,再读取配置。');
expect(thinking).not.toHaveTextContent('最后确认本轮只读取、不修改项目内容。');
expect(thinking).toHaveAttribute('data-collapsed-lines', '1');
expect(thinking).toHaveAttribute('data-expanded', 'false');
expect(thinking).toHaveAttribute('data-streaming', 'true');
@@ -340,19 +340,19 @@ describe('CodingConversationTimeline', () => {
expect(processNote).toHaveAttribute('data-collapsed-lines', '1');
expect(processNote).toHaveClass('max-h-[1.65em]', 'overflow-hidden');
const commentaryPreview = within(processNote).getByTestId('process-progress-preview');
expect(commentaryPreview).toHaveTextContent('让我看看 index.html 当前的实际内容:');
expect(commentaryPreview).toHaveTextContent('好的,两件事都办:先再试一次产品素材服务,然后整体优化手机移动端体验。');
expect(commentaryPreview).toHaveAttribute('data-progress-origin', 'head');
expect(commentaryPreview).toHaveClass('text-foreground');
expect(commentaryPreview).not.toHaveClass('text-muted-foreground/75');
expect(within(commentaryPreview).getByText('index.html')).toHaveClass('text-foreground');
expect(within(commentaryPreview).getByText('index.html')).not.toHaveClass('text-muted-foreground');
expect(commentaryPreview).toHaveAttribute('data-progress-shimmer', 'false');
expect(commentaryPreview).toHaveAttribute('data-progress-update-motion', 'none');
expect(commentaryPreview).not.toHaveAttribute('data-roll-revision');
expect(commentaryPreview.querySelector('.streaming-progress-shimmer')).not.toBeInTheDocument();
expect(commentaryPreview.querySelector('.streaming-progress-roll')).not.toBeInTheDocument();
expect(processNote).not.toHaveTextContent('好的,两件事都办');
expect(processNote).not.toHaveTextContent('让我看看 index.html 当前的实际内容:');
fireEvent.click(screen.getByRole('button', { name: '展开过程说明' }));
expect(screen.getByText(/好的,两件事都办/).closest('[data-testid="coding-process-group"]')).toBe(process);
expect(within(processNote).getByText('index.html').tagName).toBe('CODE');
expect(within(processNote).getByTestId('assistant-markdown')).toHaveClass('text-foreground');
expect(within(processNote).getByTestId('assistant-markdown')).not.toHaveClass('text-muted-foreground');
fireEvent.click(screen.getByRole('button', { name: '收起过程说明' }));
@@ -362,8 +362,8 @@ describe('CodingConversationTimeline', () => {
expect(tool.querySelector('summary')).toHaveClass('h-8', 'overflow-hidden');
const toolPreview = within(tool).getByTestId('tool-progress-preview');
const initialToolRevision = toolPreview.getAttribute('data-roll-revision');
expect(toolPreview).toHaveTextContent('正在读取入口文件…');
expect(toolPreview).toHaveAttribute('data-progress-tail', 'true');
expect(toolPreview).toHaveTextContent('已定位项目根目录');
expect(toolPreview).toHaveAttribute('data-progress-origin', 'head');
expect(toolPreview).toHaveAttribute('data-progress-alignment', 'left');
expect(toolPreview).toHaveAttribute('data-progress-update-motion', 'roll');
expect(toolPreview).toHaveAttribute('data-progress-shimmer', 'true');
@@ -387,21 +387,21 @@ describe('CodingConversationTimeline', () => {
}));
expect(within(thinking).getByTestId('process-progress-preview'))
.toHaveTextContent('正在确认最新入口 main.ts。');
.toHaveTextContent('先确认 project.json 项目边界,再读取配置。');
expect(within(thinking).getByTestId('process-progress-preview'))
.not.toHaveAttribute('data-roll-revision');
expect(within(thinking).getByTestId('process-progress-preview')
.querySelector('.streaming-progress-roll')).not.toBeInTheDocument();
expect(within(processNote).getByTestId('process-progress-preview'))
.toHaveTextContent('正在整理最新结论。');
.toHaveTextContent('好的,两件事都办:先再试一次产品素材服务,然后整体优化手机移动端体验。');
expect(within(processNote).getByTestId('process-progress-preview'))
.toHaveClass('text-foreground');
expect(within(processNote).getByTestId('process-progress-preview'))
.toHaveAttribute('data-progress-shimmer', 'false');
expect(within(tool).getByTestId('tool-progress-preview'))
.toHaveTextContent('正在追踪最新工具输出main.ts 已读取。');
expect(within(tool).getByTestId('tool-progress-preview'))
.not.toHaveAttribute('data-roll-revision', initialToolRevision);
.toHaveTextContent('已定位项目根目录');
expect(within(tool).getByTestId('tool-progress-preview').getAttribute('data-roll-revision'))
.toBe(initialToolRevision);
fireEvent.click(tool.querySelector('summary')!);
await waitFor(() => expect(tool).toHaveAttribute('open'));
@@ -447,7 +447,12 @@ describe('CodingConversationTimeline', () => {
stopReason: 'tool-use' as const,
blocks: [
{ kind: 'thinking' as const, id: 'thinking-completed-process', text: '先读取配置,再核对入口。', status: 'streaming' as const },
{ kind: 'text' as const, id: 'preamble-completed-process', text: '我先检查项目配置。', status: 'complete' as const },
{
kind: 'text' as const,
id: 'preamble-completed-process',
text: '我先检查项目配置。\n\n现在开始核对 `index.html` 入口文件。',
status: 'complete' as const,
},
],
},
{
@@ -502,6 +507,29 @@ describe('CodingConversationTimeline', () => {
.toHaveAttribute('data-progress-shimmer', 'false');
expect(within(settledThinking).getByTestId('process-progress-preview')
.querySelector('.streaming-progress-shimmer')).not.toBeInTheDocument();
const completedCommentary = document.querySelector(
'[data-node-id="message-work-completed-process"][data-node-kind="assistant-commentary"]',
)!;
const completedCommentaryViewport = within(completedCommentary as HTMLElement)
.getByLabelText('过程说明');
expect(completedCommentaryViewport).toHaveAttribute('data-streaming', 'false');
expect(completedCommentaryViewport).toHaveAttribute('data-expanded', 'false');
expect(within(completedCommentaryViewport).getByTestId('process-progress-preview'))
.toHaveTextContent('我先检查项目配置。');
expect(within(completedCommentaryViewport).getByTestId('process-progress-preview'))
.toHaveAttribute('data-progress-origin', 'head');
expect(completedCommentaryViewport).not.toHaveTextContent('现在开始核对 index.html 入口文件。');
const completedCommentaryToggle = within(completedCommentary as HTMLElement)
.getByRole('button', { name: '展开过程说明' });
expect(completedCommentaryToggle).toHaveAttribute('aria-expanded', 'false');
fireEvent.click(completedCommentaryToggle);
expect(completedCommentaryViewport).toHaveAttribute('data-expanded', 'true');
expect(completedCommentaryViewport).toHaveTextContent('我先检查项目配置。');
expect(completedCommentaryViewport).toHaveTextContent('现在开始核对 index.html 入口文件。');
expect(within(completedCommentaryViewport).getByText('index.html').tagName).toBe('CODE');
fireEvent.click(within(completedCommentary as HTMLElement)
.getByRole('button', { name: '收起过程说明' }));
expect(completedCommentaryViewport).toHaveAttribute('data-expanded', 'false');
const tool = screen.getByText('读取项目配置').closest('details')!;
expect(tool).not.toHaveAttribute('open');
fireEvent.click(tool.querySelector('summary')!);