Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
test(desktop): align Cindy Make inline recovery regression (#4886)
Chris Zhangeb138ba90a11
diff --git a/apps/desktop/src/renderer/__tests__/cindyMakeInlineEntry.test.ts b/apps/desktop/src/renderer/__tests__/cindyMakeInlineEntry.test.tsindex 4edeb36161..3038ea0c27 100644--- a/apps/desktop/src/renderer/__tests__/cindyMakeInlineEntry.test.ts+++ b/apps/desktop/src/renderer/__tests__/cindyMakeInlineEntry.test.ts@@ -1,15 +1,36 @@-import { sharedTaskHostPeer } from '@cindy/device-link';+import { isSharedTaskPeer, sharedTaskHostPeer } from '@cindy/device-link';import { readFileSync } from 'node:fs';import { resolve } from 'node:path';+import { createElement, isValidElement } from 'react';import { describe, expect, it } from 'vitest';import ts from 'typescript';-import { isSharedTaskPeer } from '@cindy/device-link';const composer = readFileSync(resolve(__dirname, '../components/new-chat/ChatInput.tsx'), 'utf8');const sessionView = readFileSync(resolve(__dirname, '../features/cc-agent/CCAgentSessionView.tsx'),'utf8',);+const ast = ts.createSourceFile('session.tsx', sessionView, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);++function findNode<T extends ts.Node>(matches: (node: ts.Node) => node is T): T {+ const nodes: T[] = [];+ const visit = (node: ts.Node) => {+ if (matches(node)) nodes.push(node);+ ts.forEachChild(node, visit);+ };+ visit(ast);+ expect(nodes).toHaveLength(1);+ return nodes[0]!;+}++// Execute the production expressions without mounting the full session/runtime.+function evaluate(expression: ts.Expression, scope: Record<string, unknown>): unknown {+ const { outputText } = ts.transpileModule(`return (${expression.getText(ast)});`, {+ fileName: 'composer-expression.tsx',+ compilerOptions: { target: ts.ScriptTarget.ESNext, jsx: ts.JsxEmit.React, jsxFactory: 'createElement' },+ });+ return new Function(...Object.keys(scope), outputText)(...Object.values(scope));+}describe('Cindy Make composer presentation', () => {it('opens preflight in place and only routes standalone diagnostics to their container', () => {@@ -28,7 +49,6 @@ describe('Cindy Make composer presentation', () => {expect(input).toBeGreaterThan(mask);const promptEnd = sessionView.indexOf('</InteractionPromptHost>');// Parse the real guard so grouping/formatting does not change the contract.- const ast = ts.createSourceFile('session.tsx', sessionView, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);let condition: ts.Expression | undefined;const visit = (node: ts.Node) => {if (ts.isConditionalExpression(node) && node.getStart(ast) > promptEnd && node.getStart(ast) < mask@@ -56,11 +76,67 @@ describe('Cindy Make composer presentation', () => {const testCard = sessionView.indexOf('<CindyMakeTestCard', mask);expect(testCard).toBeGreaterThan(mask);expect(testCard).toBeLessThan(input);- // Continued editing keeps the composer; recovery actions live inside its top slot.- const recovery = sessionView.indexOf('topSlot={cindyMakeRecoveryId && session ? (');- expect(recovery).toBeGreaterThan(input);- const recoverySlot = sessionView.slice(recovery, sessionView.indexOf('onSend=', recovery));- expect(recoverySlot).toContain('<CindyMakeEditingActions');- expect(recoverySlot).toContain(') : undefined}');+ });++ it('keeps recovery actions in the ordinary input top slot with the current task and message', () => {+ const input = findNode((node): node is ts.JsxSelfClosingElement =>+ ts.isJsxSelfClosingElement(node) && node.tagName.getText(ast) === 'ChatInput');+ const topSlot = input.attributes.properties.find((attribute) =>+ ts.isJsxAttribute(attribute) && attribute.name.getText(ast) === 'topSlot');+ if (!topSlot || !ts.isJsxAttribute(topSlot) || !topSlot.initializer+ || !ts.isJsxExpression(topSlot.initializer) || !topSlot.initializer.expression) {+ throw new Error('ChatInput must expose its recovery actions through topSlot');+ }+ const expression = topSlot.initializer.expression;+ const renderSlot = (cindyMakeRecoveryId: string | null, session: { id: string } | null) =>+ evaluate(expression, { createElement, CindyMakeEditingActions: 'editing-actions', cindyMakeRecoveryId, session });++ // Recovery must still reach ChatInput, never replace it with a blocking card.+ for (let child: ts.Node = input; !ts.isJsxExpression(child.parent); child = child.parent) {+ const parent = child.parent;+ if (!ts.isConditionalExpression(parent)) continue;+ expect(child).toBe(parent.whenFalse);+ expect(Boolean(evaluate(parent.condition, {+ isSharedTaskPeer, remoteDeviceId: undefined,+ pendingPlanReview: null, pendingPermission: null, pendingAskUser: null,+ pendingPluginSetup: null, pendingIssueConfirm: null,+ pendingRenameSessionsConfirm: null, pendingGhostGrantConfirm: null,+ sessionBinding: { attached: false }, sessionId: 'task-a', session: { id: 'task-a' },+ cindyMakeComposerPhase: null, cindyMakePendingTest: null,+ cindyMakeRecoveryId: 'continued-completion',+ worktreePreparing: false, smoothedBranchName: null, shareSelectionActive: false,+ })), parent.condition.getText(ast)).toBe(false);+ }++ for (const sessionId of ['task-a', 'task-b']) {+ for (const messageId of ['completion-a', 'completion-b']) {+ const actions = renderSlot(messageId, { id: sessionId });+ expect(isValidElement(actions)).toBe(true);+ if (!isValidElement(actions)) throw new Error('Missing recovery actions');+ expect(actions.type).toBe('editing-actions');+ expect(actions.key).toBe(`${sessionId}:${messageId}`);+ expect(actions.props).toEqual({ sessionId, messageId });+ }+ }+ expect(renderSlot(null, { id: 'task-a' })).toBeUndefined();+ expect(renderSlot('completion-a', null)).toBeUndefined();+ expect(renderSlot(null, null)).toBeUndefined();+ });++ it('locks preparation and first-test input but leaves continued editing unlocked', () => {+ const lock = findNode((node): node is ts.VariableDeclaration =>+ ts.isVariableDeclaration(node) && node.name.getText(ast) === 'cindyMakeInputLocked');+ expect(lock.initializer).toBeDefined();+ for (const phase of [null, 'preparing']) {+ for (const pendingTest of [null, { completionId: 'first-completion' }]) {+ for (const recoveryId of [null, 'continued-completion']) {+ expect(evaluate(lock.initializer!, {+ cindyMakeComposerPhase: phase,+ cindyMakePendingTest: pendingTest,+ cindyMakeRecoveryId: recoveryId,+ })).toBe(Boolean(phase || pendingTest));+ }+ }+ }});});