Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
test(bots): 对齐流式历史和成果卡的进度可见性断言
Dash7297756aeb62
diff --git a/apps/desktop/src/renderer/__tests__/botGeneratedArtifactsCard.test.tsx b/apps/desktop/src/renderer/__tests__/botGeneratedArtifactsCard.test.tsxindex 516bc7a1cf..1c0a4b01db 100644--- a/apps/desktop/src/renderer/__tests__/botGeneratedArtifactsCard.test.tsx+++ b/apps/desktop/src/renderer/__tests__/botGeneratedArtifactsCard.test.tsx@@ -192,7 +192,7 @@ describe('伙伴成果卡', () => {expect(screen.getByTestId('bot-generated-artifacts')).toBeTruthy();});- it.each(['stop', 'error', 'history'])('omits the preamble once a real generated file is visible: %s', async (ending) => {+ it.each(['stop', 'error', 'history'])('keeps progress when a file arrives without a final reply: %s', async (ending) => {let finish!: (value: FileStat) => void;const stat = vi.fn(() => new Promise<FileStat>((resolve) => { finish = resolve; }));window.electronAPI.fsBrowse.statPath = stat;@@ -201,24 +201,21 @@ describe('伙伴成果卡', () => {clientId: 'error', role: 'error', content: 'Generation interrupted',} });const view = render(<Conversation items={items} streaming={ending !== 'history'} />);- if (ending !== 'history') expect(screen.queryByTestId('main-prose')).toBeNull();+ expect(screen.getByTestId('main-prose').textContent).toBe('Generating the report');view.rerender(<Conversation items={items} />);- // Until stat confirms a visible delivery, a no-final turn keeps useful text.+ // A no-final turn keeps useful text before and after file confirmation.expect(screen.getByTestId('main-prose').textContent).toBe('Generating the report');await act(async () => finish({ kind: 'file', resolvedPath: '/bot/workspace/result.pdf', birthtimeMs: START + 100, mtimeMs: START + 100 }));expect(screen.getByText('result.pdf')).toBeTruthy();- expect(screen.queryByTestId('main-prose')).toBeNull();- // The turn is over, so its work process has left (cindy-bots-runtime.md); the preamble- // does not resurface anywhere.- expect(screen.queryByTestId('public-process')).toBeNull();- expect(screen.queryByText('Generating the report')).toBeNull();+ expect(screen.getByTestId('main-prose').textContent).toBe('Generating the report');+ expect(screen.getByTestId('public-process')).toBeTruthy();if (ending === 'error') expect(screen.getByTestId('error').textContent).toBe('Generation interrupted');expect(stat).toHaveBeenCalledTimes(1);- // Virtualized cards leaving the viewport must not revive the preamble.+ // Virtualized cards leaving the viewport must not change progress visibility.view.rerender(<Conversation items={items} mounted={false} />);- expect(screen.queryByTestId('main-prose')).toBeNull();+ expect(screen.getByTestId('main-prose')).toBeTruthy();view.rerender(<Conversation items={items} />);- expect(screen.queryByTestId('main-prose')).toBeNull();+ expect(screen.getByTestId('main-prose')).toBeTruthy();expect(stat).toHaveBeenCalledTimes(2);await act(async () => finish({ kind: 'missing', resolvedPath: '/bot/workspace/result.pdf' }));expect(screen.getByTestId('main-prose')).toBeTruthy();@@ -252,7 +249,7 @@ describe('伙伴成果卡', () => {it('does not use a previous candidate confirmation for a missing replacement', async () => {const view = render(<Conversation items={conversationFiles()} />);await screen.findByTestId('bot-generated-artifacts');- expect(screen.queryByTestId('main-prose')).toBeNull();+ expect(screen.getByTestId('main-prose')).toBeTruthy();window.electronAPI.fsBrowse.statPath = vi.fn(async (): Promise<FileStat> => ({ kind: 'missing', resolvedPath: '/bot/workspace/missing.pdf' }));await act(async () => { view.rerender(<Conversation items={conversationFiles('/bot/workspace/missing.pdf')} />); });expect(screen.queryByTestId('bot-generated-artifacts')).toBeNull();@@ -263,7 +260,7 @@ describe('伙伴成果卡', () => {const items = conversationFiles();const view = render(<Conversation items={items} />);await screen.findByTestId('bot-generated-artifacts');- expect(screen.queryByTestId('main-prose')).toBeNull();+ expect(screen.getByTestId('main-prose')).toBeTruthy();const stat = vi.fn(async (): Promise<FileStat> => ({ kind: 'missing', resolvedPath: '/bot/workspace/missing.pdf' }));window.electronAPI.fsBrowse.statPath = stat;const scope = { ...fileScope, sessionId: 'different-session', workingDir: '/different' };diff --git a/apps/desktop/src/renderer/__tests__/buildRenderItemsKeyStability.test.ts b/apps/desktop/src/renderer/__tests__/buildRenderItemsKeyStability.test.tsindex cebc44a30c..181353e57f 100644--- a/apps/desktop/src/renderer/__tests__/buildRenderItemsKeyStability.test.ts+++ b/apps/desktop/src/renderer/__tests__/buildRenderItemsKeyStability.test.ts@@ -127,7 +127,7 @@ it.each(['running', 'failed', 'cancelled', 'completed'])();describe('Bot 流式正文呈现', () => {- it('preserves consecutive Claude final text blocks only after the turn seal', () => {+ it('preserves Claude progress and folds it only after the turn seal', () => {let state = { ...EMPTY_SESSION_STATE, isStreaming: true, messages: [mkUser('u1')] };const visibleProse = () => simplifyBotRenderItems(groupWorkRuns(buildRenderItems(state.messages).items, state.isStreaming), state.isStreaming,@@ -149,9 +149,9 @@ describe('Bot 流式正文呈现', () => {data: { toolUseId: 'tool', result: 'ok' },});emitText('first', 'first');- expect(visibleProse()).toEqual([]);+ expect(visibleProse()).toEqual(['我查一下:', 'first']);emitText('second', 'second');- expect(visibleProse()).toEqual([]);+ expect(visibleProse()).toEqual(['我查一下:', 'first', 'second']);state = handleStreamEvent(state, {sessionId: 'claude-multi-block', type: 'text', persistId: 'second',data: { text: 'second', isFinal: true, isFullText: true },@@ -162,7 +162,7 @@ describe('Bot 流式正文呈现', () => {expect(visibleProse()).toEqual(['first', 'second']);});- it('运行中从首字隐藏未封口正文,工具留在普通工作组里', () => {+ it('运行中从首字显示未封口正文,工具留在普通工作组里', () => {const messages = [mkUser('u1'),mkTool('t1', 'Bash'),@@ -174,7 +174,7 @@ describe('Bot 流式正文呈现', () => {expect(visible.flatMap((item) => (item.type === 'message' ? [item.message.clientId] : [])),- ).toEqual(['u1']);+ ).toEqual(['u1', 'a1']);// 与普通任务同一个工作组:正文开始后,前面的动作段不再是运行中尾段。const groups = visible.filter((item) => item.type === 'work_group');expect(groups).toHaveLength(1);@@ -183,16 +183,17 @@ describe('Bot 流式正文呈现', () => {// Contracts: claude-code/translator assistant text blocks; pi/translator// message_end authoritative full text; codex/translator phase-marked deltas.- // A closed block is not a turn seal. Only a provider-marked final can stream early.+ // A closed block is not a turn seal: progress stays visible until the final seal.it.each(['claude-code', 'pi', 'codex'] as const)(- '%s: hides intermediate text and preserves provider final through the turn seal', (source) => {+ '%s: preserves progress and provider final through the turn seal', (source) => {let state = { ...EMPTY_SESSION_STATE, isStreaming: true, messages: [mkUser('u1')] };const project = () => simplifyBotRenderItems(groupWorkRuns(buildRenderItems(state.messages).items, state.isStreaming), state.isStreaming,);const visibleProse = () => project().flatMap((item) =>item.type === 'message' && item.message.role === 'assistant' ? [item.message.content] : []);- for (const [index, text] of ['我查一下:', '已找到线索,继续核实', '这是最终答复'].entries()) {+ const progressTexts = ['我查一下:', '已找到线索,继续核实', '这是最终答复'];+ for (const [index, text] of progressTexts.entries()) {const persistId = `answer-${index}`;const providerFinal = source === 'codex' && index === 2;state = handleStreamEvent(state, {@@ -201,13 +202,13 @@ describe('Bot 流式正文呈现', () => {...(source === 'codex' ? { agentMessageId: persistId, phase: index === 2 ? 'final_answer' : 'commentary' } : {}),},});- expect(visibleProse()).toEqual(providerFinal ? ['这是'] : []);+ expect(visibleProse()).toEqual([...progressTexts.slice(0, index), providerFinal ? '这是' : text]);if (providerFinal) {state = handleStreamEvent(state, {sessionId: 'bot-event-fixture', type: 'text', persistId,data: { text: '最终答复', isFinal: false, agentMessageId: persistId, phase: 'final_answer' },});- expect(visibleProse()).toEqual(['这是最终答复']);+ expect(visibleProse()).toEqual(progressTexts);}state = handleStreamEvent(state, {sessionId: 'bot-event-fixture', type: 'text', persistId,@@ -216,7 +217,7 @@ describe('Bot 流式正文呈现', () => {...(source === 'codex' ? { agentMessageId: persistId, phase: index === 2 ? 'final_answer' : 'commentary' } : {}),},});- expect(visibleProse()).toEqual(providerFinal ? ['这是最终答复'] : []);+ expect(visibleProse()).toEqual(progressTexts.slice(0, index + 1));if (index < 2) {state = handleStreamEvent(state, {sessionId: 'bot-event-fixture', type: 'tool_use', persistId: `tool-${index}`,@@ -226,7 +227,7 @@ describe('Bot 流式正文呈现', () => {sessionId: 'bot-event-fixture', type: 'tool_result', persistId: `result-${index}`,data: { toolUseId: `tool-${index}`, result: 'ok' },});- expect(visibleProse()).toEqual([]);+ expect(visibleProse()).toEqual(progressTexts.slice(0, index + 1));}}const streamingFinalKey = project().find(item => item.type === 'message'@@ -284,7 +285,7 @@ describe('Bot 流式正文呈现', () => {expect(visible.flatMap((item) => (item.type === 'message' ? [item.message.clientId] : [])),- ).toEqual(['u1', 'dm-sent', 'dm-received']);+ ).toEqual(['u1', 'dm-sent', 'dm-received', 'a1']);});});@@ -2434,7 +2435,7 @@ it('places the same Bot task card after its introduction and keeps it through stconst project = (streaming: boolean) => simplifyBotRenderItems(buildRenderItems(messages, undefined, undefined, { botSessionId: 'bot' }).items, streaming,).flatMap((item) => item.type === 'message' ? [item.message.clientId] : []);- expect(project(true)).toEqual(['start', 'intro', 'task-card']);+ expect(project(true)).toEqual(['start', 'intro', 'task-card', 'done']);expect(project(false).filter((id) => id !== 'finished-trigger')).toEqual(['start', 'intro', 'task-card', 'done']);});diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreAroundClientId.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreAroundClientId.test.tsindex 06c746b37e..99f43b35ad 100644--- a/apps/desktop/src/renderer/__tests__/makerChatStoreAroundClientId.test.ts+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreAroundClientId.test.ts@@ -126,8 +126,8 @@ describe('makerChatStore loadAroundMessageClientId', () => {const visible = simplifyBotRenderItems(groupWorkRuns(items, running), running).flatMap(item => item.type === 'message' && item.message.role === 'assistant' ? [item.message.content] : []);expect(visible).toContain('Explicit reply');- expect(visible).not.toContain('Working before');- expect(visible).not.toContain('Working after');+ expect(visible.includes('Working before')).toBe(running);+ expect(visible.includes('Working after')).toBe(running);});it('hydrates shorter authoritative tool_result content during around-message hydration', async () => {diff --git a/apps/desktop/src/renderer/__tests__/workGroupHistoryGap.test.ts b/apps/desktop/src/renderer/__tests__/workGroupHistoryGap.test.tsindex 17781b163b..650ab43bc9 100644--- a/apps/desktop/src/renderer/__tests__/workGroupHistoryGap.test.ts+++ b/apps/desktop/src/renderer/__tests__/workGroupHistoryGap.test.ts@@ -125,17 +125,17 @@ describe('历史窗口空洞 — 跨空洞不合并工作组', () => {expect(groupContains(beforeGap[0], 't2')).toBe(false);});- it.each([false, true])('伙伴投影保留空洞前答复,只有仍在运行的一轮露出工作过程,active=%s', (streaming) => {+ it.each([false, true])('伙伴投影保留空洞两侧的正文与独立工作组,active=%s', (streaming) => {const { items } = buildRenderItems(gapMessages());const projected = simplifyBotRenderItems(groupWorkRuns(items, streaming), streaming);const prose = projected.flatMap((item) => item.type === 'message' && item.message.role === 'assistant'? [item.message.clientId] : []);- expect(prose).toEqual(streaming ? ['a1'] : ['a1', 'a2']);+ expect(prose).toEqual(['a1', 'a2']);const groups = workGroups(projected);- // 空洞前那一轮已做完,工作过程随之离开(cindy-bots-runtime.md,2026-10-20「做完了,去掉」);- // 运行中的空洞后一轮仍露出自己的工作组,且不吞进空洞前的动作。- expect(groups.some((group) => groupContains(group, 't1'))).toBe(false);- expect(groups.some((group) => groupContains(group, 't2'))).toBe(streaming);+ // 完成的过程仍可展开,但不能跨空洞合并两轮动作。+ expect(groups.some((group) => groupContains(group, 't1'))).toBe(true);+ expect(groups.some((group) => groupContains(group, 't2'))).toBe(true);+ expect(groups.some((group) => groupContains(group, 't1') && groupContains(group, 't2'))).toBe(false);expect(projected.some(item => item.type === 'tool_segment')).toBe(false);});@@ -233,8 +233,8 @@ describe('历史窗口空洞 — 长任务不被误判', () => {const projected = simplifyBotRenderItems(grouped, false);expect(projected.flatMap((item) => item.type === 'message' && item.message.role === 'assistant'? [item.message.clientId] : [])).toEqual(['a1']);- // 伙伴的这一轮已做完:工作过程整块离开,进度文字也不外露,只留最终答复。- expect(workGroups(projected)).toEqual([]);+ // 完成后进度文字进入可展开过程,最终答复留在外面。+ expect(workGroups(projected)).toEqual(groups);});});