import { runConversationSetupConcurrency } from '../conversation/runConversationSetupConcurrency.js'; describe('runConversationSetupConcurrency', () => { it('returns history and persisted message when both tasks succeed', async () => { const history = [{ id: '1' }]; const persistedMessage = { id: 'persisted' }; const loadHistory = jest.fn().mockResolvedValue(history); const persistMessage = jest.fn().mockResolvedValue(persistedMessage); const result = await runConversationSetupConcurrency({ loadHistory, persistMessage }); expect(loadHistory).toHaveBeenCalledTimes(1); expect(persistMessage).toHaveBeenCalledTimes(1); expect(result.history).toEqual(history); expect(result.persistedMessage).toBe(persistedMessage); expect(result.historyError).toBeUndefined(); expect(result.persistenceError).toBeUndefined(); }); it('converts task rejections to errors without throwing', async () => { const loadHistoryError = new Error('history failed'); const persistenceError = new Error('persist failed'); const loadHistory = jest.fn().mockRejectedValue(loadHistoryError); const persistMessage = jest.fn().mockRejectedValue(persistenceError); const result = await runConversationSetupConcurrency({ loadHistory, persistMessage }); expect(result.history).toEqual([]); expect(result.persistedMessage).toBeNull(); expect(result.historyError).toEqual(loadHistoryError); expect(result.persistenceError).toEqual(persistenceError); }); it('handles optional persistence task by returning null message', async () => { const history = [{ id: '1' }]; const loadHistory = jest.fn().mockResolvedValue(history); const result = await runConversationSetupConcurrency({ loadHistory }); expect(loadHistory).toHaveBeenCalledTimes(1); expect(result.history).toEqual(history); expect(result.persistedMessage).toBeNull(); expect(result.persistenceError).toBeUndefined(); }); });