Skip to content

Commit

Permalink
fix(editor): Prevent running workflow that has issues if listening to…
Browse files Browse the repository at this point in the history
… webhook (#11402)
  • Loading branch information
ivov authored Oct 25, 2024
1 parent 7fc3b25 commit 8b0a48f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ vi.mock('@/stores/workflows.store', () => ({
getCurrentWorkflow: vi.fn().mockReturnValue({ id: '123' }),
getNodeByName: vi.fn(),
getExecution: vi.fn(),
nodeIssuesExit: vi.fn(),
}),
}));

Expand Down Expand Up @@ -124,6 +125,21 @@ describe('useRunWorkflow({ router })', () => {
expect(uiStore.addActiveAction).toHaveBeenCalledWith('workflowRunning');
});

it('should prevent running a webhook-based workflow that has issues', async () => {
const { runWorkflowApi } = useRunWorkflow({ router });
vi.mocked(workflowsStore).nodesIssuesExist = true;
vi.mocked(workflowsStore).runWorkflow.mockResolvedValue({
executionId: '123',
waitingForWebhook: true,
});

await expect(runWorkflowApi({} as IStartRunData)).rejects.toThrow(
'workflowRun.showError.resolveOutstandingIssues',
);

vi.mocked(workflowsStore).nodesIssuesExist = false;
});

it('should handle workflow run failure', async () => {
const { runWorkflowApi } = useRunWorkflow({ router });

Expand Down
5 changes: 5 additions & 0 deletions packages/editor-ui/src/composables/useRunWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
workflowsStore.activeExecutionId = response.executionId;
}

if (response.waitingForWebhook === true && useWorkflowsStore().nodesIssuesExist) {
uiStore.removeActiveAction('workflowRunning');
throw new Error(i18n.baseText('workflowRun.showError.resolveOutstandingIssues'));
}

if (response.waitingForWebhook === true) {
workflowsStore.executionWaitingForWebhook = true;
}
Expand Down
1 change: 1 addition & 0 deletions packages/editor-ui/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,7 @@
"workflowRun.noActiveConnectionToTheServer": "Lost connection to the server",
"workflowRun.showError.title": "Problem running workflow",
"workflowRun.showError.payloadTooLarge": "Please execute the whole workflow, rather than just the node. (Existing execution data is too large.)",
"workflowRun.showError.resolveOutstandingIssues": "Please resolve outstanding issues before you activate it",
"workflowRun.showMessage.message": "Please fix them before executing",
"workflowRun.showMessage.title": "Workflow has issues",
"workflowSettings.callerIds": "IDs of workflows that can call this one",
Expand Down

0 comments on commit 8b0a48f

Please sign in to comment.