Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 伙伴跳转等待任务抽屉关闭
Dash1d8e1a48b5af
diff --git a/apps/mobile/src/__tests__/HomeTeammatesSection.test.tsx b/apps/mobile/src/__tests__/HomeTeammatesSection.test.tsxindex 2f8d857552..8641a1fe22 100644--- a/apps/mobile/src/__tests__/HomeTeammatesSection.test.tsx+++ b/apps/mobile/src/__tests__/HomeTeammatesSection.test.tsx@@ -2,7 +2,8 @@import { act, createContext, createElement as el } from 'react';import { createRoot, type Root } from 'react-dom/client';import { afterEach, beforeEach, expect, it, vi } from 'vitest';-const h = vi.hoisted(() => ({ cloudRefresh: vi.fn(async () => {}) }));+const h = vi.hoisted(() => ({ cloudRefresh: vi.fn(async () => {}), push: vi.fn(),+ cloudActor: null as null | { id: string }, createOptions: null as any }));vi.mock('react-native', () => ({View: ({ children, testID }: any) => el('div', { 'data-testid': testID }, children),ScrollView: ({ children, testID }: any) => el('div', { 'data-testid': testID }, children),@@ -19,10 +20,12 @@ vi.mock('lucide-react-native', () => ({ ChevronDown: () => null, ChevronRight: (vi.mock('@/auth/AuthContext', () => ({ useAuth: () => ({ user: { id: 'owner' } }) }));vi.mock('@/components/AppText', () => ({ Text: ({ children, testID }: any) => el('span', { 'data-testid': testID }, children) }));vi.mock('@/components/RemoteCompanionAvatar', () => ({ RemoteCompanionAvatar: () => null }));-vi.mock('@/chat/cloudCompanion', () => ({ CLOUD_ROW_REVISION: 'cloud', cloudActorForRow: () => null, cloudCompanionRows: (items: unknown) => items }));+vi.mock('@/chat/cloudCompanion', () => ({ CLOUD_ROW_REVISION: 'cloud', cloudActorForRow: () => h.cloudActor, cloudCompanionRows: (items: unknown) => items }));+vi.mock('@/session/teammateNavigation', () => ({ cloudCompanionRoute: () => '/cloud-chat' }));+vi.mock('@/session/botGroupNavigation', () => ({ botGroupRoute: () => '/group-chat' }));vi.mock('@/chat/useCloudCompanion', () => ({ useCloudCompanionHome: () => ({ supported: true, actors: [], deviceNames: {}, refresh: h.cloudRefresh }) }));vi.mock('@/device-link/remoteResourceCache', () => ({ isRemoteResourceUnread: () => false, remoteResourceCacheRevision: () => 0, subscribeRemoteResourceCache: () => () => {} }));-vi.mock('@/utils/useGuardedPush', () => ({ useGuardedPush: () => () => {} }));+vi.mock('@/utils/useGuardedPush', () => ({ useGuardedPush: () => h.push }));vi.mock('@/theme', async () => {const tokens = await import('@/theme/tokens');const colors = tokens.lightColors;@@ -35,11 +38,14 @@ vi.mock('@/session/CompanionPresenceRing', () => ({ CompanionPresenceRing: () =>vi.mock('@/session/HomeRosterContext', () => ({ useHomeRoster: () => null }));vi.mock('@/session/HomeListVisuals', () => ({ homeListStyles: () => ({}) }));vi.mock('@/session/listDisclosureTransition', () => ({ DisclosureItem: ({ children, testID }: any) => el('div', { 'data-testid': testID }, children) }));-vi.mock('@/session/TeammateCreateController', () => ({ useTeammateCreateController: () => ({- renderTrigger: (trigger: unknown) => trigger, press: () => {}, label: 'create', sheets: null }) }));+vi.mock('@/session/TeammateCreateController', () => ({ useTeammateCreateController: (options: any) => {+ h.createOptions = options;+ return { renderTrigger: (trigger: unknown) => trigger, press: () => {}, label: 'create', sheets: null };+} }));vi.mock('@/session/TeammateList', () => ({- useTeammateEntries: (items: any[]) => items.map(row => ({ kind: 'bot', row })),- useTeammateRowRenderer: () => (entry: any) => el('div', { key: entry.row.key }, entry.row.item.display.title),+ useTeammateEntries: (items: any[], groups: any[] = []) => [...items.map(row => ({ kind: 'bot', row })), ...groups.map(row => ({ kind: 'group', row }))],+ useTeammateRowRenderer: (options: any) => (entry: any) => el('button', { key: entry.row.key,+ 'data-testid': `row.${entry.kind}`, onClick: () => entry.kind === 'bot' ? options.onSelect(entry.row) : options.groups.onSelect(entry.row) }, entry.row.item.display.title),}));vi.mock('@/session/useTeammateNavigation', () => ({ useTeammateNavigation: () => ({owner: 'owner', teammatesCollapsed: false, lastTeammate: null,@@ -52,11 +58,12 @@ const roster = { items: [item], createTargets: [], groupTargets: [], loading: faisOnline: () => true, connectionState: undefined, refresh: vi.fn(async () => {}) };const groups = { items: [], supported: true, refreshing: false, error: null, isOnline: () => true, refresh: vi.fn(async () => {}) };let root: Root; let node: HTMLDivElement;-beforeEach(() => { Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true }); node = document.createElement('div'); root = createRoot(node); vi.clearAllMocks(); });+beforeEach(() => { Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true }); node = document.createElement('div'); root = createRoot(node); vi.clearAllMocks(); h.cloudActor = null; });afterEach(async () => { await act(async () => root.unmount()); });-const render = (refreshKey: number) => act(async () => root.render(el(HomeTeammatesSection, {+const render = (refreshKey: number, overrides: Partial<Parameters<typeof HomeTeammatesSection>[0]> = {}) => act(async () => root.render(el(HomeTeammatesSection, {context: { navigation: null, route: null, shared: { roster, groups } } as any, active: true, refreshKey,visible: true, query: '', showFooter: false, runDisclosure: (apply: () => void) => apply(), prepareDisclosure: () => {},+ ...overrides,})));const byId = (id: string) => node.querySelector<HTMLElement>(`[data-testid="${id}"]`);@@ -79,3 +86,22 @@ it('re-reads cloud companions on each manual home refresh', async () => {await render(1);expect(h.cloudRefresh).toHaveBeenCalledTimes(1);});++// PR #7079: unit-tier component coverage of the cloud/group routes that bypass the teammate hook.+// Existing coverage only refreshed the roster. A deferred host push must prevent navigation until+// drawer close; the creation receipt is a separate entry after its own sheet has already closed.+it.each(['cloud', 'group', 'created-group'] as const)('defers the %s route until the drawer closes', async kind => {+ let routeAfterClose: (() => void) | undefined;+ const bot = { ...item, item: { ...item.item, revision: 'cloud' } };+ const group = { ...item, key: 'host:group', item: { ...item.item, ref: { ...item.item.ref, id: 'group' } } };+ h.cloudActor = { id: 'actor' };+ await render(0, { push: href => { routeAfterClose = () => h.push(href); },+ context: { navigation: null, route: null, shared: { roster: { ...roster, items: [bot] }, groups: { ...groups, items: [group] } } } as any });+ await act(async () => {+ if (kind === 'created-group') h.createOptions.onGroupCreated(item.host, 'group');+ else byId(`row.${kind === 'cloud' ? 'bot' : 'group'}`)!.click();+ });+ expect(h.push).not.toHaveBeenCalled();+ routeAfterClose?.();+ expect(h.push).toHaveBeenCalledExactlyOnceWith(kind === 'cloud' ? '/cloud-chat' : '/group-chat');+});diff --git a/apps/mobile/src/__tests__/useTeammateNavigation.test.tsx b/apps/mobile/src/__tests__/useTeammateNavigation.test.tsxindex c35334538a..e6979da9dc 100644--- a/apps/mobile/src/__tests__/useTeammateNavigation.test.tsx+++ b/apps/mobile/src/__tests__/useTeammateNavigation.test.tsx@@ -26,8 +26,8 @@ const teammate = { key: 'mac:writer', host: { deviceId: 'mac', deviceName: 'My MObject.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });let root: Root | undefined;let result: ReturnType<typeof useTeammateNavigation>;-function Probe() { result = useTeammateNavigation(); return null; }-async function render() { root ??= createRoot(document.createElement('div')); await act(async () => root!.render(createElement(Probe))); }+function Probe({ push }: { push?: ReturnType<typeof import('@/utils/useGuardedPush').useGuardedPush> }) { result = useTeammateNavigation(push); return null; }+async function render(push?: ReturnType<typeof import('@/utils/useGuardedPush').useGuardedPush>) { root ??= createRoot(document.createElement('div')); await act(async () => root!.render(createElement(Probe, { push }))); }let serial = 0;beforeEach(() => {vi.clearAllMocks(); h.sessions = []; h.routes = []; h.disk.clear(); h.accountGeneration = ++serial;@@ -37,6 +37,19 @@ beforeEach(() => {});afterEach(() => { act(() => root?.unmount()); root = undefined; vi.useRealTimers(); });describe('header/home shared navigation', () => {+ // PR #7079: the drawer must unmount before routing. Existing tests only covered immediate home+ // pushes; one teammate or creation receipt with a deferred host push reproduces the regression.+ // Unit tier, real navigation hook; the queued route must survive the source hook's unmount.+ it.each(['existing', 'created'] as const)('waits for the drawer to close before opening an %s teammate', async (kind) => {+ let routeAfterClose: (() => void) | undefined;+ await render(href => { routeAfterClose = () => h.push(href); });+ await act(async () => kind === 'existing' ? result.openTeammate(teammate) : result.openCreatedTeammate(teammate.host, teammate.item.ref));+ expect(h.push).not.toHaveBeenCalled();+ expect(result.lastTeammate).toEqual(teammateIdentity(teammate));+ await act(async () => root!.unmount()); root = undefined;+ routeAfterClose?.();+ expect(h.push).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ pathname: '/resources/[collectionId]/[resourceId]' }));+ });it('restores the remembered teammate and section fold, and returning home keeps them', async () => {const owner = homeNavigationOwner(h.user);await saveHomeNavigationPreferences(owner, { teammatesCollapsed: true, lastTeammate: teammateIdentity(teammate) });diff --git a/apps/mobile/src/session/HomeSurface.tsx b/apps/mobile/src/session/HomeSurface.tsxindex c5ac971dcf..80f4b8b5db 100644--- a/apps/mobile/src/session/HomeSurface.tsx+++ b/apps/mobile/src/session/HomeSurface.tsx@@ -2977,6 +2977,7 @@ function HomeScreenContent({ active = true, width, newSessionInSystemBar = falsesections={sections}ListHeaderComponent={<><HomeTeammatesSection context={teammatesSectionContext} active={active} refreshKey={teammatesRefreshKey}+ push={guardedPush}// Independent of the computer-connection guide: server group chats and cloud companions need no computer.visible={indexedSearch.activeFilterCount === 0 && statusFilter !== 'archived'}query={searchQuery}diff --git a/apps/mobile/src/session/HomeTeammatesSection.tsx b/apps/mobile/src/session/HomeTeammatesSection.tsxindex bea2e8a0e0..da2f49263e 100644--- a/apps/mobile/src/session/HomeTeammatesSection.tsx+++ b/apps/mobile/src/session/HomeTeammatesSection.tsx@@ -57,7 +57,7 @@ export function useHomeTeammatesSectionContext() {return useMemo(() => ({ navigation, route, shared }), [navigation, route, shared]);}-export function HomeTeammatesSection({ context, active, refreshKey, visible, query, showFooter, runDisclosure, prepareDisclosure }: {+export function HomeTeammatesSection({ context, active, refreshKey, visible, query, showFooter, push, runDisclosure, prepareDisclosure }: {context: ReturnType<typeof useHomeTeammatesSectionContext>;/** The home is the screen in front. */active: boolean;@@ -69,6 +69,8 @@ export function HomeTeammatesSection({ context, active, refreshKey, visible, quequery: string;/** Full-width hairline under the section, unless the next block draws its own top line. */showFooter: boolean;+ /** Embedded lists close their modal drawer before dispatching the route. */+ push?: ReturnType<typeof useGuardedPush>;runDisclosure(apply: () => void): void;prepareDisclosure(): void;}) {@@ -76,21 +78,23 @@ export function HomeTeammatesSection({ context, active, refreshKey, visible, queif (!shared) return null;return <NavigationContext.Provider value={navigation}><NavigationRouteContext.Provider value={route}><SectionContent shared={shared} active={active} refreshKey={refreshKey} visible={visible} query={query} showFooter={showFooter}- runDisclosure={runDisclosure} prepareDisclosure={prepareDisclosure} />+ push={push} runDisclosure={runDisclosure} prepareDisclosure={prepareDisclosure} /></NavigationRouteContext.Provider></NavigationContext.Provider>;}-function SectionContent({ shared, active, refreshKey, visible, query, showFooter, runDisclosure, prepareDisclosure }: {+function SectionContent({ shared, active, refreshKey, visible, query, showFooter, push: hostPush, runDisclosure, prepareDisclosure }: {shared: NonNullable<ReturnType<typeof useHomeRoster>>;active: boolean; refreshKey: number; visible: boolean; query: string; showFooter: boolean;+ push?: ReturnType<typeof useGuardedPush>;runDisclosure(apply: () => void): void; prepareDisclosure(): void;}) {const { t, i18n } = useTranslation();const { colors } = useTheme();const styles = useThemedStyles(makeStyles);const list = useThemedStyles(homeListStyles);- const push = useGuardedPush();- const navigation = useTeammateNavigation();+ const guardedPush = useGuardedPush();+ const push = hostPush ?? guardedPush;+ const navigation = useTeammateNavigation(push);const focused = useIsFocused() && active;const { roster, groups } = shared;const cloud = useCloudCompanionHome(focused && visible);diff --git a/apps/mobile/src/session/useTeammateNavigation.ts b/apps/mobile/src/session/useTeammateNavigation.tsindex 06ebd5238c..85214de7dd 100644--- a/apps/mobile/src/session/useTeammateNavigation.ts+++ b/apps/mobile/src/session/useTeammateNavigation.ts@@ -12,11 +12,14 @@ import { remoteSessionStore } from './remoteSessionStore';import { readRemoteCollectionCache, writeRemoteCollectionCache } from '@/device-link/remoteResourceAvailability';/** Push keeps the current chat/composer mounted; known teammates validate in the destination. */-export function useTeammateNavigation() {+export function useTeammateNavigation(hostPush?: ReturnType<typeof useGuardedPush>) {const preferences = useHomeMode();const { user, accountGeneration } = useAuth();const { i18n } = useTranslation();- const push = useGuardedPush();+ const guardedPush = useGuardedPush();+ // Defer only the final dispatch: selection and its account/mount guards must finish while the+ // drawer still exists. The host then closes/unmounts the drawer before executing the push.+ const push = hostPush ?? guardedPush;const router = useRouter();const navigation = useNavigation();const current = useRef(accountGeneration); current.current = accountGeneration;