Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
test(remote): 通过生产入口验证历史文件变更卡片
Dashfcc8909ee4ba
diff --git a/apps/desktop/src/renderer/__tests__/historyTurnChangesProjection.test.ts b/apps/desktop/src/renderer/__tests__/historyTurnChangesProjection.test.tsindex 9263360abc..8bfb731c40 100644--- a/apps/desktop/src/renderer/__tests__/historyTurnChangesProjection.test.ts+++ b/apps/desktop/src/renderer/__tests__/historyTurnChangesProjection.test.ts@@ -1,29 +1,12 @@-import { readFileSync } from 'node:fs';-import { resolve } from 'node:path';-import ts from 'typescript';import { describe, expect, it } from 'vitest';-import { buildRenderItems, groupWorkRuns } from '../components/chat/MessageStream';-import type { ChatMessage } from '../lib/makerChatStore';+import { HistoryViewController } from '@cindy/maker-shared/message-window';+import { buildMessageStreamRenderProjection } from '../components/chat/MessageStream';+import type { ChatMessage, HistoryChatMessage } from '../lib/makerChatStore';import type { TurnChangeSetSummary } from '../../shared/turnChangeSet';-// Exercise the actual history-view build callback, rather than supplying the-// missing option directly to buildRenderItems (which already has unit coverage).-const source = ts.createSourceFile('MessageStream.tsx', readFileSync(- resolve(__dirname, '../components/chat/MessageStream.tsx'), 'utf8',-), ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);-let callback: ts.ArrowFunction | undefined;-function visit(node: ts.Node) {- if (ts.isCallExpression(node) && node.expression.getText(source) === 'renderHistoryView') {- const options = node.arguments[0] as ts.ObjectLiteralExpression;- callback = (options.properties.find(p => ts.isPropertyAssignment(p)- && p.name.getText(source) === 'build') as ts.PropertyAssignment).initializer as ts.ArrowFunction;- }- ts.forEachChild(node, visit);-}-visit(source);-const code = ts.transpileModule(`return (${callback!.getText(source)});`, {- compilerOptions: { target: ts.ScriptTarget.ES2022 },-}).outputText;+// Unit: use MessageStream's production entry so history selection and option+// forwarding are included. Extracting only the callback lost its renderOptions+// binding after refactoring; keep all card content/order/page-boundary assertions.const changeSet: TurnChangeSetSummary = {id: 'changes-1', sessionId: 'session-1', anchorClientId: 'user-1', provider: 'codex',providerTurnId: 'turn-1', cwd: 'C:/fixture', state: 'complete', workspaceState: 'applied',@@ -32,46 +15,57 @@ const changeSet: TurnChangeSetSummary = {oldPath: null, status: 'modified' as const, additions: 1, deletions: 1 })),fileCount: 5, additions: 5, deletions: 5,};-function render(rows: ChatMessage[], streaming = false) {- const bindings = { buildRenderItems, groupWorkRuns, results: new Map(),- taskUpdates: undefined, ghostCardSnapshot: undefined, workingDir: 'C:/fixture',- turnChangeSets: [changeSet], simplifiedBotConversation: false, sessionId: 'session-1',- markdownImageTargetCacheRef: { current: new Map() }, cindyMakeSessionId: undefined,- cindyMakeCompletionInComposer: undefined, subagentRunStatuses: undefined,- isSessionStreaming: streaming };- const build = new Function(...Object.keys(bindings), code)(...Object.values(bindings)) as- (rows: ChatMessage[], streaming: boolean) => ReturnType<typeof buildRenderItems>['items'];- return build(rows, streaming);+async function render(rows: ChatMessage[], streaming = false) {+ const messages: HistoryChatMessage[] = rows.map((row, index) => ({+ ...row, id: row.clientId, createdAt: new Date(index * 1000).toISOString(),+ }));+ const view = new HistoryViewController<HistoryChatMessage>({+ page: async () => ({ version: 1, items: [{ type: 'messages', key: 'page', messages }],+ hasMore: false, nextCursor: null }),+ details: async () => ({ version: 1, messages: [], hasMore: false, nextCursor: null }),+ expanded: async () => undefined,+ });+ try {+ await view.refresh();+ return buildMessageStreamRenderProjection({+ historyView: view, historySnapshot: view.getSnapshot(), historyLiveMessages: [],+ isSessionStreaming: streaming, generatedFilesItemCache: new Map(),+ renderOptions: { workingDir: 'C:/fixture', turnChangeSets: [changeSet] },+ buildRaw: () => { throw new Error('Ready history must not build raw messages'); },+ }).items;+ } finally {+ view.setActive(false);+ }}describe('history-view changed files cards', () => {- it('keeps the completed five-file card before the next streaming turn', () => {+ it('keeps the completed five-file card before the next streaming turn', async () => {const rows: ChatMessage[] = [{ clientId: 'user-1', role: 'user', content: 'Edit five files' },{ clientId: 'answer-1', role: 'assistant', content: 'Done' },{ clientId: 'user-2', role: 'user', content: 'Continue' },{ clientId: 'answer-2', role: 'assistant', content: 'Streaming', isStreaming: true },];- const items = render(rows, true);+ const items = await render(rows, true);const cards = items.filter(item => item.type === 'turn_changes');expect(cards).toHaveLength(1);expect(cards[0].changeSet.files).toHaveLength(5);expect(items.map(item => item.key)).toEqual(['msg-user-1', 'msg-answer-1', 'turnchanges-changes-1', 'msg-user-2', 'msg-answer-2',]);- expect(render(rows.slice(0, 2)).filter(item => item.type === 'turn_changes')).toHaveLength(1);+ expect((await render(rows.slice(0, 2))).filter(item => item.type === 'turn_changes')).toHaveLength(1);});- it('keeps the review card after the reviewed turn and its changed-files card', () => {+ it('keeps the review card after the reviewed turn and its changed-files card', async () => {const rows: ChatMessage[] = [{ clientId: 'user-1', role: 'user', content: 'Edit five files' },{ clientId: 'answer-1', role: 'assistant', content: 'Done' },{ clientId: 'review:run-1', role: 'assistant', content: 'P1 finding', systemCardType: 'review' },];- expect(render(rows).map(item => item.key)).toEqual([+ expect((await render(rows)).map(item => item.key)).toEqual(['msg-user-1', 'msg-answer-1', 'turnchanges-changes-1', 'msg-review:run-1',]);});- it('does not pull a changed-files card from a turn outside the loaded history', () => {- expect(render([{ clientId: 'user-2', role: 'user', content: 'Another page' }])+ it('does not pull a changed-files card from a turn outside the loaded history', async () => {+ expect((await render([{ clientId: 'user-2', role: 'user', content: 'Another page' }])).filter(item => item.type === 'turn_changes')).toEqual([]);});});