Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

test(chat): align motion lifecycle fixtures and native boundaries

Chris3ffa0e459f64
diff --git a/apps/desktop/src/renderer/__tests__/markdownMathRendering.test.ts b/apps/desktop/src/renderer/__tests__/markdownMathRendering.test.ts
index 5e8cfe4131..dfbb755fdc 100644
--- a/apps/desktop/src/renderer/__tests__/markdownMathRendering.test.ts
+++ b/apps/desktop/src/renderer/__tests__/markdownMathRendering.test.ts
@@ -151,7 +151,7 @@ describe('MarkdownRenderer — math 接线 source contract', () => {
expect(source).toContain('normalizeMarkdownRendererContent(repairedContent, emitSourceLines)');
expect(source).toContain('normalizeMathDelimiters(content, { preserveLineCount })');
expect(source).toContain(
- 'streamFade ? repairStreamingMarkdown(throttledContent) : throttledContent',
+ 'streamFade && isStreaming ? repairStreamingMarkdown(throttledContent) : throttledContent',
);
});
diff --git a/apps/desktop/src/renderer/__tests__/workGroupBlockLivePreview.test.tsx b/apps/desktop/src/renderer/__tests__/workGroupBlockLivePreview.test.tsx
index 2971e7b29f..f4e2b0558e 100644
--- a/apps/desktop/src/renderer/__tests__/workGroupBlockLivePreview.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/workGroupBlockLivePreview.test.tsx
@@ -128,10 +128,23 @@ const group = (
childItems,
});
+function containerPreview() {
+ return document.querySelector('[data-live-work-preview]')?.parentElement?.parentElement;
+}
+
function clickGroup(label: string) {
const button = screen.getByText(label).closest('button');
if (!button) throw new Error(`Missing work-group button: ${label}`);
fireEvent.click(button);
+ // The outgoing preview now retains its rows until its height transition ends.
+ // Finish that real production lifecycle event instead of counting both the
+ // exiting preview and expanded details, or waiting on a wall-clock fallback.
+ for (const preview of document.querySelectorAll('[data-live-work-preview]')) {
+ const body = preview.parentElement;
+ if (body?.getAttribute('aria-hidden') === 'true') {
+ fireEvent.transitionEnd(body.parentElement!, { propertyName: 'height' });
+ }
+ }
}
// #6351: production grouping feeds the real disclosure/Collapse/state store.
@@ -489,6 +502,8 @@ describe('WorkGroupBlock — running latest-five preview', () => {
const doneButton = screen.getByText('chat.workGroup.worked:12s').closest('button');
expect(doneButton?.hasAttribute('disabled')).toBe(false);
expect(doneButton?.querySelector('svg.lucide-chevron-right')).toBeTruthy();
+ const outgoing = containerPreview();
+ if (outgoing) fireEvent.transitionEnd(outgoing, { propertyName: 'height' });
expect(screen.queryByTestId('direct-tool')).toBeNull();
clickGroup('chat.workGroup.worked:12s');
expect(screen.getByTestId('direct-tool').textContent).toBe('git status');
@@ -801,14 +816,17 @@ describe('WorkGroupBlock — Host-projected running lines', () => {
expect(screen.getByText('Checking the failing case')).toBeTruthy();
expect(screen.queryByTestId('assistant-progress')).toBeNull();
// The detail body is already open, so the handoff below swaps rows without replaying its expansion.
- const body = container.querySelector('.grid');
+ const body = container.querySelector('[data-live-work-preview]')?.parentElement?.parentElement?.nextElementSibling;
expect(body).not.toBeNull();
rerender(createElement(WorkGroupBlock, {
...props, deferred: { ...deferred(lines), awaitingDetails: false },
}));
+ const exiting = containerPreview();
+ if (exiting) fireEvent.transitionEnd(exiting, { propertyName: 'height' });
expect(container.querySelector('[data-live-work-preview]')).toBeNull();
- expect(container.querySelector('.grid')).toBe(body);
+ expect(body?.isConnected).toBe(true);
+ expect(body?.contains(screen.getByTestId('assistant-progress'))).toBe(true);
expect(screen.getByTestId('assistant-progress').textContent).toBe('Every detail row');
});
diff --git a/apps/mobile/src/__tests__/BotGroupMessageAttachments.test.tsx b/apps/mobile/src/__tests__/BotGroupMessageAttachments.test.tsx
index bc9491692a..1788429e70 100644
--- a/apps/mobile/src/__tests__/BotGroupMessageAttachments.test.tsx
+++ b/apps/mobile/src/__tests__/BotGroupMessageAttachments.test.tsx
@@ -6,6 +6,15 @@ import type { ResolveRemoteMediaFn } from '@/session/remoteMedia';
import { openBrowserAsync } from 'expo-web-browser';
// The shared renderer imports site-video; replace only its native surface.
+// Adapt only the native animation/list surfaces. These suites keep the real
+// attachment/message gates; native motion has separate hook and device coverage.
+vi.mock('@legendapp/list/reanimated', async () => ({ AnimatedLegendList: (await import('@legendapp/list/react-native')).LegendList }));
+vi.mock('@/session/AnimatedContentHeight', () => ({ AnimatedContentHeight: ({ open = true, children }: any) => open ? children : null }));
+vi.mock('@/session/ComposerDockKeyboardFollow', () => ({ DockKeyboardLift: ({ children }: any) => children }));
+vi.mock('@/session/useSmoothMessageFollow', async () => {
+ const { useRef, useCallback } = await import('react');
+ return { useSmoothMessageFollow: () => ({ scrollRef: useRef(null), move: useCallback(() => {}, []), cancel: useCallback(() => {}, []) }) };
+});
vi.mock('@/platform/gestureHandler', () => {
const chain = (): any => new Proxy({}, { get: (_target, key) => key === 'then' ? undefined : () => chain() });
return { GestureDetector: ({ children }: { children: unknown }) => children, Gesture: { LongPress: chain } };
diff --git a/apps/mobile/src/__tests__/botGroupAttachmentLightbox.test.tsx b/apps/mobile/src/__tests__/botGroupAttachmentLightbox.test.tsx
index 624d056811..2ebba13a48 100644
--- a/apps/mobile/src/__tests__/botGroupAttachmentLightbox.test.tsx
+++ b/apps/mobile/src/__tests__/botGroupAttachmentLightbox.test.tsx
@@ -6,6 +6,15 @@ import type { BotGroupAttachment } from '@cindy/maker-shared/botGroupChat';
import type { ResolveRemoteMediaFn } from '@/session/remoteMedia';
// This suite exercises attachments; MCP App's native WebView is covered by mcpAppCard.test.tsx.
+// Adapt only the native animation/list surfaces. These suites keep the real
+// attachment/message gates; native motion has separate hook and device coverage.
+vi.mock('@legendapp/list/reanimated', async () => ({ AnimatedLegendList: (await import('@legendapp/list/react-native')).LegendList }));
+vi.mock('@/session/AnimatedContentHeight', () => ({ AnimatedContentHeight: ({ open = true, children }: any) => open ? children : null }));
+vi.mock('@/session/ComposerDockKeyboardFollow', () => ({ DockKeyboardLift: ({ children }: any) => children }));
+vi.mock('@/session/useSmoothMessageFollow', async () => {
+ const { useRef, useCallback } = await import('react');
+ return { useSmoothMessageFollow: () => ({ scrollRef: useRef(null), move: useCallback(() => {}, []), cancel: useCallback(() => {}, []) }) };
+});
vi.mock('@/session/McpAppCard', () => ({ McpAppCard: () => null }));
// The shared message renderer also imports the site-video native surface.
vi.mock('react-native-webview', () => ({ WebView: () => null }));
diff --git a/apps/mobile/src/__tests__/fileChipNameWidth.test.tsx b/apps/mobile/src/__tests__/fileChipNameWidth.test.tsx
index 6273d442ba..be732470fd 100644
--- a/apps/mobile/src/__tests__/fileChipNameWidth.test.tsx
+++ b/apps/mobile/src/__tests__/fileChipNameWidth.test.tsx
@@ -6,6 +6,15 @@ import type { BotGroupAttachment } from '@cindy/maker-shared/botGroupChat';
import type { ResolveRemoteMediaFn } from '@/session/remoteMedia';
// This suite exercises attachment layout; keep the unrelated native App surface out of Node.
+// Adapt only the native animation/list surfaces. These suites keep the real
+// attachment/message gates; native motion has separate hook and device coverage.
+vi.mock('@legendapp/list/reanimated', async () => ({ AnimatedLegendList: (await import('@legendapp/list/react-native')).LegendList }));
+vi.mock('@/session/AnimatedContentHeight', () => ({ AnimatedContentHeight: ({ open = true, children }: any) => open ? children : null }));
+vi.mock('@/session/ComposerDockKeyboardFollow', () => ({ DockKeyboardLift: ({ children }: any) => children }));
+vi.mock('@/session/useSmoothMessageFollow', async () => {
+ const { useRef, useCallback } = await import('react');
+ return { useSmoothMessageFollow: () => ({ scrollRef: useRef(null), move: useCallback(() => {}, []), cancel: useCallback(() => {}, []) }) };
+});
vi.mock('@/platform/gestureHandler', () => {
const chain = (): any => new Proxy({}, { get: (_target, key) => key === 'then' ? undefined : () => chain() });
return { GestureDetector: ({ children }: { children: unknown }) => children, Gesture: { LongPress: chain } };
diff --git a/apps/mobile/src/__tests__/fixtures/messageRendererComponents.ts b/apps/mobile/src/__tests__/fixtures/messageRendererComponents.ts
index ee3b40e5f9..fa69c86206 100644
--- a/apps/mobile/src/__tests__/fixtures/messageRendererComponents.ts
+++ b/apps/mobile/src/__tests__/fixtures/messageRendererComponents.ts
@@ -48,6 +48,9 @@ export function collaborationRenderer() {
.map(name => rendererFunction(name).getText(rendererSource)).join(String.fromCharCode(10));
const bindings = { useMemo: React.useMemo, useState: React.useState, useEffect: React.useEffect, useCallback: React.useCallback, useTranslation, i18n, View, Text, useTheme: () => ({ colors: lightColors }),
useThemedStyles: () => ({}), makeStyles: () => ({}),
+ // Native occupancy/entrance is outside these collaboration routing tests.
+ CompanionEntering: ({ children }: NativeProps) => children,
+ AnimatedContentHeight: ({ open = true, children }: NativeProps & { open?: boolean }) => open ? children : null,
useAuth: () => ({ accountGeneration: state.accountGeneration }),
useRecyclingState: React.useState, useFoldableExpandedState,
buildMessageHierarchyLayout, formatLocalizedDuration, iconSize, iconStroke,
diff --git a/apps/mobile/src/__tests__/messageEntryPositioning.test.ts b/apps/mobile/src/__tests__/messageEntryPositioning.test.ts
index 9b591e6dc7..c16cafe384 100644
--- a/apps/mobile/src/__tests__/messageEntryPositioning.test.ts
+++ b/apps/mobile/src/__tests__/messageEntryPositioning.test.ts
@@ -41,6 +41,7 @@ function fixture(focused: string | null = null, saved?: object) {
mobileMessageHistoryRowKeyByIdentity: vi.fn(),
lastAppliedFocusKeyRef: ref(null), userScrollForOlderRef: ref(false), lastAutoLoadEarlierKeyRef: ref(null),
focusRunKey: focused ? `request:${focused}` : null, focusedItemKey: focused,
+ cancelTailMotion: vi.fn(), syncingWhileEmpty: false, historyPositioning: true,
};
bindings.revealPositionedHistory = callback('if (!initialAnchorDoneRef.current || !animation)', bindings);
bindings.scrollToIndexProgrammatically = callback('return listRef.current?.scrollToIndex', bindings);
@@ -106,12 +107,16 @@ describe('message entry lifecycle', () => {
finish(); await Promise.resolve();
expect(h.state.revealed).toBe(false);
});
- it('opens normal histories at the latest row once, including a previously empty cache', () => {
+ it('keeps an already-visible empty history positioned when its first live row arrives', () => {
const h = fixture();
h.bindings.listData = []; h.layout();
expect(h.state.revealed).toBe(true);
h.bindings.listData = [{ key: 'latest' }]; h.layout(); h.layout();
- expect(h.bindings.scrollToEndProgrammatically).toHaveBeenCalledExactlyOnceWith(false);
+ // A first live row uses the existing content-follow path; do not replay
+ // the initial full-history conceal/reveal or force a separate layout jump.
+ expect(h.bindings.scrollToEndProgrammatically).not.toHaveBeenCalled();
+ expect(h.bindings.initialRevealProgress.setValue).not.toHaveBeenCalledWith(0);
+ expect(h.state.revealed).toBe(true);
expect(h.bindings.nearBottomRef.current).toBe(true);
});
it('restores deliberate history reading and lets an explicit link override the bookmark', () => {
@@ -141,6 +146,7 @@ it('reconciles late attachment, composer and keyboard measurements through the p
});
const bindings = {
scrollMetricsRef: metrics, nearBottomRef: nearBottom, readingOlderRef: readingOlder,
+ nativeKeyboardInset: ref(0),
historyPrependTransactionRef: ref(null),
// Companion receipt behavior is covered by the mounted MessageRenderer tests.
acknowledgeCompanionReadRef: ref(vi.fn()),
diff --git a/apps/mobile/src/__tests__/pendingSendItems.test.ts b/apps/mobile/src/__tests__/pendingSendItems.test.ts
index 8e0dac999f..12e58649e1 100644
--- a/apps/mobile/src/__tests__/pendingSendItems.test.ts
+++ b/apps/mobile/src/__tests__/pendingSendItems.test.ts
@@ -473,7 +473,7 @@ describe('pending_send 渲染接线', () => {
readNames(callback);
const pendingSend = { onSelect: vi.fn(), onRemove: vi.fn(), onSendNow: vi.fn() };
const bindings: Record<string, unknown> = Object.fromEntries([...identifiers].map((name) => [name, undefined]));
- Object.assign(bindings, { pendingSend, viewportLayout: { contentWidth: 390 } });
+ Object.assign(bindings, { pendingSend, viewportLayout: { contentWidth: 390 }, retainedRows: { exiting: new Set(), onExited: vi.fn() } });
const compiled = ts.transpileModule('const project = ' + callback.getText(tree) + ';', { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText;
const actions = new Function(...Object.keys(bindings), compiled + '\nreturn project();')(...Object.values(bindings));
expect(actions.pendingSend).toBe(pendingSend);
diff --git a/apps/mobile/src/__tests__/pluginAttachmentBubble.test.tsx b/apps/mobile/src/__tests__/pluginAttachmentBubble.test.tsx
index b8ac4ffc9e..c9a94f8d2a 100644
--- a/apps/mobile/src/__tests__/pluginAttachmentBubble.test.tsx
+++ b/apps/mobile/src/__tests__/pluginAttachmentBubble.test.tsx
@@ -6,6 +6,15 @@ import { describe, expect, it, vi } from 'vitest';
const viewportHarness = vi.hoisted(() => ({ list: null as any, finishReveal: null as any, renders: 0, expanded: false }));
// Keep site-video's native surface out of this Node message-rendering test.
+// Adapt only the native animation/list surfaces. These suites keep the real
+// attachment/message gates; native motion has separate hook and device coverage.
+vi.mock('@legendapp/list/reanimated', async () => ({ AnimatedLegendList: (await import('@legendapp/list/react-native')).LegendList }));
+vi.mock('@/session/AnimatedContentHeight', () => ({ AnimatedContentHeight: ({ open = true, children }: any) => open ? children : null }));
+vi.mock('@/session/ComposerDockKeyboardFollow', () => ({ DockKeyboardLift: ({ children }: any) => children }));
+vi.mock('@/session/useSmoothMessageFollow', async () => {
+ const { useRef, useCallback } = await import('react');
+ return { useSmoothMessageFollow: () => ({ scrollRef: useRef(null), move: useCallback(() => {}, []), cancel: useCallback(() => {}, []) }) };
+});
vi.mock('@/platform/gestureHandler', () => {
const chain = (): any => new Proxy({}, { get: (_target, key) => key === 'then' ? undefined : () => chain() });
return { GestureDetector: ({ children }: { children: unknown }) => children, Gesture: { LongPress: chain } };
@@ -24,7 +33,11 @@ vi.mock('react-native', async () => {
View: view, Text: view, Pressable: view, ScrollView: view, Modal: () => null,
Image: Object.assign(view, { getSize() {} }), ActivityIndicator: view,
Animated: { Value, View: view, Text: view, createAnimatedComponent: (c: any) => c,
- timing: () => ({ start(callback: any) { viewportHarness.finishReveal = callback; }, stop() {} }), loop: () => ({ start() {}, stop() {} }), sequence: () => ({ start() {}, stop() {} }) },
+ timing: () => ({ start(callback: any) {
+ // Decorative entrances call start() without a completion callback;
+ // they must not overwrite the history reveal completion under test.
+ if (typeof callback === 'function') viewportHarness.finishReveal = callback;
+ }, stop() {} }), loop: () => ({ start() {}, stop() {} }), sequence: () => ({ start() {}, stop() {} }) },
Platform: { OS: 'ios', select: (s: any) => s.ios ?? s.default },
StyleSheet: { create: (s: any) => s, flatten: (s: any) => s, hairlineWidth: 1 },
Easing: { linear: (n: number) => n, bezier: () => (n: number) => n },
@@ -360,6 +373,11 @@ describe('companion native read position', () => {
visible();
viewportHarness.list.onLayout({ nativeEvent: { layout: { height: 500 } } });
viewportHarness.list.onContentSizeChange(400, 300);
+ // A keyed native list reports its reset offset. Programmatic motion
+ // completion alone is no longer allowed to fabricate read position.
+ viewportHarness.list.onScroll({ nativeEvent: {
+ contentSize: { height: 300 }, layoutMeasurement: { height: 500 }, contentOffset: { y: 0 },
+ } });
});
expect(acknowledge).not.toHaveBeenCalled();
await act(async () => { viewportHarness.finishReveal?.({ finished: true }); });
diff --git a/apps/mobile/src/__tests__/sessionComposerDesktopFirst.test.ts b/apps/mobile/src/__tests__/sessionComposerDesktopFirst.test.ts
index d6196118ed..0afdb3ed59 100644
--- a/apps/mobile/src/__tests__/sessionComposerDesktopFirst.test.ts
+++ b/apps/mobile/src/__tests__/sessionComposerDesktopFirst.test.ts
@@ -398,7 +398,7 @@ describe('mobile session composer desktop-first surface', () => {
expect(source).toContain("position: 'absolute'");
expect(source).toContain('bottom: 0');
expect(source).toContain('safeAreaBottomInset: insets.bottom');
- expect(source).toContain('const bottomOverlayHeight = useMemo(');
+ expect(source).toContain('<ComposerOverlayHeight source={composerOverlayLayout}>');
expect(source).toContain('nativeShellLayout.keyboardBottomInset');
expect(source).toContain('onLayout={handleBottomOverlayLayout}');
expect(source).toContain('bottomOverlayHeight={bottomOverlayHeight}');
diff --git a/apps/mobile/src/__tests__/sessionHeaderDesktopFirst.test.ts b/apps/mobile/src/__tests__/sessionHeaderDesktopFirst.test.ts
index c327908893..67e7f1ea24 100644
--- a/apps/mobile/src/__tests__/sessionHeaderDesktopFirst.test.ts
+++ b/apps/mobile/src/__tests__/sessionHeaderDesktopFirst.test.ts
@@ -96,7 +96,7 @@ describe('mobile session header desktop-first surface', () => {
expect(source).toContain("topInset={Platform.OS === 'android' ? 0 : topOverlayHeight}");
// 输入区同理:安卓整块经根浮层盖在消息层上,外框高度取键盘避让容器的实测高度。
expect(source).toContain("const androidFrostedComposer = Platform.OS === 'android' && !companionChat;");
- expect(source).toContain('bottomInset={androidFrostedComposer ? 0 : bottomOverlayHeight}');
+ expect(source).toContain('bottomInset={androidFrostedComposer || androidComposerClearance ? 0 : bottomOverlayHeight}');
expect(source).toContain('height={keyboardAreaHeight ?? windowDimensions.height}');
expect(source).toContain('<View onLayout={handleKeyboardAreaLayout} pointerEvents="none" style={StyleSheet.absoluteFill} />');
expect(source).toContain('testID="session.composerFrost"');