From 4929bf01f9148bb39a538b99d29fa3f4376d27cc Mon Sep 17 00:00:00 2001 From: Assem Hafez Date: Tue, 1 Oct 2024 12:20:07 +0000 Subject: [PATCH 1/4] replace old formatters --- .../__tests__/format-workflow-history.test.ts | 32 +- ...-cancel-requested-event-attributes.test.ts | 68 -- ...xecution-canceled-event-attributes.test.ts | 64 -- ...ecution-completed-event-attributes.test.ts | 69 -- ...-continued-as-new-event-attributes.test.ts | 89 -- ...-execution-failed-event-attributes.test.ts | 37 - ...xecution-signaled-event-attributes.test.ts | 31 - ...execution-started-event-attributes.test.ts | 204 ----- ...cution-terminated-event-attributes.test.ts | 36 - .../__tests__/index.test.ts | 123 +-- .../__tests__/index.test.ts.snapshot | 758 ++++++++++++++++++ ...ution-cancel-requested-event-attributes.ts | 40 - ...low-execution-canceled-event-attributes.ts | 38 - ...ow-execution-completed-event-attributes.ts | 38 - ...ution-continued-as-new-event-attributes.ts | 67 -- ...kflow-execution-failed-event-attributes.ts | 36 - ...low-execution-signaled-event-attributes.ts | 32 - ...flow-execution-started-event-attributes.ts | 91 --- ...w-execution-terminated-event-attributes.ts | 34 - .../format-workflow-history-event/index.ts | 49 +- .../format-workflow-history.ts | 10 +- .../schema/format-history-event-schema.ts | 381 +++++++++ .../__fixtures__/all-workflow-event-types.ts | 101 +++ ...request-cancel-external-workflow-events.ts | 28 + 24 files changed, 1285 insertions(+), 1171 deletions(-) delete mode 100644 src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-cancel-requested-event-attributes.test.ts delete mode 100644 src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-canceled-event-attributes.test.ts delete mode 100644 src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-completed-event-attributes.test.ts delete mode 100644 src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-continued-as-new-event-attributes.test.ts delete mode 100644 src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-failed-event-attributes.test.ts delete mode 100644 src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-signaled-event-attributes.test.ts delete mode 100644 src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-started-event-attributes.test.ts delete mode 100644 src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-terminated-event-attributes.test.ts create mode 100644 src/utils/data-formatters/format-workflow-history-event/__tests__/index.test.ts.snapshot delete mode 100644 src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-cancel-requested-event-attributes.ts delete mode 100644 src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-canceled-event-attributes.ts delete mode 100644 src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-completed-event-attributes.ts delete mode 100644 src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-continued-as-new-event-attributes.ts delete mode 100644 src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-failed-event-attributes.ts delete mode 100644 src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-signaled-event-attributes.ts delete mode 100644 src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-started-event-attributes.ts delete mode 100644 src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-terminated-event-attributes.ts create mode 100644 src/utils/data-formatters/schema/format-history-event-schema.ts create mode 100644 src/views/workflow-history/__fixtures__/all-workflow-event-types.ts diff --git a/src/utils/data-formatters/__tests__/format-workflow-history.test.ts b/src/utils/data-formatters/__tests__/format-workflow-history.test.ts index 68b6901f5..9800db2ad 100644 --- a/src/utils/data-formatters/__tests__/format-workflow-history.test.ts +++ b/src/utils/data-formatters/__tests__/format-workflow-history.test.ts @@ -1,3 +1,5 @@ +import { completeActivityTaskEvent } from '@/views/workflow-history/__fixtures__/workflow-history-activity-events'; + import formatTimestampToDatetime from '../format-timestamp-to-datetime'; import formatWorkflowHistory from '../format-workflow-history'; import formatWorkflowHistoryEvent from '../format-workflow-history-event'; @@ -16,10 +18,6 @@ const mockedFormatWorkflowHistoryEvent = formatWorkflowHistoryEvent as jest.MockedFunction< typeof formatWorkflowHistoryEvent >; -const mockedFormatWorkflowHistoryEventType = - formatWorkflowHistoryEventType as jest.MockedFunction< - typeof formatWorkflowHistoryEventType - >; describe('formatWorkflowHistory', () => { beforeEach(() => { @@ -29,21 +27,13 @@ describe('formatWorkflowHistory', () => { it('should format workflow history correctly', () => { const expectedTimestamp = new Date('2023-06-18T12:34:56.Z'); mockedFormatTimestampToDatetime.mockReturnValue(expectedTimestamp); + //@ts-expect-error using mock value that doesn't match formatting schema for easier validation mockedFormatWorkflowHistoryEvent.mockReturnValue({ formattedEvent: true }); - mockedFormatWorkflowHistoryEventType.mockReturnValue( - 'ActivityTaskCanceled' - ); const input = { archived: true, history: { - events: [ - { - eventId: '1', - eventTime: { seconds: '1234567890', nano: 0 }, - attributes: 'workflowExecutionStartedEventAttributes', - }, - ], + events: [completeActivityTaskEvent], }, rawHistory: ['raw event data'], otherData: 'some other data', @@ -54,10 +44,6 @@ describe('formatWorkflowHistory', () => { history: { events: [ { - eventId: 1, - timestamp: expectedTimestamp, - eventType: 'ActivityTaskCanceled', - attributes: 'workflowExecutionStartedEventAttributes', formattedEvent: true, }, ], @@ -67,16 +53,6 @@ describe('formatWorkflowHistory', () => { }; expect(formatWorkflowHistory(input)).toEqual(expectedOutput); - expect(mockedFormatTimestampToDatetime).toHaveBeenCalledWith({ - seconds: '1234567890', - nano: 0, - }); - expect(mockedFormatWorkflowHistoryEvent).toHaveBeenCalledWith({ - attributes: 'workflowExecutionStartedEventAttributes', - }); - expect(formatWorkflowHistoryEventType).toHaveBeenCalledWith( - 'workflowExecutionStartedEventAttributes' - ); }); it('should set archived to null if not provided', () => { diff --git a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-cancel-requested-event-attributes.test.ts b/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-cancel-requested-event-attributes.test.ts deleted file mode 100644 index fe2dcb9e1..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-cancel-requested-event-attributes.test.ts +++ /dev/null @@ -1,68 +0,0 @@ -import formatWorkflowExecutionCancelRequestedEventAttributes from '../format-workflow-execution-cancel-requested-event-attributes'; - -describe('formatWorkflowExecutionCancelRequestedEventAttributes', () => { - test('should return formatted attributes with valid externalExecutionInfo', () => { - const externalExecutionInfo = { - initiatedId: '123', - workflowExecution: { workflowId: 'workflowId', runId: 'runId' }, - }; - - const formattedAttributes = - formatWorkflowExecutionCancelRequestedEventAttributes({ - externalExecutionInfo, - otherAttribute: 'value', - }); - - expect(formattedAttributes).toEqual({ - externalInitiatedEventId: 123, - externalWorkflowExecution: { workflowId: 'workflowId', runId: 'runId' }, - otherAttribute: 'value', - }); - }); - - test('should handle null externalExecutionInfo', () => { - const formattedAttributes = - formatWorkflowExecutionCancelRequestedEventAttributes({ - externalExecutionInfo: null, - otherAttribute: 'value', - }); - - expect(formattedAttributes).toEqual({ - externalInitiatedEventId: null, - externalWorkflowExecution: undefined, - otherAttribute: 'value', - }); - }); - - test('should handle undefined externalExecutionInfo', () => { - const formattedAttributes = - formatWorkflowExecutionCancelRequestedEventAttributes({ - otherAttribute: 'value', - }); - - expect(formattedAttributes).toEqual({ - externalInitiatedEventId: null, - externalWorkflowExecution: undefined, - otherAttribute: 'value', - }); - }); - - test('should handle missing initiatedId in externalExecutionInfo', () => { - const externalExecutionInfo = { - workflowExecution: { workflowId: 'workflowId', runId: 'runId' }, - }; - - const formattedAttributes = - formatWorkflowExecutionCancelRequestedEventAttributes({ - // @ts-expect-error - initiatedId is missing intentionally - externalExecutionInfo, - otherAttribute: 'value', - }); - - expect(formattedAttributes).toEqual({ - externalInitiatedEventId: null, - externalWorkflowExecution: { workflowId: 'workflowId', runId: 'runId' }, - otherAttribute: 'value', - }); - }); -}); diff --git a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-canceled-event-attributes.test.ts b/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-canceled-event-attributes.test.ts deleted file mode 100644 index d8d9f86ec..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-canceled-event-attributes.test.ts +++ /dev/null @@ -1,64 +0,0 @@ -import formatPayload from '../../format-payload'; -import formatWorkflowEventId from '../../format-workflow-event-id'; -import formatWorkflowExecutionCanceledEventAttributes from '../format-workflow-execution-canceled-event-attributes'; - -jest.mock('../../format-workflow-event-id'); -jest.mock('../../format-payload'); - -const mockedFormatWorkflowEventId = - formatWorkflowEventId as jest.MockedFunction; -const mockedFormatPayload = formatPayload as jest.MockedFunction< - typeof formatPayload ->; - -describe('formatWorkflowExecutionCanceledEventAttributes', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - - test('should format attributes correctly with valid input', () => { - const decisionTaskCompletedEventId = 123; - const details = { data: 'someData' }; - - mockedFormatWorkflowEventId.mockReturnValueOnce( - decisionTaskCompletedEventId - ); - mockedFormatPayload.mockReturnValueOnce(details); - - const formattedAttributes = formatWorkflowExecutionCanceledEventAttributes({ - decisionTaskCompletedEventId, - details, - }); - - expect(formattedAttributes).toEqual({ - decisionTaskCompletedEventId, - details, - }); - }); - - test('should call formatWorkflowEventId with decisionTaskCompletedEventId', () => { - const decisionTaskCompletedEventId = 123; - const details = { data: 'someData' }; - - formatWorkflowExecutionCanceledEventAttributes({ - decisionTaskCompletedEventId, - details, - }); - - expect(formatWorkflowEventId).toHaveBeenCalledWith( - decisionTaskCompletedEventId - ); - }); - - test('should call formatPayload with details', () => { - const decisionTaskCompletedEventId = 123; - const details = { data: 'someData' }; - - formatWorkflowExecutionCanceledEventAttributes({ - decisionTaskCompletedEventId, - details, - }); - - expect(formatPayload).toHaveBeenCalledWith(details); - }); -}); diff --git a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-completed-event-attributes.test.ts b/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-completed-event-attributes.test.ts deleted file mode 100644 index 623e8cddd..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-completed-event-attributes.test.ts +++ /dev/null @@ -1,69 +0,0 @@ -import formatPayload from '../../format-payload'; -import formatWorkflowEventId from '../../format-workflow-event-id'; -import formatWorkflowExecutionCompletedEventAttributes from '../format-workflow-execution-completed-event-attributes'; - -jest.mock('../../format-workflow-event-id'); -jest.mock('../../format-payload'); -const mockedFormatWorkflowEventId = - formatWorkflowEventId as jest.MockedFunction; -const mockedFormatPayload = formatPayload as jest.MockedFunction< - typeof formatPayload ->; - -describe('formatWorkflowExecutionCompletedEventAttributes', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - - test('should format attributes correctly with valid input', () => { - const decisionTaskCompletedEventId = 123; - const result = { data: 'someData' }; - mockedFormatWorkflowEventId.mockReturnValueOnce( - decisionTaskCompletedEventId - ); - mockedFormatPayload.mockReturnValueOnce(result); - - const formattedAttributes = formatWorkflowExecutionCompletedEventAttributes( - { - decisionTaskCompletedEventId, - result, - } - ); - - expect(formatWorkflowEventId).toHaveBeenCalledWith( - decisionTaskCompletedEventId - ); - expect(formatPayload).toHaveBeenCalledWith(result); - - expect(formattedAttributes).toEqual({ - decisionTaskCompletedEventId, - result, - }); - }); - - test('should call formatWorkflowEventId with decisionTaskCompletedEventId', () => { - const decisionTaskCompletedEventId = 123; - const result = { data: 'someData' }; - - formatWorkflowExecutionCompletedEventAttributes({ - decisionTaskCompletedEventId, - result, - }); - - expect(formatWorkflowEventId).toHaveBeenCalledWith( - decisionTaskCompletedEventId - ); - }); - - test('should call formatPayload with result', () => { - const decisionTaskCompletedEventId = 123; - const result = { data: 'someData' }; - - formatWorkflowExecutionCompletedEventAttributes({ - decisionTaskCompletedEventId, - result, - }); - - expect(formatPayload).toHaveBeenCalledWith(result); - }); -}); diff --git a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-continued-as-new-event-attributes.test.ts b/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-continued-as-new-event-attributes.test.ts deleted file mode 100644 index 6e274c8fa..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-continued-as-new-event-attributes.test.ts +++ /dev/null @@ -1,89 +0,0 @@ -import formatDurationToSeconds from '../../format-duration-to-seconds'; -import formatEnum from '../../format-enum'; -import formatFailureDetails from '../../format-failure-details'; -import formatPayloadMap from '../../format-payload-map'; -import formatWorkflowEventId from '../../format-workflow-event-id'; -import formatWorkflowInputPayload from '../../format-workflow-input-payload'; -import formatWorkflowExecutionContinuedAsNewEventAttributes from '../format-workflow-execution-continued-as-new-event-attributes'; - -jest.mock('../../format-duration-to-seconds'); -jest.mock('../../format-workflow-event-id'); -jest.mock('../../format-failure-details'); -jest.mock('../../format-enum'); -jest.mock('../../format-payload-map'); -jest.mock('../../format-workflow-input-payload'); - -const mockedFormatDurationToSeconds = - formatDurationToSeconds as jest.MockedFunction< - typeof formatDurationToSeconds - >; -const mockedFormatWorkflowEventId = - formatWorkflowEventId as jest.MockedFunction; -const mockedFormatFailureDetails = formatFailureDetails as jest.MockedFunction< - typeof formatFailureDetails ->; -const mockedFormatEnum = formatEnum as jest.MockedFunction; -const mockedFormatPayloadMap = formatPayloadMap as jest.MockedFunction< - typeof formatPayloadMap ->; -const mockedFormatWorkflowInputPayload = - formatWorkflowInputPayload as jest.MockedFunction< - typeof formatWorkflowInputPayload - >; - -describe('formatWorkflowExecutionContinuedAsNewEventAttributes', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - - test('should format attributes correctly with valid input', () => { - const eventAttributes = { - backoffStartInterval: { seconds: 60 }, - decisionTaskCompletedEventId: 123, - executionStartToCloseTimeout: { seconds: 3600 }, - failure: { reason: 'failure reason' }, - header: { fields: { key: 'value' } }, - initiator: 'someInitiator', - input: { data: 'someData' }, - memo: { fields: { memoKey: 'memoValue' } }, - searchAttributes: { indexedFields: { attrKey: 'attrValue' } }, - taskList: { kind: 'someKind', name: 'taskListName' }, - taskStartToCloseTimeout: { seconds: 1800 }, - }; - - mockedFormatDurationToSeconds - .mockReturnValueOnce(60) - .mockReturnValueOnce(3600) - .mockReturnValueOnce(1800); - mockedFormatWorkflowEventId.mockReturnValueOnce(123); - mockedFormatFailureDetails.mockReturnValueOnce('formattedFailureDetails'); - mockedFormatEnum - .mockReturnValueOnce('formattedInitiator') - .mockReturnValueOnce('formattedKind'); - mockedFormatPayloadMap - .mockReturnValueOnce(eventAttributes.header) - .mockReturnValueOnce(eventAttributes.memo) - .mockReturnValueOnce(eventAttributes.searchAttributes); - mockedFormatWorkflowInputPayload.mockReturnValueOnce(['someData']); - - const formattedAttributes = - formatWorkflowExecutionContinuedAsNewEventAttributes(eventAttributes); - expect(formattedAttributes).toEqual({ - decisionTaskCompletedEventId: 123, - executionStartToCloseTimeoutSeconds: 3600, - header: { fields: { key: 'value' } }, - initiator: 'formattedInitiator', - input: ['someData'], - memo: { fields: { memoKey: 'memoValue' } }, - searchAttributes: { indexedFields: { attrKey: 'attrValue' } }, - taskList: { - kind: 'formattedKind', - name: 'taskListName', - }, - backoffStartIntervalInSeconds: 60, - failureDetails: 'formattedFailureDetails', - failureReason: 'failure reason', - taskStartToCloseTimeoutSeconds: 1800, - }); - }); -}); diff --git a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-failed-event-attributes.test.ts b/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-failed-event-attributes.test.ts deleted file mode 100644 index 7df8f18e6..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-failed-event-attributes.test.ts +++ /dev/null @@ -1,37 +0,0 @@ -import formatFailureDetails from '../../format-failure-details'; -import formatWorkflowEventId from '../../format-workflow-event-id'; -import formatWorkflowExecutionFailedEventAttributes from '../format-workflow-execution-failed-event-attributes'; - -jest.mock('../../format-failure-details'); -jest.mock('../../format-workflow-event-id'); - -const mockedFormatFailureDetails = formatFailureDetails as jest.MockedFunction< - typeof formatFailureDetails ->; -const mockedFormatWorkflowEventId = - formatWorkflowEventId as jest.MockedFunction; - -describe('formatWorkflowExecutionFailedEventAttributes', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - - test('should format attributes correctly with valid input', () => { - const failure = { reason: 'some reason' }; - const decisionTaskCompletedEventId = 123; - - mockedFormatWorkflowEventId.mockReturnValueOnce(123); - mockedFormatFailureDetails.mockReturnValueOnce('formattedFailureDetails'); - - const formattedAttributes = formatWorkflowExecutionFailedEventAttributes({ - failure, - decisionTaskCompletedEventId, - }); - - expect(formattedAttributes).toEqual({ - decisionTaskCompletedEventId: 123, - details: 'formattedFailureDetails', - reason: 'some reason', - }); - }); -}); diff --git a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-signaled-event-attributes.test.ts b/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-signaled-event-attributes.test.ts deleted file mode 100644 index 88ad1faba..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-signaled-event-attributes.test.ts +++ /dev/null @@ -1,31 +0,0 @@ -import formatWorkflowInputPayload from '../../format-workflow-input-payload'; -import formatWorkflowExecutionSignaledEventAttributes from '../format-workflow-execution-signaled-event-attributes'; - -jest.mock('../../format-workflow-input-payload'); - -const mockedFormatWorkflowInputPayload = - formatWorkflowInputPayload as jest.MockedFunction< - typeof formatWorkflowInputPayload - >; - -describe('formatWorkflowExecutionSignaledEventAttributes', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - - test('should format attributes correctly with valid input', () => { - const input = { data: 'someData' }; - - const mockedFormattedInput = ['someData']; - mockedFormatWorkflowInputPayload.mockReturnValueOnce(mockedFormattedInput); - - const formattedAttributes = formatWorkflowExecutionSignaledEventAttributes({ - input, - }); - - expect(mockedFormatWorkflowInputPayload).toHaveBeenCalledWith(input); - expect(formattedAttributes).toEqual({ - input: mockedFormattedInput, - }); - }); -}); diff --git a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-started-event-attributes.test.ts b/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-started-event-attributes.test.ts deleted file mode 100644 index 1b2db6faa..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-started-event-attributes.test.ts +++ /dev/null @@ -1,204 +0,0 @@ -import formatDurationToSeconds from '../../format-duration-to-seconds'; -import formatEnum from '../../format-enum'; -import formatFailureDetails from '../../format-failure-details'; -import formatPayloadMap from '../../format-payload-map'; -import formatPrevAutoResetPoints from '../../format-prev-auto-reset-points'; -import formatRetryPolicy from '../../format-retry-policy'; -import formatTimestampToDatetime from '../../format-timestamp-to-datetime'; -import formatWorkflowInputPayload from '../../format-workflow-input-payload'; -import formatWorkflowExecutionStartedEventAttributes from '../format-workflow-execution-started-event-attributes'; - -jest.mock('../../format-workflow-input-payload'); -jest.mock('../../format-enum'); -jest.mock('../../format-failure-details'); -jest.mock('../../format-payload-map'); -jest.mock('../../format-timestamp-to-datetime'); -jest.mock('../../format-duration-to-seconds'); -jest.mock('../../format-retry-policy'); -jest.mock('../../format-prev-auto-reset-points'); - -const mockedFormatWorkflowInputPayload = - formatWorkflowInputPayload as jest.MockedFunction< - typeof formatWorkflowInputPayload - >; -const mockedFormatEnum = formatEnum as jest.MockedFunction; -const mockedFormatFailureDetails = formatFailureDetails as jest.MockedFunction< - typeof formatFailureDetails ->; -const mockedFormatPayloadMap = formatPayloadMap as jest.MockedFunction< - typeof formatPayloadMap ->; -const mockedFormatTimestampToDatetime = - formatTimestampToDatetime as jest.MockedFunction< - typeof formatTimestampToDatetime - >; -const mockedFormatDurationToSeconds = - formatDurationToSeconds as jest.MockedFunction< - typeof formatDurationToSeconds - >; -const mockedFormatRetryPolicy = formatRetryPolicy as jest.MockedFunction< - typeof formatRetryPolicy ->; -const mockedFormatPrevAutoResetPoints = - formatPrevAutoResetPoints as jest.MockedFunction< - typeof formatPrevAutoResetPoints - >; - -describe('formatWorkflowExecutionStartedEventAttributes', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - - test('should format attributes correctly with valid input', () => { - const eventAttributes = { - attempt: 1, - continuedExecutionRunId: 'continuedRunId', - continuedFailure: { reason: 'failure reason' }, - cronSchedule: '*/5 * * * *', - executionStartToCloseTimeout: { seconds: 3600 }, - expirationTime: { seconds: 1652817600 }, - firstDecisionTaskBackoff: { seconds: 60 }, - firstExecutionRunId: 'firstRunId', - firstScheduledTimeNano: 123456789, - identity: 'identity', - initiator: 'someInitiator', - input: { data: 'someData' }, - memo: { fields: { memoKey: 'memoValue' } }, - originalExecutionRunId: 'originalRunId', - parentExecutionInfo: { - initiatedId: '456', - domainName: 'parentDomain', - workflowExecution: 'parentWorkflow', - }, - prevAutoResetPoints: { - points: [ - { - createdTime: { seconds: 123, nanos: 456 }, - expiringTime: { seconds: 789, nanos: 101 }, - }, - ], - }, - retryPolicy: { - expirationInterval: { seconds: 600 }, - initialInterval: { seconds: 30 }, - maximumInterval: { seconds: 300 }, - }, - searchAttributes: { indexedFields: { attrKey: 'attrValue' } }, - taskList: { kind: 'someKind', name: 'taskListName' }, - taskStartToCloseTimeout: { seconds: 1800 }, - }; - - mockedFormatWorkflowInputPayload.mockReturnValueOnce(['someData']); - mockedFormatEnum - .mockReturnValueOnce('formattedKind') - .mockReturnValueOnce('formattedInitiator'); - mockedFormatFailureDetails.mockReturnValueOnce('formattedFailureDetails'); - mockedFormatPayloadMap - .mockReturnValueOnce(eventAttributes.memo) - .mockReturnValueOnce(eventAttributes.searchAttributes); - mockedFormatTimestampToDatetime.mockReturnValueOnce( - new Date(1652817600000) - ); - mockedFormatDurationToSeconds - .mockReturnValueOnce(3600) - .mockReturnValueOnce(1800) - .mockReturnValueOnce(60); - mockedFormatRetryPolicy.mockReturnValueOnce({ - expirationIntervalInSeconds: 600, - initialIntervalInSeconds: 30, - maximumIntervalInSeconds: 300, - backoffCoefficient: 100, - maximumAttempts: 1, - nonRetryableErrorReasons: [], - }); - mockedFormatPrevAutoResetPoints.mockReturnValueOnce({ - points: [ - { - createdTimeNano: new Date(123456000), - expiringTimeNano: new Date(789000101), - binaryChecksum: '122434', - firstDecisionCompletedId: '123', - resettable: true, - runId: '2348yjk', - }, - ], - }); - - const formattedAttributes = - formatWorkflowExecutionStartedEventAttributes(eventAttributes); - - expect(mockedFormatWorkflowInputPayload).toHaveBeenCalledWith( - eventAttributes.input - ); - expect(formatEnum).toHaveBeenCalledWith( - eventAttributes.initiator, - 'CONTINUE_AS_NEW_INITIATOR' - ); - expect(formatFailureDetails).toHaveBeenCalledWith( - eventAttributes.continuedFailure - ); - expect(formatPayloadMap).toHaveBeenCalledWith( - eventAttributes.memo, - 'fields' - ); - expect(formatTimestampToDatetime).toHaveBeenCalledWith( - eventAttributes.expirationTime - ); - expect(formatDurationToSeconds).toHaveBeenCalledWith( - eventAttributes.executionStartToCloseTimeout - ); - expect(formatDurationToSeconds).toHaveBeenCalledWith( - eventAttributes.firstDecisionTaskBackoff - ); - expect(formatRetryPolicy).toHaveBeenCalledWith(eventAttributes.retryPolicy); - expect(formatPrevAutoResetPoints).toHaveBeenCalledWith( - eventAttributes.prevAutoResetPoints - ); - expect(formattedAttributes).toEqual({ - taskList: { - kind: 'formattedKind', - name: 'taskListName', - }, - input: ['someData'], - executionStartToCloseTimeoutSeconds: 3600, - taskStartToCloseTimeoutSeconds: 1800, - attempt: 1, - continuedExecutionRunId: 'continuedRunId', - continuedFailureDetails: 'formattedFailureDetails', - continuedFailureReason: 'failure reason', - cronSchedule: '*/5 * * * *', - expirationTimestamp: new Date(1652817600000), - firstDecisionTaskBackoffSeconds: 60, - firstExecutionRunId: 'firstRunId', - firstScheduledTimeNano: 123456789, - identity: 'identity', - initiator: 'formattedInitiator', - memo: eventAttributes.memo, - originalExecutionRunId: 'originalRunId', - parentInitiatedEventId: 456, - parentWorkflowDomain: 'parentDomain', - parentWorkflowExecution: 'parentWorkflow', - prevAutoResetPoints: { - points: [ - { - createdTimeNano: new Date(123456000), - expiringTimeNano: new Date(789000101), - binaryChecksum: '122434', - firstDecisionCompletedId: '123', - resettable: true, - runId: '2348yjk', - }, - ], - }, - retryPolicy: { - expirationIntervalInSeconds: 600, - initialIntervalInSeconds: 30, - maximumIntervalInSeconds: 300, - backoffCoefficient: 100, - maximumAttempts: 1, - nonRetryableErrorReasons: [], - }, - searchAttributes: eventAttributes.searchAttributes, - }); - }); -}); diff --git a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-terminated-event-attributes.test.ts b/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-terminated-event-attributes.test.ts deleted file mode 100644 index 08527731d..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/__tests__/format-workflow-execution-terminated-event-attributes.test.ts +++ /dev/null @@ -1,36 +0,0 @@ -import formatPayload from '../../format-payload'; -import formatWorkflowExecutionTerminatedEventAttributes from '../format-workflow-execution-terminated-event-attributes'; - -jest.mock('../../format-payload'); - -const mockedFormatPayload = formatPayload as jest.MockedFunction< - typeof formatPayload ->; - -describe('formatWorkflowExecutionTerminatedEventAttributes', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - - test('should format attributes correctly with valid input', () => { - const details = { data: 'someData' }; - - mockedFormatPayload.mockReturnValueOnce(details); - - const formattedAttributes = - formatWorkflowExecutionTerminatedEventAttributes({ - details, - }); - expect(formattedAttributes).toEqual({ - details, - }); - }); - - test('should call formatPayload with details', () => { - const details = { data: 'someData' }; - - formatWorkflowExecutionTerminatedEventAttributes({ details }); - - expect(formatPayload).toHaveBeenCalledWith(details); - }); -}); diff --git a/src/utils/data-formatters/format-workflow-history-event/__tests__/index.test.ts b/src/utils/data-formatters/format-workflow-history-event/__tests__/index.test.ts index 1822880b3..1735b516e 100644 --- a/src/utils/data-formatters/format-workflow-history-event/__tests__/index.test.ts +++ b/src/utils/data-formatters/format-workflow-history-event/__tests__/index.test.ts @@ -1,124 +1,11 @@ -import formatWorkflowExecutionCancelRequestedEventAttributes from '../format-workflow-execution-cancel-requested-event-attributes'; -import formatWorkflowExecutionCanceledEventAttributes from '../format-workflow-execution-canceled-event-attributes'; -import formatWorkflowExecutionCompletedEventAttributes from '../format-workflow-execution-completed-event-attributes'; -import formatWorkflowExecutionContinuedAsNewEventAttributes from '../format-workflow-execution-continued-as-new-event-attributes'; -import formatWorkflowExecutionFailedEventAttributes from '../format-workflow-execution-failed-event-attributes'; -import formatWorkflowExecutionSignaledEventAttributes from '../format-workflow-execution-signaled-event-attributes'; -import formatWorkflowExecutionStartedEventAttributes from '../format-workflow-execution-started-event-attributes'; -import formatWorkflowExecutionTerminatedEventAttributes from '../format-workflow-execution-terminated-event-attributes'; -import formatWorkflowHistoryEvent, { - type AttributesFormattersEvent, -} from '../index'; +import { allWorkflowEvents } from '@/views/workflow-history/__fixtures__/all-workflow-event-types'; -jest.mock('../format-workflow-execution-cancel-requested-event-attributes'); -jest.mock('../format-workflow-execution-canceled-event-attributes'); -jest.mock('../format-workflow-execution-completed-event-attributes'); -jest.mock('../format-workflow-execution-continued-as-new-event-attributes'); -jest.mock('../format-workflow-execution-failed-event-attributes'); -jest.mock('../format-workflow-execution-signaled-event-attributes'); -jest.mock('../format-workflow-execution-started-event-attributes'); -jest.mock('../format-workflow-execution-terminated-event-attributes'); - -const mockedFormatWorkflowExecutionCancelRequestedEventAttributes = - formatWorkflowExecutionCancelRequestedEventAttributes as jest.MockedFunction< - typeof formatWorkflowExecutionCancelRequestedEventAttributes - >; -const mockedFormatWorkflowExecutionCanceledEventAttributes = - formatWorkflowExecutionCanceledEventAttributes as jest.MockedFunction< - typeof formatWorkflowExecutionCanceledEventAttributes - >; -const mockedFormatWorkflowExecutionCompletedEventAttributes = - formatWorkflowExecutionCompletedEventAttributes as jest.MockedFunction< - typeof formatWorkflowExecutionCompletedEventAttributes - >; -const mockedFormatWorkflowExecutionContinuedAsNewEventAttributes = - formatWorkflowExecutionContinuedAsNewEventAttributes as jest.MockedFunction< - typeof formatWorkflowExecutionContinuedAsNewEventAttributes - >; -const mockedFormatWorkflowExecutionFailedEventAttributes = - formatWorkflowExecutionFailedEventAttributes as jest.MockedFunction< - typeof formatWorkflowExecutionFailedEventAttributes - >; -const mockedFormatWorkflowExecutionSignaledEventAttributes = - formatWorkflowExecutionSignaledEventAttributes as jest.MockedFunction< - typeof formatWorkflowExecutionSignaledEventAttributes - >; -const mockedFormatWorkflowExecutionStartedEventAttributes = - formatWorkflowExecutionStartedEventAttributes as jest.MockedFunction< - typeof formatWorkflowExecutionStartedEventAttributes - >; -const mockedFormatWorkflowExecutionTerminatedEventAttributes = - formatWorkflowExecutionTerminatedEventAttributes as jest.MockedFunction< - typeof formatWorkflowExecutionTerminatedEventAttributes - >; +import formatWorkflowHistoryEvent from '..'; describe('formatWorkflowHistoryEvent', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - - const testCases: AttributesFormattersEvent[] = [ - { - attributes: 'workflowExecutionCancelRequestedEventAttributes', - formatter: mockedFormatWorkflowExecutionCancelRequestedEventAttributes, - }, - { - attributes: 'workflowExecutionCanceledEventAttributes', - formatter: mockedFormatWorkflowExecutionCanceledEventAttributes, - }, - { - attributes: 'workflowExecutionCompletedEventAttributes', - formatter: mockedFormatWorkflowExecutionCompletedEventAttributes, - }, - { - attributes: 'workflowExecutionContinuedAsNewEventAttributes', - formatter: mockedFormatWorkflowExecutionContinuedAsNewEventAttributes, - }, - { - attributes: 'workflowExecutionFailedEventAttributes', - formatter: mockedFormatWorkflowExecutionFailedEventAttributes, - }, - { - attributes: 'workflowExecutionSignaledEventAttributes', - formatter: mockedFormatWorkflowExecutionSignaledEventAttributes, - }, - { - attributes: 'workflowExecutionStartedEventAttributes', - formatter: mockedFormatWorkflowExecutionStartedEventAttributes, - }, - { - attributes: 'workflowExecutionTerminatedEventAttributes', - formatter: mockedFormatWorkflowExecutionTerminatedEventAttributes, - }, - ]; - - testCases.forEach(({ attributes, formatter }) => { - test(`should format ${attributes} correctly`, () => { - const event = { - attributes: attributes, - [attributes]: { someData: 'someValue' }, - }; - - formatter.mockReturnValueOnce({ formattedData: 'formattedValue' }); - - const result = formatWorkflowHistoryEvent(event); - - expect(formatter).toHaveBeenCalledWith(event[attributes]); - expect(result).toEqual({ - [attributes]: { formattedData: 'formattedValue' }, - }); + allWorkflowEvents.forEach((event) => { + it(`should format workflow ${event.attributes} to match snapshot`, () => { + expect(formatWorkflowHistoryEvent(event)).toMatchSnapshot(); }); }); - - test('should return event as is if no formatter is found', () => { - const event = { - attributes: 'unknownAttributes', - someData: 'someValue', - }; - - // @ts-expect-error - intentionally testing unknown attributes - const result = formatWorkflowHistoryEvent(event); - - expect(result).toEqual(event); - }); }); diff --git a/src/utils/data-formatters/format-workflow-history-event/__tests__/index.test.ts.snapshot b/src/utils/data-formatters/format-workflow-history-event/__tests__/index.test.ts.snapshot new file mode 100644 index 000000000..79a098942 --- /dev/null +++ b/src/utils/data-formatters/format-workflow-history-event/__tests__/index.test.ts.snapshot @@ -0,0 +1,758 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`formatWorkflowHistoryEvent should format workflow activityTaskCancelRequestedEventAttributes to match snapshot 1`] = ` +{ + "activityId": "0", + "decisionTaskCompletedEventId": 4, + "eventId": 52, + "eventType": "ActivityTaskCancelRequested", + "taskId": "605133998", + "timestamp": 2024-09-19T12:08:35.549Z, + "version": "587402", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow activityTaskCanceledEventAttributes to match snapshot 1`] = ` +{ + "details": null, + "eventId": 14, + "eventType": "ActivityTaskCanceled", + "identity": "canary@958hb341-a376-431b-a17a-ed7d8a97ba91", + "latestCancelRequestedEventId": 13, + "scheduledEventId": 7, + "startedEventId": 9, + "taskId": "22647174813", + "timestamp": 2024-09-07T22:16:10.632Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow activityTaskCompletedEventAttributes to match snapshot 1`] = ` +{ + "eventId": 10, + "eventType": "ActivityTaskCompleted", + "identity": "cadence@958ab341-a386-431b-a17a-ed7d8a97ba91", + "result": null, + "scheduledEventId": 7, + "startedEventId": 9, + "taskId": "22647174813", + "timestamp": 2024-09-07T22:16:10.632Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow activityTaskFailedEventAttributes to match snapshot 1`] = ` +{ + "details": null, + "eventId": 11, + "eventType": "ActivityTaskFailed", + "identity": "cadence@958ab341-a376-431n-a17a-ed7d8a97ba91", + "reason": "", + "scheduledEventId": 7, + "startedEventId": 9, + "taskId": "22647174813", + "timestamp": 2024-09-07T22:16:10.632Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow activityTaskScheduledEventAttributes to match snapshot 1`] = ` +{ + "activityId": "0", + "activityType": { + "name": "activity.cron.Start", + }, + "decisionTaskCompletedEventId": 4, + "domain": null, + "eventId": 7, + "eventType": "ActivityTaskScheduled", + "header": { + "fields": { + "test-field": "1kqptday8h@xu-13tt7m", + }, + }, + "heartbeatTimeoutSeconds": 0, + "input": [ + "1725747370575409843", + "gadence-canary-xdc", + "workflow.sanity", + ], + "retryPolicy": null, + "scheduleToCloseTimeoutSeconds": 360, + "scheduleToStartTimeoutSeconds": 180, + "startToCloseTimeoutSeconds": 180, + "taskId": "22647174805", + "taskList": { + "kind": null, + "name": "task-queue", + }, + "timestamp": 2024-09-07T22:16:10.599Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow activityTaskStartedEventAttributes to match snapshot 1`] = ` +{ + "attempt": 0, + "eventId": 9, + "eventType": "ActivityTaskStarted", + "identity": "cadence@958ab341-a375-431b-a17a-ed7d8a97ba91", + "lastFailureDetails": null, + "lastFailureReason": "", + "requestId": "27e61b29-7rc9-48f4-9e78-0366e9ffd413", + "scheduledEventId": 7, + "taskId": "22647174807", + "timestamp": 2024-09-07T22:16:10.599Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow activityTaskTimedOutEventAttributes to match snapshot 1`] = ` +{ + "details": null, + "eventId": 12, + "eventType": "ActivityTaskTimedOut", + "lastFailureDetails": null, + "lastFailureReason": "", + "scheduledEventId": 7, + "startedEventId": 9, + "taskId": "22647174813", + "timeoutType": "TIMEOUT_TYPE_START_TO_CLOSE", + "timestamp": 2024-09-07T22:16:10.632Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow cancelTimerFailedEventAttributes to match snapshot 1`] = ` +{ + "cause": "", + "decisionTaskCompletedEventId": 9, + "eventId": 53, + "eventType": "CancelTimerFailed", + "identity": "67b17b8c-fc30-4c5c-ac7e-bc3046311b18", + "taskId": "12690929028", + "timerId": "0", + "timestamp": 2024-09-07T22:37:50.860Z, + "version": "587402", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow childWorkflowExecutionCanceledEventAttributes to match snapshot 1`] = ` +{ + "details": "canceled before starting other workflow: CanceledError", + "domain": "cadence-domain", + "eventId": 44, + "eventType": "ChildWorkflowExecutionCanceled", + "initiatedEventId": 40, + "startedEventId": 42, + "taskId": "5877269786", + "timestamp": 2024-09-08T04:27:55.993Z, + "version": "575102", + "workflowExecution": { + "runId": "107495f0-ab19-4631-b6b9-dca2c2a30482", + "workflowId": "workflow.cancellation-workflow.cancellation.external-child", + }, + "workflowType": { + "name": "workflow.cancellation.external", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow childWorkflowExecutionCompletedEventAttributes to match snapshot 1`] = ` +{ + "domain": "cadence-domain", + "eventId": 43, + "eventType": "ChildWorkflowExecutionCompleted", + "initiatedEventId": 9, + "result": null, + "startedEventId": 41, + "taskId": "5877269785", + "timestamp": 2024-09-08T04:27:54.218Z, + "version": "575102", + "workflowExecution": { + "runId": "107495f0-ab19-4631-b6b9-dca2c2a30482", + "workflowId": "workflow.cancellation-workflow.cancellation.external-child", + }, + "workflowType": { + "name": "workflow.cancellation.external", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow childWorkflowExecutionFailedEventAttributes to match snapshot 1`] = ` +{ + "details": null, + "domain": "cadence-domain", + "eventId": 47, + "eventType": "ChildWorkflowExecutionFailed", + "initiatedEventId": 40, + "reason": "", + "startedEventId": 42, + "taskId": "5877269789", + "timestamp": 2024-09-08T04:27:58.993Z, + "version": "575102", + "workflowExecution": { + "runId": "107495f0-ab19-4631-b6b9-dca2c2a30482", + "workflowId": "workflow.cancellation-workflow.cancellation.external-child", + }, + "workflowType": { + "name": "workflow.cancellation.external", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow childWorkflowExecutionStartedEventAttributes to match snapshot 1`] = ` +{ + "domain": "cadence-domain", + "eventId": 42, + "eventType": "ChildWorkflowExecutionStarted", + "header": { + "fields": {}, + }, + "initiatedEventId": 40, + "taskId": "5877269784", + "timestamp": 2024-09-08T04:27:53.862Z, + "version": "575102", + "workflowExecution": { + "runId": "107495f0-ab19-4631-b6b9-dca2c2a30482", + "workflowId": "workflow.cancellation-workflow.cancellation.external-child", + }, + "workflowType": { + "name": "workflow.cancellation.external", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow childWorkflowExecutionTerminatedEventAttributes to match snapshot 1`] = ` +{ + "domain": "cadence-domain", + "eventId": 45, + "eventType": "ChildWorkflowExecutionTerminated", + "initiatedEventId": 40, + "startedEventId": 42, + "taskId": "5877269787", + "timestamp": 2024-09-08T04:27:56.993Z, + "version": "575102", + "workflowExecution": { + "runId": "107495f0-ab19-4631-b6b9-dca2c2a30482", + "workflowId": "workflow.cancellation-workflow.cancellation.external-child", + }, + "workflowType": { + "name": "workflow.cancellation.external", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow childWorkflowExecutionTimedOutEventAttributes to match snapshot 1`] = ` +{ + "domain": "cadence-domain", + "eventId": 46, + "eventType": "ChildWorkflowExecutionTimedOut", + "initiatedEventId": 40, + "startedEventId": 42, + "taskId": "5877269788", + "timeoutType": "TIMEOUT_TYPE_HEARTBEAT", + "timestamp": 2024-09-08T04:27:57.993Z, + "version": "575102", + "workflowExecution": { + "runId": "107495f0-ab19-4631-b6b9-dca2c2a30482", + "workflowId": "workflow.cancellation-workflow.cancellation.external-child", + }, + "workflowType": { + "name": "workflow.cancellation.external", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow decisionTaskCompletedEventAttributes to match snapshot 1`] = ` +{ + "binaryChecksum": "cadence:eb16a90a9182002897d7a6c6585871eedace71d1", + "eventId": 4, + "eventType": "DecisionTaskCompleted", + "executionContext": "", + "identity": "cadence@958ab342-a376-431b-a17a-ed7d8a97ba91", + "scheduledEventId": "2", + "startedEventId": "3", + "taskId": "22647174802", + "timestamp": 2024-09-07T22:16:10.599Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow decisionTaskScheduledEventAttributes to match snapshot 1`] = ` +{ + "attempt": 0, + "eventId": 2, + "eventType": "DecisionTaskScheduled", + "startToCloseTimeoutSeconds": 10, + "taskId": "22647174794", + "taskList": { + "kind": null, + "name": "task-queue", + }, + "timestamp": 2024-09-07T22:16:10.552Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow decisionTaskStartedEventAttributes to match snapshot 1`] = ` +{ + "eventId": 3, + "eventType": "DecisionTaskStarted", + "identity": "cadence@958ab341-a376-431b-a17a-ed7d8a97ba92", + "requestId": "66f7f58b-3d3b-4178-972a-fa7825ceec38", + "scheduledEventId": 2, + "taskId": "22647174798", + "timestamp": 2024-09-07T22:16:10.575Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow decisionTaskTimedOutEventAttributes to match snapshot 1`] = ` +{ + "baseRunId": "", + "cause": "DECISION_TASK_TIMED_OUT_CAUSE_TIMEOUT", + "eventId": 6, + "eventType": "DecisionTaskTimedOut", + "forkEventVersion": 0, + "newRunId": "", + "reason": "Missed heart beat", + "requestId": "66f7f58b-3d3b-4178-972a-fa7825ceec40", + "scheduledEventId": 2, + "startedEventId": 3, + "taskId": "22647174903", + "timeoutType": "TIMEOUT_TYPE_HEARTBEAT", + "timestamp": 2024-09-07T22:16:10.599Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow externalWorkflowExecutionCancelRequestedEventAttributes to match snapshot 1`] = ` +{ + "domain": "cadence-domain", + "eventId": 26, + "eventType": "ExternalWorkflowExecutionCancelRequested", + "initiatedEventId": 25, + "taskId": "5877269818", + "timestamp": 2024-09-07T22:52:50.927Z, + "version": "575102", + "workflowExecution": { + "runId": "", + "workflowId": "workflow.cancellation-workflow.cancellation.external-child", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow externalWorkflowExecutionSignaledEventAttributes to match snapshot 1`] = ` +{ + "control": 0, + "domain": "cadence-domain", + "eventId": 31, + "eventType": "ExternalWorkflowExecutionSignaled", + "initiatedEventId": 30, + "taskId": "8090823672", + "timestamp": 2024-09-08T04:26:10.375Z, + "version": "575102", + "workflowExecution": { + "runId": "", + "workflowId": "workflow.reset.base-b3439f7e-1daa-4716-a42e-3a621631bad3", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow markerRecordedEventAttributes to match snapshot 1`] = ` +{ + "decisionTaskCompletedEventId": 4, + "details": [ + "initial version", + "3", + ], + "eventId": 3, + "eventType": "MarkerRecorded", + "header": null, + "markerName": "Version", + "taskId": "22647173802", + "timestamp": 2024-08-27T08:31:55.549Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow requestCancelActivityTaskFailedEventAttributes to match snapshot 1`] = ` +{ + "activityId": "0", + "cause": "", + "decisionTaskCompletedEventId": 4, + "eventId": 54, + "eventType": "RequestCancelActivityTaskFailed", + "taskId": "22647174807", + "timestamp": 2024-09-07T22:16:10.599Z, + "version": "587402", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow requestCancelExternalWorkflowExecutionFailedEventAttributes to match snapshot 1`] = ` +{ + "cause": "CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_INVALID", + "control": null, + "decisionTaskCompletedEventId": 24, + "domain": "cadence-domain", + "eventId": 25, + "eventType": "RequestCancelExternalWorkflowExecutionFailed", + "initiatedEventId": 25, + "taskId": "5877269814", + "timestamp": 2024-09-07T22:51:10.886Z, + "version": "575102", + "workflowExecution": { + "runId": "", + "workflowId": "workflow.cancellation-workflow.cancellation.external-child", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow requestCancelExternalWorkflowExecutionInitiatedEventAttributes to match snapshot 1`] = ` +{ + "childWorkflowOnly": true, + "control": null, + "decisionTaskCompletedEventId": 24, + "domain": "cadence-domain", + "eventId": 25, + "eventType": "RequestCancelExternalWorkflowExecutionInitiated", + "taskId": "5877269814", + "timestamp": 2024-09-07T22:51:10.886Z, + "version": "575102", + "workflowExecution": { + "runId": "", + "workflowId": "workflow.cancellation-workflow.cancellation.external-child", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow signalExternalWorkflowExecutionFailedEventAttributes to match snapshot 1`] = ` +{ + "cause": "SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_INVALID", + "control": 0, + "decisionTaskCompletedEventId": 4, + "domain": "cadence-domain", + "eventId": 31, + "eventType": "SignalExternalWorkflowExecutionFailed", + "initiatedEventId": 30, + "taskId": "8090823672", + "timestamp": 2024-09-08T04:27:50.375Z, + "version": "575102", + "workflowExecution": { + "runId": "", + "workflowId": "workflow.reset.base-b3439f7e-1daa-4716-a42e-3a621631bad3", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow signalExternalWorkflowExecutionInitiatedEventAttributes to match snapshot 1`] = ` +{ + "childWorkflowOnly": true, + "control": 0, + "decisionTaskCompletedEventId": 4, + "domain": "cadence-domain", + "eventId": 30, + "eventType": "SignalExternalWorkflowExecutionInitiated", + "input": [ + "signalValue", + ], + "signalName": "signalBeforeReset", + "taskId": "8090823668", + "timestamp": 2024-09-08T04:24:30.356Z, + "version": "575102", + "workflowExecution": { + "runId": "", + "workflowId": "workflow.reset.base-b3439f7e-1daa-4716-a42e-3a621631bad3", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow startChildWorkflowExecutionFailedEventAttributes to match snapshot 1`] = ` +{ + "cause": "CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_INVALID", + "control": null, + "decisionTaskCompletedEventId": 4, + "domain": "cadence-domain", + "eventId": 41, + "eventType": "StartChildWorkflowExecutionFailed", + "initiatedEventId": NaN, + "taskId": "5877269783", + "timestamp": 2024-09-08T04:27:52.830Z, + "version": "575102", + "workflowId": "workflow.cancellation-workflow.cancellation.external-child", + "workflowType": { + "name": "workflow.cancellation.external", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow startChildWorkflowExecutionInitiatedEventAttributes to match snapshot 1`] = ` +{ + "control": null, + "cronSchedule": "", + "decisionTaskCompletedEventId": 4, + "delayStartSeconds": null, + "domain": "cadence-domain", + "eventId": 40, + "eventType": "StartChildWorkflowExecutionInitiated", + "executionStartToCloseTimeoutSeconds": 360, + "firstRunAt": null, + "header": { + "fields": {}, + }, + "input": [ + 1726492751798812400, + 30000000000, + ], + "jitterStart": null, + "memo": null, + "parentClosePolicy": "abandon", + "retryPolicy": null, + "searchAttributes": null, + "taskId": "5877269782", + "taskList": { + "kind": null, + "name": "canary-task-queue", + }, + "taskStartToCloseTimeoutSeconds": 10, + "timestamp": 1975-06-21T10:47:51.830Z, + "version": "575102", + "workflowId": "workflow.cancellation-workflow.cancellation.external-child", + "workflowIdReusePolicy": "allow duplicate", + "workflowType": { + "name": "workflow.cancellation.external", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow timerCanceledEventAttributes to match snapshot 1`] = ` +{ + "decisionTaskCompletedEventId": 9, + "eventId": 18, + "eventType": "TimerCanceled", + "identity": "67b17b8c-fc30-4c5c-ac7e-bc3046311b18", + "startedEventId": 5, + "taskId": "12690929028", + "timerId": "0", + "timestamp": 2024-09-07T22:37:50.860Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow timerFiredEventAttributes to match snapshot 1`] = ` +{ + "eventId": 17, + "eventType": "TimerFired", + "startedEventId": 10, + "taskId": "12690929027", + "timerId": "0", + "timestamp": 2024-09-07T22:34:30.005Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow timerStartedEventAttributes to match snapshot 1`] = ` +{ + "decisionTaskCompletedEventId": 4, + "eventId": 16, + "eventType": "TimerStarted", + "startToFireTimeoutSeconds": 5, + "taskId": "12690929026", + "timerId": "0", + "timestamp": 2024-09-07T22:32:50.632Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow upsertWorkflowSearchAttributesEventAttributes to match snapshot 1`] = ` +{ + "decisionTaskCompletedEventId": 4, + "eventId": 58, + "eventType": "UpsertWorkflowSearchAttributes", + "searchAttributes": { + "indexedFields": { + "CadenceChangeVersion": [ + "initial version-3", + ], + }, + }, + "taskId": "6051339897", + "timestamp": 2024-09-17T07:00:43.322Z, + "version": "587402", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow workflowExecutionCancelRequestedEventAttributes to match snapshot 1`] = ` +{ + "cause": "", + "eventId": 56, + "eventType": "WorkflowExecutionCancelRequested", + "externalInitiatedEventId": null, + "externalWorkflowExecution": { + "runId": "", + "workflowId": "", + }, + "identity": "", + "requestId": "", + "taskId": "12690929027", + "timestamp": 2024-09-11T09:16:12.860Z, + "version": "580100", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow workflowExecutionCanceledEventAttributes to match snapshot 1`] = ` +{ + "decisionTaskCompletedEventId": 9, + "details": "workflow sleep: CanceledError", + "eventId": 57, + "eventType": "WorkflowExecutionCanceled", + "taskId": "12690929027", + "timestamp": 2024-09-11T09:16:12.860Z, + "version": "580100", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow workflowExecutionCompletedEventAttributes to match snapshot 1`] = ` +{ + "decisionTaskCompletedEventId": 4, + "eventId": 51, + "eventType": "WorkflowExecutionCompleted", + "result": null, + "taskId": "605133998", + "timestamp": 2024-09-19T12:08:35.549Z, + "version": "587402", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow workflowExecutionContinuedAsNewEventAttributes to match snapshot 1`] = ` +{ + "backoffStartIntervalInSeconds": 55, + "decisionTaskCompletedEventId": 17, + "eventId": 55, + "eventType": "WorkflowExecutionContinuedAsNew", + "executionStartToCloseTimeoutSeconds": 1080, + "failureDetails": null, + "failureReason": "", + "header": { + "fields": {}, + }, + "initiator": "cron_schedule", + "input": [], + "lastCompletionResult": null, + "memo": null, + "newExecutionRunId": "8f27807a-9125-4833-b8f1-d52a4c59be9a", + "searchAttributes": null, + "taskId": "22647174866", + "taskList": { + "kind": null, + "name": "cadence-task-queue", + }, + "taskStartToCloseTimeoutSeconds": 10, + "timestamp": 2024-09-07T22:16:15.636Z, + "version": "587402", + "workflowType": { + "name": "workflow.cron", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow workflowExecutionFailedEventAttributes to match snapshot 1`] = ` +{ + "decisionTaskCompletedEventId": 4, + "details": "new execution triggered by reset is not completed", + "eventId": 48, + "eventType": "WorkflowExecutionFailed", + "reason": "cadenceInternal:Generic", + "taskId": "22647173803", + "timestamp": 2024-09-19T12:05:15.549Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow workflowExecutionSignaledEventAttributes to match snapshot 1`] = ` +{ + "eventId": 2, + "eventType": "WorkflowExecutionSignaled", + "identity": "cadence-service", + "input": [ + "cadence.signal", + ], + "requestId": "488cd24f-37b0-48f7-955a-c5c8c7653290", + "signalName": "signal-name", + "taskId": "22647173801", + "timestamp": 2024-08-27T08:30:15.549Z, + "version": "575102", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow workflowExecutionStartedEventAttributes to match snapshot 1`] = ` +{ + "attempt": null, + "continuedExecutionRunId": "e8565005-a234-4077-a917-6e5992ccbe4a", + "continuedFailureDetails": null, + "continuedFailureReason": null, + "cronSchedule": "@every 1m", + "eventId": 1, + "eventType": "WorkflowExecutionStarted", + "executionStartToCloseTimeoutSeconds": 1080, + "expirationTimestamp": null, + "firstDecisionTaskBackoffSeconds": 55, + "firstExecutionRunId": "1d0e29d3-9c20-4eda-aeca-daed7f0ccb2e", + "firstScheduledTimeNano": 1716246362895.4253, + "header": { + "fields": {}, + }, + "identity": null, + "initiator": "cron_schedule", + "input": [], + "lastCompletionResult": null, + "memo": null, + "originalExecutionRunId": "9c42ffa3-c9b1-430d-a993-b84fdce8c9f2", + "parentInitiatedEventId": null, + "parentWorkflowDomain": null, + "parentWorkflowExecution": null, + "partitionConfig": {}, + "prevAutoResetPoints": { + "points": [], + }, + "requestId": "8b2d2b6f-996a-431e-96b3-17d19cf0e508", + "retryPolicy": null, + "searchAttributes": null, + "taskId": "22647173800", + "taskList": { + "kind": null, + "name": "cadence-tasklist", + }, + "taskStartToCloseTimeoutSeconds": 10, + "timestamp": 2024-08-27T08:28:35.549Z, + "version": "575102", + "workflowType": { + "name": "workflow.cron", + }, +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow workflowExecutionTerminatedEventAttributes to match snapshot 1`] = ` +{ + "details": null, + "eventId": 49, + "eventType": "WorkflowExecutionTerminated", + "identity": "history-service", + "reason": "reset domain", + "taskId": "6051339957", + "timestamp": 2024-09-19T12:06:55.549Z, + "version": "587402", +} +`; + +exports[`formatWorkflowHistoryEvent should format workflow workflowExecutionTimedOutEventAttributes to match snapshot 1`] = ` +{ + "eventId": 50, + "eventType": "WorkflowExecutionTimedOut", + "taskId": "6051339957", + "timeoutType": "TIMEOUT_TYPE_START_TO_CLOSE", + "timestamp": 2024-09-19T12:08:35.549Z, + "version": "587402", +} +`; diff --git a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-cancel-requested-event-attributes.ts b/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-cancel-requested-event-attributes.ts deleted file mode 100644 index 0395c6981..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-cancel-requested-event-attributes.ts +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2022-2024 Uber Technologies Inc. -// -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -import formatWorkflowEventId from '../format-workflow-event-id'; - -const formatWorkflowExecutionCancelRequestedEventAttributes = ({ - externalExecutionInfo, - ...eventAttributes -}: { - externalExecutionInfo?: - | { initiatedId: string | number; workflowExecution: any } - | null - | undefined; -} & Record) => ({ - ...eventAttributes, - externalInitiatedEventId: formatWorkflowEventId( - externalExecutionInfo?.initiatedId - ), - externalWorkflowExecution: externalExecutionInfo?.workflowExecution, -}); - -export default formatWorkflowExecutionCancelRequestedEventAttributes; diff --git a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-canceled-event-attributes.ts b/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-canceled-event-attributes.ts deleted file mode 100644 index 390823860..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-canceled-event-attributes.ts +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2022-2024 Uber Technologies Inc. -// -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -import formatPayload from '../format-payload'; -import formatWorkflowEventId from '../format-workflow-event-id'; - -const formatWorkflowExecutionCanceledEventAttributes = ({ - decisionTaskCompletedEventId, - details, -}: { - decisionTaskCompletedEventId: string | number; - details: { data?: string | null } | null | undefined; -}) => ({ - decisionTaskCompletedEventId: formatWorkflowEventId( - decisionTaskCompletedEventId - ), - details: formatPayload(details), -}); - -export default formatWorkflowExecutionCanceledEventAttributes; diff --git a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-completed-event-attributes.ts b/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-completed-event-attributes.ts deleted file mode 100644 index bce97fcbc..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-completed-event-attributes.ts +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2022-2024 Uber Technologies Inc. -// -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -import formatPayload from '../format-payload'; -import formatWorkflowEventId from '../format-workflow-event-id'; - -const formatWorkflowExecutionCompletedEventAttributes = ({ - decisionTaskCompletedEventId, - result, -}: { - decisionTaskCompletedEventId: string | number; - result: { data?: string | null } | null | undefined; -}) => ({ - decisionTaskCompletedEventId: formatWorkflowEventId( - decisionTaskCompletedEventId - ), - result: formatPayload(result), -}); - -export default formatWorkflowExecutionCompletedEventAttributes; diff --git a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-continued-as-new-event-attributes.ts b/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-continued-as-new-event-attributes.ts deleted file mode 100644 index 714409ef3..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-continued-as-new-event-attributes.ts +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2022-2024 Uber Technologies Inc. -// -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -import formatDurationToSeconds from '../format-duration-to-seconds'; -import formatEnum from '../format-enum'; -import formatFailureDetails from '../format-failure-details'; -import formatPayloadMap from '../format-payload-map'; -import formatWorkflowEventId from '../format-workflow-event-id'; -import formatWorkflowInputPayload from '../format-workflow-input-payload'; - -const formatWorkflowExecutionContinuedAsNewEventAttributes = ({ - backoffStartInterval, - decisionTaskCompletedEventId, - executionStartToCloseTimeout, - failure, - header, - initiator, - input, - memo, - searchAttributes, - taskList, - taskStartToCloseTimeout, - ...eventAttributes -}: any) => ({ - ...eventAttributes, - backoffStartIntervalInSeconds: formatDurationToSeconds(backoffStartInterval), - decisionTaskCompletedEventId: formatWorkflowEventId( - decisionTaskCompletedEventId - ), - executionStartToCloseTimeoutSeconds: formatDurationToSeconds( - executionStartToCloseTimeout - ), - failureDetails: formatFailureDetails(failure), - failureReason: failure?.reason || '', - header: formatPayloadMap(header, 'fields'), - initiator: formatEnum(initiator, 'CONTINUE_AS_NEW_INITIATOR'), - input: formatWorkflowInputPayload(input), - memo: formatPayloadMap(memo, 'fields'), - searchAttributes: formatPayloadMap(searchAttributes, 'indexedFields'), - taskList: { - kind: formatEnum(taskList?.kind, 'TASK_LIST_KIND'), - name: taskList?.name || null, - }, - taskStartToCloseTimeoutSeconds: formatDurationToSeconds( - taskStartToCloseTimeout - ), -}); - -export default formatWorkflowExecutionContinuedAsNewEventAttributes; diff --git a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-failed-event-attributes.ts b/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-failed-event-attributes.ts deleted file mode 100644 index dd79e7fea..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-failed-event-attributes.ts +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2022-2024 Uber Technologies Inc. -// -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -import formatFailureDetails from '../format-failure-details'; -import formatWorkflowEventId from '../format-workflow-event-id'; - -const formatWorkflowExecutionFailedEventAttributes = ({ - failure, - decisionTaskCompletedEventId, -}: any) => ({ - decisionTaskCompletedEventId: formatWorkflowEventId( - decisionTaskCompletedEventId - ), - details: formatFailureDetails(failure), - reason: failure?.reason || '', -}); - -export default formatWorkflowExecutionFailedEventAttributes; diff --git a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-signaled-event-attributes.ts b/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-signaled-event-attributes.ts deleted file mode 100644 index 48c323191..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-signaled-event-attributes.ts +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2022-2024 Uber Technologies Inc. -// -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -import formatWorkflowInputPayload from '../format-workflow-input-payload'; - -const formatWorkflowExecutionSignaledEventAttributes = ({ - input, - ...eventAttributes -}: any) => ({ - ...eventAttributes, - input: formatWorkflowInputPayload(input), -}); - -export default formatWorkflowExecutionSignaledEventAttributes; diff --git a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-started-event-attributes.ts b/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-started-event-attributes.ts deleted file mode 100644 index d2dabcd3d..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-started-event-attributes.ts +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (c) 2022-2024 Uber Technologies Inc. -// -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -import formatDurationToSeconds from '../format-duration-to-seconds'; -import formatEnum from '../format-enum'; -import formatFailureDetails from '../format-failure-details'; -import formatPayloadMap from '../format-payload-map'; -import formatPrevAutoResetPoints from '../format-prev-auto-reset-points'; -import formatRetryPolicy from '../format-retry-policy'; -import formatTimestampToDatetime from '../format-timestamp-to-datetime'; -import formatWorkflowInputPayload from '../format-workflow-input-payload'; - -const formatWorkflowExecutionStartedEventAttributes = ({ - attempt, - continuedExecutionRunId, - continuedFailure, - cronSchedule, - executionStartToCloseTimeout, - expirationTime, - firstDecisionTaskBackoff, - firstExecutionRunId, - firstScheduledTimeNano, - identity, - initiator, - input, - memo, - originalExecutionRunId, - parentExecutionInfo, - prevAutoResetPoints, - retryPolicy, - searchAttributes, - taskList, - taskStartToCloseTimeout, - ...eventAttributes -}: any) => ({ - ...eventAttributes, - taskList: { - kind: formatEnum(taskList?.kind, 'TASK_LIST_KIND'), - name: taskList?.name || null, - }, - input: formatWorkflowInputPayload(input), - executionStartToCloseTimeoutSeconds: formatDurationToSeconds( - executionStartToCloseTimeout - ), - taskStartToCloseTimeoutSeconds: formatDurationToSeconds( - taskStartToCloseTimeout - ), - attempt: attempt || null, - continuedExecutionRunId: continuedExecutionRunId || null, - continuedFailureDetails: formatFailureDetails(continuedFailure), - continuedFailureReason: continuedFailure?.reason || null, - cronSchedule: cronSchedule || null, - expirationTimestamp: formatTimestampToDatetime(expirationTime), - firstDecisionTaskBackoffSeconds: formatDurationToSeconds( - firstDecisionTaskBackoff - ), - firstExecutionRunId: firstExecutionRunId || null, - firstScheduledTimeNano: firstScheduledTimeNano || null, - identity: identity || null, - initiator: formatEnum(initiator, 'CONTINUE_AS_NEW_INITIATOR'), - memo: formatPayloadMap(memo, 'fields'), - originalExecutionRunId: originalExecutionRunId || null, - parentInitiatedEventId: parentExecutionInfo?.initiatedId - ? parseInt(parentExecutionInfo.initiatedId) - : null, - parentWorkflowDomain: parentExecutionInfo?.domainName || null, - parentWorkflowExecution: parentExecutionInfo?.workflowExecution || null, - prevAutoResetPoints: formatPrevAutoResetPoints(prevAutoResetPoints), - retryPolicy: formatRetryPolicy(retryPolicy), - searchAttributes: formatPayloadMap(searchAttributes, 'indexedFields'), -}); - -export default formatWorkflowExecutionStartedEventAttributes; diff --git a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-terminated-event-attributes.ts b/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-terminated-event-attributes.ts deleted file mode 100644 index 4fde2d342..000000000 --- a/src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-terminated-event-attributes.ts +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2022-2024 Uber Technologies Inc. -// -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -import formatPayload from '../format-payload'; - -const formatWorkflowExecutionTerminatedEventAttributes = ({ - details, - ...eventAttributes -}: { - details: any; -}) => ({ - ...eventAttributes, - details: formatPayload(details), -}); - -export default formatWorkflowExecutionTerminatedEventAttributes; diff --git a/src/utils/data-formatters/format-workflow-history-event/index.ts b/src/utils/data-formatters/format-workflow-history-event/index.ts index c07733fc7..eb8d3a510 100644 --- a/src/utils/data-formatters/format-workflow-history-event/index.ts +++ b/src/utils/data-formatters/format-workflow-history-event/index.ts @@ -1,46 +1,11 @@ -import formatWorkflowExecutionCancelRequestedEventAttributes from './format-workflow-execution-cancel-requested-event-attributes'; -import formatWorkflowExecutionCanceledEventAttributes from './format-workflow-execution-canceled-event-attributes'; -import formatWorkflowExecutionCompletedEventAttributes from './format-workflow-execution-completed-event-attributes'; -import formatWorkflowExecutionContinuedAsNewEventAttributes from './format-workflow-execution-continued-as-new-event-attributes'; -import formatWorkflowExecutionFailedEventAttributes from './format-workflow-execution-failed-event-attributes'; -import formatWorkflowExecutionSignaledEventAttributes from './format-workflow-execution-signaled-event-attributes'; -import formatWorkflowExecutionStartedEventAttributes from './format-workflow-execution-started-event-attributes'; -import formatWorkflowExecutionTerminatedEventAttributes from './format-workflow-execution-terminated-event-attributes'; +import type { HistoryEvent } from '@/__generated__/proto-ts/uber/cadence/api/v1/HistoryEvent'; -const AttributesFormatterMap = { - workflowExecutionCancelRequestedEventAttributes: - formatWorkflowExecutionCancelRequestedEventAttributes, - workflowExecutionCanceledEventAttributes: - formatWorkflowExecutionCanceledEventAttributes, - workflowExecutionCompletedEventAttributes: - formatWorkflowExecutionCompletedEventAttributes, - workflowExecutionContinuedAsNewEventAttributes: - formatWorkflowExecutionContinuedAsNewEventAttributes, - workflowExecutionFailedEventAttributes: - formatWorkflowExecutionFailedEventAttributes, - workflowExecutionSignaledEventAttributes: - formatWorkflowExecutionSignaledEventAttributes, - workflowExecutionStartedEventAttributes: - formatWorkflowExecutionStartedEventAttributes, - workflowExecutionTerminatedEventAttributes: - formatWorkflowExecutionTerminatedEventAttributes, -}; +import { getFormatHistoryEventSchema } from '../schema/format-history-event-schema'; -export type AttributesFormattersKeys = keyof typeof AttributesFormatterMap; -export type AttributesFormattersEvent = { - attributes: AttributesFormattersKeys; -} & Record; - -export default function formatWorkflowHistoryEvent( - event: AttributesFormattersEvent -) { - const formatter = AttributesFormatterMap[event.attributes]; - - if (formatter) { - return { - [event.attributes]: formatter(event[event.attributes]), - }; +export default function formatWorkflowHistoryEvent(event: HistoryEvent) { + const schema = getFormatHistoryEventSchema(event); + if (schema) { + const { data } = schema.safeParse(event); + return data ?? null; } - - return event; } diff --git a/src/utils/data-formatters/format-workflow-history.ts b/src/utils/data-formatters/format-workflow-history.ts index d02909bbc..910bfe9fe 100644 --- a/src/utils/data-formatters/format-workflow-history.ts +++ b/src/utils/data-formatters/format-workflow-history.ts @@ -19,9 +19,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import formatTimestampToDatetime from './format-timestamp-to-datetime'; import formatWorkflowHistoryEvent from './format-workflow-history-event'; -import formatWorkflowHistoryEventType from './format-workflow-history-event-type'; const formatWorkflowHistory = ({ archived, @@ -32,13 +30,7 @@ const formatWorkflowHistory = ({ ...response, archived: archived || null, history: { - events: events.map(({ eventId, eventTime, ...event }: any) => ({ - eventId: parseInt(eventId), - timestamp: formatTimestampToDatetime(eventTime), - eventType: formatWorkflowHistoryEventType(event.attributes), - ...event, - ...formatWorkflowHistoryEvent(event), - })), + events: events.map(formatWorkflowHistoryEvent), }, rawHistory: rawHistory?.length ? rawHistory : null, }); diff --git a/src/utils/data-formatters/schema/format-history-event-schema.ts b/src/utils/data-formatters/schema/format-history-event-schema.ts new file mode 100644 index 000000000..100efa392 --- /dev/null +++ b/src/utils/data-formatters/schema/format-history-event-schema.ts @@ -0,0 +1,381 @@ +import { type HistoryEvent } from '@/__generated__/proto-ts/uber/cadence/api/v1/HistoryEvent'; + +import formatActivityTaskCancelRequestedEvent from '../format-workflow-history-event/format-activity-task-cancel-requested-event'; +import formatActivityTaskCanceledEvent from '../format-workflow-history-event/format-activity-task-canceled-event'; +import formatActivityTaskCompletedEvent from '../format-workflow-history-event/format-activity-task-completed-event'; +import formatActivityTaskFailedEvent from '../format-workflow-history-event/format-activity-task-failed-event'; +import formatActivityTaskScheduledEvent from '../format-workflow-history-event/format-activity-task-scheduled-event'; +import formatActivityTaskStartedEvent from '../format-workflow-history-event/format-activity-task-started-event'; +import formatActivityTaskTimedOutEvent from '../format-workflow-history-event/format-activity-task-timed-out-event'; +import formatCancelTimerFailedEvent from '../format-workflow-history-event/format-cancel-timer-failed-event'; +import formatChildWorkflowExecutionCanceledEvent from '../format-workflow-history-event/format-child-workflow-execution-canceled-event'; +import formatChildWorkflowExecutionTerminatedEvent from '../format-workflow-history-event/format-child-workflow-execution-canceled-terminated'; +import formatChildWorkflowExecutionCompletedEvent from '../format-workflow-history-event/format-child-workflow-execution-completed-event'; +import formatChildWorkflowExecutionFailedEvent from '../format-workflow-history-event/format-child-workflow-execution-failed-event'; +import formatChildWorkflowExecutionStartedEvent from '../format-workflow-history-event/format-child-workflow-execution-started-event'; +import formatChildWorkflowExecutionTimedOutEvent from '../format-workflow-history-event/format-child-workflow-execution-timed-out-event'; +import formatDecisionTaskCompletedEvent from '../format-workflow-history-event/format-decision-task-completed-event'; +import formatDecisionTaskFailedEvent from '../format-workflow-history-event/format-decision-task-failed-event'; +import formatDecisionTaskStartedEvent from '../format-workflow-history-event/format-decision-task-scheduled-event'; +import formatDecisionTaskScheduledEvent from '../format-workflow-history-event/format-decision-task-started-event'; +import formatDecisionTaskTimedOutEvent from '../format-workflow-history-event/format-decision-timed-out-event'; +import formatExternalWorkflowExecutionCancelRequestedEvent from '../format-workflow-history-event/format-external-workflow-execution-cancel-requested-event'; +import formatExternalWorkflowExecutionSignaledEvent from '../format-workflow-history-event/format-external-workflow-execution-signaled-event'; +import formatMarkerRecordedEvent from '../format-workflow-history-event/format-format-marker-recorded-event'; +import formatRequestCancelActivityTaskFailedEvent from '../format-workflow-history-event/format-request-cancel-activity-task-failed-event'; +import formatRequestCancelExternalWorkflowExecutionFailedEvent from '../format-workflow-history-event/format-request-cancel-external-workflow-execution-failed-event'; +import formatRequestCancelExternalWorkflowExecutionInitiatedEvent from '../format-workflow-history-event/format-request-cancel-external-workflow-execution-initiated-event'; +import formatSignalExternalWorkflowExecutionFailedEvent from '../format-workflow-history-event/format-signal-external-workflow-execution-failed-event'; +import formatSignalExternalWorkflowExecutionInitiatedEvent from '../format-workflow-history-event/format-signal-external-workflow-execution-initiated-event'; +import formatStartChildWorkflowExecutionFailedEvent from '../format-workflow-history-event/format-start-child-workflow-execution-failed-event'; +import formatStartChildWorkflowExecutionInitiatedEvent from '../format-workflow-history-event/format-start-child-workflow-execution-initiated-event'; +import formatTimerCanceledEvent from '../format-workflow-history-event/format-timer-canceled-event'; +import formatTimerFiredEvent from '../format-workflow-history-event/format-timer-fired-event'; +import formatTimerStartedEvent from '../format-workflow-history-event/format-timer-started-event'; +import formatUpsertWorkflowSearchAttributesEvent from '../format-workflow-history-event/format-upsert-workflow-search-attributes-event'; +import formatWorkflowExecutionCancelRequestedEvent from '../format-workflow-history-event/format-workflow-execution-cancel-requested-event'; +import formatWorkflowExecutionCanceledEvent from '../format-workflow-history-event/format-workflow-execution-canceled-event'; +import formatWorkflowExecutionCompletedEvent from '../format-workflow-history-event/format-workflow-execution-completed-event'; +import formatWorkflowExecutionContinuedAsNewEvent from '../format-workflow-history-event/format-workflow-execution-continued-as-new-event'; +import formatWorkflowExecutionFailedEvent from '../format-workflow-history-event/format-workflow-execution-failed-event'; +import formatWorkflowExecutionSignaledEvent from '../format-workflow-history-event/format-workflow-execution-signaled-event'; +import formatWorkflowExecutionStartedEvent from '../format-workflow-history-event/format-workflow-execution-started-event'; +import formatWorkflowExecutionTerminatedEvent from '../format-workflow-history-event/format-workflow-execution-terminated-event'; +import formatWorkflowExecutionTimedOutEvent from '../format-workflow-history-event/format-workflow-execution-timed-out-event'; + +import { + activityTaskCancelRequestedEventSchema, + activityTaskCanceledEventSchema, + activityTaskCompletedEventSchema, + activityTaskFailedEventSchema, + activityTaskScheduledEventSchema, + activityTaskStartedEventSchema, + activityTaskTimedOutEventSchema, + cancelTimerFailedEventSchema, + childWorkflowExecutionCanceledEventSchema, + childWorkflowExecutionCompletedEventSchema, + childWorkflowExecutionFailedEventSchema, + childWorkflowExecutionStartedEventSchema, + childWorkflowExecutionTerminatedEventSchema, + childWorkflowExecutionTimedOutEventSchema, + decisionTaskCompletedEventSchema, + decisionTaskFailedEventSchema, + decisionTaskScheduledEventSchema, + decisionTaskStartedEventSchema, + decisionTaskTimedOutEventSchema, + externalWorkflowExecutionCancelRequestedEventSchema, + externalWorkflowExecutionSignaledEventSchema, + markerRecordedEventSchema, + requestCancelActivityTaskFailedEventSchema, + requestCancelExternalWorkflowExecutionFailedEventSchema, + requestCancelExternalWorkflowExecutionInitiatedEventSchema, + signalExternalWorkflowExecutionFailedEventSchema, + signalExternalWorkflowExecutionInitiatedEventSchema, + startChildWorkflowExecutionFailedEventSchema, + startChildWorkflowExecutionInitiatedEventSchema, + timerCanceledEventSchema, + timerFiredEventSchema, + timerStartedEventSchema, + upsertWorkflowSearchAttributesEventSchema, + workflowExecutionCancelRequestedEventAttributesSchema, + workflowExecutionCanceledEventSchema, + workflowExecutionCompletedEventSchema, + workflowExecutionContinuedAsNewEventSchema, + workflowExecutionFailedEventSchema, + workflowExecutionSignaledEventSchema, + workflowExecutionStartedEventSchema, + workflowExecutionTerminatedEventSchema, + workflowExecutionTimedOutEventSchema, +} from './history-event-schema'; + +export const formatWorkflowExecutionStartedEventSchema = + workflowExecutionStartedEventSchema.transform( + formatWorkflowExecutionStartedEvent + ); + +export const formatWorkflowExecutionCompletedEventSchema = + workflowExecutionCompletedEventSchema.transform( + formatWorkflowExecutionCompletedEvent + ); + +export const formatWorkflowExecutionFailedEventSchema = + workflowExecutionFailedEventSchema.transform( + formatWorkflowExecutionFailedEvent + ); + +export const formatWorkflowExecutionTimedOutEventSchema = + workflowExecutionTimedOutEventSchema.transform( + formatWorkflowExecutionTimedOutEvent + ); + +export const formatWorkflowExecutionSignaledEventSchema = + workflowExecutionSignaledEventSchema.transform( + formatWorkflowExecutionSignaledEvent + ); + +export const formatWorkflowExecutionTerminatedEventSchema = + workflowExecutionTerminatedEventSchema.transform( + formatWorkflowExecutionTerminatedEvent + ); + +export const formatWorkflowExecutionCanceledEventSchema = + workflowExecutionCanceledEventSchema.transform( + formatWorkflowExecutionCanceledEvent + ); + +export const formatWorkflowExecutionContinuedAsNewEventSchema = + workflowExecutionContinuedAsNewEventSchema.transform( + formatWorkflowExecutionContinuedAsNewEvent + ); +export const formatWorkflowExecutionCancelRequestedEventAttributesSchema = + workflowExecutionCancelRequestedEventAttributesSchema.transform( + formatWorkflowExecutionCancelRequestedEvent + ); + +export const formatDecisionTaskScheduledEventSchema = + decisionTaskScheduledEventSchema.transform(formatDecisionTaskScheduledEvent); + +export const formatDecisionTaskStartedEventSchema = + decisionTaskStartedEventSchema.transform(formatDecisionTaskStartedEvent); + +export const formatDecisionTaskCompletedEventSchema = + decisionTaskCompletedEventSchema.transform(formatDecisionTaskCompletedEvent); + +export const formatDecisionTaskTimedOutEventSchema = + decisionTaskTimedOutEventSchema.transform(formatDecisionTaskTimedOutEvent); + +export const formatDecisionTaskFailedEventSchema = + decisionTaskFailedEventSchema.transform(formatDecisionTaskFailedEvent); + +export const formatActivityTaskScheduledEventSchema = + activityTaskScheduledEventSchema.transform(formatActivityTaskScheduledEvent); + +export const formatActivityTaskStartedEventSchema = + activityTaskStartedEventSchema.transform(formatActivityTaskStartedEvent); + +export const formatActivityTaskCompletedEventSchema = + activityTaskCompletedEventSchema.transform(formatActivityTaskCompletedEvent); + +export const formatActivityTaskFailedEventSchema = + activityTaskFailedEventSchema.transform(formatActivityTaskFailedEvent); + +export const formatActivityTaskTimedOutEventSchema = + activityTaskTimedOutEventSchema.transform(formatActivityTaskTimedOutEvent); + +export const formatRequestCancelActivityTaskFailedEventSchema = + requestCancelActivityTaskFailedEventSchema.transform( + formatRequestCancelActivityTaskFailedEvent + ); + +export const formatActivityTaskCancelRequestedEventSchema = + activityTaskCancelRequestedEventSchema.transform( + formatActivityTaskCancelRequestedEvent + ); + +export const formatActivityTaskCanceledEventSchema = + activityTaskCanceledEventSchema.transform(formatActivityTaskCanceledEvent); + +export const formatTimerStartedEventSchema = timerStartedEventSchema.transform( + formatTimerStartedEvent +); + +export const formatTimerFiredEventSchema = timerFiredEventSchema.transform( + formatTimerFiredEvent +); + +export const formatTimerCanceledEventSchema = + timerCanceledEventSchema.transform(formatTimerCanceledEvent); + +export const formatCancelTimerFailedEventSchema = + cancelTimerFailedEventSchema.transform(formatCancelTimerFailedEvent); + +export const formatMarkerRecordedEventSchema = + markerRecordedEventSchema.transform(formatMarkerRecordedEvent); + +export const formatExternalWorkflowExecutionCancelRequestedEventSchema = + externalWorkflowExecutionCancelRequestedEventSchema.transform( + formatExternalWorkflowExecutionCancelRequestedEvent + ); + +export const formatExternalWorkflowExecutionSignaledEventSchema = + externalWorkflowExecutionSignaledEventSchema.transform( + formatExternalWorkflowExecutionSignaledEvent + ); + +export const formatRequestCancelExternalWorkflowExecutionInitiatedEventSchema = + requestCancelExternalWorkflowExecutionInitiatedEventSchema.transform( + formatRequestCancelExternalWorkflowExecutionInitiatedEvent + ); + +export const formatRequestCancelExternalWorkflowExecutionFailedEventSchema = + requestCancelExternalWorkflowExecutionFailedEventSchema.transform( + formatRequestCancelExternalWorkflowExecutionFailedEvent + ); + +export const formatSignalExternalWorkflowExecutionInitiatedEventSchema = + signalExternalWorkflowExecutionInitiatedEventSchema.transform( + formatSignalExternalWorkflowExecutionInitiatedEvent + ); + +export const formatSignalExternalWorkflowExecutionFailedEventSchema = + signalExternalWorkflowExecutionFailedEventSchema.transform( + formatSignalExternalWorkflowExecutionFailedEvent + ); + +export const formatStartChildWorkflowExecutionInitiatedEventSchema = + startChildWorkflowExecutionInitiatedEventSchema.transform( + formatStartChildWorkflowExecutionInitiatedEvent + ); + +export const formatStartChildWorkflowExecutionFailedEventSchema = + startChildWorkflowExecutionFailedEventSchema.transform( + formatStartChildWorkflowExecutionFailedEvent + ); + +export const formatChildWorkflowExecutionStartedEventSchema = + childWorkflowExecutionStartedEventSchema.transform( + formatChildWorkflowExecutionStartedEvent + ); + +export const formatChildWorkflowExecutionCompletedEventSchema = + childWorkflowExecutionCompletedEventSchema.transform( + formatChildWorkflowExecutionCompletedEvent + ); + +export const formatChildWorkflowExecutionFailedEventSchema = + childWorkflowExecutionFailedEventSchema.transform( + formatChildWorkflowExecutionFailedEvent + ); + +export const formatChildWorkflowExecutionCanceledEventSchema = + childWorkflowExecutionCanceledEventSchema.transform( + formatChildWorkflowExecutionCanceledEvent + ); + +export const formatChildWorkflowExecutionTimedOutEventSchema = + childWorkflowExecutionTimedOutEventSchema.transform( + formatChildWorkflowExecutionTimedOutEvent + ); + +export const formatChildWorkflowExecutionTerminatedEventSchema = + childWorkflowExecutionTerminatedEventSchema.transform( + formatChildWorkflowExecutionTerminatedEvent + ); + +export const formatUpsertWorkflowSearchAttributesEventSchema = + upsertWorkflowSearchAttributesEventSchema.transform( + formatUpsertWorkflowSearchAttributesEvent + ); + +function unExistingEventType(_: never) { + return null; +} +export const getFormatHistoryEventSchema = function (event: HistoryEvent) { + switch (event.attributes) { + case 'workflowExecutionStartedEventAttributes': + return formatWorkflowExecutionStartedEventSchema; + case 'workflowExecutionCompletedEventAttributes': + return formatWorkflowExecutionCompletedEventSchema; + case 'workflowExecutionFailedEventAttributes': + return formatWorkflowExecutionFailedEventSchema; + case 'workflowExecutionTimedOutEventAttributes': + return formatWorkflowExecutionTimedOutEventSchema; + case 'workflowExecutionSignaledEventAttributes': + return formatWorkflowExecutionSignaledEventSchema; + case 'workflowExecutionTerminatedEventAttributes': + return formatWorkflowExecutionTerminatedEventSchema; + case 'workflowExecutionCanceledEventAttributes': + return formatWorkflowExecutionCanceledEventSchema; + case 'workflowExecutionContinuedAsNewEventAttributes': + return formatWorkflowExecutionContinuedAsNewEventSchema; + + case 'workflowExecutionCancelRequestedEventAttributes': + return formatWorkflowExecutionCancelRequestedEventAttributesSchema; + + case 'decisionTaskCompletedEventAttributes': + return formatDecisionTaskCompletedEventSchema; + case 'decisionTaskFailedEventAttributes': + return formatDecisionTaskFailedEventSchema; + case 'decisionTaskScheduledEventAttributes': + return formatDecisionTaskScheduledEventSchema; + case 'decisionTaskStartedEventAttributes': + return formatDecisionTaskStartedEventSchema; + case 'decisionTaskTimedOutEventAttributes': + return formatDecisionTaskTimedOutEventSchema; + + case 'activityTaskCancelRequestedEventAttributes': + return formatActivityTaskCancelRequestedEventSchema; + case 'activityTaskCanceledEventAttributes': + return formatActivityTaskCanceledEventSchema; + case 'activityTaskCompletedEventAttributes': + return formatActivityTaskCompletedEventSchema; + case 'activityTaskFailedEventAttributes': + return formatActivityTaskFailedEventSchema; + case 'activityTaskScheduledEventAttributes': + return formatActivityTaskScheduledEventSchema; + case 'activityTaskStartedEventAttributes': + return formatActivityTaskStartedEventSchema; + case 'activityTaskTimedOutEventAttributes': + return formatActivityTaskTimedOutEventSchema; + case 'requestCancelActivityTaskFailedEventAttributes': + return formatRequestCancelActivityTaskFailedEventSchema; + + case 'timerCanceledEventAttributes': + return formatTimerCanceledEventSchema; + case 'timerFiredEventAttributes': + return formatTimerFiredEventSchema; + case 'timerStartedEventAttributes': + return formatTimerStartedEventSchema; + case 'cancelTimerFailedEventAttributes': + return formatCancelTimerFailedEventSchema; + case 'markerRecordedEventAttributes': + return formatMarkerRecordedEventSchema; + + case 'externalWorkflowExecutionCancelRequestedEventAttributes': + return formatExternalWorkflowExecutionCancelRequestedEventSchema; + case 'externalWorkflowExecutionSignaledEventAttributes': + return formatExternalWorkflowExecutionSignaledEventSchema; + + case 'signalExternalWorkflowExecutionFailedEventAttributes': + return formatSignalExternalWorkflowExecutionFailedEventSchema; + + case 'signalExternalWorkflowExecutionInitiatedEventAttributes': + return formatSignalExternalWorkflowExecutionInitiatedEventSchema; + + case 'requestCancelExternalWorkflowExecutionFailedEventAttributes': + return formatRequestCancelExternalWorkflowExecutionFailedEventSchema; + + case 'requestCancelExternalWorkflowExecutionInitiatedEventAttributes': + return formatRequestCancelExternalWorkflowExecutionInitiatedEventSchema; + + case 'childWorkflowExecutionCanceledEventAttributes': + return formatChildWorkflowExecutionCanceledEventSchema; + + case 'childWorkflowExecutionCompletedEventAttributes': + return formatChildWorkflowExecutionCompletedEventSchema; + + case 'childWorkflowExecutionFailedEventAttributes': + return formatChildWorkflowExecutionFailedEventSchema; + + case 'childWorkflowExecutionStartedEventAttributes': + return formatChildWorkflowExecutionStartedEventSchema; + + case 'childWorkflowExecutionTerminatedEventAttributes': + return formatChildWorkflowExecutionTerminatedEventSchema; + + case 'childWorkflowExecutionTimedOutEventAttributes': + return formatChildWorkflowExecutionTimedOutEventSchema; + + case 'startChildWorkflowExecutionFailedEventAttributes': + return formatStartChildWorkflowExecutionFailedEventSchema; + + case 'startChildWorkflowExecutionInitiatedEventAttributes': + return formatStartChildWorkflowExecutionInitiatedEventSchema; + + case 'upsertWorkflowSearchAttributesEventAttributes': + return formatUpsertWorkflowSearchAttributesEventSchema; + + default: + return unExistingEventType(event.attributes); // should not be unreachable, used to show a type error if not all attributes cases are covered + } +}; diff --git a/src/views/workflow-history/__fixtures__/all-workflow-event-types.ts b/src/views/workflow-history/__fixtures__/all-workflow-event-types.ts new file mode 100644 index 000000000..d2c909f1a --- /dev/null +++ b/src/views/workflow-history/__fixtures__/all-workflow-event-types.ts @@ -0,0 +1,101 @@ +import { + scheduleActivityTaskEvent, + cancelActivityTaskEvent, + completeActivityTaskEvent, + failedActivityTaskEvent, + startActivityTaskEvent, + timeoutActivityTaskEvent, +} from './workflow-history-activity-events'; +import { + startChildWorkflowEvent, + cancelChildWorkflowEvent, + failChildWorkflowEvent, + initiateChildWorkflowEvent, + terminateChildWorkflowEvent, + timeoutChildWorkflowEvent, + completeChildWorkflowEvent, + initiateFailureChildWorkflowEvent, +} from './workflow-history-child-workflow-events'; +import { + scheduleDecisionTaskEvent, + completeDecisionTaskEvent, + failedDecisionTaskEvent, + startDecisionTaskEvent, + timeoutDecisionTaskEvent, +} from './workflow-history-decision-events'; +import { + initiateRequestCancelExternalWorkflowEvent, + requestCancelExternalWorkflowEvent, + failRequestCancelExternalWorkflowEvent, +} from './workflow-history-request-cancel-external-workflow-events'; +import { + signalExternalWorkflowEvent, + failSignalExternalWorkflowEvent, + initiateSignalExternalWorkflowEvent, +} from './workflow-history-singal-external-workflow-events'; +import { + startWorkflowExecutionEvent, + cancelRequestActivityTaskEvent, + cancelWorkflowExecutionEvent, + completeWorkflowExecutionEvent, + continueAsNewWorkflowExecutionEvent, + failCancelRequestActivityTaskEvent, + failCancelTimerEvent, + failWorkflowExecutionEvent, + recordMarkerExecutionEvent, + requestCancelWorkflowExecutionEvent, + signalWorkflowExecutionEvent, + terminateWorkflowExecutionEvent, + timeoutWorkflowExecutionEvent, + upsertWorkflowSearchAttributesEvent, +} from './workflow-history-single-events'; +import { + startTimerTaskEvent, + cancelTimerTaskEvent, + fireTimerTaskEvent, +} from './workflow-history-timer-events'; + +export const allWorkflowEvents = [ + scheduleActivityTaskEvent, + cancelActivityTaskEvent, + completeActivityTaskEvent, + failedActivityTaskEvent, + startActivityTaskEvent, + timeoutActivityTaskEvent, + scheduleDecisionTaskEvent, + completeDecisionTaskEvent, + failedDecisionTaskEvent, + startDecisionTaskEvent, + timeoutDecisionTaskEvent, + startTimerTaskEvent, + cancelTimerTaskEvent, + fireTimerTaskEvent, + startChildWorkflowEvent, + cancelChildWorkflowEvent, + failChildWorkflowEvent, + initiateChildWorkflowEvent, + terminateChildWorkflowEvent, + timeoutChildWorkflowEvent, + completeChildWorkflowEvent, + initiateFailureChildWorkflowEvent, + signalExternalWorkflowEvent, + failSignalExternalWorkflowEvent, + initiateSignalExternalWorkflowEvent, + initiateRequestCancelExternalWorkflowEvent, + requestCancelExternalWorkflowEvent, + failRequestCancelExternalWorkflowEvent, + startWorkflowExecutionEvent, + cancelRequestActivityTaskEvent, + cancelWorkflowExecutionEvent, + completeWorkflowExecutionEvent, + continueAsNewWorkflowExecutionEvent, + failCancelRequestActivityTaskEvent, + failCancelTimerEvent, + failWorkflowExecutionEvent, + recordMarkerExecutionEvent, + requestCancelWorkflowExecutionEvent, + signalWorkflowExecutionEvent, + terminateWorkflowExecutionEvent, + timeoutWorkflowExecutionEvent, + upsertWorkflowSearchAttributesEvent, +]; diff --git a/src/views/workflow-history/__fixtures__/workflow-history-request-cancel-external-workflow-events.ts b/src/views/workflow-history/__fixtures__/workflow-history-request-cancel-external-workflow-events.ts index bc8085f79..3ef718402 100644 --- a/src/views/workflow-history/__fixtures__/workflow-history-request-cancel-external-workflow-events.ts +++ b/src/views/workflow-history/__fixtures__/workflow-history-request-cancel-external-workflow-events.ts @@ -40,8 +40,36 @@ export const requestCancelExternalWorkflowEvent = { attributes: 'externalWorkflowExecutionCancelRequestedEventAttributes', } as const satisfies RequestCancelExternalWorkflowExecutionHistoryEvent; +export const failRequestCancelExternalWorkflowEvent = { + eventId: '25', + eventTime: { + seconds: '1725749470', + nanos: 886551263, + }, + version: '575102', + taskId: '5877269814', + requestCancelExternalWorkflowExecutionFailedEventAttributes: { + decisionTaskCompletedEventId: '24', + domain: 'cadence-domain', + workflowExecution: { + workflowId: 'workflow.cancellation-workflow.cancellation.external-child', + runId: '', + }, + control: '', + cause: 'CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_INVALID', + initiatedEventId: '25', + }, + attributes: 'requestCancelExternalWorkflowExecutionFailedEventAttributes', +} as const satisfies RequestCancelExternalWorkflowExecutionHistoryEvent; + export const requestedCancelExternalWorkflowEvents: RequestCancelExternalWorkflowExecutionHistoryEvent[] = [ initiateRequestCancelExternalWorkflowEvent, requestCancelExternalWorkflowEvent, ]; + +export const failedCancelExternalWorkflowEvents: RequestCancelExternalWorkflowExecutionHistoryEvent[] = + [ + initiateRequestCancelExternalWorkflowEvent, + failRequestCancelExternalWorkflowEvent, + ]; From cbeab15487749a674b0b9eb3e8f340d7097c2edc Mon Sep 17 00:00:00 2001 From: Assem Hafez Date: Tue, 1 Oct 2024 12:42:44 +0000 Subject: [PATCH 2/4] fix failed reason mock --- .../__tests__/format-workflow-history.test.ts | 1 - .../__tests__/index.test.ts.snapshot | 21 +++++++++++++++++++ .../workflow-history-decision-events.ts | 7 +++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/utils/data-formatters/__tests__/format-workflow-history.test.ts b/src/utils/data-formatters/__tests__/format-workflow-history.test.ts index 9800db2ad..771a1a28b 100644 --- a/src/utils/data-formatters/__tests__/format-workflow-history.test.ts +++ b/src/utils/data-formatters/__tests__/format-workflow-history.test.ts @@ -3,7 +3,6 @@ import { completeActivityTaskEvent } from '@/views/workflow-history/__fixtures__ import formatTimestampToDatetime from '../format-timestamp-to-datetime'; import formatWorkflowHistory from '../format-workflow-history'; import formatWorkflowHistoryEvent from '../format-workflow-history-event'; -import formatWorkflowHistoryEventType from '../format-workflow-history-event-type'; jest.mock('../format-timestamp-to-datetime'); jest.mock('../format-workflow-history-event'); diff --git a/src/utils/data-formatters/format-workflow-history-event/__tests__/index.test.ts.snapshot b/src/utils/data-formatters/format-workflow-history-event/__tests__/index.test.ts.snapshot index 79a098942..b067a46d4 100644 --- a/src/utils/data-formatters/format-workflow-history-event/__tests__/index.test.ts.snapshot +++ b/src/utils/data-formatters/format-workflow-history-event/__tests__/index.test.ts.snapshot @@ -279,6 +279,27 @@ exports[`formatWorkflowHistoryEvent should format workflow decisionTaskCompleted } `; +exports[`formatWorkflowHistoryEvent should format workflow decisionTaskFailedEventAttributes to match snapshot 1`] = ` +{ + "baseRunId": "", + "binaryChecksum": "ffc875a4c3571872881f79c939921e00398ab360", + "cause": "DECISION_TASK_FAILED_CAUSE_BAD_START_CHILD_EXECUTION_ATTRIBUTES", + "details": "WorkflowId exceeds length limit.", + "eventId": 5, + "eventType": "DecisionTaskFailed", + "forkEventVersion": 0, + "identity": "cadence@958ab341-a375-431b-a27a-ed7d8a97ba91", + "newRunId": "", + "reason": "", + "requestId": "66f7f58b-3d3b-4178-972a-fa7825ceec39", + "scheduledEventId": 2, + "startedEventId": 3, + "taskId": "22647174902", + "timestamp": 2024-09-07T22:16:10.599Z, + "version": "575102", +} +`; + exports[`formatWorkflowHistoryEvent should format workflow decisionTaskScheduledEventAttributes to match snapshot 1`] = ` { "attempt": 0, diff --git a/src/views/workflow-history/__fixtures__/workflow-history-decision-events.ts b/src/views/workflow-history/__fixtures__/workflow-history-decision-events.ts index 08595134f..1c1e254ec 100644 --- a/src/views/workflow-history/__fixtures__/workflow-history-decision-events.ts +++ b/src/views/workflow-history/__fixtures__/workflow-history-decision-events.ts @@ -71,14 +71,13 @@ export const failedDecisionTaskEvent = { cause: 'DECISION_TASK_FAILED_CAUSE_BAD_START_CHILD_EXECUTION_ATTRIBUTES', failure: { reason: '', - details: 'WorkflowId exceeds length limit.', + details: 'V29ya2Zsb3dJZCBleGNlZWRzIGxlbmd0aCBsaW1pdC4=', }, - identity: - '1@dca50-hrk@cadence-canary-production@canary-task-queue@bd570bec-e2cf-470f-937b-0e71d3d8a6d8', + identity: 'cadence@958ab341-a375-431b-a27a-ed7d8a97ba91', baseRunId: '', newRunId: '', forkEventVersion: '0', - binaryChecksum: 'uDeploy:ffc875a4c3571872881f79c939921e00398ab260', + binaryChecksum: 'ffc875a4c3571872881f79c939921e00398ab360', requestId: '66f7f58b-3d3b-4178-972a-fa7825ceec39', }, } as const satisfies DecisionHistoryEvent; From aeedcb6e106e9ae2a4eac7c814e5fcd7671427ed Mon Sep 17 00:00:00 2001 From: Assem Hafez Date: Tue, 1 Oct 2024 12:51:33 +0000 Subject: [PATCH 3/4] ignore config files in coverage report --- jest.config.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index 6ad6376d5..a2d98f42e 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,23 +1,24 @@ -const config= { +const config = { collectCoverage: true, - coverageDirectory: "coverage", + coverageDirectory: 'coverage', coveragePathIgnorePatterns: [ - "/node_modules/", - "src/test-utils", + '/node_modules/', + 'src/test-utils', + '*.config.ts', ], - coverageProvider: "v8", + coverageProvider: 'v8', coverageThreshold: { global: { branches: 85, functions: 85, lines: 85, - statements: 85 - } + statements: 85, + }, }, projects: [ '/jest/browser/jest.config.ts', '/jest/node/jest.config.ts', '/jest/tsd/jest.config.ts', ], -} -export default config; \ No newline at end of file +}; +export default config; From 22e68d5d7c7075bfc1c9c46f26a6d966f8c01a74 Mon Sep 17 00:00:00 2001 From: Assem Hafez Date: Tue, 1 Oct 2024 14:11:50 +0000 Subject: [PATCH 4/4] update the ignore pattern for config files --- jest.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jest.config.ts b/jest.config.ts index a2d98f42e..d4305f45c 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -4,7 +4,7 @@ const config = { coveragePathIgnorePatterns: [ '/node_modules/', 'src/test-utils', - '*.config.ts', + '\\.config\\.ts$', ], coverageProvider: 'v8', coverageThreshold: {