import { describe, it, expect, vi, beforeEach, MockInstance, Mock } from 'vitest' import { updateAllConversations, WorkflowProps } from './updateAllConversations' import * as summaryUpdater from './tagsUpdater' const as = (x: Partial): T => x as T type WorkflowProxy = WorkflowProps['workflow'] type Client = WorkflowProps['client'] type Logger = WorkflowProps['logger'] type Conversation = Awaited>['conversations'][number] type Message = Awaited>['messages'][number] // NOTE: These tests are temporarily skipped because the mocks need to be // adjusted to use plugin proxies instead of direct client calls (the // plugin should not rely on the client at all). describe.skip('updateAllConversations', () => { let updateTitleAndSummarySpy: MockInstance let acknowledgeStartOfProcessingMock: Mock let setCompletedMock: Mock let listConversationsMock: Mock let listMessagesMock: Mock let loggerInfoMock: Mock const initProps = (): WorkflowProps => as({ workflow: as({ acknowledgeStartOfProcessing: acknowledgeStartOfProcessingMock, setCompleted: setCompletedMock, }), client: as({ listConversations: listConversationsMock, listMessages: listMessagesMock, }), logger: as({ info: loggerInfoMock, }), }) beforeEach(() => { updateTitleAndSummarySpy = vi.spyOn(summaryUpdater, 'updateTitleAndSummary').mockResolvedValue(undefined) acknowledgeStartOfProcessingMock = vi.fn().mockResolvedValue(undefined) setCompletedMock = vi.fn().mockResolvedValue(undefined) listConversationsMock = vi.fn() listMessagesMock = vi.fn() loggerInfoMock = vi.fn() }) it('should acknowledge start, update all dirty conversations, and complete if no nextToken', async () => { listConversationsMock.mockResolvedValue({ conversations: [as({ id: 'c1' }), as({ id: 'c2' })], meta: {}, }) listMessagesMock.mockResolvedValue({ messages: [ as({ id: 'm1', conversationId: 'c1', type: 'text', payload: { text: 'Hello1' } }), as({ id: 'm2', conversationId: 'c1', type: 'text', payload: { text: 'Hello2' } }), ], meta: {}, }) const props = initProps() await updateAllConversations(props) expect(props.workflow.acknowledgeStartOfProcessing).toHaveBeenCalled() expect(props.client.listConversations).toHaveBeenCalledWith({ tags: { isDirty: 'true' } }) expect(props.client.listMessages).toHaveBeenCalledTimes(2) expect(updateTitleAndSummarySpy).toHaveBeenCalledTimes(2) expect(props.workflow.setCompleted).toHaveBeenCalled() }) it('should handle no dirty conversations gracefully', async () => { listConversationsMock.mockResolvedValue({ conversations: [], meta: { nextToken: undefined }, }) const props = initProps() await updateAllConversations(props) expect(props.client.listMessages).not.toHaveBeenCalled() expect(updateTitleAndSummarySpy).not.toHaveBeenCalled() expect(props.workflow.setCompleted).toHaveBeenCalled() }) })