Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
test(chat): wire saved chat dependencies into existing consumer fixtures
Chriseb2435ef1d52
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServerMembership.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServerMembership.test.tsindex 51eca0c7f3..976edf0792 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServerMembership.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServerMembership.test.ts@@ -5,6 +5,10 @@ vi.mock('../../clientEndpointsService.js', () => ({ getClientEndpoint: () => 'htvi.mock('../chatServerMedia.js', () => ({ createChatMedia: () => ({ upload: vi.fn(async () => []), download: fixture.download }) }));vi.mock('../chatServerWorkspaces.js', () => ({ chatServerWorkspaces: () => ({ read: () => null, save: vi.fn() }) }));vi.mock('../chatMigrationReceipts.js', () => ({ chatMigrationReceipts: () => ({ read: () => null, save: vi.fn() }) }));+// These transport/lifecycle fixtures isolate native disk IO; actual snapshot and+// journal persistence is exercised through chatPersistence.test.ts and chatServer.test.ts.+vi.mock('../chatLocalHistory.js', () => ({ chatLocalHistory: () => ({ read: () => null, save: vi.fn(), forget: vi.fn() }) }));+vi.mock('../chatSendJournal.js', () => ({ chatSendJournal: () => ({ read: () => null, save: vi.fn(), confirm: vi.fn(), forgetRoom: vi.fn() }) }));vi.mock('electron', () => ({ app: { get isPackaged() { return fixture.packaged; }, getPath: () => '/isolated' } }));vi.mock('node:fs', () => ({ existsSync: fixture.exists, readFileSync: () => fixture.config || '{"baseUrl":"https://example.com","token":"test"}' }));vi.mock('../botGroupChatService.js', () => ({ readPersistedReplyText: vi.fn() }));diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServerParity.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServerParity.test.tsindex fe8c9c7a6a..0efe291273 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServerParity.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServerParity.test.ts@@ -5,6 +5,10 @@ vi.mock('../../clientEndpointsService.js', () => ({ getClientEndpoint: () => 'htvi.mock('../chatServerMedia.js', () => ({ createChatMedia: () => ({ upload: fixture.upload, download: fixture.download }) }));vi.mock('../chatServerWorkspaces.js', () => ({ chatServerWorkspaces: () => ({ read: () => null, save: vi.fn() }) }));vi.mock('../chatMigrationReceipts.js', () => ({ chatMigrationReceipts: () => ({ read: () => null, save: vi.fn() }) }));+// These transport/lifecycle fixtures isolate native disk IO; actual snapshot and+// journal persistence is exercised through chatPersistence.test.ts and chatServer.test.ts.+vi.mock('../chatLocalHistory.js', () => ({ chatLocalHistory: () => ({ read: () => null, save: vi.fn(), forget: vi.fn() }) }));+vi.mock('../chatSendJournal.js', () => ({ chatSendJournal: () => ({ read: () => null, save: vi.fn(), confirm: vi.fn(), forgetRoom: vi.fn() }) }));vi.mock('electron', () => ({ app: { get isPackaged() { return fixture.packaged; }, getPath: () => '/isolated' } }));vi.mock('node:fs', () => ({ existsSync: fixture.exists, readFileSync: () => fixture.config || '{"baseUrl":"https://example.com","token":"test"}' }));vi.mock('../botGroupChatService.js', () => ({ readPersistedReplyText: vi.fn() }));diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botSessionPresentation.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botSessionPresentation.test.tsxindex 01999e46d6..28e514d649 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botSessionPresentation.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/botSessionPresentation.test.tsx@@ -20,6 +20,7 @@ vi.mock('../companionCloudStore', async (importOriginal) => {vi.mock('../botStore', async () => {const { useSyncExternalStore } = await import('react');return {+ getBotProfiles: () => h.profiles,useBotProfiles: () => useSyncExternalStore((listener) => {h.profileListeners.add(listener);return () => h.profileListeners.delete(listener);diff --git a/apps/mobile/src/__tests__/chatServerEndpointDiscovery.test.tsx b/apps/mobile/src/__tests__/chatServerEndpointDiscovery.test.tsxindex 4964ae82c6..d675b27ef1 100644--- a/apps/mobile/src/__tests__/chatServerEndpointDiscovery.test.tsx+++ b/apps/mobile/src/__tests__/chatServerEndpointDiscovery.test.tsx@@ -9,13 +9,27 @@ import { getBundledEndpointManifest } from '@cindy/maker-shared/client-endpointsconst h = vi.hoisted(() => ({auth: { user: { id: 'phone-owner' }, accountGeneration: 1, apiFetch: vi.fn(), getAccessToken: vi.fn() },storage: new Map<string, string>(),+ history: new Map<string, string>(),sockets: [] as any[],}));vi.mock('@/auth/AuthContext', () => ({ useAuth: () => h.auth }));vi.mock('@react-native-async-storage/async-storage', () => ({ default: {getItem: async (key: string) => h.storage.get(key) ?? null,setItem: async (key: string, value: string) => { h.storage.set(key, value); },+ getAllKeys: async () => [...h.storage.keys()],+ removeItem: async (key: string) => { h.storage.delete(key); },} }));+// Keep native IO controlled while exercising the real history cache and durable ledger.+vi.mock('@/session/historyDiskStoreExpo', () => ({ createHistoryDiskIO: () => ({+ files: async () => [...h.history.keys()], read: async (key: string) => h.history.get(key) ?? null,+ write: async (key: string, value: string) => { h.history.set(key, value); },+ remove: async (key: string) => { h.history.delete(key); },+}) }));+vi.mock('@/session/mobileDurableOutbox', async () => {+ const { createDurableOutbox } = await import('@/session/durableOutbox');+ const { default: storage } = await import('@react-native-async-storage/async-storage');+ return { mobileDurableOutbox: createDurableOutbox(storage) };+});vi.mock('react-native', () => ({ AppState: { currentState: 'active', addEventListener: () => ({ remove() {} }) } }));vi.mock('expo-router', async () => { const { useEffect } = await import('react'); return { useFocusEffect: (fn: any) => useEffect(fn, [fn]) }; });@@ -32,13 +46,22 @@ const room = { id: roomId, kind: 'group', state: 'joined', name: 'Fixture', archlet root: Root | undefined;let roster: any;let group: any;+let api: ReturnType<typeof import('@/chat/useChatServer')['useChatClient']>;let hooks: typeof import('@/chat/useChatServer');-function Probe() { roster = hooks.useChatServerRoster(true); group = hooks.useChatServerGroup(roomId, true); return null; }-async function render() { root ??= createRoot(document.createElement('div')); await act(async () => root!.render(createElement(Probe))); }+function Probe() { api = hooks.useChatClient(); roster = hooks.useChatServerRoster(true); group = hooks.useChatServerGroup(roomId, true); return null; }+async function render() {+ const { setMobileAuthOwner, getMobileAuthOwner } = await import('@/auth/authOwnerGeneration');+ const { getActiveMobileSessionRealm } = await import('@/config/env');+ const { mobileDurableOutbox } = await import('@/session/mobileDurableOutbox');+ setMobileAuthOwner(h.auth.user.id, getActiveMobileSessionRealm());+ await mobileDurableOutbox.activate(getMobileAuthOwner().accountKey);+ root ??= createRoot(document.createElement('div'));+ await act(async () => root!.render(createElement(Probe)));+}Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });beforeEach(() => {// reset-modules: each case reconstructs process-owned endpoint/realm startup caches.- vi.resetModules(); vi.clearAllMocks(); h.storage.clear(); h.sockets = [];+ vi.resetModules(); vi.clearAllMocks(); h.storage.clear(); h.history.clear(); h.sockets = [];vi.stubGlobal('__DEV__', false);vi.stubEnv('EXPO_PUBLIC_CINDY_AUTH_REGION', 'global');vi.stubEnv('EXPO_PUBLIC_ENDPOINT_MANIFEST_BASE_URL', bases.global);@@ -49,6 +72,7 @@ beforeEach(() => {options.assertCurrent();if (path === '/v1/me') return { actor: { id: self, kind: 'human' } };if (path.startsWith('/v1/conversations?')) return [room];+ if (path.endsWith('/members')) return [];if (path.endsWith('/snapshot')) return { room, members: [], messages: [], cursor: '1' };if ((path.endsWith('/executions') || path.includes('/execution-failures?'))) return [];if (path.includes('/messages?')) return [];@@ -82,7 +106,13 @@ it.each(['cn', 'global'] as const)('release %s discovery feeds HTTP, WS and theexpect(h.sockets.every(socket => socket.url === ws.href)).toBe(true);await act(async () => h.sockets.forEach(socket => socket.onopen({})));expect(h.sockets[0].send).toHaveBeenCalledWith(JSON.stringify({ type: 'auth', token: 'fixture-token:phone-owner' }));- await act(async () => { await group.act('send', { text: 'fixture', clientId: 'fixture-operation', mentions: { all: false, botIds: [] } }); });+ await act(async () => {+ await group.act('send', { text: 'fixture', clientId: 'fixture-operation', mentions: { all: false, botIds: [] } });+ const { mobileDurableOutbox } = await import('@/session/mobileDurableOutbox');+ const { createChatOutboxDelivery } = await import('@/chat/chatOutbox');+ await createChatOutboxDelivery({ store: mobileDurableOutbox, client: api.client,+ current: api.current, canRun: () => true, accessLost: async () => {} }).run();+ });const sent = h.auth.apiFetch.mock.calls.find(([path, options]) => path.endsWith('/messages') && options.method === 'POST')!;expect(sent[1].body).toEqual({ operationId: 'fixture-operation', content: [{ type: 'text', text: 'fixture' }], mentions: [] });// PR #7145: exercise the real group hook/client/HTTP adapter, not only a fake resolver.diff --git a/apps/mobile/src/__tests__/remoteCollectionRead.test.tsx b/apps/mobile/src/__tests__/remoteCollectionRead.test.tsxindex e4fe7c568d..d3bc2ec463 100644--- a/apps/mobile/src/__tests__/remoteCollectionRead.test.tsx+++ b/apps/mobile/src/__tests__/remoteCollectionRead.test.tsx@@ -53,6 +53,7 @@ vi.mock('@/utils/useGuardedPush', () => ({ useGuardedPush: () => h.push }));vi.mock('@/device-link/focusedTopicSubscription', () => ({ startFocusedTopicSubscription: () => () => {} }));vi.mock('@/device-link/remoteResourceAvailability', async (original) => ({ ...await original<typeof import('@/device-link/remoteResourceAvailability')>(), isRemoteResourceHostOnline: () => true, readRemoteCollectionCache: () => [], writeRemoteCollectionCache: () => {} }));vi.mock('@/device-link/remoteResourceCache', () => ({+ peekRemoteResourceSnapshot: () => null,cacheRemoteResourceItems: vi.fn(), readRemoteResourceSnapshot: async () => ({ items: {} }),isRemoteResourceUnread: () => true, markRemoteResourceRead: h.markRead,subscribeRemoteResourceCache: () => () => {}, remoteResourceCacheRevision: () => 0,