Skip to content

The open alternative to Salesforce, designed for AI.

feat(workflow): honor continueOnFailure in the executor (#25222)

Thomas Trompette0a68cee38e5e
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/should-execute-child-step.util.spec.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/should-execute-child-step.util.spec.ts
index 58d1fbe8be7..58d50144e4d 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/should-execute-child-step.util.spec.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/should-execute-child-step.util.spec.ts
@@ -1,5 +1,6 @@
import { StepStatus, WorkflowActionType } from 'twenty-shared/workflow';
+import { createMockCodeStep } from 'src/modules/workflow/workflow-executor/utils/create-mock-workflow-steps.util';
import { shouldExecuteChildStep } from 'src/modules/workflow/workflow-executor/utils/should-execute-child-step.util';
import { type WorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
@@ -555,4 +556,64 @@ describe('shouldExecuteChildStep', () => {
expect(result).toBe(false);
});
+
+ it('should return true when the only parent failed and continues on failure', () => {
+ const continuingParent = createMockCodeStep(
+ 'continuing-parent',
+ [CHILD_STEP_ID],
+ {
+ continueOnFailure: true,
+ },
+ );
+
+ const result = shouldExecuteChildStep({
+ childStepId: CHILD_STEP_ID,
+ parentSteps: [continuingParent],
+ stepInfos: {
+ 'continuing-parent': {
+ status: StepStatus.FAILED_SAFELY,
+ error: 'some error',
+ },
+ },
+ });
+
+ expect(result).toBe(true);
+ });
+
+ it('should return false when the only parent failed safely without continuing on failure', () => {
+ const parent = createMockCodeStep('plain-parent', [CHILD_STEP_ID]);
+
+ const result = shouldExecuteChildStep({
+ childStepId: CHILD_STEP_ID,
+ parentSteps: [parent],
+ stepInfos: {
+ 'plain-parent': {
+ status: StepStatus.FAILED_SAFELY,
+ error: 'some error',
+ },
+ },
+ });
+
+ expect(result).toBe(false);
+ });
+
+ it('should return false when a continuing parent was failed safely by cascade', () => {
+ const continuingParent = createMockCodeStep(
+ 'continuing-parent',
+ [CHILD_STEP_ID],
+ {
+ continueOnFailure: true,
+ },
+ );
+
+ const result = shouldExecuteChildStep({
+ childStepId: CHILD_STEP_ID,
+ parentSteps: [continuingParent],
+ stepInfos: {
+ 'continuing-parent': { status: StepStatus.FAILED_SAFELY },
+ },
+ });
+
+ expect(result).toBe(false);
+ });
});
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/should-fail-safely.util.spec.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/should-fail-safely.util.spec.ts
index 0b9dcd9d609..d019550c944 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/should-fail-safely.util.spec.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/should-fail-safely.util.spec.ts
@@ -144,6 +144,43 @@ describe('shouldFailSafely', () => {
},
});
+ expect(result).toBe(false);
+ });
+ it('should return true when a continuing parent is joined by a cascaded FAILED_SAFELY parent', () => {
+ const continuingParent = createMockCodeStep('parent1', ['child'], {
+ continueOnFailure: true,
+ });
+ const cascadedParent = createMockCodeStep('parent2', ['child']);
+ const childStep = createMockCodeStep('child');
+ const steps = [continuingParent, cascadedParent, childStep];
+
+ const result = shouldFailSafely({
+ step: childStep,
+ steps,
+ stepInfos: {
+ parent1: { status: StepStatus.FAILED_SAFELY, error: 'some error' },
+ parent2: { status: StepStatus.FAILED_SAFELY },
+ },
+ });
+
+ expect(result).toBe(true);
+ });
+
+ it('should return false when the FAILED_SAFELY parent continued on failure', () => {
+ const parent = createMockCodeStep('parent', ['child'], {
+ continueOnFailure: true,
+ });
+ const childStep = createMockCodeStep('child');
+ const steps = [parent, childStep];
+
+ const result = shouldFailSafely({
+ step: childStep,
+ steps,
+ stepInfos: {
+ parent: { status: StepStatus.FAILED_SAFELY, error: 'some error' },
+ },
+ });
+
expect(result).toBe(false);
});
});
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/should-skip-step-execution.util.spec.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/should-skip-step-execution.util.spec.ts
index 032fb1fbde0..fa9b7e0e1f9 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/should-skip-step-execution.util.spec.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/should-skip-step-execution.util.spec.ts
@@ -336,4 +336,27 @@ describe('shouldSkipStepExecution', () => {
expect(result).toBe(false);
});
+
+ it('should return false when a parent failed and continues on failure', () => {
+ const steps = [
+ createMockCodeStep('step-1', ['step-3'], {
+ continueOnFailure: true,
+ }),
+ createMockCodeStep('step-2', ['step-3']),
+ createMockCodeStep('step-3', []),
+ ];
+ const stepInfos = {
+ 'step-1': { status: StepStatus.FAILED_SAFELY, error: 'some error' },
+ 'step-2': { status: StepStatus.SKIPPED },
+ 'step-3': { status: StepStatus.NOT_STARTED },
+ };
+
+ const result = shouldSkipStepExecution({
+ step: steps[2],
+ steps,
+ stepInfos,
+ });
+
+ expect(result).toBe(false);
+ });
});
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/step-failed-and-continued.util.spec.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/step-failed-and-continued.util.spec.ts
new file mode 100644
index 00000000000..32fa486960d
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/step-failed-and-continued.util.spec.ts
@@ -0,0 +1,70 @@
+import { StepStatus } from 'twenty-shared/workflow';
+
+import {
+ createMockCodeStep,
+ createMockIfElseStep,
+} from 'src/modules/workflow/workflow-executor/utils/create-mock-workflow-steps.util';
+import { stepFailedAndContinued } from 'src/modules/workflow/workflow-executor/utils/step-failed-and-continued.util';
+
+describe('stepFailedAndContinued', () => {
+ it('should return true when the step failed on its own and continues on failure', () => {
+ const step = createMockCodeStep('step-1', [], {
+ continueOnFailure: true,
+ });
+
+ const result = stepFailedAndContinued({
+ step,
+ stepInfos: {
+ 'step-1': { status: StepStatus.FAILED_SAFELY, error: 'some error' },
+ },
+ });
+
+ expect(result).toBe(true);
+ });
+
+ it('should return false when the step does not continue on failure', () => {
+ const step = createMockCodeStep('step-1');
+
+ const result = stepFailedAndContinued({
+ step,
+ stepInfos: {
+ 'step-1': { status: StepStatus.FAILED_SAFELY, error: 'some error' },
+ },
+ });
+
+ expect(result).toBe(false);
+ });
+
+ it('should return false when the step was failed safely by cascade', () => {
+ const step = createMockCodeStep('step-1', [], {
+ continueOnFailure: true,
+ });
+
+ const result = stepFailedAndContinued({
+ step,
+ stepInfos: {
+ 'step-1': { status: StepStatus.FAILED_SAFELY },
+ },
+ });
+
+ expect(result).toBe(false);
+ });
+
+ it('should return false for an if/else step even when it continues on failure', () => {
+ const step = createMockIfElseStep(
+ 'step-1',
+ [{ id: 'branch-1', nextStepIds: ['step-2'] }],
+ [],
+ { continueOnFailure: true },
+ );
+
+ const result = stepFailedAndContinued({
+ step,
+ stepInfos: {
+ 'step-1': { status: StepStatus.FAILED_SAFELY, error: 'some error' },
+ },
+ });
+
+ expect(result).toBe(false);
+ });
+});
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/create-mock-workflow-steps.util.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/create-mock-workflow-steps.util.ts
index a9dfadd6a6e..950c2d2f502 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/create-mock-workflow-steps.util.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/create-mock-workflow-steps.util.ts
@@ -15,6 +15,7 @@ import {
export const createMockCodeStep = (
id: string,
nextStepIds: string[] = [],
+ { continueOnFailure = false }: { continueOnFailure?: boolean } = {},
): WorkflowCodeAction => ({
id,
name: `Step ${id}`,
@@ -25,7 +26,7 @@ export const createMockCodeStep = (
input: {},
outputSchema: {},
errorHandlingOptions: {
- continueOnFailure: { value: false },
+ continueOnFailure: { value: continueOnFailure },
retryOnFailure: { value: false },
},
} as WorkflowCodeActionSettings,
@@ -59,6 +60,7 @@ export const createMockIfElseStep = (
id: string,
branches: StepIfElseBranch[],
nextStepIds: string[] = [],
+ { continueOnFailure = false }: { continueOnFailure?: boolean } = {},
): WorkflowIfElseAction => ({
id,
name: `Step ${id}`,
@@ -73,7 +75,7 @@ export const createMockIfElseStep = (
},
outputSchema: {},
errorHandlingOptions: {
- continueOnFailure: { value: false },
+ continueOnFailure: { value: continueOnFailure },
retryOnFailure: { value: false },
},
} as WorkflowIfElseActionSettings,
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/should-execute-child-step.util.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/should-execute-child-step.util.ts
index ffa0337f718..70c7d94bac5 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/should-execute-child-step.util.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/should-execute-child-step.util.ts
@@ -1,6 +1,7 @@
import { StepStatus, type WorkflowRunStepInfos } from 'twenty-shared/workflow';
import { getEffectiveParentStatus } from 'src/modules/workflow/workflow-executor/utils/get-effective-parent-status.util';
+import { stepFailedAndContinued } from 'src/modules/workflow/workflow-executor/utils/step-failed-and-continued.util';
import { type WorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
export const shouldExecuteChildStep = ({
@@ -16,20 +17,23 @@ export const shouldExecuteChildStep = ({
return true;
}
- const statuses = parentSteps.map((parentStep) =>
- getEffectiveParentStatus({ parentStep, childStepId, stepInfos }),
- );
+ const parentOutcomes = parentSteps.map((parentStep) => ({
+ status: getEffectiveParentStatus({ parentStep, childStepId, stepInfos }),
+ failedAndContinued: stepFailedAndContinued({ step: parentStep, stepInfos }),
+ }));
- const hasSuccessfulParentStep = statuses.some(
- (status) => status === StepStatus.SUCCESS,
+ const hasSuccessfulOrContinuedParentStep = parentOutcomes.some(
+ ({ status, failedAndContinued }) =>
+ status === StepStatus.SUCCESS || failedAndContinued,
);
- const areAllParentsCompleted = statuses.every(
- (status) =>
+ const areAllParentsCompleted = parentOutcomes.every(
+ ({ status, failedAndContinued }) =>
status === StepStatus.SUCCESS ||
status === StepStatus.STOPPED ||
- status === StepStatus.SKIPPED,
+ status === StepStatus.SKIPPED ||
+ failedAndContinued,
);
- return hasSuccessfulParentStep && areAllParentsCompleted;
+ return hasSuccessfulOrContinuedParentStep && areAllParentsCompleted;
};
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/should-fail-safely.util.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/should-fail-safely.util.ts
index 4df50cafdfb..2d16080fe2e 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/should-fail-safely.util.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/should-fail-safely.util.ts
@@ -4,6 +4,7 @@ import { StepStatus, type WorkflowRunStepInfos } from 'twenty-shared/workflow';
import { TERMINAL_STEP_STATUSES } from 'src/modules/workflow/workflow-executor/constants/terminal-step-statuses.constant';
import { findParentSteps } from 'src/modules/workflow/workflow-executor/utils/find-parent-steps.util';
import { getEffectiveParentStatus } from 'src/modules/workflow/workflow-executor/utils/get-effective-parent-status.util';
+import { stepFailedAndContinued } from 'src/modules/workflow/workflow-executor/utils/step-failed-and-continued.util';
import { isWorkflowIteratorAction } from 'src/modules/workflow/workflow-executor/workflow-actions/iterator/guards/is-workflow-iterator-action.guard';
import { shouldFailSafelyIteratorStep } from 'src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/should-fail-safely-iterator-step.util';
import { type WorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
@@ -31,16 +32,23 @@ export const shouldFailSafely = ({
return false;
}
- const statuses = parentSteps.map((parentStep) =>
- getEffectiveParentStatus({ parentStep, childStepId: step.id, stepInfos }),
- );
+ const parentOutcomes = parentSteps.map((parentStep) => ({
+ status: getEffectiveParentStatus({
+ parentStep,
+ childStepId: step.id,
+ stepInfos,
+ }),
+ failedAndContinued: stepFailedAndContinued({ step: parentStep, stepInfos }),
+ }));
- const areAllParentsTerminal = statuses.every(
- (status) => isDefined(status) && TERMINAL_STEP_STATUSES.includes(status),
+ const areAllParentsTerminal = parentOutcomes.every(
+ ({ status }) =>
+ isDefined(status) && TERMINAL_STEP_STATUSES.includes(status),
);
- const hasFailedSafelyParent = statuses.some(
- (status) => status === StepStatus.FAILED_SAFELY,
+ const hasFailedSafelyParent = parentOutcomes.some(
+ ({ status, failedAndContinued }) =>
+ status === StepStatus.FAILED_SAFELY && !failedAndContinued,
);
return areAllParentsTerminal && hasFailedSafelyParent;
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/should-skip-step-execution.util.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/should-skip-step-execution.util.ts
index b4a17d30758..031e9f47380 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/should-skip-step-execution.util.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/should-skip-step-execution.util.ts
@@ -2,6 +2,7 @@ import { StepStatus, type WorkflowRunStepInfos } from 'twenty-shared/workflow';
import { findParentSteps } from 'src/modules/workflow/workflow-executor/utils/find-parent-steps.util';
import { getEffectiveParentStatus } from 'src/modules/workflow/workflow-executor/utils/get-effective-parent-status.util';
+import { stepFailedAndContinued } from 'src/modules/workflow/workflow-executor/utils/step-failed-and-continued.util';
import { isWorkflowIteratorAction } from 'src/modules/workflow/workflow-executor/workflow-actions/iterator/guards/is-workflow-iterator-action.guard';
import { shouldSkipIteratorStepExecution } from 'src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/should-skip-iterator-step-execution.util';
import { type WorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
@@ -30,6 +31,10 @@ export const shouldSkipStepExecution = ({
}
return parentSteps.every((parentStep) => {
+ if (stepFailedAndContinued({ step: parentStep, stepInfos })) {
+ return false;
+ }
+
const status = getEffectiveParentStatus({
parentStep,
childStepId: step.id,
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/step-failed-and-continued.util.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/step-failed-and-continued.util.ts
new file mode 100644
index 00000000000..c322ec26f8b
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/step-failed-and-continued.util.ts
@@ -0,0 +1,21 @@
+import { isDefined } from 'twenty-shared/utils';
+import { StepStatus, type WorkflowRunStepInfos } from 'twenty-shared/workflow';
+
+import { stepShouldContinueOnFailure } from 'src/modules/workflow/workflow-executor/utils/step-should-continue-on-failure.util';
+import { type WorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
+
+export const stepFailedAndContinued = ({
+ step,
+ stepInfos,
+}: {
+ step: WorkflowAction;
+ stepInfos: WorkflowRunStepInfos;
+}): boolean => {
+ const stepInfo = stepInfos[step.id];
+
+ return (
+ stepInfo?.status === StepStatus.FAILED_SAFELY &&
+ isDefined(stepInfo.error) &&
+ stepShouldContinueOnFailure(step)
+ );
+};
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/step-should-continue-on-failure.util.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/step-should-continue-on-failure.util.ts
new file mode 100644
index 00000000000..6f096c301ec
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/step-should-continue-on-failure.util.ts
@@ -0,0 +1,6 @@
+import { isWorkflowIfElseAction } from 'src/modules/workflow/workflow-executor/workflow-actions/if-else/guards/is-workflow-if-else-action.guard';
+import { type WorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
+
+export const stepShouldContinueOnFailure = (step: WorkflowAction): boolean =>
+ !isWorkflowIfElseAction(step) &&
+ step.settings.errorHandlingOptions.continueOnFailure.value;
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/__tests__/should-execute-iterator-step.util.spec.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/__tests__/should-execute-iterator-step.util.spec.ts
index 5627863b248..f5e95337745 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/__tests__/should-execute-iterator-step.util.spec.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/utils/__tests__/should-execute-iterator-step.util.spec.ts
@@ -241,6 +241,30 @@ describe('shouldExecuteIteratorStep', () => {
expect(result).toBe(true);
});
+ it('should return true when a loop step failed and continues on failure, even without the iteration flag', () => {
+ const iteratorStep = createMockIteratorStep('iterator-1', [], ['step-1']);
+ const steps = [
+ createMockCodeStep('step-1', ['iterator-1'], {
+ continueOnFailure: true,
+ }),
+ iteratorStep,
+ ];
+ const stepInfos = {
+ 'iterator-1': { status: StepStatus.RUNNING },
+ 'step-1': { status: StepStatus.FAILED_SAFELY, error: 'some error' },
+ };
+
+ getAllStepIdsInLoop.mockReturnValue(['step-1']);
+
+ const result = shouldExecuteIteratorStep({
+ step: iteratorStep,
+ steps,
+ stepInfos,
+ });
+
+ expect(result).toBe(true);
+ });
+
it('should return false if some of the steps targeting the iterator have failed', () => {
const iteratorStep = createMockIteratorStep('iterator-1', [], ['step-1']);
const steps = [
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts
index e290103c2fd..baf5e0e5b75 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts
@@ -37,6 +37,7 @@ import {
import { shouldExecuteStep } from 'src/modules/workflow/workflow-executor/utils/should-execute-step.util';
import { shouldFailSafely } from 'src/modules/workflow/workflow-executor/utils/should-fail-safely.util';
import { shouldSkipStepExecution } from 'src/modules/workflow/workflow-executor/utils/should-skip-step-execution.util';
+import { stepShouldContinueOnFailure } from 'src/modules/workflow/workflow-executor/utils/step-should-continue-on-failure.util';
import { workflowShouldFail } from 'src/modules/workflow/workflow-executor/utils/workflow-should-fail.util';
import { workflowShouldKeepRunning } from 'src/modules/workflow/workflow-executor/utils/workflow-should-keep-running.util';
import { isWorkflowIfElseAction } from 'src/modules/workflow/workflow-executor/workflow-actions/if-else/guards/is-workflow-if-else-action.guard';
@@ -147,7 +148,10 @@ export class WorkflowExecutorWorkspaceService {
steps,
});
- if (isDefined(enclosingIterator)) {
+ if (
+ isDefined(enclosingIterator) ||
+ stepShouldContinueOnFailure(stepToExecute)
+ ) {
actionOutput.shouldFailSafely = true;
}
}
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/continue-on-failure-workflow.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/continue-on-failure-workflow.integration-spec.ts
new file mode 100644
index 00000000000..87764cb6cd2
--- /dev/null
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/continue-on-failure-workflow.integration-spec.ts
@@ -0,0 +1,264 @@
+import request from 'supertest';
+import {
+ destroyWorkflowRun,
+ runWorkflowVersion,
+ waitForWorkflowCompletion,
+} from 'test/integration/graphql/suites/workflow/utils/workflow-run-test.util';
+
+import {
+ type WorkflowAction,
+ type WorkflowHttpRequestAction,
+} from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
+import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';
+
+const client = request(`http://localhost:${APP_PORT}`);
+
+const BLOCKED_REQUEST_URL = 'http://127.0.0.1:1/';
+
+describe('Continue on failure workflow (e2e)', () => {
+ let createdWorkflowId: string | null = null;
+ let createdWorkflowVersionId: string | null = null;
+ let httpRequestStepId: string | null = null;
+ let filterStepId: string | null = null;
+
+ const getSteps = async (): Promise<WorkflowAction[]> => {
+ const response = await client
+ .post('/graphql')
+ .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
+ .send({
+ query: `
+ query GetWorkflowVersion($id: UUID!) {
+ workflowVersion(filter: { id: { eq: $id } }) {
+ id
+ steps
+ }
+ }
+ `,
+ variables: { id: createdWorkflowVersionId },
+ });
+
+ expect(response.body.errors).toBeUndefined();
+
+ return response.body.data.workflowVersion.steps;
+ };
+
+ const createStep = async ({
+ stepType,
+ parentStepId,
+ }: {
+ stepType: string;
+ parentStepId: string;
+ }) => {
+ const response = await client
+ .post('/graphql')
+ .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
+ .send({
+ query: `
+ mutation CreateWorkflowVersionStep($input: CreateWorkflowVersionStepInput!) {
+ createWorkflowVersionStep(input: $input) {
+ stepsDiff
+ }
+ }
+ `,
+ variables: {
+ input: {
+ workflowVersionId: createdWorkflowVersionId,
+ stepType,
+ parentStepId,
+ position: { x: 200, y: 0 },
+ },
+ },
+ });
+
+ expect(response.body.errors).toBeUndefined();
+ };
+
+ const setUpFailingHttpRequestStep = async ({
+ continueOnFailure,
+ }: {
+ continueOnFailure: boolean;
+ }) => {
+ const steps = await getSteps();
+
+ const httpRequestStep = steps.find(
+ (step) => step.id === httpRequestStepId,
+ ) as WorkflowHttpRequestAction;
+
+ const response = await client
+ .post('/graphql')
+ .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
+ .send({
+ query: `
+ mutation UpdateWorkflowVersionStep($input: UpdateWorkflowVersionStepInput!) {
+ updateWorkflowVersionStep(input: $input) {
+ id
+ }
+ }
+ `,
+ variables: {
+ input: {
+ workflowVersionId: createdWorkflowVersionId,
+ step: {
+ ...httpRequestStep,
+ settings: {
+ ...httpRequestStep.settings,
+ input: {
+ ...httpRequestStep.settings.input,
+ url: BLOCKED_REQUEST_URL,
+ },
+ errorHandlingOptions: {
+ ...httpRequestStep.settings.errorHandlingOptions,
+ continueOnFailure: { value: continueOnFailure },
+ },
+ },
+ },
+ },
+ },
+ });
+
+ expect(response.body.errors).toBeUndefined();
+ };
+
+ beforeAll(async () => {
+ const createWorkflowResponse = await client
+ .post('/graphql')
+ .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
+ .send({
+ query: `
+ mutation CreateWorkflow {
+ createWorkflow(data: {
+ name: "Continue On Failure Test Workflow"
+ }) {
+ id
+ }
+ }
+ `,
+ });
+
+ expect(createWorkflowResponse.body.errors).toBeUndefined();
+ createdWorkflowId = createWorkflowResponse.body.data.createWorkflow.id;
+
+ const getWorkflowResponse = await client
+ .post('/graphql')
+ .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
+ .send({
+ query: `
+ query GetWorkflow($id: UUID!) {
+ workflow(filter: { id: { eq: $id } }) {
+ id
+ versions {
+ edges {
+ node {
+ id
+ }
+ }
+ }
+ }
+ }
+ `,
+ variables: { id: createdWorkflowId },
+ });
+
+ expect(getWorkflowResponse.body.errors).toBeUndefined();
+ createdWorkflowVersionId =
+ getWorkflowResponse.body.data.workflow.versions.edges[0].node.id;
+
+ const updateTriggerResponse = await updateWorkflowVersionTrigger({
+ workflowVersionId: createdWorkflowVersionId!,
+ trigger: {
+ name: 'Manual Trigger',
+ type: 'MANUAL',
+ settings: { outputSchema: {} },
+ nextStepIds: [],
+ position: { x: 0, y: 0 },
+ },
+ });
+
+ expect(updateTriggerResponse.body.errors).toBeUndefined();
+
+ await createStep({ stepType: 'HTTP_REQUEST', parentStepId: 'trigger' });
+
+ const stepsAfterHttpRequestCreation = await getSteps();
+
+ httpRequestStepId =
+ stepsAfterHttpRequestCreation.find((step) => step.type === 'HTTP_REQUEST')
+ ?.id ?? null;
+
+ expect(httpRequestStepId).not.toBeNull();
+
+ await createStep({ stepType: 'FILTER', parentStepId: httpRequestStepId! });
+
+ const stepsAfterFilterCreation = await getSteps();
+
+ filterStepId =
+ stepsAfterFilterCreation.find((step) => step.type === 'FILTER')?.id ??
+ null;
+
+ expect(filterStepId).not.toBeNull();
+ });
+
+ afterAll(async () => {
+ if (createdWorkflowId) {
+ await client
+ .post('/graphql')
+ .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
+ .send({
+ query: `
+ mutation DestroyWorkflow($id: ID!) {
+ destroyWorkflow(id: $id) {
+ id
+ }
+ }
+ `,
+ variables: { id: createdWorkflowId },
+ });
+ }
+ });
+
+ it('should run the next step and complete the run when the failing step continues on failure', async () => {
+ await setUpFailingHttpRequestStep({ continueOnFailure: true });
+
+ const workflowRunId = await runWorkflowVersion({
+ workflowVersionId: createdWorkflowVersionId!,
+ });
+
+ try {
+ const workflowRun = await waitForWorkflowCompletion(workflowRunId);
+
+ expect(workflowRun?.status).toBe('COMPLETED');
+
+ const httpRequestStepInfo =
+ workflowRun?.state?.stepInfos?.[httpRequestStepId!];
+
+ expect(httpRequestStepInfo?.status).toBe('FAILED_SAFELY');
+ expect(httpRequestStepInfo?.error).toBeDefined();
+ expect(workflowRun?.state?.stepInfos?.[filterStepId!]?.status).toBe(
+ 'SUCCESS',
+ );
+ } finally {
+ await destroyWorkflowRun(workflowRunId);
+ }
+ });
+
+ it('should fail the run and leave the next step not started when the failing step does not continue on failure', async () => {
+ await setUpFailingHttpRequestStep({ continueOnFailure: false });
+
+ const workflowRunId = await runWorkflowVersion({
+ workflowVersionId: createdWorkflowVersionId!,
+ });
+
+ try {
+ const workflowRun = await waitForWorkflowCompletion(workflowRunId);
+
+ expect(workflowRun?.status).toBe('FAILED');
+ expect(workflowRun?.state?.stepInfos?.[httpRequestStepId!]?.status).toBe(
+ 'FAILED',
+ );
+ expect(workflowRun?.state?.stepInfos?.[filterStepId!]?.status).toBe(
+ 'NOT_STARTED',
+ );
+ } finally {
+ await destroyWorkflowRun(workflowRunId);
+ }
+ });
+});