Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/mobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ MOBILE_LIVE_HOST_URL='http://127.0.0.1:<port>/?token=<token>' pnpm vitest run ap
pnpm --filter @botharness/mobile export # Metro bundles for iOS and Android
```

For first-DM visibility, working-indicator ordering and reply scrolling, use the [first-reply regression checks](../../docs/agents/mobile-first-reply.md) ([中文](../../docs/agents/mobile-first-reply.zh.md)). The guide separates source coverage from queued iOS/Android acceptance.

## Full client in the app

Every native screen can offer "Open full client" (`src/ui/open-full-client.tsx`), which opens `app/full-client.tsx` as a full-screen modal with no header bar; a draggable floating exit button (`src/ui/floating-exit.tsx`) that snaps to either side edge leaves it, and holding it shows an "Exit web mode" tooltip. It loads `<route>/botharness-device/web/` in a WebView on the route the native screens are using and sends the device credential as a header only on that first load; the Host answers with a session cookie scoped to that directory ([ADR-0199](../../docs/adr/0199-paired-devices-reach-the-host-through-a-same-listener-device-gateway.md#full-web-client-in-the-app-1654)). The target (`home`, a PersonaBot DM, or a private input request) becomes a hash the Web Client reads to land there. Links that leave the Host's web directory open in the system browser. When the Host refuses the device, the modal shows "Pair again" instead of the page. `react-native-webview` is native code, so a development build made before this change must be rebuilt.
Expand Down
258 changes: 247 additions & 11 deletions apps/mobile/test/conversation-streaming-rows.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// @vitest-environment jsdom
import { act, type ReactNode } from 'react';
import { createRoot } from 'react-dom/client';
import { expect, it, vi } from 'vitest';
import type {
FlatListProps,
LayoutChangeEvent,
NativeScrollEvent,
NativeSyntheticEvent,
} from 'react-native';
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
import type { RosterBot } from '../src/host/client';
import type { ConversationTimelineSnapshot } from '../src/host/conversation';

Expand All @@ -16,21 +22,29 @@ const state = vi.hoisted(() => ({
}));

const counts = vi.hoisted(() => ({ renderItem: 0, rows: new Map<string, number>() }));
const native = vi.hoisted(() => ({
list: undefined as FlatListProps<unknown> | undefined,
scrollToOffset: vi.fn(),
}));

const stream = vi.hoisted(() => {
const timelineListeners = new Set<() => void>();
const bubbleListeners = new Map<string, Set<() => void>>();
const bubbles = new Map<string, string>();
const history = (id: string, body: string, author: 'bot' | 'human') => ({
const history = (
id: string,
body: string,
author: 'bot' | 'human',
): ConversationTimelineSnapshot['messages'][number] => ({
id,
at: '2026-10-19T08:00:00Z',
author,
bot: author === 'bot' ? 'ada' : undefined,
...(author === 'bot' ? { bot: 'ada' } : {}),
body,
attachments: [],
delivery: 'committed',
});
const timeline = {
let timeline: ConversationTimelineSnapshot = {
status: 'live',
messages: [history('m1', 'question', 'human'), history('m2', 'earlier answer', 'bot')],
drafts: [{ draftId: 'd1', botSlug: 'ada' }],
Expand All @@ -39,9 +53,22 @@ const stream = vi.hoisted(() => {
fromCache: false,
};
return {
conversation: { loadOlder: () => Promise.resolve() },
history,
publish(next: Partial<ConversationTimelineSnapshot>) {
timeline = { ...timeline, ...next };
for (const listener of timelineListeners) listener();
},
reset() {
bubbles.clear();
timeline = {
...timeline,
messages: [history('m1', 'question', 'human'), history('m2', 'earlier answer', 'bot')],
drafts: [{ draftId: 'd1', botSlug: 'ada' }],
};
},
conversation: { loadOlder: () => Promise.resolve(), send: vi.fn() },
playback: {
getTimelineSnapshot: () => timeline as unknown as ConversationTimelineSnapshot,
getTimelineSnapshot: () => timeline,
subscribe(listener: () => void) {
timelineListeners.add(listener);
return () => timelineListeners.delete(listener);
Expand All @@ -68,7 +95,10 @@ vi.mock('../src/ui/shell/recent-chats', () => ({
chatHref: () => '',
useRecentChat: () => () => {},
}));
vi.mock('../src/host/native-source-drafts', () => ({ useSourceDraft: () => ['', () => {}] }));
vi.mock('../src/host/native-source-drafts', async () => {
const { useState } = await import('react');
return { useSourceDraft: () => useState('') };
});
vi.mock('expo-router', () => ({
useIsFocused: () => true,
Stack: {
Expand All @@ -93,15 +123,40 @@ vi.mock('react-native', async () => {
});
vi.mock('react-native-reanimated', async () => {
const shim = await import('./reanimated-shim');
const FlatList = (props: Parameters<typeof shim.default.FlatList>[0]) =>
shim.default.FlatList({
const { useLayoutEffect, useMemo } = await import('react');
const FlatList = (
props: Parameters<typeof shim.default.FlatList>[0] &
FlatListProps<unknown> & {
ref: (node: unknown) => void;
},
) => {
native.list = props;
useLayoutEffect(() => {
props.ref({ scrollToOffset: native.scrollToOffset });
return () => props.ref(null);
}, [props.ref]);
return shim.default.FlatList({
...props,
renderItem: (info) => {
counts.renderItem += 1;
return props.renderItem(info);
},
});
return { ...shim, default: { ...shim.default, FlatList } };
};
return {
...shim,
useAnimatedRef: () =>
useMemo(() => {
const ref = Object.assign(
(node: unknown) => {
ref.current = node;
},
{ current: null as unknown },
);
return ref;
}, []),
default: { ...shim.default, FlatList },
};
});
vi.mock('react-native-worklets', () => ({ scheduleOnRN: (callback: () => void) => callback() }));
vi.mock('../src/host/host-session', async () => {
Expand Down Expand Up @@ -185,7 +240,18 @@ vi.mock('../src/ui/chat/activity-row', () => ({ ActivityRow: () => null }));
vi.mock('../src/ui/chat/question-card', () => ({ QuestionCard: () => null }));
vi.mock('../src/ui/chat/channel-title', () => ({ ChannelTitle: () => null }));
vi.mock('../src/ui/chat/chat-title', () => ({ ChatTitle: () => null }));
vi.mock('../src/ui/chat/composer', () => ({ Composer: () => null }));
vi.mock('../src/ui/chat/composer', () => ({
Composer: ({ onChange, onSend }: { onChange(value: string): void; onSend(): void }) => (
<>
<button type="button" onClick={() => onChange('What is six times seven?')}>
Write question
</button>
<button type="button" onClick={onSend}>
Send question
</button>
</>
),
}));
vi.mock('../src/ui/chat/image-viewer', () => ({ ImageViewer: () => null }));
vi.mock('../src/ui/chat/jump-to-latest', () => ({ JumpToLatest: () => null }));
vi.mock('../src/ui/chat/pull-to-compose-hint', () => ({ PullToComposeHint: () => null }));
Expand Down Expand Up @@ -228,6 +294,35 @@ import { ConversationScreen } from '../src/ui/chat/conversation-screen';

Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });

let frames = new Map<number, FrameRequestCallback>();
let nextFrame = 0;
beforeEach(() => {
frames = new Map();
nextFrame = 0;
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => {
frames.set(++nextFrame, callback);
return nextFrame;
});
vi.stubGlobal('cancelAnimationFrame', (id: number) => frames.delete(id));
native.list = undefined;
native.scrollToOffset.mockClear();
stream.conversation.send.mockClear();
stream.reset();
state.host.roster.bots = [];
counts.rows.clear();
counts.renderItem = 0;
});
afterEach(() => vi.unstubAllGlobals());

const flushFrames = () =>
act(() => {
for (let round = 0; round < 64 && frames.size; round += 1) {
const pending = [...frames.values()];
frames.clear();
for (const callback of pending) callback(round * 16);
}
});

it('re-renders only the streaming row when a draft token arrives', async () => {
const container = document.createElement('div');
document.body.append(container);
Expand Down Expand Up @@ -257,3 +352,144 @@ it('re-renders only the streaming row when a draft token arrives', async () => {
await act(async () => root.unmount());
container.remove();
});

it('keeps a first DM visible through send, working, streaming and commit, then respects history browsing', () => {
const bot: RosterBot = {
slug: 'ada',
displayName: 'Ada',
state: 'idle',
description: '',
roles: [],
computerAccess: false,
browserAccess: false,
paused: false,
};
state.host.roster.bots = [bot];
stream.publish({ messages: [], drafts: [] });
const container = document.createElement('div');
document.body.append(container);
const root = createRoot(container);
const render = () =>
act(() =>
root.render(<ConversationScreen place={{ kind: 'dm', slug: 'ada' }} focus={undefined} />),
);
const visible = () => expect(native.list?.style).toMatchObject({ opacity: 1 });
const rows = () =>
[...container.querySelectorAll('[data-testid="chat-list"] [data-testid]')].map((node) =>
node.getAttribute('data-testid'),
);
const scrollEvent = (offset: number, content: number): NativeSyntheticEvent<NativeScrollEvent> =>
({
nativeEvent: {
contentOffset: { x: 0, y: offset },
contentSize: { width: 390, height: content },
layoutMeasurement: { width: 390, height: 800 },
velocity: { x: 0, y: 0 },
contentInset: { top: 80, bottom: 0, left: 0, right: 0 },
zoomScale: 1,
},
}) as NativeSyntheticEvent<NativeScrollEvent>;
try {
render();
act(() => {
native.list?.onLayout?.({ nativeEvent: { layout: { height: 800 } } } as LayoutChangeEvent);
native.list?.onContentSizeChange?.(390, 720);
});
flushFrames();
visible();
expect(native.scrollToOffset).toHaveBeenLastCalledWith({ offset: -80, animated: false });
expect(native.list?.maintainVisibleContentPosition).toBeUndefined();

const press = (label: string) =>
act(() => {
const button = [...container.querySelectorAll('button')].find(
(node) => node.textContent === label,
);
expect(button).toBeDefined();
button!.click();
});
press('Write question');
press('Send question');
expect(stream.conversation.send).toHaveBeenCalledOnce();
expect(stream.conversation.send.mock.calls[0]?.[0]).toBe('What is six times seven?');
const human = stream.history('first-human', 'What is six times seven?', 'human');
act(() => stream.publish({ messages: [human] }));
visible();
expect(rows()).toEqual(['first-human']);

state.host.roster.bots = [{ ...bot, state: 'thinking' }];
render();
expect(container.querySelector('[data-testid="pending"]')).not.toBeNull();
expect(container.querySelector('[data-testid="chat-list"] [data-testid="pending"]')).toBeNull();
visible();
act(() => stream.publish({ drafts: [{ draftId: 'first', botSlug: 'ada' }] }));
act(() => stream.append('draft:first', '42'));
expect(rows()).toEqual(['first-human', 'draft:first']);
expect(container.querySelector('[data-testid="draft:first"]')?.textContent).toBe('42');
visible();
expect(native.list?.maintainVisibleContentPosition).toBeUndefined();

const reply = stream.history('first-reply', '42', 'bot');
act(() => stream.publish({ messages: [human, reply], drafts: [] }));
visible();
expect(rows()).toEqual(['first-human', 'first-reply']);
expect(container.querySelector('[data-testid="pending"]')).not.toBeNull();
state.host.roster.bots = [bot];
render();
expect(container.querySelector('[data-testid="pending"]')).toBeNull();
visible();

act(() => native.list?.onContentSizeChange?.(390, 1100));
flushFrames();
expect(native.scrollToOffset).toHaveBeenLastCalledWith({ offset: 300, animated: false });
native.scrollToOffset.mockClear();
act(() => {
native.list?.onScrollBeginDrag?.(scrollEvent(300, 1100));
native.list?.onScroll?.(scrollEvent(100, 1100));
native.list?.onScrollEndDrag?.(scrollEvent(100, 1100));
});
expect(native.list?.maintainVisibleContentPosition).toEqual({ minIndexForVisible: 0 });
act(() =>
stream.publish({ messages: [human, reply, stream.history('later', 'Later reply', 'bot')] }),
);
act(() => native.list?.onContentSizeChange?.(390, 1400));
flushFrames();
expect(native.scrollToOffset).not.toHaveBeenCalled();
visible();

act(() => {
native.list?.onScrollBeginDrag?.(scrollEvent(100, 1400));
native.list?.onScrollEndDrag?.(scrollEvent(600, 1400));
});
expect(native.list?.maintainVisibleContentPosition).toBeUndefined();
act(() => native.list?.onContentSizeChange?.(390, 1500));
flushFrames();
expect(native.scrollToOffset).toHaveBeenLastCalledWith({ offset: 700, animated: false });
} finally {
act(() => root.unmount());
container.remove();
}
});

it('keeps a known-empty DM visible when the first message arrives from another client without a size change', () => {
stream.publish({ messages: [], drafts: [] });
const container = document.createElement('div');
const root = createRoot(container);
try {
act(() =>
root.render(<ConversationScreen place={{ kind: 'dm', slug: 'ada' }} focus={undefined} />),
);
act(() => {
native.list?.onLayout?.({ nativeEvent: { layout: { height: 800 } } } as LayoutChangeEvent);
native.list?.onContentSizeChange?.(390, 720);
});
flushFrames();
act(() => stream.publish({ messages: [stream.history('remote-human', 'Hello', 'human')] }));
expect(native.list?.style).toMatchObject({ opacity: 1 });
expect(container.querySelector('[data-testid="remote-human"]')?.textContent).toBe('Hello');
expect(native.list?.maintainVisibleContentPosition).toBeUndefined();
expect(stream.conversation.send).not.toHaveBeenCalled();
} finally {
act(() => root.unmount());
}
});
11 changes: 11 additions & 0 deletions changes/2521-mobile-first-reply-verification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
section: Documentation
---

## en

- Documented how to distinguish first-DM visibility, reply scrolling and working-indicator regressions, with a non-Connect native verification journey and explicit source-test limits ([#2521](https://github.com/BotHarness/DeepSeekBot/issues/2521), [English](../docs/agents/mobile-first-reply.md), [中文](../docs/agents/mobile-first-reply.zh.md)).

## zh

- 补充首次私信可见性、回复滚动及工作状态行回归的区分方法,提供非 Connect 路由的原生验收流程,并明确源码测试的验证边界([#2521](https://github.com/BotHarness/DeepSeekBot/issues/2521)、[English](../docs/agents/mobile-first-reply.md)、[中文](../docs/agents/mobile-first-reply.zh.md))。
Loading
Loading