The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Move workflow node, core workflow, lifecycle and permission integration tests to the core workflow API (#27849)
Thomas Trompette0d709cd63e30
diff --git a/packages/twenty-server/test/integration/constants/workflow-gql-fields.constants.ts b/packages/twenty-server/test/integration/constants/workflow-gql-fields.constants.tsindex b19d6c54f36..e8c7bbce89f 100644--- a/packages/twenty-server/test/integration/constants/workflow-gql-fields.constants.ts+++ b/packages/twenty-server/test/integration/constants/workflow-gql-fields.constants.ts@@ -1,19 +1,3 @@-export const WORKFLOW_GQL_FIELDS = `- id- name- lastPublishedVersionId- statuses- position- createdBy {- source- workspaceMemberId- name- }- createdAt- updatedAt- deletedAt-`;-export const WORKFLOW_RUN_GQL_FIELDS = `idnamediff --git a/packages/twenty-server/test/integration/graphql/suites/settings-permissions/granular-settings-permissions.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/settings-permissions/granular-settings-permissions.integration-spec.tsindex f6b3cbb5492..c29c5b31125 100644--- a/packages/twenty-server/test/integration/graphql/suites/settings-permissions/granular-settings-permissions.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/settings-permissions/granular-settings-permissions.integration-spec.ts@@ -1,6 +1,6 @@import request from 'supertest';+import { deleteCoreWorkflows } from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import { deleteOneRoleOperationFactory } from 'test/integration/graphql/utils/delete-one-role-operation-factory.util';-import { destroyOneOperationFactory } from 'test/integration/graphql/utils/destroy-one-operation-factory.util';import { createOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/create-one-object-metadata.util';import { deleteOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/delete-one-object-metadata.util';import { updateOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/update-one-object-metadata.util';@@ -26,7 +26,6 @@ describe('Granular settings permissions', () => {originalMemberRoleId = memberRole.id;- // canUpdateAllObjectRecords must be true to allow creating records like workflowsconst createRoleQuery = {query: `mutation CreateOneRole {@@ -196,8 +195,8 @@ describe('Granular settings permissions', () => {it('should allow access to workflows operations when user has WORKFLOWS setting permission', async () => {const createWorkflowQuery = {query: `- mutation CreateWorkflow {- createWorkflow(data: {+ mutation CreateCoreWorkflow {+ createCoreWorkflow(input: {name: "Test Workflow"}) {id@@ -214,21 +213,12 @@ describe('Granular settings permissions', () => {expect(response.status).toBe(200);expect(response.body.errors).toBeUndefined();- expect(response.body.data.createWorkflow).toBeDefined();- expect(response.body.data.createWorkflow.name).toBe('Test Workflow');+ expect(response.body.data.createCoreWorkflow).toBeDefined();+ expect(response.body.data.createCoreWorkflow.name).toBe('Test Workflow');- const graphqlOperation = destroyOneOperationFactory({- objectMetadataSingularName: 'workflow',- gqlFields: `- id- `,- recordId: response.body.data.createWorkflow.id,+ await deleteCoreWorkflows({+ coreWorkflowIds: [response.body.data.createCoreWorkflow.id],});-- await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send(graphqlOperation);});});diff --git a/packages/twenty-server/test/integration/graphql/suites/settings-permissions/workflows.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/settings-permissions/workflows.integration-spec.tsindex 0cec710ae9e..aeccdfd0815 100644--- a/packages/twenty-server/test/integration/graphql/suites/settings-permissions/workflows.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/settings-permissions/workflows.integration-spec.ts@@ -1,33 +1,41 @@-import { randomUUID } from 'node:crypto';--import { WORKFLOW_GQL_FIELDS } from 'test/integration/constants/workflow-gql-fields.constants';-import { createOneOperationFactory } from 'test/integration/graphql/utils/create-one-operation-factory.util';-import { destroyOneOperationFactory } from 'test/integration/graphql/utils/destroy-one-operation-factory.util';-import { makeGraphqlApiRequestWithApiKey } from 'test/integration/graphql/utils/make-graphql-api-request-with-api-key.util';+import gql from 'graphql-tag';+import {+ createCoreWorkflow,+ deleteCoreWorkflows,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import { makeGraphqlApiRequestWithGuestRole } from 'test/integration/graphql/utils/make-graphql-api-request-with-guest-role.util';import { makeGraphqlApiRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';-import { updateOneOperationFactory } from 'test/integration/graphql/utils/update-one-operation-factory.util';import { ErrorCode } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';import { PermissionsExceptionMessage } from 'src/engine/metadata-modules/permissions/permissions.exception';+const CREATE_CORE_WORKFLOW_MUTATION = gql`+ mutation CreateCoreWorkflow($input: CreateCoreWorkflowInput!) {+ createCoreWorkflow(input: $input) {+ id+ name+ }+ }+`;++const UPDATE_CORE_WORKFLOW_MUTATION = gql`+ mutation UpdateCoreWorkflow($input: UpdateCoreWorkflowInput!) {+ updateCoreWorkflow(input: $input) {+ id+ name+ }+ }+`;+describe('workflowsPermissions', () => {- describe('createOne workflow', () => {+ describe('createCoreWorkflow', () => {it('should throw a permission error when user does not have permission (guest role)', async () => {- const workflowId = randomUUID();- const graphqlOperation = createOneOperationFactory({- objectMetadataSingularName: 'workflow',- gqlFields: WORKFLOW_GQL_FIELDS,- data: {- id: workflowId,- name: 'Test Workflow V2',- },+ const response = await makeGraphqlApiRequestWithGuestRole({+ query: CREATE_CORE_WORKFLOW_MUTATION,+ variables: { input: { name: 'Test Workflow V2' } },});- const response =- await makeGraphqlApiRequestWithGuestRole(graphqlOperation);-- expect(response.body.data).toStrictEqual({ createWorkflow: null });+ expect(response.body.data).toBeNull();expect(response.body.errors).toBeDefined();expect(response.body.errors[0].message).toBe(PermissionsExceptionMessage.PERMISSION_DENIED,@@ -36,110 +44,45 @@ describe('workflowsPermissions', () => {});it('should create a workflow when user has permission (admin role)', async () => {- const workflowId = randomUUID();- const graphqlOperation = createOneOperationFactory({- objectMetadataSingularName: 'workflow',- gqlFields: WORKFLOW_GQL_FIELDS,- data: {- id: workflowId,- name: 'Test Workflow Admin',- },+ const response = await makeGraphqlApiRequest({+ query: CREATE_CORE_WORKFLOW_MUTATION,+ variables: { input: { name: 'Test Workflow Admin' } },});- const response = await makeGraphqlApiRequest(graphqlOperation);-expect(response.body.data).toBeDefined();- expect(response.body.data.createWorkflow).toBeDefined();- expect(response.body.data.createWorkflow.id).toBe(workflowId);- expect(response.body.data.createWorkflow.name).toBe(+ expect(response.body.data.createCoreWorkflow).toBeDefined();+ expect(response.body.data.createCoreWorkflow.name).toBe('Test Workflow Admin',);- const destroyWorkflowOperation = destroyOneOperationFactory({- objectMetadataSingularName: 'workflow',- gqlFields: `- id- `,- recordId: response.body.data.createWorkflow.id,+ await deleteCoreWorkflows({+ coreWorkflowIds: [response.body.data.createCoreWorkflow.id],});-- await makeGraphqlApiRequest(destroyWorkflowOperation);- });-- it('should create a workflow when executed by api key', async () => {- const workflowId = randomUUID();- const graphqlOperation = createOneOperationFactory({- objectMetadataSingularName: 'workflow',- gqlFields: WORKFLOW_GQL_FIELDS,- data: {- id: workflowId,- name: 'Test Workflow API Key',- },- });-- const response = await makeGraphqlApiRequestWithApiKey(graphqlOperation);-- expect(response.body.data).toBeDefined();- expect(response.body.data.createWorkflow).toBeDefined();- expect(response.body.data.createWorkflow.id).toBe(workflowId);- expect(response.body.data.createWorkflow.name).toBe(- 'Test Workflow API Key',- );-- const destroyWorkflowOperation = destroyOneOperationFactory({- objectMetadataSingularName: 'workflow',- gqlFields: `- id- `,- recordId: response.body.data.createWorkflow.id,- });-- await makeGraphqlApiRequest(destroyWorkflowOperation);});});- describe('updateOne workflow', () => {- const workflowId = randomUUID();+ describe('updateCoreWorkflow', () => {+ let coreWorkflowId: string;beforeAll(async () => {- const createWorkflowOperation = createOneOperationFactory({- objectMetadataSingularName: 'workflow',- gqlFields: WORKFLOW_GQL_FIELDS,- data: {- id: workflowId,- name: 'Original Workflow V2',- },- });-- await makeGraphqlApiRequest(createWorkflowOperation);+ ({ coreWorkflowId } = await createCoreWorkflow({+ name: 'Original Workflow V2',+ }));});afterAll(async () => {- const destroyWorkflowOperation = destroyOneOperationFactory({- objectMetadataSingularName: 'workflow',- gqlFields: `- id- `,- recordId: workflowId,- });-- await makeGraphqlApiRequest(destroyWorkflowOperation);+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });});it('should throw a permission error when user does not have permission (guest role)', async () => {- const graphqlOperation = updateOneOperationFactory({- objectMetadataSingularName: 'workflow',- gqlFields: WORKFLOW_GQL_FIELDS,- recordId: workflowId,- data: {- name: 'Updated Workflow V2 Guest',+ const response = await makeGraphqlApiRequestWithGuestRole({+ query: UPDATE_CORE_WORKFLOW_MUTATION,+ variables: {+ input: { coreWorkflowId, name: 'Updated Workflow V2 Guest' },},});- const response =- await makeGraphqlApiRequestWithGuestRole(graphqlOperation);-- expect(response.body.data).toStrictEqual({ updateWorkflow: null });+ expect(response.body.data).toStrictEqual({ updateCoreWorkflow: null });expect(response.body.errors).toBeDefined();expect(response.body.errors[0].message).toBe(PermissionsExceptionMessage.PERMISSION_DENIED,@@ -148,43 +91,19 @@ describe('workflowsPermissions', () => {});it('should update a workflow when user has permission (admin role)', async () => {- const graphqlOperation = updateOneOperationFactory({- objectMetadataSingularName: 'workflow',- gqlFields: WORKFLOW_GQL_FIELDS,- recordId: workflowId,- data: {- name: 'Updated Workflow V2 Admin',+ const response = await makeGraphqlApiRequest({+ query: UPDATE_CORE_WORKFLOW_MUTATION,+ variables: {+ input: { coreWorkflowId, name: 'Updated Workflow V2 Admin' },},});- const response = await makeGraphqlApiRequest(graphqlOperation);-expect(response.body.data).toBeDefined();- expect(response.body.data.updateWorkflow).toBeDefined();- expect(response.body.data.updateWorkflow.id).toBe(workflowId);- expect(response.body.data.updateWorkflow.name).toBe(+ expect(response.body.data.updateCoreWorkflow).toBeDefined();+ expect(response.body.data.updateCoreWorkflow.id).toBe(coreWorkflowId);+ expect(response.body.data.updateCoreWorkflow.name).toBe('Updated Workflow V2 Admin',);});-- it('should update a workflow when executed by api key', async () => {- const graphqlOperation = updateOneOperationFactory({- objectMetadataSingularName: 'workflow',- gqlFields: WORKFLOW_GQL_FIELDS,- recordId: workflowId,- data: {- name: 'Updated Workflow API Key',- },- });-- const response = await makeGraphqlApiRequestWithApiKey(graphqlOperation);-- expect(response.body.data).toBeDefined();- expect(response.body.data.updateWorkflow).toBeDefined();- expect(response.body.data.updateWorkflow.id).toBe(workflowId);- expect(response.body.data.updateWorkflow.name).toBe(- 'Updated Workflow API Key',- );- });});});diff --git a/packages/twenty-server/test/integration/graphql/suites/settings-permissions/workspace.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/settings-permissions/workspace.integration-spec.tsindex b2f487a867f..1b05ceca940 100644--- a/packages/twenty-server/test/integration/graphql/suites/settings-permissions/workspace.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/settings-permissions/workspace.integration-spec.ts@@ -634,8 +634,7 @@ describe('workspace permissions', () => {`,variables: {input: {- publicFeatureFlag:- FeatureFlagKey.IS_WORKFLOW_CORE_INDEX_PAGE_ENABLED,+ publicFeatureFlag: FeatureFlagKey.IS_JSON_FILTER_ENABLED,value: true,},},diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/classify-workflow-activation.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/classify-workflow-activation.integration-spec.tsindex 4d74edd6135..bc392cb49d2 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/classify-workflow-activation.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/classify-workflow-activation.integration-spec.ts@@ -1,5 +1,11 @@import request from 'supertest';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';+import {+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ updateCoreWorkflowVersionStep,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';const client = request(`http://localhost:${APP_PORT}`);@@ -14,39 +20,33 @@ const graphql = async (query: string, variables?: Record<string, unknown>) =>.set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`).send({ query, variables });-const graphqlOrFail = async (- query: string,- variables?: Record<string, unknown>,-) => {- const response = await graphql(query, variables);-- expect(response.body.errors).toBeUndefined();-- return response.body.data;-};--const validateWorkflowVersion = (workflowVersionId: string) =>+const activateVersion = (coreWorkflowVersionId: string) =>graphql(`- mutation ValidateWorkflowVersion($workflowVersionId: UUID!) {- validateWorkflowVersion(workflowVersionId: $workflowVersionId)+ mutation ActivateCoreWorkflowVersion($coreWorkflowVersionId: UUID!) {+ activateCoreWorkflowVersion(+ coreWorkflowVersionId: $coreWorkflowVersionId+ )}`,- { workflowVersionId },+ { coreWorkflowVersionId },);-const updateStep = (workflowVersionId: string, step: Record<string, unknown>) =>+const updateStep = (+ coreWorkflowVersionId: string,+ step: Record<string, unknown>,+) =>graphql(`- mutation UpdateWorkflowVersionStep(- $input: UpdateWorkflowVersionStepInput!+ mutation UpdateCoreWorkflowVersionStep(+ $input: UpdateCoreWorkflowVersionStepInput!) {- updateWorkflowVersionStep(input: $input) {+ updateCoreWorkflowVersionStep(input: $input) {id}}`,- { input: { workflowVersionId, step } },+ { input: { coreWorkflowVersionId, step } },);type ClassifyQuestion = {@@ -66,39 +66,20 @@ type ClassifyStep = {};describe('Classify step activation (e2e)', () => {- let workflowVersionId: string;+ let coreWorkflowId: string;+ let coreWorkflowVersionId: string;let classifyStep: ClassifyStep;beforeAll(async () => {- const createData = await graphqlOrFail(`- mutation CreateWorkflow {- createWorkflow(data: { name: "Classify activation test" }) {- id- }- }- `);-- const workflowData = await graphqlOrFail(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: createData.createWorkflow.id },- );+ const createdCoreWorkflow = await createCoreWorkflow({+ name: 'Classify activation test',+ });- workflowVersionId = workflowData.workflow.versions.edges[0].node.id;+ coreWorkflowId = createdCoreWorkflow.coreWorkflowId;+ coreWorkflowVersionId = createdCoreWorkflow.coreWorkflowVersionId;- await updateWorkflowVersionTrigger({- workflowVersionId,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -108,40 +89,14 @@ describe('Classify step activation (e2e)', () => {},});- await graphqlOrFail(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId,- stepType: 'CLASSIFY',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- );-- const stepsData = await graphqlOrFail(- `- query GetWorkflowVersion($id: UUID!) {- workflowVersion(filter: { id: { eq: $id } }) {- steps- }- }- `,- { id: workflowVersionId },- );+ classifyStep = await createCoreWorkflowVersionStep<ClassifyStep>({+ coreWorkflowVersionId,+ stepType: 'CLASSIFY',+ });+ });- classifyStep = stepsData.workflowVersion.steps.find(- (step: { type: string }) => step.type === 'CLASSIFY',- );+ afterAll(async () => {+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });});const stepWithQuestions = (@@ -183,8 +138,8 @@ describe('Classify step activation (e2e)', () => {]);});- it('should refuse to validate the step as it ships', async () => {- const response = await validateWorkflowVersion(workflowVersionId);+ it('should refuse to activate the step as it ships', async () => {+ const response = await activateVersion(coreWorkflowVersionId);expect(response.body.errors).toBeDefined();expect(response.body.errors[0].extensions.subCode).toBe(@@ -195,39 +150,27 @@ describe('Classify step activation (e2e)', () => {// The variable resolver reads a dot as structure, so the answer could never be referenced downstream.it('should refuse an answer name that is not a valid variable key', async () => {const response = await updateStep(- workflowVersionId,+ coreWorkflowVersionId,stepWithQuestions([completeQuestion({ name: 'customer.intent' })]),);expect(response.body.errors).toBeDefined();- expect(response.body.errors[0].extensions.subCode).toBe(- 'MALFORMED_WORKFLOW_VERSION',+ expect(response.body.errors[0].extensions.code).toBe('FORBIDDEN');+ expect(response.body.errors[0].message).toContain(+ 'Workflow version is malformed',);});it('should refuse two questions that would write the same answer', async () => {- await graphqlOrFail(- `- mutation UpdateWorkflowVersionStep(- $input: UpdateWorkflowVersionStepInput!- ) {- updateWorkflowVersionStep(input: $input) {- id- }- }- `,- {- input: {- workflowVersionId,- step: stepWithQuestions([- completeQuestion(),- completeQuestion({ id: SECOND_QUESTION_ID }),- ]),- },- },- );+ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ step: stepWithQuestions([+ completeQuestion(),+ completeQuestion({ id: SECOND_QUESTION_ID }),+ ]),+ });- const response = await validateWorkflowVersion(workflowVersionId);+ const response = await activateVersion(coreWorkflowVersionId);expect(response.body.errors).toBeDefined();expect(response.body.errors[0].extensions.subCode).toBe(@@ -236,28 +179,15 @@ describe('Classify step activation (e2e)', () => {expect(response.body.errors[0].message).toMatch(/intent/i);});- it('should validate a fully configured step', async () => {- await graphqlOrFail(- `- mutation UpdateWorkflowVersionStep(- $input: UpdateWorkflowVersionStepInput!- ) {- updateWorkflowVersionStep(input: $input) {- id- }- }- `,- {- input: {- workflowVersionId,- step: stepWithQuestions([completeQuestion()]),- },- },- );+ it('should activate a fully configured step', async () => {+ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ step: stepWithQuestions([completeQuestion()]),+ });- const response = await validateWorkflowVersion(workflowVersionId);+ const response = await activateVersion(coreWorkflowVersionId);expect(response.body.errors).toBeUndefined();- expect(response.body.data.validateWorkflowVersion).toBe(true);+ expect(response.body.data.activateCoreWorkflowVersion).toBe(true);});});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-discard-draft.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-discard-draft.integration-spec.tsindex 2cff2e10162..48141a73840 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-discard-draft.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-discard-draft.integration-spec.ts@@ -1,4 +1,11 @@-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';+import {+ activateCoreWorkflowVersion,+ coreWorkflowGraphqlRequest,+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import { workflowGraphqlRequest } from 'test/integration/graphql/suites/workflow/utils/workflow-graphql-request.util';import { isDefined } from 'twenty-shared/utils';@@ -18,48 +25,20 @@ const DISCARD_MUTATION = `describe('discardCoreWorkflowDraft (e2e)', () => {let coreWorkflowId: string;- let workspaceWorkflowId: string;- let initialWorkspaceVersionId: string;+ let draftCoreVersionId: string;let draftWorkspaceVersionId: string;beforeAll(async () => {- const createResponse = await workflowGraphqlRequest(`- mutation {- createCoreWorkflow(input: { name: "Discard Draft Target" }) {- id- workspaceWorkflowId- }- }- `);-- expect(createResponse.body.errors).toBeUndefined();-- coreWorkflowId = createResponse.body.data.createCoreWorkflow.id;- workspaceWorkflowId =- createResponse.body.data.createCoreWorkflow.workspaceWorkflowId;-- const versionsResponse = await workflowGraphqlRequest(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: workspaceWorkflowId },- );+ const createdCoreWorkflow = await createCoreWorkflow({+ name: 'Discard Draft Target',+ });- initialWorkspaceVersionId =- versionsResponse.body.data.workflow.versions.edges[0].node.id;+ coreWorkflowId = createdCoreWorkflow.coreWorkflowId;- await updateWorkflowVersionTrigger({- workflowVersionId: initialWorkspaceVersionId,+ const initialCoreVersionId = createdCoreWorkflow.coreWorkflowVersionId;++ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId: initialCoreVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -69,78 +48,53 @@ describe('discardCoreWorkflowDraft (e2e)', () => {},});- const stepResponse = await workflowGraphqlRequest(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId: initialWorkspaceVersionId,- stepType: 'FIND_RECORDS',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- );-- expect(stepResponse.body.errors).toBeUndefined();-- const activateResponse = await workflowGraphqlRequest(- `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- { workflowVersionId: initialWorkspaceVersionId },- );+ await createCoreWorkflowVersionStep({+ coreWorkflowVersionId: initialCoreVersionId,+ stepType: 'FIND_RECORDS',+ });- expect(activateResponse.body.errors).toBeUndefined();+ await activateCoreWorkflowVersion({+ coreWorkflowVersionId: initialCoreVersionId,+ });- const draftResponse = await workflowGraphqlRequest(- `- mutation CreateDraft($input: CreateDraftFromWorkflowVersionInput!) {- createDraftFromWorkflowVersion(input: $input) {- id+ const { createDraftFromCoreWorkflowVersion: draftVersion } =+ await coreWorkflowGraphqlRequest<{+ createDraftFromCoreWorkflowVersion: {+ id: string;+ workspaceWorkflowVersionId: string;+ };+ }>({+ query: `+ mutation CreateDraft(+ $input: CreateDraftFromCoreWorkflowVersionInput!+ ) {+ createDraftFromCoreWorkflowVersion(input: $input) {+ id+ workspaceWorkflowVersionId+ }}- }- `,- {- input: {- workflowId: workspaceWorkflowId,- workflowVersionIdToCopy: initialWorkspaceVersionId,+ `,+ variables: {+ input: {+ coreWorkflowId,+ coreWorkflowVersionIdToCopy: initialCoreVersionId,+ },},- },- );+ });- expect(draftResponse.body.errors).toBeUndefined();- draftWorkspaceVersionId =- draftResponse.body.data.createDraftFromWorkflowVersion.id;+ draftCoreVersionId = draftVersion.id;+ draftWorkspaceVersionId = draftVersion.workspaceWorkflowVersionId;});afterAll(async () => {- if (isDefined(workspaceWorkflowId)) {- await workflowGraphqlRequest(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workspaceWorkflowId },- );+ if (isDefined(coreWorkflowId)) {+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });}});it('soft-deletes the workspace draft, removes its core row and returns the refreshed workflow', async () => {const discardResponse = await workflowGraphqlRequest(DISCARD_MUTATION, {- input: { workspaceWorkflowVersionId: draftWorkspaceVersionId },+ input: { coreWorkflowVersionId: draftCoreVersionId },});expect(discardResponse.body.errors).toBeUndefined();@@ -159,11 +113,8 @@ describe('discardCoreWorkflowDraft (e2e)', () => {expect(workspaceRows[0]?.deletedAt).not.toBeNull();const coreVersionRows = await global.testDataSource.query(- `SELECT cv.id FROM core."workflowVersion" cv- JOIN "${WORKSPACE_SCHEMA}"."workflowVersion" wv- ON wv."coreWorkflowVersionId" = cv.id- WHERE cv."workspaceId" = $1 AND wv.id = $2`,- [SEED_APPLE_WORKSPACE_ID, draftWorkspaceVersionId],+ `SELECT id FROM core."workflowVersion" WHERE "workspaceId" = $1 AND id = $2`,+ [SEED_APPLE_WORKSPACE_ID, draftCoreVersionId],);expect(coreVersionRows).toHaveLength(0);@@ -171,7 +122,7 @@ describe('discardCoreWorkflowDraft (e2e)', () => {it('returns null when the draft is already discarded', async () => {const discardResponse = await workflowGraphqlRequest(DISCARD_MUTATION, {- input: { workspaceWorkflowVersionId: draftWorkspaceVersionId },+ input: { coreWorkflowVersionId: draftCoreVersionId },});expect(discardResponse.body.errors).toBeUndefined();@@ -179,56 +130,22 @@ describe('discardCoreWorkflowDraft (e2e)', () => {});it('refuses to discard the only remaining version', async () => {- const createResponse = await workflowGraphqlRequest(`- mutation {- createCoreWorkflow(input: { name: "Only Version Guard" }) {- workspaceWorkflowId- }- }- `);-- expect(createResponse.body.errors).toBeUndefined();-- const guardedWorkspaceWorkflowId =- createResponse.body.data.createCoreWorkflow.workspaceWorkflowId;-- const versionsResponse = await workflowGraphqlRequest(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: guardedWorkspaceWorkflowId },- );-- const onlyVersionId =- versionsResponse.body.data.workflow.versions.edges[0].node.id;+ const guardedCoreWorkflow = await createCoreWorkflow({+ name: 'Only Version Guard',+ });const discardResponse = await workflowGraphqlRequest(DISCARD_MUTATION, {- input: { workspaceWorkflowVersionId: onlyVersionId },+ input: {+ coreWorkflowVersionId: guardedCoreWorkflow.coreWorkflowVersionId,+ },});expect(discardResponse.body.errors?.[0]?.message).toContain('initial version',);- await workflowGraphqlRequest(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: guardedWorkspaceWorkflowId },- );+ await deleteCoreWorkflows({+ coreWorkflowIds: [guardedCoreWorkflow.coreWorkflowId],+ });});});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-id-mutations.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-id-mutations.integration-spec.tsindex ba2b6e33787..52180b1c3c7 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-id-mutations.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-id-mutations.integration-spec.ts@@ -614,25 +614,4 @@ describe('core workflow id mutations (e2e)', () => {expect(response.body.errors).toBeDefined();expect(response.body.errors[0].message).toContain('not found');});-- it('rejects a discard carrying both transitional ids', async () => {- const response = await workflowGraphqlRequest(- `- mutation DiscardCoreWorkflowDraft($input: DiscardCoreWorkflowDraftInput!) {- discardCoreWorkflowDraft(input: $input) {- id- }- }- `,- {- input: {- coreWorkflowVersionId: coreWorkflowVersionId,- workspaceWorkflowVersionId: coreWorkflowVersionId,- },- },- );-- expect(response.body.errors).toBeDefined();- expect(response.body.errors[0].message).toContain('Only one');- });});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-id-native-queries.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-id-native-queries.integration-spec.tsindex 9a041997f28..eb7653afaae 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-id-native-queries.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-id-native-queries.integration-spec.ts@@ -1,3 +1,4 @@+import { deleteCoreWorkflows } from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import { workflowGraphqlRequest } from 'test/integration/graphql/suites/workflow/utils/workflow-graphql-request.util';const CORE_WORKFLOW_VERSIONS_BY_CORE_WORKFLOW_ID = `@@ -59,16 +60,7 @@ describe('core workflow id native queries (e2e)', () => {});afterAll(async () => {- await workflowGraphqlRequest(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workspaceWorkflowId },- );+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });});it('lists the versions by core workflow id, mirror ids included', async () => {diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-mutations.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-mutations.integration-spec.tsindex a05011dd452..daf2c678e3f 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-mutations.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-mutations.integration-spec.ts@@ -1,4 +1,5 @@import request from 'supertest';+import { deleteCoreWorkflows } from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import { isDefined } from 'twenty-shared/utils';const TEST_SCHEMA_NAME = 'workspace_1wgvd1injqtife6y4rvfbu3h5';@@ -53,20 +54,11 @@ describe('coreWorkflow mutations (e2e)', () => {};afterAll(async () => {- if (!isDefined(workspaceWorkflowId)) {+ if (!isDefined(coreWorkflowId)) {return;}- await graphql(- `- mutation DestroyWorkflow($id: UUID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workspaceWorkflowId },- );+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });});it('should create a workflow listed synchronously with a draft version', async () => {@@ -217,16 +209,7 @@ describe('coreWorkflow mutations (e2e)', () => {await findListedCoreWorkflowById(createdCoreWorkflow.id),).toBeDefined();- await graphql(- `- mutation DestroyWorkflow($id: UUID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: createdCoreWorkflow.workspaceWorkflowId },- );+ await deleteCoreWorkflows({ coreWorkflowIds: [createdCoreWorkflow.id] });});it('should finish the cleanup on a retry after the core row is gone', async () => {@@ -286,17 +269,6 @@ describe('coreWorkflow mutations (e2e)', () => {expect(workflowVersionRows).toHaveLength(1);expect(workflowVersionRows[0].deletedAt).not.toBeNull();-- await graphql(- `- mutation DestroyWorkflow($id: UUID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: retryWorkspaceWorkflowId },- );});it('should delete nothing for unknown core workflow ids', async () => {diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-read.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-read.integration-spec.tsindex aad8ebcc570..2fac1bea414 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-read.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-read.integration-spec.ts@@ -1,5 +1,9 @@import { isDefined } from 'twenty-shared/utils';+import {+ createCoreWorkflow,+ deleteCoreWorkflows,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import { pollWorkflowGraphqlRequest } from 'test/integration/graphql/suites/workflow/utils/poll-workflow-graphql-request.util';import { workflowGraphqlRequest } from 'test/integration/graphql/suites/workflow/utils/workflow-graphql-request.util';@@ -78,37 +82,24 @@ type CoreWorkflowVersionResult = {};describe('coreWorkflow (e2e)', () => {- let workspaceWorkflowId: string;+ let coreWorkflowId: string;+ let workspaceWorkflowId: string | null;beforeAll(async () => {- const createResponse = await workflowGraphqlRequest(`- mutation {- createWorkflow(data: { name: "Core Workflow Read" }) {- id- }- }- `);-- expect(createResponse.body.errors).toBeUndefined();+ const createdCoreWorkflow = await createCoreWorkflow({+ name: 'Core Workflow Read',+ });- workspaceWorkflowId = createResponse.body.data.createWorkflow.id;+ coreWorkflowId = createdCoreWorkflow.coreWorkflowId;+ workspaceWorkflowId = createdCoreWorkflow.workspaceWorkflowId;});afterAll(async () => {- if (!isDefined(workspaceWorkflowId)) {+ if (!isDefined(coreWorkflowId)) {return;}- await workflowGraphqlRequest(- `- mutation DestroyWorkflow($id: UUID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workspaceWorkflowId },- );+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });});it('should read one workflow by its workspace id', async () => {diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-visibility.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-visibility.integration-spec.tsindex fe891d70e22..50ab3a178c0 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-visibility.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-visibility.integration-spec.ts@@ -14,8 +14,15 @@ import { upsertPermissionFlags } from 'test/integration/metadata/suites/role-perimport { createCommandMenuItem } from 'test/integration/metadata/suites/command-menu-item/utils/create-command-menu-item.util';import { deleteCommandMenuItem } from 'test/integration/metadata/suites/command-menu-item/utils/delete-command-menu-item.util';import { findCommandMenuItems } from 'test/integration/metadata/suites/command-menu-item/utils/find-command-menu-items.util';-import { pollWorkflowGraphqlRequest } from 'test/integration/graphql/suites/workflow/utils/poll-workflow-graphql-request.util';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';+import {+ activateCoreWorkflowVersion,+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ findCoreWorkflowVersion,+ runCoreWorkflowVersion,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import { workflowGraphqlRequest } from 'test/integration/graphql/suites/workflow/utils/workflow-graphql-request.util';import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';@@ -53,9 +60,6 @@ const metadataRequestAs = (const asOtherMember = (query: string, variables?: object) =>graphqlRequestAs(APPLE_JONY_MEMBER_ACCESS_TOKEN, query, variables);-const asApiKey = (query: string, variables?: object) =>- graphqlRequestAs(API_KEY_ACCESS_TOKEN, query, variables);-const CORE_WORKFLOW_BY_ID_QUERY = `query CoreWorkflowById($coreWorkflowId: UUID!) {coreWorkflowById(coreWorkflowId: $coreWorkflowId) {@@ -114,29 +118,14 @@ const UPDATE_VISIBILITY_MUTATION = `}`;-const LEGACY_RUN_MUTATION = `- mutation RunWorkflowVersion($input: RunWorkflowVersionInput!) {- runWorkflowVersion(input: $input) {+const RUN_MUTATION = `+ mutation RunCoreWorkflowVersion($input: RunCoreWorkflowVersionInput!) {+ runCoreWorkflowVersion(input: $input) {workflowRunId}}`;-const CREATE_CORE_WORKFLOW_MUTATION = `- mutation CreateCoreWorkflow($input: CreateCoreWorkflowInput!) {- createCoreWorkflow(input: $input) {- id- workspaceWorkflowId- }- }-`;--const ACTIVATE_VERSION_MUTATION = `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)- }-`;-const setVisibility = (coreWorkflowId: string,visibility: WorkflowVisibility,@@ -157,49 +146,28 @@ const listCoreWorkflowIds = async ();};-const DESTROY_WORKFLOW_MUTATION = `- mutation DestroyWorkflow($id: UUID!) {- destroyWorkflow(id: $id) {- id- }- }-`;--const createActiveManualWorkflow = async (name: string) => {- const createResponse = await workflowGraphqlRequest(- CREATE_CORE_WORKFLOW_MUTATION,- { input: { name } },- );-- expect(createResponse.body.errors).toBeUndefined();+const createWorkflowWithMirrorIds = async (name: string) => {+ const { coreWorkflowId, coreWorkflowVersionId, workspaceWorkflowId } =+ await createCoreWorkflow({ name });- const coreWorkflowId: string = createResponse.body.data.createCoreWorkflow.id;- const workspaceWorkflowId: string =- createResponse.body.data.createCoreWorkflow.workspaceWorkflowId;-- const versions = await pollWorkflowGraphqlRequest<- {- coreWorkflowVersions: { workspaceWorkflowVersionId: string | null }[];- },- { workspaceWorkflowVersionId: string | null }[] | undefined- >({- query: `- query CoreWorkflowVersions($workspaceWorkflowId: UUID!) {- coreWorkflowVersions(workspaceWorkflowId: $workspaceWorkflowId) {- workspaceWorkflowVersionId- }- }- `,- variables: { workspaceWorkflowId },- extract: (data) => data?.coreWorkflowVersions,- until: (coreWorkflowVersions) =>- isDefined(coreWorkflowVersions?.[0]?.workspaceWorkflowVersionId),+ const { workspaceWorkflowVersionId } = await findCoreWorkflowVersion({+ coreWorkflowVersionId,});- const workspaceWorkflowVersionId = versions![0].workspaceWorkflowVersionId!;+ return {+ coreWorkflowId,+ coreWorkflowVersionId,+ workspaceWorkflowId: workspaceWorkflowId!,+ workspaceWorkflowVersionId: workspaceWorkflowVersionId!,+ };+};++const createActiveManualWorkflow = async (name: string) => {+ const createdWorkflow = await createWorkflowWithMirrorIds(name);+ const { coreWorkflowVersionId } = createdWorkflow;- await updateWorkflowVersionTrigger({- workflowVersionId: workspaceWorkflowVersionId,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -209,36 +177,14 @@ const createActiveManualWorkflow = async (name: string) => {},});- const stepResponse = await workflowGraphqlRequest(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId: workspaceWorkflowVersionId,- stepType: 'FIND_RECORDS',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- );-- expect(stepResponse.body.errors).toBeUndefined();-- const activateResponse = await workflowGraphqlRequest(- ACTIVATE_VERSION_MUTATION,- { workflowVersionId: workspaceWorkflowVersionId },- );+ await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'FIND_RECORDS',+ });- expect(activateResponse.body.errors).toBeUndefined();+ await activateCoreWorkflowVersion({ coreWorkflowVersionId });- return { coreWorkflowId, workspaceWorkflowId, workspaceWorkflowVersionId };+ return createdWorkflow;};// The record API the run pages read, not the core workflow API #26243 already gates.@@ -272,6 +218,7 @@ const findRecordIds = async (describe('core workflow visibility (e2e)', () => {let workspaceWorkflowId: string;let coreWorkflowId: string;+ let coreWorkflowVersionId: string;let workspaceWorkflowVersionId: string;let originalMemberRoleId: string;let workflowsRoleId: string;@@ -319,51 +266,18 @@ describe('core workflow visibility (e2e)', () => {},});- const createResponse = await workflowGraphqlRequest(- CREATE_CORE_WORKFLOW_MUTATION,- { input: { name: 'Private Workflow Access' } },- );-- expect(createResponse.body.errors).toBeUndefined();- coreWorkflowId = createResponse.body.data.createCoreWorkflow.id;- workspaceWorkflowId =- createResponse.body.data.createCoreWorkflow.workspaceWorkflowId;-- const versions = await pollWorkflowGraphqlRequest<- {- coreWorkflowVersions: { workspaceWorkflowVersionId: string | null }[];- },- { workspaceWorkflowVersionId: string | null }[] | undefined- >({- query: `- query CoreWorkflowVersions($workspaceWorkflowId: UUID!) {- coreWorkflowVersions(workspaceWorkflowId: $workspaceWorkflowId) {- workspaceWorkflowVersionId- }- }- `,- variables: { workspaceWorkflowId },- extract: (data) => data?.coreWorkflowVersions,- until: (coreWorkflowVersions) =>- isDefined(coreWorkflowVersions?.[0]?.workspaceWorkflowVersionId),- });-- workspaceWorkflowVersionId = versions![0].workspaceWorkflowVersionId!;+ ({+ coreWorkflowId,+ coreWorkflowVersionId,+ workspaceWorkflowId,+ workspaceWorkflowVersionId,+ } = await createWorkflowWithMirrorIds('Private Workflow Access'));});afterAll(async () => {- if (isDefined(workspaceWorkflowId)) {+ if (isDefined(coreWorkflowId)) {await setVisibility(coreWorkflowId, WorkflowVisibility.WORKSPACE);- await workflowGraphqlRequest(- `- mutation DestroyWorkflow($id: UUID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workspaceWorkflowId },- );+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });}if (isDefined(workflowsRoleId)) {@@ -408,51 +322,25 @@ describe('core workflow visibility (e2e)', () => {// Pre-visibility workflows and those whose creator left (owner FK is ON DELETE SET NULL) have no owner,// and without a claim nobody could reach them while they still run.describe('an ownerless workflow', () => {- let ownerlessWorkspaceWorkflowId: string;let ownerlessCoreWorkflowId: string;beforeAll(async () => {- const createResponse = await workflowGraphqlRequest(`- mutation {- createWorkflow(data: { name: "Ownerless Workflow" }) {- id- }- }- `);-- expect(createResponse.body.errors).toBeUndefined();- ownerlessWorkspaceWorkflowId = createResponse.body.data.createWorkflow.id;-- const coreWorkflow = await pollWorkflowGraphqlRequest<- { coreWorkflow: { id: string } | null },- { id: string } | null | undefined- >({- query: `- query CoreWorkflow($workspaceWorkflowId: UUID!) {- coreWorkflow(workspaceWorkflowId: $workspaceWorkflowId) {- id- }- }- `,- variables: { workspaceWorkflowId: ownerlessWorkspaceWorkflowId },- extract: (data) => data?.coreWorkflow,- until: isDefined,- });+ ({ coreWorkflowId: ownerlessCoreWorkflowId } = await createCoreWorkflow({+ name: 'Ownerless Workflow',+ }));- ownerlessCoreWorkflowId = coreWorkflow!.id;+ await global.testDataSource.query(+ `UPDATE core."workflow" SET "createdByUserWorkspaceId" = NULL WHERE id = $1`,+ [ownerlessCoreWorkflowId],+ );});afterAll(async () => {- await workflowGraphqlRequest(- `- mutation DestroyWorkflow($id: UUID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: ownerlessWorkspaceWorkflowId },- );+ if (isDefined(ownerlessCoreWorkflowId)) {+ await deleteCoreWorkflows({+ coreWorkflowIds: [ownerlessCoreWorkflowId],+ });+ }});it('is claimable by any member who can already edit it', async () => {@@ -620,7 +508,7 @@ describe('core workflow visibility (e2e)', () => {{input: {step: { type: 'MANUAL', settings: { outputSchema: {} } },- workflowVersionId: workspaceWorkflowVersionId,+ coreWorkflowVersionId,},},);@@ -629,24 +517,13 @@ describe('core workflow visibility (e2e)', () => {expect(response.body.data?.computeStepOutputSchema ?? null).toBeNull();});- // The legacy resolver uses the mirror's ids and never goes through CoreWorkflowIdResolutionService.- it('refuses to run it from the legacy API for another member', async () => {- const response = await asOtherMember(LEGACY_RUN_MUTATION, {- input: { workflowVersionId: workspaceWorkflowVersionId },+ it('refuses to run it for another member', async () => {+ const response = await asOtherMember(RUN_MUTATION, {+ input: { coreWorkflowVersionId },});expect(response.body.errors).toBeDefined();- expect(response.body.data?.runWorkflowVersion ?? null).toBeNull();- });-- // Unlike the core workflow API, WorkflowTriggerResolver's AuthPrincipalGuard accepts API keys.- it('refuses to activate it for an API key', async () => {- const response = await asApiKey(ACTIVATE_VERSION_MUTATION, {- workflowVersionId: workspaceWorkflowVersionId,- });-- expect(response.body.errors).toBeDefined();- expect(response.body.data?.activateWorkflowVersion ?? null).toBeNull();+ expect(response.body.data?.runCoreWorkflowVersion ?? null).toBeNull();});it('refuses to let another member publish it back to the workspace', async () => {@@ -672,7 +549,6 @@ describe('core workflow visibility (e2e)', () => {// Activating a manual trigger writes a workspace-wide command menu item carrying the workflow name.describe('a workflow with an active manual trigger', () => {- let manualWorkspaceWorkflowId: string;let manualCoreWorkflowId: string;let manualWorkspaceWorkflowVersionId: string;@@ -695,24 +571,14 @@ describe('core workflow visibility (e2e)', () => {beforeAll(async () => {({coreWorkflowId: manualCoreWorkflowId,- workspaceWorkflowId: manualWorkspaceWorkflowId,workspaceWorkflowVersionId: manualWorkspaceWorkflowVersionId,} = await createActiveManualWorkflow('Manual Trigger Workflow'));});afterAll(async () => {- if (isDefined(manualWorkspaceWorkflowId)) {+ if (isDefined(manualCoreWorkflowId)) {await setVisibility(manualCoreWorkflowId, WorkflowVisibility.WORKSPACE);- await workflowGraphqlRequest(- `- mutation DestroyWorkflow($id: UUID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: manualWorkspaceWorkflowId },- );+ await deleteCoreWorkflows({ coreWorkflowIds: [manualCoreWorkflowId] });}});@@ -777,36 +643,27 @@ describe('core workflow visibility (e2e)', () => {describe('the runs of a workflow', () => {let runsCoreWorkflowId: string;- let runsWorkspaceWorkflowId: string;- let runsWorkspaceWorkflowVersionId: string;+ let runsCoreWorkflowVersionId: string;let workflowRunId: string;- const runWorkflow = async () => {- const runResponse = await workflowGraphqlRequest(LEGACY_RUN_MUTATION, {- input: { workflowVersionId: runsWorkspaceWorkflowVersionId },+ const runWorkflow = () =>+ runCoreWorkflowVersion({+ coreWorkflowVersionId: runsCoreWorkflowVersionId,});- expect(runResponse.body.errors).toBeUndefined();-- return runResponse.body.data.runWorkflowVersion.workflowRunId as string;- };-beforeAll(async () => {({coreWorkflowId: runsCoreWorkflowId,- workspaceWorkflowId: runsWorkspaceWorkflowId,- workspaceWorkflowVersionId: runsWorkspaceWorkflowVersionId,+ coreWorkflowVersionId: runsCoreWorkflowVersionId,} = await createActiveManualWorkflow('Workflow With Runs'));workflowRunId = await runWorkflow();});afterAll(async () => {- if (isDefined(runsWorkspaceWorkflowId)) {+ if (isDefined(runsCoreWorkflowId)) {await setVisibility(runsCoreWorkflowId, WorkflowVisibility.WORKSPACE);- await workflowGraphqlRequest(DESTROY_WORKFLOW_MUTATION, {- id: runsWorkspaceWorkflowId,- });+ await deleteCoreWorkflows({ coreWorkflowIds: [runsCoreWorkflowId] });}});@@ -869,7 +726,6 @@ describe('core workflow visibility (e2e)', () => {// An agent step's conversation belongs to its recipient, or else the workflow's creator, whatever the workflow's visibility.describe('the conversation an agent step records on a run', () => {let conversationCoreWorkflowId: string;- let conversationWorkspaceWorkflowId: string;let workflowRunId: string;let threadId: string;@@ -891,21 +747,17 @@ describe('core workflow visibility (e2e)', () => {);beforeAll(async () => {- let workspaceWorkflowVersionId: string;+ let conversationCoreWorkflowVersionId: string;({coreWorkflowId: conversationCoreWorkflowId,- workspaceWorkflowId: conversationWorkspaceWorkflowId,- workspaceWorkflowVersionId,+ coreWorkflowVersionId: conversationCoreWorkflowVersionId,} = await createActiveManualWorkflow('Workflow With A Conversation'));- const runResponse = await workflowGraphqlRequest(LEGACY_RUN_MUTATION, {- input: { workflowVersionId: workspaceWorkflowVersionId },+ workflowRunId = await runCoreWorkflowVersion({+ coreWorkflowVersionId: conversationCoreWorkflowVersionId,});- expect(runResponse.body.errors).toBeUndefined();- workflowRunId = runResponse.body.data.runWorkflowVersion.workflowRunId;-const conversationService =getAppProviderByClassName<WorkflowAgentConversationWorkspaceService>('WorkflowAgentConversationWorkspaceService',@@ -953,13 +805,13 @@ describe('core workflow visibility (e2e)', () => {});afterAll(async () => {- if (isDefined(conversationWorkspaceWorkflowId)) {+ if (isDefined(conversationCoreWorkflowId)) {await setVisibility(conversationCoreWorkflowId,WorkflowVisibility.WORKSPACE,);- await workflowGraphqlRequest(DESTROY_WORKFLOW_MUTATION, {- id: conversationWorkspaceWorkflowId,+ await deleteCoreWorkflows({+ coreWorkflowIds: [conversationCoreWorkflowId],});}});@@ -1001,17 +853,15 @@ describe('core workflow visibility (e2e)', () => {describe('the runs of a private workflow whose creator is removed from the workspace', () => {const removedUserId = randomUUID();const removedUserWorkspaceId = randomUUID();- let orphanedWorkflowId: string;let orphanedCoreWorkflowId: string;let orphanedRunId: string;beforeAll(async () => {- let orphanedWorkflowVersionId: string;+ let orphanedCoreWorkflowVersionId: string;({coreWorkflowId: orphanedCoreWorkflowId,- workspaceWorkflowId: orphanedWorkflowId,- workspaceWorkflowVersionId: orphanedWorkflowVersionId,+ coreWorkflowVersionId: orphanedCoreWorkflowVersionId,} = await createActiveManualWorkflow('Workflow Of A Removed Member'));expect(@@ -1023,13 +873,10 @@ describe('core workflow visibility (e2e)', () => {).body.errors,).toBeUndefined();- const runResponse = await workflowGraphqlRequest(LEGACY_RUN_MUTATION, {- input: { workflowVersionId: orphanedWorkflowVersionId },+ orphanedRunId = await runCoreWorkflowVersion({+ coreWorkflowVersionId: orphanedCoreWorkflowVersionId,});- expect(runResponse.body.errors).toBeUndefined();- orphanedRunId = runResponse.body.data.runWorkflowVersion.workflowRunId;-await global.testDataSource.query(`INSERT INTO core."user" (id, email) VALUES ($1, $2)`,[removedUserId, `removed-${removedUserId}@apple.dev`],@@ -1045,11 +892,6 @@ describe('core workflow visibility (e2e)', () => {});afterAll(async () => {- if (isDefined(orphanedWorkflowId)) {- await workflowGraphqlRequest(DESTROY_WORKFLOW_MUTATION, {- id: orphanedWorkflowId,- });- }await global.testDataSource.query(`DELETE FROM core."userWorkspace" WHERE id = $1`,[removedUserWorkspaceId],@@ -1058,6 +900,12 @@ describe('core workflow visibility (e2e)', () => {`DELETE FROM core."user" WHERE id = $1`,[removedUserId],);++ if (isDefined(orphanedCoreWorkflowId)) {+ await deleteCoreWorkflows({+ coreWorkflowIds: [orphanedCoreWorkflowId],+ });+ }});it('become readable to the workspace, as core now shows the workflow', async () => {diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflows.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflows.integration-spec.tsindex e9b51e4d8b1..e4cf80e4c9c 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflows.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflows.integration-spec.ts@@ -1,5 +1,12 @@import request from 'supertest';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';+import {+ activateCoreWorkflowVersion,+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deactivateCoreWorkflowVersion,+ deleteCoreWorkflows,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import { isDefined } from 'twenty-shared/utils';const POLL_ATTEMPTS = 20;@@ -65,10 +72,9 @@ type CoreWorkflowFilter = {};describe('coreWorkflows (e2e)', () => {- let workflowId: string;- let firstVersionId: string;+ let coreWorkflowId: string;+ let firstCoreWorkflowVersionId: string;let alreadyDestroyed = false;- let softDeletedWorkflowId: string | undefined;const listCoreWorkflows = async (filter?: CoreWorkflowFilter,@@ -95,14 +101,9 @@ describe('coreWorkflows (e2e)', () => {filter?: CoreWorkflowFilter,): Promise<CoreWorkflow | undefined> =>(await listCoreWorkflows(filter)).find(- (workflow) => workflow.workspaceWorkflowId === workflowId,+ (workflow) => workflow.id === coreWorkflowId,);- const findCoreWorkflowByName = async (- name: string,- ): Promise<CoreWorkflow | undefined> =>- (await listCoreWorkflows()).find((workflow) => workflow.name === name);-const waitForCoreWorkflow = async (predicate: (workflow: CoreWorkflow | undefined) => boolean,): Promise<CoreWorkflow | undefined> => {@@ -120,65 +121,16 @@ describe('coreWorkflows (e2e)', () => {};beforeAll(async () => {- const createResponse = await graphql(`- mutation {- createWorkflow(data: { name: "Core Workflows List" }) {- id- }- }- `);-- expect(createResponse.body.errors).toBeUndefined();- workflowId = createResponse.body.data.createWorkflow.id;-- const getResponse = await graphql(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: workflowId },- );-- firstVersionId = getResponse.body.data.workflow.versions.edges[0].node.id;+ ({ coreWorkflowId, coreWorkflowVersionId: firstCoreWorkflowVersionId } =+ await createCoreWorkflow({ name: 'Core Workflows List' }));});afterAll(async () => {- if (isDefined(softDeletedWorkflowId)) {- await graphql(- `- mutation DestroyWorkflow($id: UUID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: softDeletedWorkflowId },- );- }-- if (alreadyDestroyed) {+ if (alreadyDestroyed || !isDefined(coreWorkflowId)) {return;}- await graphql(- `- mutation DestroyWorkflow($id: UUID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workflowId },- );+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });});it('should list the workflow as DRAFT right after creation', async () => {@@ -346,7 +298,7 @@ describe('coreWorkflows (e2e)', () => {],});- expect(updatedAfter?.workspaceWorkflowId).toBe(workflowId);+ expect(updatedAfter?.id).toBe(coreWorkflowId);const updatedBefore = await findCoreWorkflow({logicalOperator: 'AND',@@ -372,7 +324,7 @@ describe('coreWorkflows (e2e)', () => {],});- expect(updatedOnTheSameDay?.workspaceWorkflowId).toBe(workflowId);+ expect(updatedOnTheSameDay?.id).toBe(coreWorkflowId);});it('should reject an operand the field does not support', async () => {@@ -390,8 +342,8 @@ describe('coreWorkflows (e2e)', () => {});it('should list the workflow as ACTIVE once its version is activated', async () => {- await updateWorkflowVersionTrigger({- workflowVersionId: firstVersionId,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId: firstCoreWorkflowVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -401,38 +353,14 @@ describe('coreWorkflows (e2e)', () => {},});- const stepResponse = await graphql(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId: firstVersionId,- stepType: 'FIND_RECORDS',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- );-- expect(stepResponse.body.errors).toBeUndefined();-- const activateResponse = await graphql(- `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- { workflowVersionId: firstVersionId },- );+ await createCoreWorkflowVersionStep({+ coreWorkflowVersionId: firstCoreWorkflowVersionId,+ stepType: 'FIND_RECORDS',+ });- expect(activateResponse.body.errors).toBeUndefined();+ await activateCoreWorkflowVersion({+ coreWorkflowVersionId: firstCoreWorkflowVersionId,+ });const coreWorkflow = await waitForCoreWorkflow((workflow) => workflow?.statuses[0] === 'ACTIVE',@@ -442,16 +370,9 @@ describe('coreWorkflows (e2e)', () => {});it('should list the workflow as DEACTIVATED once its version is deactivated', async () => {- const deactivateResponse = await graphql(- `- mutation DeactivateWorkflowVersion($workflowVersionId: UUID!) {- deactivateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- { workflowVersionId: firstVersionId },- );-- expect(deactivateResponse.body.errors).toBeUndefined();+ await deactivateCoreWorkflowVersion({+ coreWorkflowVersionId: firstCoreWorkflowVersionId,+ });const coreWorkflow = await waitForCoreWorkflow((workflow) => workflow?.statuses[0] === 'DEACTIVATED',@@ -518,168 +439,8 @@ describe('coreWorkflows (e2e)', () => {expect(secondPage.edges[0].node.id).not.toBe(firstPage.edges[0].node.id);});- it('should not list a workflow once it is soft-deleted', async () => {- const softDeletedName = 'Core Workflows Soft Deleted';-- const createResponse = await graphql(- `- mutation CreateWorkflow($name: String!) {- createWorkflow(data: { name: $name }) {- id- }- }- `,- { name: softDeletedName },- );-- expect(createResponse.body.errors).toBeUndefined();-- softDeletedWorkflowId = createResponse.body.data.createWorkflow.id;-- const versionResponse = await graphql(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: softDeletedWorkflowId },- );-- const softDeletedVersionId =- versionResponse.body.data.workflow.versions.edges[0].node.id;-- await updateWorkflowVersionTrigger({- workflowVersionId: softDeletedVersionId,- trigger: {- name: 'Manual Trigger',- type: 'MANUAL',- settings: { outputSchema: {} },- nextStepIds: [],- position: { x: 0, y: 0 },- },- });-- await graphql(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId: softDeletedVersionId,- stepType: 'FIND_RECORDS',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- );-- const activateResponse = await graphql(- `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- { workflowVersionId: softDeletedVersionId },- );-- expect(activateResponse.body.errors).toBeUndefined();-- let activated: CoreWorkflow | undefined;-- for (let attempt = 0; attempt < POLL_ATTEMPTS; attempt++) {- activated = await findCoreWorkflowByName(softDeletedName);-- if (activated?.statuses.includes('ACTIVE')) {- break;- }-- await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));- }-- expect(activated?.statuses).toEqual(['ACTIVE']);-- const deleteResponse = await graphql(- `- mutation DeleteWorkflow($id: UUID!) {- deleteWorkflow(id: $id) {- id- }- }- `,- { id: softDeletedWorkflowId },- );-- expect(deleteResponse.body.errors).toBeUndefined();-- let deletedWorkflowStatuses: string[] | undefined;-- for (let attempt = 0; attempt < POLL_ATTEMPTS; attempt++) {- const deletedWorkflowResponse = await graphql(- `- query DeletedWorkflow($id: UUID!) {- workflow(- filter: { id: { eq: $id }, not: { deletedAt: { is: "NULL" } } }- ) {- id- statuses- }- }- `,- { id: softDeletedWorkflowId },- );-- deletedWorkflowStatuses =- deletedWorkflowResponse.body.data?.workflow?.statuses;-- if (deletedWorkflowStatuses?.includes('DEACTIVATED')) {- break;- }-- await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));- }-- expect(deletedWorkflowStatuses).toEqual(['DEACTIVATED']);-- for (let attempt = 0; attempt < POLL_ATTEMPTS; attempt++) {- if (!isDefined(await findCoreWorkflowByName(softDeletedName))) {- break;- }-- await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));- }-- for (let attempt = 0; attempt < POLL_ATTEMPTS; attempt++) {- expect(await findCoreWorkflowByName(softDeletedName)).toBeUndefined();-- await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));- }- });-it('should not list the workflow once it is destroyed', async () => {- await graphql(- `- mutation DestroyWorkflow($id: UUID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workflowId },- );+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });alreadyDestroyed = true;diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/duplicate-workflow.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/duplicate-workflow.integration-spec.tsindex 47edfd474ac..5a08f21287a 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/duplicate-workflow.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/duplicate-workflow.integration-spec.ts@@ -1,55 +1,42 @@import request from 'supertest';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';-+import {+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ findCoreWorkflowVersion,+ findCoreWorkflowVersions,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';+import { isDefined } from 'twenty-shared/utils';++import { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/get-workspace-schema-name.util';import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';const client = request(`http://localhost:${APP_PORT}`);+const WORKSPACE_SCHEMA = getWorkspaceSchemaName(SEED_APPLE_WORKSPACE_ID);+const graphql = (query: string, variables?: object) =>client.post('/graphql').set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`).send({ query, variables });-describe('duplicateWorkflow (e2e)', () => {- let sourceWorkflowId: string;- let sourceVersionId: string;- let duplicatedWorkflowId: string | undefined;+describe('duplicateCoreWorkflow (e2e)', () => {+ let sourceCoreWorkflowId: string;+ let sourceCoreVersionId: string;+ let duplicatedCoreWorkflowId: string | undefined;beforeAll(async () => {- const createResponse = await graphql(`- mutation {- createWorkflow(data: { name: "Duplicate Source" }) {- id- }- }- `);-- expect(createResponse.body.errors).toBeUndefined();- sourceWorkflowId = createResponse.body.data.createWorkflow.id;-- const getResponse = await graphql(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- id- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: sourceWorkflowId },- );+ const createdCoreWorkflow = await createCoreWorkflow({+ name: 'Duplicate Source',+ });- sourceVersionId = getResponse.body.data.workflow.versions.edges[0].node.id;+ sourceCoreWorkflowId = createdCoreWorkflow.coreWorkflowId;+ sourceCoreVersionId = createdCoreWorkflow.coreWorkflowVersionId;- await updateWorkflowVersionTrigger({- workflowVersionId: sourceVersionId,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId: sourceCoreVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -59,91 +46,76 @@ describe('duplicateWorkflow (e2e)', () => {},});- const stepResponse = await graphql(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId: sourceVersionId,- stepType: 'FIND_RECORDS',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- );-- expect(stepResponse.body.errors).toBeUndefined();+ await createCoreWorkflowVersionStep({+ coreWorkflowVersionId: sourceCoreVersionId,+ stepType: 'FIND_RECORDS',+ });});afterAll(async () => {- for (const id of [duplicatedWorkflowId, sourceWorkflowId]) {- if (id) {- await graphql(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id },- );- }+ const coreWorkflowIds = [+ duplicatedCoreWorkflowId,+ sourceCoreWorkflowId,+ ].filter(isDefined);++ if (coreWorkflowIds.length > 0) {+ await deleteCoreWorkflows({ coreWorkflowIds });}});- it('duplicates the workflow and mirrors the new draft version to core', async () => {+ it('duplicates the workflow and mirrors the new draft version to the workspace', async () => {const response = await graphql(`- mutation DuplicateWorkflow($input: DuplicateWorkflowInput!) {- duplicateWorkflow(input: $input) {+ mutation DuplicateCoreWorkflow($input: DuplicateCoreWorkflowInput!) {+ duplicateCoreWorkflow(input: $input) {id- workflowId- status- trigger- steps+ workspaceWorkflowId}}`,{input: {- workflowIdToDuplicate: sourceWorkflowId,- workflowVersionIdToCopy: sourceVersionId,+ coreWorkflowIdToDuplicate: sourceCoreWorkflowId,+ coreWorkflowVersionIdToCopy: sourceCoreVersionId,},},);expect(response.body.errors).toBeUndefined();- const duplicated = response.body.data.duplicateWorkflow;+ const duplicated = response.body.data.duplicateCoreWorkflow;++ duplicatedCoreWorkflowId = duplicated?.id;- duplicatedWorkflowId = duplicated?.workflowId;+ expect(duplicated.id).not.toBe(sourceCoreWorkflowId);++ const duplicatedVersions = await findCoreWorkflowVersions({+ coreWorkflowId: duplicated.id,+ });++ expect(duplicatedVersions).toHaveLength(1);++ const duplicatedVersion = await findCoreWorkflowVersion({+ coreWorkflowVersionId: duplicatedVersions[0].id,+ });- expect(duplicated.id).not.toBe(sourceVersionId);- expect(duplicated.workflowId).not.toBe(sourceWorkflowId);- expect(duplicated.status).toBe('DRAFT');- expect(duplicated.trigger?.type).toBe('MANUAL');- expect(Array.isArray(duplicated.steps)).toBe(true);- expect(duplicated.steps.length).toBeGreaterThan(0);+ expect(duplicatedVersion.id).not.toBe(sourceCoreVersionId);+ expect(duplicatedVersion.status).toBe('DRAFT');+ expect(duplicatedVersion.trigger?.type).toBe('MANUAL');+ expect(Array.isArray(duplicatedVersion.steps)).toBe(true);+ expect(duplicatedVersion.steps?.length).toBeGreaterThan(0);- const coreRows = await global.testDataSource.query(- `SELECT "id", "steps", "triggers", "status" FROM core."workflowVersion"- WHERE "workspaceId" = $1 AND "workflowId" = $2`,- [SEED_APPLE_WORKSPACE_ID, duplicated.workflowId],+ const mirrorRows = await global.testDataSource.query(+ `SELECT "id", "steps", "trigger", "status" FROM "${WORKSPACE_SCHEMA}"."workflowVersion"+ WHERE "workflowId" = $1 AND "deletedAt" IS NULL`,+ [duplicated.workspaceWorkflowId],);- expect(coreRows).toHaveLength(1);- expect(coreRows[0].status).toBe('DRAFT');- expect(Array.isArray(coreRows[0].steps)).toBe(true);- expect(coreRows[0].steps.length).toBe(duplicated.steps.length);- expect(Array.isArray(coreRows[0].triggers)).toBe(true);- expect(coreRows[0].triggers[0].type).toBe('MANUAL');+ expect(mirrorRows).toHaveLength(1);+ expect(mirrorRows[0].id).toBe(duplicatedVersion.workspaceWorkflowVersionId);+ expect(mirrorRows[0].status).toBe('DRAFT');+ expect(Array.isArray(mirrorRows[0].steps)).toBe(true);+ expect(mirrorRows[0].steps.length).toBe(duplicatedVersion.steps?.length);+ expect(mirrorRows[0].trigger.type).toBe('MANUAL');});});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/find-records-relation-traversal-workflow.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/find-records-relation-traversal-workflow.integration-spec.tsindex 90318f14d71..4ca0c27be64 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/find-records-relation-traversal-workflow.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/find-records-relation-traversal-workflow.integration-spec.ts@@ -1,20 +1,24 @@import gql from 'graphql-tag';-import request from 'supertest';import { createManyOperationFactory } from 'test/integration/graphql/utils/create-many-operation-factory.util';import { deleteManyOperationFactory } from 'test/integration/graphql/utils/delete-many-operation-factory.util';import { makeGraphqlApiRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';+import {+ activateCoreWorkflowVersion,+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ runCoreWorkflowVersion,+ updateCoreWorkflowVersionStep,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import {destroyWorkflowRun,- runWorkflowVersion,waitForWorkflowCompletion,} from 'test/integration/graphql/suites/workflow/utils/workflow-run-test.util';import { makeMetadataApiRequest } from 'test/integration/metadata/suites/utils/make-metadata-api-request.util';import { isDefined } from 'twenty-shared/utils';import { v4 as uuidv4 } from 'uuid';-const client = request(`http://localhost:${APP_PORT}`);-const TEST_COMPANY_AIRBNB_ID = '20202020-eeee-4000-8000-000000000001';const TEST_COMPANY_STRIPE_ID = '20202020-eeee-4000-8000-000000000002';const TEST_PERSON_AIRBNB_1_ID = '20202020-ffff-4000-8000-000000000001';@@ -28,8 +32,8 @@ const ALL_TEST_PERSON_IDS = [const ALL_TEST_COMPANY_IDS = [TEST_COMPANY_AIRBNB_ID, TEST_COMPANY_STRIPE_ID];describe('FindRecords workflow action with relation-traversal filter (e2e)', () => {- let createdWorkflowId: string | null = null;- let createdWorkflowVersionId: string | null = null;+ let coreWorkflowId: string | null = null;+ let coreWorkflowVersionId: string | null = null;let findRecordsStepId: string | null = null;const createdWorkflowRunIds: string[] = [];let personCompanyFieldMetadataId: string | null = null;@@ -121,42 +125,15 @@ describe('FindRecords workflow action with relation-traversal filter (e2e)', ()};const buildWorkflow = async () => {- const createWorkflowResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation CreateWorkflow {- createWorkflow(data: { name: "Relation Traversal Find Records Test" }) {- 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 },- });+ const coreWorkflow = await createCoreWorkflow({+ name: 'Relation Traversal Find Records Test',+ });- createdWorkflowVersionId =- getWorkflowResponse.body.data.workflow.versions.edges[0].node.id;+ coreWorkflowId = coreWorkflow.coreWorkflowId;+ coreWorkflowVersionId = coreWorkflow.coreWorkflowVersionId;- await updateWorkflowVersionTrigger({- workflowVersionId: createdWorkflowVersionId!,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -166,116 +143,55 @@ describe('FindRecords workflow action with relation-traversal filter (e2e)', ()},});- const createStepResponse = 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: 'FIND_RECORDS',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- });-- expect(createStepResponse.body.errors).toBeUndefined();-- const getVersionResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- query GetWorkflowVersion($id: UUID!) {- workflowVersion(filter: { id: { eq: $id } }) { steps }- }- `,- variables: { id: createdWorkflowVersionId },- });-- const steps = getVersionResponse.body.data.workflowVersion.steps;- const findRecordsStep = steps.find(- (step: { type: string }) => step.type === 'FIND_RECORDS',- );+ const findRecordsStep = await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'FIND_RECORDS',+ });- expect(findRecordsStep).toBeDefined();findRecordsStepId = findRecordsStep.id;const filterGroupId = uuidv4();const filterId = uuidv4();- const updateStepResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation UpdateWorkflowVersionStep($input: UpdateWorkflowVersionStepInput!) {- updateWorkflowVersionStep(input: $input) { id }- }- `,- variables: {+ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ step: {+ ...findRecordsStep,+ settings: {+ ...findRecordsStep.settings,input: {- workflowVersionId: createdWorkflowVersionId,- step: {- ...findRecordsStep,- settings: {- ...findRecordsStep.settings,- input: {- ...findRecordsStep.settings.input,- objectName: 'person',- limit: 25,- filter: {- recordFilters: [- {- id: filterId,- type: 'TEXT',- label: 'Company → Name',- value: '{{trigger.companyName}}',- operand: 'CONTAINS',- displayValue: '{{trigger.companyName}}',- fieldMetadataId: personCompanyFieldMetadataId,- relationTargetFieldMetadataId:- companyNameFieldMetadataId,- recordFilterGroupId: filterGroupId,- },- ],- recordFilterGroups: [- { id: filterGroupId, logicalOperator: 'AND' },- ],- },+ ...findRecordsStep.settings.input,+ objectName: 'person',+ limit: 25,+ filter: {+ recordFilters: [+ {+ id: filterId,+ type: 'TEXT',+ label: 'Company → Name',+ value: '{{trigger.companyName}}',+ operand: 'CONTAINS',+ displayValue: '{{trigger.companyName}}',+ fieldMetadataId: personCompanyFieldMetadataId,+ relationTargetFieldMetadataId: companyNameFieldMetadataId,+ recordFilterGroupId: filterGroupId,},- },+ ],+ recordFilterGroups: [+ { id: filterGroupId, logicalOperator: 'AND' },+ ],},},},- });-- expect(updateStepResponse.body.errors).toBeUndefined();-- const activateResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- variables: { workflowVersionId: createdWorkflowVersionId },- });+ },+ });- expect(activateResponse.body.errors).toBeUndefined();+ await activateCoreWorkflowVersion({ coreWorkflowVersionId });};const runWithCompanyName = async (companyName: string | null) => {- const workflowRunId = await runWorkflowVersion({- workflowVersionId: createdWorkflowVersionId!,+ const workflowRunId = await runCoreWorkflowVersion({+ coreWorkflowVersionId: coreWorkflowVersionId!,payload: { companyName },});@@ -294,14 +210,8 @@ describe('FindRecords workflow action with relation-traversal filter (e2e)', ()for (const workflowRunId of createdWorkflowRunIds) {await destroyWorkflowRun(workflowRunId);}- 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 },- });+ if (coreWorkflowId) {+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });}await makeGraphqlApiRequest(deleteManyOperationFactory({diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/if-else-workflow.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/if-else-workflow.integration-spec.tsindex 03ee8df98bc..7d08ec257b7 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/if-else-workflow.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/if-else-workflow.integration-spec.ts@@ -1,7 +1,16 @@import request from 'supertest';+import {+ activateCoreWorkflowVersion,+ coreWorkflowGraphqlRequest,+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ runCoreWorkflowVersion,+ updateCoreWorkflowVersionStep,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import {destroyWorkflowRun,- runWorkflowVersion,waitForWorkflowCompletion,} from 'test/integration/graphql/suites/workflow/utils/workflow-run-test.util';import { expectEventually } from 'test/integration/utils/expect-eventually.util';@@ -10,11 +19,12 @@ import { type StepIfElseBranch } from 'twenty-shared/workflow';import { v4 } from 'uuid';import { type WorkflowIfElseAction } 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}`);describe('If/Else Workflow (e2e)', () => {+ let coreWorkflowId: string | null = null;+ let coreWorkflowVersionId: string | null = null;let createdWorkflowId: string | null = null;let createdWorkflowVersionId: string | null = null;let ifElseStepId: string | null = null;@@ -24,23 +34,13 @@ describe('If/Else Workflow (e2e)', () => {let elseIfBranchId: string | null = null;beforeAll(async () => {- const createWorkflowResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation CreateWorkflow {- createWorkflow(data: {- name: "If/Else Test Workflow"- }) {- id- }- }- `,- });+ const coreWorkflow = await createCoreWorkflow({+ name: 'If/Else Test Workflow',+ });- expect(createWorkflowResponse.body.errors).toBeUndefined();- createdWorkflowId = createWorkflowResponse.body.data.createWorkflow.id;+ coreWorkflowId = coreWorkflow.coreWorkflowId;+ coreWorkflowVersionId = coreWorkflow.coreWorkflowVersionId;+ createdWorkflowId = coreWorkflow.workspaceWorkflowId;const getWorkflowResponse = await client.post('/graphql')@@ -87,35 +87,15 @@ describe('If/Else Workflow (e2e)', () => {position: { x: 0, y: 0 },};- const updateWorkflowVersionResponse = await updateWorkflowVersionTrigger({- workflowVersionId: createdWorkflowVersionId!,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId,trigger: manualTrigger,});- expect(updateWorkflowVersionResponse.body.errors).toBeUndefined();-- const createIfElseStepResponse = 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: 'IF_ELSE',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- });-- expect(createIfElseStepResponse.body.errors).toBeUndefined();+ await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'IF_ELSE',+ });const getWorkflowVersionResponse = await client.post('/graphql')@@ -173,70 +153,48 @@ describe('If/Else Workflow (e2e)', () => {expect(filterGroup).toBeDefined();- const updateIfElseStepResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation UpdateWorkflowVersionStep($input: UpdateWorkflowVersionStepInput!) {- updateWorkflowVersionStep(input: $input) {- id- type- name- }- }- `,- variables: {+ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ step: {+ ...ifElseStep,+ settings: {+ ...ifElseStep.settings,input: {- workflowVersionId: createdWorkflowVersionId,- step: {- ...ifElseStep,- settings: {- ...ifElseStep.settings,- input: {- ...ifElseStep.settings.input,- stepFilters: [- {- id: ifElseStep.settings.input.stepFilters[0].id,- type: 'NUMBER',- stepOutputKey: '{{trigger.number}}',- operand: ViewFilterOperand.IS,- value: '10',- stepFilterGroupId: ifFilterGroupId,- positionInStepFilterGroup: 0,- },- ],- },+ ...ifElseStep.settings.input,+ stepFilters: [+ {+ id: ifElseStep.settings.input.stepFilters[0].id,+ type: 'NUMBER',+ stepOutputKey: '{{trigger.number}}',+ operand: ViewFilterOperand.IS,+ value: '10',+ stepFilterGroupId: ifFilterGroupId,+ positionInStepFilterGroup: 0,},- },+ ],},},- });-- expect(updateIfElseStepResponse.body.errors).toBeUndefined();+ },+ });- const createEmptyNodeResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation CreateWorkflowVersionStep($input: CreateWorkflowVersionStepInput!) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }+ await coreWorkflowGraphqlRequest({+ query: `+ mutation CreateCoreWorkflowVersionStep(+ $input: CreateCoreWorkflowVersionStepInput!+ ) {+ createCoreWorkflowVersionStep(input: $input) {+ stepsDiff}- `,- variables: {- input: {- workflowVersionId: createdWorkflowVersionId,- stepType: 'EMPTY',- parentStepId: undefined,- position: { x: 300, y: 100 },- },+ }+ `,+ variables: {+ input: {+ coreWorkflowVersionId,+ stepType: 'EMPTY',+ position: { x: 300, y: 100 },},- });-- expect(createEmptyNodeResponse.body.errors).toBeUndefined();+ },+ });const getUpdatedWorkflowVersionResponse = await client.post('/graphql')@@ -326,71 +284,28 @@ describe('If/Else Workflow (e2e)', () => {},];- const updateIfElseStepWithElseIfResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation UpdateWorkflowVersionStep($input: UpdateWorkflowVersionStepInput!) {- updateWorkflowVersionStep(input: $input) {- id- type- name- }- }- `,- variables: {+ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ step: {+ ...currentIfElseStep,+ settings: {+ ...currentIfElseStep.settings,input: {- workflowVersionId: createdWorkflowVersionId,- step: {- ...currentIfElseStep,- settings: {- ...currentIfElseStep.settings,- input: {- ...currentIfElseStep.settings.input,- branches: updatedBranches,- stepFilterGroups: updatedStepFilterGroups,- stepFilters: updatedStepFilters,- },- },- },+ ...currentIfElseStep.settings.input,+ branches: updatedBranches,+ stepFilterGroups: updatedStepFilterGroups,+ stepFilters: updatedStepFilters,},},- });-- expect(updateIfElseStepWithElseIfResponse.body.errors).toBeUndefined();-- const activateResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- variables: { workflowVersionId: createdWorkflowVersionId },- });+ },+ });- expect(activateResponse.body.errors).toBeUndefined();- expect(activateResponse.body.data.activateWorkflowVersion).toBe(true);+ await activateCoreWorkflowVersion({ coreWorkflowVersionId });});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 },- });+ if (coreWorkflowId) {+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });}});@@ -542,8 +457,8 @@ describe('If/Else Workflow (e2e)', () => {payload: { number: number };expectedBranchType: 'if' | 'else' | 'else-if';}) => {- const workflowRunId = await runWorkflowVersion({- workflowVersionId: createdWorkflowVersionId!,+ const workflowRunId = await runCoreWorkflowVersion({+ coreWorkflowVersionId: coreWorkflowVersionId!,payload,});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/parallel-branch-leaf-resume-workflow.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/parallel-branch-leaf-resume-workflow.integration-spec.tsindex 91a98bdc49c..dd49b5b9757 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/parallel-branch-leaf-resume-workflow.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/parallel-branch-leaf-resume-workflow.integration-spec.ts@@ -1,4 +1,12 @@-import request from 'supertest';+import {+ activateCoreWorkflowVersion,+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ findCoreWorkflowVersion,+ updateCoreWorkflowVersionStep,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import {destroyWorkflowRun,getWorkflowRun,@@ -9,147 +17,32 @@ import { v4 } from 'uuid';import { type WorkflowRunRecordShareService } from 'src/engine/core-modules/workflow/services/workflow-run-record-share.service';import { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/get-workspace-schema-name.util';import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';-import {- type WorkflowAction,- type WorkflowDelayAction,- type WorkflowFormAction,-} from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';import { submitFormStep } from 'test/integration/graphql/suites/workflow/utils/submit-form-step.util';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';-const client = request(`http://localhost:${APP_PORT}`);-const schema = getWorkspaceSchemaName(SEED_APPLE_WORKSPACE_ID);const DELAY_DURATION_SECONDS = 20;describe('Parallel branch leaf resume workflow (e2e)', () => {- let createdWorkflowId: string | null = null;- let createdWorkflowVersionId: string | null = null;+ let coreWorkflowId: string | null = null;+ let coreWorkflowVersionId: string | null = null;+ let workspaceWorkflowId: string | null = null;let formStepId: string | null = null;let delayStepId: string | null = null;let sendEmailStepId: string | null = null;let createdWorkflowRunId: 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 updateStep = async (step: WorkflowAction) => {- 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,- },- },- });-- 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: "Parallel Branch Leaf Resume 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 },- });+ const coreWorkflow = await createCoreWorkflow({+ name: 'Parallel Branch Leaf Resume Workflow',+ });- expect(getWorkflowResponse.body.errors).toBeUndefined();- createdWorkflowVersionId =- getWorkflowResponse.body.data.workflow.versions.edges[0].node.id;+ coreWorkflowId = coreWorkflow.coreWorkflowId;+ coreWorkflowVersionId = coreWorkflow.coreWorkflowVersionId;+ workspaceWorkflowId = coreWorkflow.workspaceWorkflowId;- const updateTriggerResponse = await updateWorkflowVersionTrigger({- workflowVersionId: createdWorkflowVersionId!,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -159,83 +52,71 @@ describe('Parallel branch leaf resume workflow (e2e)', () => {},});- expect(updateTriggerResponse.body.errors).toBeUndefined();-- await createStep({ stepType: 'FORM', parentStepId: 'trigger' });-- formStepId =- (await getSteps()).find((step) => step.type === 'FORM')?.id ?? null;-- expect(formStepId).not.toBeNull();-- await createStep({ stepType: 'DELAY', parentStepId: 'trigger' });-- delayStepId =- (await getSteps()).find((step) => step.type === 'DELAY')?.id ?? null;-- expect(delayStepId).not.toBeNull();-- await createStep({ stepType: 'SEND_EMAIL', parentStepId: delayStepId! });+ formStepId = (+ await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'FORM',+ })+ ).id;- sendEmailStepId =- (await getSteps()).find((step) => step.type === 'SEND_EMAIL')?.id ?? null;+ delayStepId = (+ await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'DELAY',+ })+ ).id;- expect(sendEmailStepId).not.toBeNull();+ sendEmailStepId = (+ await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'SEND_EMAIL',+ parentStepId: delayStepId,+ })+ ).id;- const steps = await getSteps();+ const { steps } = await findCoreWorkflowVersion({ coreWorkflowVersionId });- const formStep = steps.find(- (step): step is WorkflowFormAction => step.id === formStepId,- );+ const formStep = steps?.find((step) => step.id === formStepId);expect(formStep).toBeDefined();- await updateStep({- ...formStep!,- settings: {- ...formStep!.settings,- input: [- {- id: v4(),- name: 'answer',- label: 'Answer',- type: FieldMetadataType.TEXT,- },- ],+ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ step: {+ ...formStep!,+ settings: {+ ...formStep!.settings,+ input: [+ {+ id: v4(),+ name: 'answer',+ label: 'Answer',+ type: FieldMetadataType.TEXT,+ },+ ],+ },},});- const delayStep = steps.find(- (step): step is WorkflowDelayAction => step.id === delayStepId,- );+ const delayStep = steps?.find((step) => step.id === delayStepId);expect(delayStep).toBeDefined();- await updateStep({- ...delayStep!,- settings: {- ...delayStep!.settings,- input: {- delayType: 'DURATION',- duration: { seconds: DELAY_DURATION_SECONDS },+ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ step: {+ ...delayStep!,+ settings: {+ ...delayStep!.settings,+ input: {+ delayType: 'DURATION',+ duration: { seconds: DELAY_DURATION_SECONDS },+ },},},});- const activateResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- variables: { workflowVersionId: createdWorkflowVersionId },- });-- expect(activateResponse.body.errors).toBeUndefined();- expect(activateResponse.body.data.activateWorkflowVersion).toBe(true);+ await activateCoreWorkflowVersion({ coreWorkflowVersionId });});afterAll(async () => {@@ -243,34 +124,16 @@ describe('Parallel branch leaf resume workflow (e2e)', () => {await destroyWorkflowRun(createdWorkflowRunId);}- 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 },- });+ if (coreWorkflowId) {+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });}});it('keeps the run alive and the delay branch pending when the parallel form leaf is submitted', async () => {- const steps = await getSteps();- const [{ trigger, coreWorkflowVersionId }] =- await global.testDataSource.query(- `SELECT trigger, "coreWorkflowVersionId" FROM "${schema}"."workflowVersion" WHERE id = $1`,- [createdWorkflowVersionId],- );- const [{ coreWorkflowId }] = await global.testDataSource.query(- `SELECT "coreWorkflowId" FROM "${schema}".workflow WHERE id = $1`,- [createdWorkflowId],- );+ const { trigger, steps, workspaceWorkflowVersionId } =+ await findCoreWorkflowVersion({+ coreWorkflowVersionId: coreWorkflowVersionId!,+ });createdWorkflowRunId = v4();@@ -279,7 +142,7 @@ describe('Parallel branch leaf resume workflow (e2e)', () => {stepInfos: {trigger: { status: 'NOT_STARTED', result: {} },...Object.fromEntries(- steps.map((step) => [step.id, { status: 'NOT_STARTED' }]),+ (steps ?? []).map((step) => [step.id, { status: 'NOT_STARTED' }]),),},};@@ -290,8 +153,8 @@ describe('Parallel branch leaf resume workflow (e2e)', () => {VALUES ($1, 'Parallel branch leaf resume run', $2, $3, $4, $5, 'ENQUEUED', $6, 0, now())`,[createdWorkflowRunId,- createdWorkflowId,- createdWorkflowVersionId,+ workspaceWorkflowId,+ workspaceWorkflowVersionId,coreWorkflowId,coreWorkflowVersionId,JSON.stringify(state),diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/pick-record-load-balanced-workflow.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/pick-record-load-balanced-workflow.integration-spec.tsindex 19cde9fed7f..7d16da6f6b3 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/pick-record-load-balanced-workflow.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/pick-record-load-balanced-workflow.integration-spec.ts@@ -1,8 +1,15 @@import request from 'supertest';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';+import {+ activateCoreWorkflowVersion,+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ runCoreWorkflowVersion,+ updateCoreWorkflowVersionStep,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import {destroyWorkflowRun,- runWorkflowVersion,waitForWorkflowCompletion,} from 'test/integration/graphql/suites/workflow/utils/workflow-run-test.util';@@ -20,46 +27,23 @@ const graphql = async (query: string, variables?: Record<string, unknown>) => {};describe('Pick Record Workflow - load balanced (e2e)', () => {- let createdWorkflowId: string | null = null;- let createdWorkflowVersionId: string | null = null;+ let coreWorkflowId: string | null = null;+ let coreWorkflowVersionId: string | null = null;let pickRecordStepId: string | null = null;let leastLoadedCompanyId: string | null = null;let mostLoadedCompanyId: string | null = null;let createdOpportunityId: string | null = null;beforeAll(async () => {- const createWorkflowData = await graphql(`- mutation CreateWorkflow {- createWorkflow(data: { name: "Pick Record Load Balanced Test" }) {- id- }- }- `);-- createdWorkflowId = createWorkflowData.createWorkflow.id;-- const getWorkflowData = await graphql(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: createdWorkflowId },- );+ const coreWorkflow = await createCoreWorkflow({+ name: 'Pick Record Load Balanced Test',+ });- createdWorkflowVersionId =- getWorkflowData.workflow.versions.edges[0].node.id;+ coreWorkflowId = coreWorkflow.coreWorkflowId;+ coreWorkflowVersionId = coreWorkflow.coreWorkflowVersionId;- await updateWorkflowVersionTrigger({- workflowVersionId: createdWorkflowVersionId!,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -69,40 +53,10 @@ describe('Pick Record Workflow - load balanced (e2e)', () => {},});- await graphql(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId: createdWorkflowVersionId,- stepType: 'PICK_RECORD',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- );-- const getStepsData = await graphql(- `- query GetWorkflowVersion($id: UUID!) {- workflowVersion(filter: { id: { eq: $id } }) {- steps- }- }- `,- { id: createdWorkflowVersionId },- );-- const pickRecordStep = getStepsData.workflowVersion.steps.find(- (step: { type: string }) => step.type === 'PICK_RECORD',- );+ const pickRecordStep = await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'PICK_RECORD',+ });pickRecordStepId = pickRecordStep.id;@@ -151,48 +105,26 @@ describe('Pick Record Workflow - load balanced (e2e)', () => {createdOpportunityId = opportunityData.createOpportunity.id;- await graphql(- `- mutation UpdateWorkflowVersionStep(- $input: UpdateWorkflowVersionStepInput!- ) {- updateWorkflowVersionStep(input: $input) {- id- }- }- `,- {- input: {- workflowVersionId: createdWorkflowVersionId,- step: {- ...pickRecordStep,- settings: {- ...pickRecordStep.settings,- input: {- objectName: 'company',- strategy: 'LOAD_BALANCED',- recordIds: [leastLoadedCompanyId, mostLoadedCompanyId],- loadBalance: {- objectNameSingular: 'opportunity',- fieldName: 'company',- },- },+ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ step: {+ ...pickRecordStep,+ settings: {+ ...pickRecordStep.settings,+ input: {+ objectName: 'company',+ strategy: 'LOAD_BALANCED',+ recordIds: [leastLoadedCompanyId, mostLoadedCompanyId],+ loadBalance: {+ objectNameSingular: 'opportunity',+ fieldName: 'company',},},},},- );-- const activateData = await graphql(- `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- { workflowVersionId: createdWorkflowVersionId },- );+ });- expect(activateData.activateWorkflowVersion).toBe(true);+ await activateCoreWorkflowVersion({ coreWorkflowVersionId });});afterAll(async () => {@@ -224,23 +156,14 @@ describe('Pick Record Workflow - load balanced (e2e)', () => {}}- if (createdWorkflowId) {- await graphql(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: createdWorkflowId },- );+ if (coreWorkflowId) {+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });}});it('picks the candidate with the fewest related records', async () => {- const workflowRunId = await runWorkflowVersion({- workflowVersionId: createdWorkflowVersionId!,+ const workflowRunId = await runCoreWorkflowVersion({+ coreWorkflowVersionId: coreWorkflowVersionId!,payload: {},});@@ -257,39 +180,14 @@ describe('Pick Record Workflow - load balanced (e2e)', () => {});it('rejects activation when the count-by relation points to another object', async () => {- const createData = await graphql(`- mutation CreateWorkflow {- createWorkflow(data: { name: "Pick Record LB misrouted relation" }) {- id- }- }- `);-- const misroutedWorkflowId = createData.createWorkflow.id;+ const {+ coreWorkflowId: misroutedCoreWorkflowId,+ coreWorkflowVersionId: misroutedCoreWorkflowVersionId,+ } = await createCoreWorkflow({ name: 'Pick Record LB misrouted relation' });try {- const workflowData = await graphql(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: misroutedWorkflowId },- );-- const misroutedWorkflowVersionId =- workflowData.workflow.versions.edges[0].node.id;-- await updateWorkflowVersionTrigger({- workflowVersionId: misroutedWorkflowVersionId,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId: misroutedCoreWorkflowVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -299,105 +197,57 @@ describe('Pick Record Workflow - load balanced (e2e)', () => {},});- await graphql(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId: misroutedWorkflowVersionId,- stepType: 'PICK_RECORD',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- );-- const stepsData = await graphql(- `- query GetWorkflowVersion($id: UUID!) {- workflowVersion(filter: { id: { eq: $id } }) {- steps- }- }- `,- { id: misroutedWorkflowVersionId },- );-- const pickRecordStep = stepsData.workflowVersion.steps.find(- (step: { type: string }) => step.type === 'PICK_RECORD',- );+ const pickRecordStep = await createCoreWorkflowVersionStep({+ coreWorkflowVersionId: misroutedCoreWorkflowVersionId,+ stepType: 'PICK_RECORD',+ });// pointOfContact is a many-to-one relation on opportunity, but it points// to person, not the company pool — the silent misrouting the guard blocks.- await graphql(- `- mutation UpdateWorkflowVersionStep(- $input: UpdateWorkflowVersionStepInput!- ) {- updateWorkflowVersionStep(input: $input) {- id- }- }- `,- {- input: {- workflowVersionId: misroutedWorkflowVersionId,- step: {- ...pickRecordStep,- settings: {- ...pickRecordStep.settings,- input: {- objectName: 'company',- strategy: 'LOAD_BALANCED',- recordIds: [],- loadBalance: {- objectNameSingular: 'opportunity',- fieldName: 'pointOfContact',- },- },+ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId: misroutedCoreWorkflowVersionId,+ step: {+ ...pickRecordStep,+ settings: {+ ...pickRecordStep.settings,+ input: {+ objectName: 'company',+ strategy: 'LOAD_BALANCED',+ recordIds: [],+ loadBalance: {+ objectNameSingular: 'opportunity',+ fieldName: 'pointOfContact',},},},},- );+ });const activateResponse = await client.post('/graphql').set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`).send({query: `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)+ mutation ActivateCoreWorkflowVersion(+ $coreWorkflowVersionId: UUID!+ ) {+ activateCoreWorkflowVersion(+ coreWorkflowVersionId: $coreWorkflowVersionId+ )}`,- variables: { workflowVersionId: misroutedWorkflowVersionId },+ variables: { coreWorkflowVersionId: misroutedCoreWorkflowVersionId },});expect(activateResponse.body.errors).toBeDefined();expect(activateResponse.body.errors[0].message).toContain('many-to-one relation',);- expect(activateResponse.body.data?.activateWorkflowVersion).not.toBe(+ expect(activateResponse.body.data?.activateCoreWorkflowVersion).not.toBe(true,);} finally {- await graphql(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: misroutedWorkflowId },- );+ await deleteCoreWorkflows({ coreWorkflowIds: [misroutedCoreWorkflowId] });}});});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/pick-record-round-robin-workflow.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/pick-record-round-robin-workflow.integration-spec.tsindex 1ba34247a76..7fedc24d6ca 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/pick-record-round-robin-workflow.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/pick-record-round-robin-workflow.integration-spec.ts@@ -1,60 +1,36 @@import request from 'supertest';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';+import {+ activateCoreWorkflowVersion,+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ runCoreWorkflowVersion,+ updateCoreWorkflowVersionStep,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import {destroyWorkflowRun,- runWorkflowVersion,waitForWorkflowCompletion,} from 'test/integration/graphql/suites/workflow/utils/workflow-run-test.util';const client = request(`http://localhost:${APP_PORT}`);describe('Pick Record Workflow - round robin (e2e)', () => {- let createdWorkflowId: string | null = null;- let createdWorkflowVersionId: string | null = null;+ let coreWorkflowId: string | null = null;+ let coreWorkflowVersionId: string | null = null;let pickRecordStepId: string | null = null;let orderedCandidateRecordIds: string[] = [];beforeAll(async () => {- const createWorkflowResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation CreateWorkflow {- createWorkflow(data: { name: "Pick Record Round Robin Test" }) {- id- }- }- `,- });-- 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 } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- variables: { id: createdWorkflowId },- });+ const createdCoreWorkflow = await createCoreWorkflow({+ name: 'Pick Record Round Robin Test',+ });- createdWorkflowVersionId =- getWorkflowResponse.body.data.workflow.versions.edges[0].node.id;+ coreWorkflowId = createdCoreWorkflow.coreWorkflowId;+ coreWorkflowVersionId = createdCoreWorkflow.coreWorkflowVersionId;- await updateWorkflowVersionTrigger({- workflowVersionId: createdWorkflowVersionId!,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -64,45 +40,10 @@ describe('Pick Record Workflow - round robin (e2e)', () => {},});- 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: 'PICK_RECORD',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- });-- const getStepsResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- query GetWorkflowVersion($id: UUID!) {- workflowVersion(filter: { id: { eq: $id } }) {- steps- }- }- `,- variables: { id: createdWorkflowVersionId },- });-- const pickRecordStep =- getStepsResponse.body.data.workflowVersion.steps.find(- (step: { type: string }) => step.type === 'PICK_RECORD',- );+ const pickRecordStep = await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'PICK_RECORD',+ });pickRecordStepId = pickRecordStep.id;@@ -136,65 +77,27 @@ describe('Pick Record Workflow - round robin (e2e)', () => {(idA: string, idB: string) => idA.localeCompare(idB),);- await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation UpdateWorkflowVersionStep($input: UpdateWorkflowVersionStepInput!) {- updateWorkflowVersionStep(input: $input) {- id- }- }- `,- variables: {+ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ step: {+ ...pickRecordStep,+ settings: {+ ...pickRecordStep.settings,input: {- workflowVersionId: createdWorkflowVersionId,- step: {- ...pickRecordStep,- settings: {- ...pickRecordStep.settings,- input: {- objectName: 'company',- strategy: 'ROUND_ROBIN',- recordIds: candidateRecordIds,- },- },- },+ objectName: 'company',+ strategy: 'ROUND_ROBIN',+ recordIds: candidateRecordIds,},},- });-- const activateResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- variables: { workflowVersionId: createdWorkflowVersionId },- });+ },+ });- expect(activateResponse.body.data.activateWorkflowVersion).toBe(true);+ await activateCoreWorkflowVersion({ coreWorkflowVersionId });});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 },- });+ if (coreWorkflowId) {+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });}});@@ -202,8 +105,8 @@ describe('Pick Record Workflow - round robin (e2e)', () => {const pickedRecordIds: string[] = [];for (let runIndex = 0; runIndex < 4; runIndex++) {- const workflowRunId = await runWorkflowVersion({- workflowVersionId: createdWorkflowVersionId!,+ const workflowRunId = await runCoreWorkflowVersion({+ coreWorkflowVersionId: coreWorkflowVersionId!,payload: {},});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/pick-record-workflow.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/pick-record-workflow.integration-spec.tsindex f06411b54cf..0beacfbd812 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/pick-record-workflow.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/pick-record-workflow.integration-spec.ts@@ -1,62 +1,36 @@import request from 'supertest';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';+import {+ activateCoreWorkflowVersion,+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ runCoreWorkflowVersion,+ updateCoreWorkflowVersionStep,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import {destroyWorkflowRun,- runWorkflowVersion,waitForWorkflowCompletion,} from 'test/integration/graphql/suites/workflow/utils/workflow-run-test.util';const client = request(`http://localhost:${APP_PORT}`);describe('Pick Record Workflow (e2e)', () => {- let createdWorkflowId: string | null = null;- let createdWorkflowVersionId: string | null = null;+ let coreWorkflowId: string | null = null;+ let coreWorkflowVersionId: string | null = null;let pickRecordStepId: string | null = null;let candidateRecordIds: string[] = [];beforeAll(async () => {- const createWorkflowResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation CreateWorkflow {- createWorkflow(data: { name: "Pick Record 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 },- });+ const createdCoreWorkflow = await createCoreWorkflow({+ name: 'Pick Record Test Workflow',+ });- createdWorkflowVersionId =- getWorkflowResponse.body.data.workflow.versions.edges[0].node.id;+ coreWorkflowId = createdCoreWorkflow.coreWorkflowId;+ coreWorkflowVersionId = createdCoreWorkflow.coreWorkflowVersionId;- const updateTriggerResponse = await updateWorkflowVersionTrigger({- workflowVersionId: createdWorkflowVersionId!,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -66,52 +40,11 @@ describe('Pick Record Workflow (e2e)', () => {},});- expect(updateTriggerResponse.body.errors).toBeUndefined();-- const createStepResponse = 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: 'PICK_RECORD',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- });-- expect(createStepResponse.body.errors).toBeUndefined();-- const getStepsResponse = 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 },- });-- const steps = getStepsResponse.body.data.workflowVersion.steps;- const pickRecordStep = steps.find(- (step: { type: string }) => step.type === 'PICK_RECORD',- );+ const pickRecordStep = await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'PICK_RECORD',+ });- expect(pickRecordStep).toBeDefined();pickRecordStepId = pickRecordStep.id;for (const name of ['Pick Record Company A', 'Pick Record Company B']) {@@ -133,68 +66,27 @@ describe('Pick Record Workflow (e2e)', () => {candidateRecordIds.push(companyResponse.body.data.createCompany.id);}- const updateStepResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation UpdateWorkflowVersionStep($input: UpdateWorkflowVersionStepInput!) {- updateWorkflowVersionStep(input: $input) {- id- }- }- `,- variables: {+ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ step: {+ ...pickRecordStep,+ settings: {+ ...pickRecordStep.settings,input: {- workflowVersionId: createdWorkflowVersionId,- step: {- ...pickRecordStep,- settings: {- ...pickRecordStep.settings,- input: {- objectName: 'company',- strategy: 'RANDOM',- recordIds: candidateRecordIds,- },- },- },+ objectName: 'company',+ strategy: 'RANDOM',+ recordIds: candidateRecordIds,},},- });-- expect(updateStepResponse.body.errors).toBeUndefined();-- const activateResponse = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({- query: `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- variables: { workflowVersionId: createdWorkflowVersionId },- });-- expect(activateResponse.body.errors).toBeUndefined();- expect(activateResponse.body.data.activateWorkflowVersion).toBe(true);+ },+ });++ await activateCoreWorkflowVersion({ coreWorkflowVersionId });});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 },- });+ if (coreWorkflowId) {+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });}for (const id of candidateRecordIds) {@@ -217,8 +109,8 @@ describe('Pick Record Workflow (e2e)', () => {});const pickRecordOnce = async (): Promise<{ id: string }> => {- const workflowRunId = await runWorkflowVersion({- workflowVersionId: createdWorkflowVersionId!,+ const workflowRunId = await runCoreWorkflowVersion({+ coreWorkflowVersionId: coreWorkflowVersionId!,payload: {},});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/step-error-handling-workflow.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/step-error-handling-workflow.integration-spec.tsindex c7bf989dfc4..b9a8d18f13d 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/step-error-handling-workflow.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/step-error-handling-workflow.integration-spec.ts@@ -1,8 +1,15 @@import { STEP_RETRY_DELAYS_MS } from 'twenty-shared/workflow';import request from 'supertest';+import {+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ runCoreWorkflowVersion,+ updateCoreWorkflowVersionStep,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import {destroyWorkflowRun,- runWorkflowVersion,waitForWorkflowCompletion,} from 'test/integration/graphql/suites/workflow/utils/workflow-run-test.util';@@ -10,7 +17,6 @@ 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}`);@@ -24,8 +30,8 @@ const TOTAL_RETRY_DELAY_MS = STEP_RETRY_DELAYS_MS.reduce(const RETRY_TEST_TIMEOUT_MS = TOTAL_RETRY_DELAY_MS + 60_000;describe('Step error handling workflow (e2e)', () => {- let createdWorkflowId: string | null = null;- let createdWorkflowVersionId: string | null = null;+ let coreWorkflowId: string | null = null;+ let coreWorkflowVersionId: string | null = null;let httpRequestStepId: string | null = null;let filterStepId: string | null = null;@@ -35,50 +41,20 @@ describe('Step error handling workflow (e2e)', () => {.set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`).send({query: `- query GetWorkflowVersion($id: UUID!) {- workflowVersion(filter: { id: { eq: $id } }) {- id+ query CoreWorkflowVersionById($coreWorkflowVersionId: UUID!) {+ coreWorkflowVersionById(+ coreWorkflowVersionId: $coreWorkflowVersionId+ ) {steps}}`,- variables: { id: createdWorkflowVersionId },+ variables: { coreWorkflowVersionId },});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();+ return response.body.data.coreWorkflowVersionById.steps;};const setUpFailingHttpRequestStep = async ({@@ -94,88 +70,36 @@ describe('Step error handling workflow (e2e)', () => {(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: {+ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId: coreWorkflowVersionId!,+ step: {+ ...httpRequestStep,+ settings: {+ ...httpRequestStep.settings,input: {- workflowVersionId: createdWorkflowVersionId,- step: {- ...httpRequestStep,- settings: {- ...httpRequestStep.settings,- input: {- ...httpRequestStep.settings.input,- url: BLOCKED_REQUEST_URL,- },- errorHandlingOptions: {- ...httpRequestStep.settings.errorHandlingOptions,- continueOnFailure: { value: continueOnFailure },- retryOnFailure: { value: retryOnFailure },- },- },- },+ ...httpRequestStep.settings.input,+ url: BLOCKED_REQUEST_URL,+ },+ errorHandlingOptions: {+ ...httpRequestStep.settings.errorHandlingOptions,+ continueOnFailure: { value: continueOnFailure },+ retryOnFailure: { value: retryOnFailure },},},- });-- 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 },- });+ const coreWorkflow = await createCoreWorkflow({+ name: 'Continue On Failure Test Workflow',+ });- expect(getWorkflowResponse.body.errors).toBeUndefined();- createdWorkflowVersionId =- getWorkflowResponse.body.data.workflow.versions.edges[0].node.id;+ coreWorkflowId = coreWorkflow.coreWorkflowId;+ coreWorkflowVersionId = coreWorkflow.coreWorkflowVersionId;- const updateTriggerResponse = await updateWorkflowVersionTrigger({- workflowVersionId: createdWorkflowVersionId!,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -185,52 +109,33 @@ describe('Step error handling workflow (e2e)', () => {},});- 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();+ httpRequestStepId = (+ await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'HTTP_REQUEST',+ })+ ).id;++ filterStepId = (+ await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'FILTER',+ parentStepId: httpRequestStepId,+ })+ ).id;});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 },- });+ if (coreWorkflowId) {+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });}});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!,+ const workflowRunId = await runCoreWorkflowVersion({+ coreWorkflowVersionId: coreWorkflowVersionId!,});try {@@ -254,8 +159,8 @@ describe('Step error handling workflow (e2e)', () => {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!,+ const workflowRunId = await runCoreWorkflowVersion({+ coreWorkflowVersionId: coreWorkflowVersionId!,});try {@@ -280,8 +185,8 @@ describe('Step error handling workflow (e2e)', () => {retryOnFailure: STEP_RETRY_DELAYS_MS.length,});- const workflowRunId = await runWorkflowVersion({- workflowVersionId: createdWorkflowVersionId!,+ const workflowRunId = await runCoreWorkflowVersion({+ coreWorkflowVersionId: coreWorkflowVersionId!,});try {diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/utils/core-workflow.util.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/utils/core-workflow.util.tsindex 7f817ade851..62fe574507d 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/utils/core-workflow.util.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/utils/core-workflow.util.ts@@ -11,12 +11,14 @@ type CoreWorkflowStep = {nextStepIds?: string[] | null;} & Record<string, unknown>;-export type CoreWorkflowVersion = {+export type CoreWorkflowVersion<+ TStep extends CoreWorkflowStep = CoreWorkflowStep,+> = {id: string;coreWorkflowId: string;status: string;trigger: Record<string, unknown> | null;- steps: CoreWorkflowStep[] | null;+ steps: TStep[] | null;workspaceWorkflowVersionId: string | null;};@@ -116,15 +118,17 @@ export const findCoreWorkflowVersions = async ({return coreWorkflowVersionsByCoreWorkflowId;};-export const findCoreWorkflowVersion = async ({+export const findCoreWorkflowVersion = async <+ TStep extends CoreWorkflowStep = CoreWorkflowStep,+>({coreWorkflowVersionId,token,}: {coreWorkflowVersionId: string;token?: string;-}): Promise<CoreWorkflowVersion> => {+}): Promise<CoreWorkflowVersion<TStep>> => {const { coreWorkflowVersionById } = await coreWorkflowGraphqlRequest<{- coreWorkflowVersionById: CoreWorkflowVersion;+ coreWorkflowVersionById: CoreWorkflowVersion<TStep>;}>({query: `query CoreWorkflowVersion($coreWorkflowVersionId: UUID!) {@@ -164,7 +168,9 @@ export const updateCoreWorkflowVersionTrigger = async ({});};-export const createCoreWorkflowVersionStep = async ({+export const createCoreWorkflowVersionStep = async <+ TStep extends CoreWorkflowStep = CoreWorkflowStep,+>({coreWorkflowVersionId,stepType,parentStepId = 'trigger',@@ -181,7 +187,7 @@ export const createCoreWorkflowVersionStep = async ({nextStepId?: string;parentStepConnectionOptions?: object;defaultSettings?: object;-}): Promise<CoreWorkflowStep> => {+}): Promise<TStep> => {const { steps: previousSteps } = await findCoreWorkflowVersion({coreWorkflowVersionId,token,@@ -210,7 +216,7 @@ export const createCoreWorkflowVersionStep = async ({token,});- const { steps } = await findCoreWorkflowVersion({+ const { steps } = await findCoreWorkflowVersion<TStep>({coreWorkflowVersionId,token,});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/wait-for-event-workflow.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/wait-for-event-workflow.integration-spec.tsindex ec60b006dde..cdd921e4d13 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/wait-for-event-workflow.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/wait-for-event-workflow.integration-spec.ts@@ -1,9 +1,17 @@import request from 'supertest';+import {+ activateCoreWorkflowVersion,+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ findCoreWorkflowVersion,+ updateCoreWorkflowVersionStep,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import {destroyWorkflowRun,getWorkflowRun,} from 'test/integration/graphql/suites/workflow/utils/workflow-run-test.util';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';import { expectEventually } from 'test/integration/utils/expect-eventually.util';import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';import { v4 } from 'uuid';@@ -15,19 +23,12 @@ import { type WorkflowRunRecordShareService } from 'src/engine/core-modules/workimport { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/get-workspace-schema-name.util';import { type WorkflowCommonWorkspaceService } from 'src/modules/workflow/common/workspace-services/workflow-common.workspace-service';import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';-import {- type WorkflowAction,- type WorkflowWaitForEventAction,-} from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';import { type WorkflowStepWaitWorkspaceService } from 'src/modules/workflow/workflow-wait/services/workflow-step-wait.workspace-service';const client = request(`http://localhost:${APP_PORT}`);const schema = getWorkspaceSchemaName(SEED_APPLE_WORKSPACE_ID);-const MIRROR_POLL_ATTEMPTS = 20;-const MIRROR_POLL_INTERVAL_MS = 250;-const graphql = (query: string, variables?: object) =>client.post('/graphql')@@ -56,62 +57,14 @@ const buildCompanyUpdatedBatch = async (companyId: string) => ({});describe('Wait for event workflow (e2e)', () => {- let createdWorkflowId: string | null = null;- let createdWorkflowVersionId: string | null = null;+ let coreWorkflowId: string | null = null;+ let coreWorkflowVersionId: string | null = null;+ let workspaceWorkflowId: string | null = null;let createdWorkflowRunId: string | null = null;let waitStepId: string | null = null;let watchedCompanyId: string | null = null;let otherCompanyId: string | null = null;- const getSteps = async (): Promise<WorkflowAction[]> => {- const response = await graphql(- `- query GetWorkflowVersion($id: UUID!) {- workflowVersion(filter: { id: { eq: $id } }) {- steps- }- }- `,- { id: createdWorkflowVersionId },- );-- expect(response.body.errors).toBeUndefined();-- return response.body.data.workflowVersion.steps;- };-- // the core mirror of a workflow and its version is linked asynchronously- const waitForCoreWorkflowMirror = async (): Promise<{- trigger: unknown;- coreWorkflowVersionId: string;- coreWorkflowId: string;- }> => {- for (let attempt = 0; attempt < MIRROR_POLL_ATTEMPTS; attempt++) {- const [version] = await global.testDataSource.query(- `SELECT trigger, "coreWorkflowVersionId" FROM "${schema}"."workflowVersion" WHERE id = $1`,- [createdWorkflowVersionId],- );- const [workflow] = await global.testDataSource.query(- `SELECT "coreWorkflowId" FROM "${schema}".workflow WHERE id = $1`,- [createdWorkflowId],- );-- if (version?.coreWorkflowVersionId && workflow?.coreWorkflowId) {- return {- trigger: version.trigger,- coreWorkflowVersionId: version.coreWorkflowVersionId,- coreWorkflowId: workflow.coreWorkflowId,- };- }-- await new Promise((resolve) =>- setTimeout(resolve, MIRROR_POLL_INTERVAL_MS),- );- }-- throw new Error('The workflow core mirror was never linked');- };-const createCompany = async (name: string): Promise<string> => {const response = await graphql(`@@ -133,40 +86,16 @@ describe('Wait for event workflow (e2e)', () => {watchedCompanyId = await createCompany('Wait For Event Watched Co');otherCompanyId = await createCompany('Wait For Event Other Co');- const createWorkflowResponse = await graphql(`- mutation CreateWorkflow {- createWorkflow(data: { name: "Wait For Event Workflow" }) {- id- }- }- `);-- expect(createWorkflowResponse.body.errors).toBeUndefined();- createdWorkflowId = createWorkflowResponse.body.data.createWorkflow.id;-- const getWorkflowResponse = await graphql(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: createdWorkflowId },- );+ const coreWorkflow = await createCoreWorkflow({+ name: 'Wait For Event Workflow',+ });- expect(getWorkflowResponse.body.errors).toBeUndefined();- createdWorkflowVersionId =- getWorkflowResponse.body.data.workflow.versions.edges[0].node.id;+ coreWorkflowId = coreWorkflow.coreWorkflowId;+ coreWorkflowVersionId = coreWorkflow.coreWorkflowVersionId;+ workspaceWorkflowId = coreWorkflow.workspaceWorkflowId;- const updateTriggerResponse = await updateWorkflowVersionTrigger({- workflowVersionId: createdWorkflowVersionId!,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -176,78 +105,29 @@ describe('Wait for event workflow (e2e)', () => {},});- expect(updateTriggerResponse.body.errors).toBeUndefined();-- const createStepResponse = await graphql(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId: createdWorkflowVersionId,- stepType: 'WAIT_FOR_EVENT',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- );-- expect(createStepResponse.body.errors).toBeUndefined();-- const waitStep = (await getSteps()).find(- (step): step is WorkflowWaitForEventAction =>- step.type === 'WAIT_FOR_EVENT',- );-- expect(waitStep).toBeDefined();- waitStepId = waitStep!.id;+ const waitStep = await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'WAIT_FOR_EVENT',+ });- const updateStepResponse = await graphql(- `- mutation UpdateWorkflowVersionStep(- $input: UpdateWorkflowVersionStepInput!- ) {- updateWorkflowVersionStep(input: $input) {- id- }- }- `,- {- input: {- workflowVersionId: createdWorkflowVersionId,- step: {- ...waitStep!,- settings: {- ...waitStep!.settings,- input: {- eventName: 'company.updated',- recordId: watchedCompanyId,- timeout: null,- },- },+ waitStepId = waitStep.id;++ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ step: {+ ...waitStep,+ settings: {+ ...waitStep.settings,+ input: {+ eventName: 'company.updated',+ recordId: watchedCompanyId,+ timeout: null,},},},- );-- expect(updateStepResponse.body.errors).toBeUndefined();-- const activateResponse = await graphql(- `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- { workflowVersionId: createdWorkflowVersionId },- );+ });- expect(activateResponse.body.errors).toBeUndefined();+ await activateCoreWorkflowVersion({ coreWorkflowVersionId });});afterAll(async () => {@@ -255,17 +135,8 @@ describe('Wait for event workflow (e2e)', () => {await destroyWorkflowRun(createdWorkflowRunId);}- if (createdWorkflowId) {- await graphql(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: createdWorkflowId },- );+ if (coreWorkflowId) {+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });}for (const companyId of [watchedCompanyId, otherCompanyId]) {@@ -285,9 +156,10 @@ describe('Wait for event workflow (e2e)', () => {});it('pauses on the event and resumes with the record once it happens', async () => {- const steps = await getSteps();- const { trigger, coreWorkflowVersionId, coreWorkflowId } =- await waitForCoreWorkflowMirror();+ const { trigger, steps, workspaceWorkflowVersionId } =+ await findCoreWorkflowVersion({+ coreWorkflowVersionId: coreWorkflowVersionId!,+ });createdWorkflowRunId = v4();@@ -296,7 +168,7 @@ describe('Wait for event workflow (e2e)', () => {stepInfos: {trigger: { status: 'NOT_STARTED', result: {} },...Object.fromEntries(- steps.map((step) => [step.id, { status: 'NOT_STARTED' }]),+ (steps ?? []).map((step) => [step.id, { status: 'NOT_STARTED' }]),),},};@@ -307,8 +179,8 @@ describe('Wait for event workflow (e2e)', () => {VALUES ($1, 'Wait for event run', $2, $3, $4, $5, 'ENQUEUED', $6, 0, now())`,[createdWorkflowRunId,- createdWorkflowId,- createdWorkflowVersionId,+ workspaceWorkflowId,+ workspaceWorkflowVersionId,coreWorkflowId,coreWorkflowVersionId,JSON.stringify(state),diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-core-mirror.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-core-mirror.integration-spec.tsdeleted file mode 100644index 2defc9b7a07..00000000000--- a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-core-mirror.integration-spec.ts+++ /dev/null@@ -1,162 +0,0 @@-import request from 'supertest';--import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';--const client = request(`http://localhost:${APP_PORT}`);--const graphql = (query: string, variables?: object) =>- client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({ query, variables });--const INITIAL_NAME = 'Core Mirror Workflow';-const RENAMED_NAME = 'Core Mirror Workflow Renamed';--const POLL_ATTEMPTS = 20;-const POLL_INTERVAL_MS = 250;--describe('workflow core mirror (e2e)', () => {- let workflowId: string;- let alreadyDestroyed = false;-- const fetchWorkspaceWorkflowIdOnCoreRowNamed = async (- name: string,- ): Promise<string | null | undefined> => {- const rows = await global.testDataSource.query(- `SELECT "workspaceWorkflowId" FROM core."workflow"- WHERE "workspaceId" = $1 AND "name" = $2`,- [SEED_APPLE_WORKSPACE_ID, name],- );-- return rows[0]?.workspaceWorkflowId;- };-- const countCoreWorkflowsNamed = async (name: string): Promise<number> => {- const rows = await global.testDataSource.query(- `SELECT "id" FROM core."workflow"- WHERE "workspaceId" = $1 AND "name" = $2`,- [SEED_APPLE_WORKSPACE_ID, name],- );-- return rows.length;- };-- // the mirror is an async database-event listener, so the core row lands- // shortly after the mutation returns rather than within it- const waitForCoreWorkflowsNamed = async (- name: string,- expected: number,- ): Promise<number> => {- for (let attempt = 0; attempt < POLL_ATTEMPTS; attempt++) {- const count = await countCoreWorkflowsNamed(name);-- if (count === expected) {- return count;- }-- await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));- }-- return countCoreWorkflowsNamed(name);- };-- afterAll(async () => {- if (workflowId && !alreadyDestroyed) {- await graphql(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workflowId },- );- }- });-- it('mirrors the workflow to core across create, rename, delete, restore and destroy', async () => {- const createResponse = await graphql(- `- mutation CreateWorkflow($name: String!) {- createWorkflow(data: { name: $name }) {- id- }- }- `,- { name: INITIAL_NAME },- );-- expect(createResponse.body.errors).toBeUndefined();- workflowId = createResponse.body.data.createWorkflow.id;-- expect(await waitForCoreWorkflowsNamed(INITIAL_NAME, 1)).toBe(1);- expect(await fetchWorkspaceWorkflowIdOnCoreRowNamed(INITIAL_NAME)).toBe(- workflowId,- );-- const renameResponse = await graphql(- `- mutation RenameWorkflow($id: UUID!, $name: String!) {- updateWorkflow(id: $id, data: { name: $name }) {- id- }- }- `,- { id: workflowId, name: RENAMED_NAME },- );-- expect(renameResponse.body.errors).toBeUndefined();- expect(await waitForCoreWorkflowsNamed(RENAMED_NAME, 1)).toBe(1);- expect(await waitForCoreWorkflowsNamed(INITIAL_NAME, 0)).toBe(0);-- const deleteResponse = await graphql(- `- mutation DeleteWorkflow($id: ID!) {- deleteWorkflow(id: $id) {- id- }- }- `,- { id: workflowId },- );-- expect(deleteResponse.body.errors).toBeUndefined();-- // no assertion on removal here: soft-delete does not reliably drop the core- // row. handleDeleted removes it, but the delete cascade then updates the- // workflow record, which emits UPDATED and re-upserts it. That is accepted,- // the row is inert because the core versions are removed by the version- // cascade, so nothing can dispatch. Destroy is what actually cleans it up.-- const restoreResponse = await graphql(- `- mutation RestoreWorkflow($id: ID!) {- restoreWorkflow(id: $id) {- id- }- }- `,- { id: workflowId },- );-- expect(restoreResponse.body.errors).toBeUndefined();- expect(await waitForCoreWorkflowsNamed(RENAMED_NAME, 1)).toBe(1);-- const destroyResponse = await graphql(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workflowId },- );-- expect(destroyResponse.body.errors).toBeUndefined();- alreadyDestroyed = true;- expect(await waitForCoreWorkflowsNamed(RENAMED_NAME, 0)).toBe(0);- });-});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-deletion-cleanup.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-deletion-cleanup.integration-spec.tsindex b8e18e03356..d2990c595c8 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-deletion-cleanup.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-deletion-cleanup.integration-spec.ts@@ -14,10 +14,17 @@ import {type TestApplicationWorkflow,waitForTestWorkflowRun,} from 'test/integration/graphql/suites/workflow/utils/application-workflow-test.util';+import {+ activateCoreWorkflowVersion,+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ findCoreWorkflowVersion,+ updateCoreWorkflowVersionStep,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import { submitFormStep } from 'test/integration/graphql/suites/workflow/utils/submit-form-step.util';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';import { workflowGraphqlRequest } from 'test/integration/graphql/suites/workflow/utils/workflow-graphql-request.util';-import { runWorkflowVersion } from 'test/integration/graphql/suites/workflow/utils/workflow-run-test.util';import { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/suites/application/utils/cleanup-application-and-app-registration.util';import { setupApplicationForSync } from 'test/integration/metadata/suites/application/utils/setup-application-for-sync.util';import { syncApplication } from 'test/integration/metadata/suites/application/utils/sync-application.util';@@ -96,7 +103,6 @@ describe('workflow deletion cleanup', () => {describe('deleting a workspace workflow', () => {type WorkspaceWorkflow = {- workflowId: string;workflowVersionId: string;coreWorkflowId: string;coreWorkflowVersionId: string;@@ -112,64 +118,14 @@ describe('workflow deletion cleanup', () => {let draftRunId: string;let formStepId: string;- const waitForCoreLink = async ({- workflowId,- workflowVersionId,- }: {- workflowId: string;- workflowVersionId: string;- }): Promise<- Pick<WorkspaceWorkflow, 'coreWorkflowId' | 'coreWorkflowVersionId'>- > => {- for (let attempt = 0; attempt < 40; attempt++) {- const [mirror] = await globalThis.testDataSource.query(- `SELECT w."coreWorkflowId", v."coreWorkflowVersionId"- FROM "${SCHEMA}".workflow w- JOIN "${SCHEMA}"."workflowVersion" v ON v."workflowId" = w.id- WHERE w.id = $1 AND v.id = $2`,- [workflowId, workflowVersionId],- );-- if (mirror?.coreWorkflowId && mirror?.coreWorkflowVersionId) {- return {- coreWorkflowId: mirror.coreWorkflowId,- coreWorkflowVersionId: mirror.coreWorkflowVersionId,- };- }-- await new Promise((resolve) => setTimeout(resolve, 250));- }-- throw new Error(- `${workflowVersionId} was never linked to its core version`,- );- };-const createWorkspaceWorkflow = async (name: string,): Promise<WorkspaceWorkflow> => {- const { createWorkflow } = await graphql(- 'mutation CreateWorkflow($name: String!) { createWorkflow(data: { name: $name }) { id } }',- { name },- );- const { workflowVersions } = await graphql(- `- query FindDraftVersion($workflowId: UUID!) {- workflowVersions(filter: { workflowId: { eq: $workflowId } }) {- edges {- node {- id- }- }- }- }- `,- { workflowId: createWorkflow.id },- );- const workflowVersionId = workflowVersions.edges[0].node.id;+ const { coreWorkflowId, coreWorkflowVersionId } =+ await createCoreWorkflow({ name });- await updateWorkflowVersionTrigger({- workflowVersionId,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -179,64 +135,37 @@ describe('workflow deletion cleanup', () => {},});+ const { workspaceWorkflowVersionId } = await findCoreWorkflowVersion({+ coreWorkflowVersionId,+ });+return {- workflowId: createWorkflow.id,- workflowVersionId,- ...(await waitForCoreLink({- workflowId: createWorkflow.id,- workflowVersionId,- })),+ workflowVersionId: workspaceWorkflowVersionId!,+ coreWorkflowId,+ coreWorkflowVersionId,};};- const createStep = async ({- workflowVersionId,- stepType,- parentStepId,- }: {- workflowVersionId: string;- stepType: 'CODE' | 'FORM';- parentStepId: string;- }): Promise<WorkflowVersionStep> => {- await graphql(- `- mutation CreateStep($input: CreateWorkflowVersionStepInput!) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId,- stepType,- parentStepId,- position: { x: 200, y: 0 },- },- },- );+ const runWorkflowVersion = async (+ coreWorkflowVersionId: string,+ ): Promise<string> => {+ const response = await runCoreWorkflowVersion(coreWorkflowVersionId);- const { workflowVersion } = await graphql(- 'query FindSteps($id: UUID!) { workflowVersion(filter: { id: { eq: $id } }) { steps } }',- { id: workflowVersionId },- );+ expect(response.body.errors).toBeUndefined();- return workflowVersion.steps.find(- (step: WorkflowVersionStep) => step.type === stepType,- );+ return response.body.data.runCoreWorkflowVersion.workflowRunId;};beforeAll(async () => {deletedWorkflow = await createWorkspaceWorkflow(`${PREFIX} deleted`);keptWorkflow = await createWorkspaceWorkflow(`${PREFIX} kept`);- const codeStep = await createStep({- workflowVersionId: deletedWorkflow.workflowVersionId,+ const codeStep = await createCoreWorkflowVersionStep({+ coreWorkflowVersionId: deletedWorkflow.coreWorkflowVersionId,stepType: 'CODE',- parentStepId: 'trigger',});- const formStepOfVersion = await createStep({- workflowVersionId: deletedWorkflow.workflowVersionId,+ const formStepOfVersion = await createCoreWorkflowVersionStep({+ coreWorkflowVersionId: deletedWorkflow.coreWorkflowVersionId,stepType: 'FORM',parentStepId: codeStep.id,});@@ -244,55 +173,42 @@ describe('workflow deletion cleanup', () => {codeLogicFunctionId = codeStep.settings.input.logicFunctionId as string;formStepId = formStepOfVersion.id;- const keptCodeStep = await createStep({- workflowVersionId: keptWorkflow.workflowVersionId,+ const keptCodeStep = await createCoreWorkflowVersionStep({+ coreWorkflowVersionId: keptWorkflow.coreWorkflowVersionId,stepType: 'CODE',- parentStepId: 'trigger',});keptCodeLogicFunctionId = keptCodeStep.settings.input.logicFunctionId as string;- await graphql(- `- mutation UpdateStep($input: UpdateWorkflowVersionStepInput!) {- updateWorkflowVersionStep(input: $input) {- id- }- }- `,- {- input: {- workflowVersionId: deletedWorkflow.workflowVersionId,- step: {- ...formStepOfVersion,- settings: {- ...formStepOfVersion.settings,- input: [- {- id: randomUUID(),- name: 'note',- label: 'Note',- type: 'TEXT',- },- ],+ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId: deletedWorkflow.coreWorkflowVersionId,+ step: {+ ...formStepOfVersion,+ settings: {+ ...formStepOfVersion.settings,+ input: [+ {+ id: randomUUID(),+ name: 'note',+ label: 'Note',+ type: 'TEXT',},- },+ ],},},- );+ });- await graphql(- 'mutation Activate($workflowVersionId: UUID!) { activateWorkflowVersion(workflowVersionId: $workflowVersionId) }',- { workflowVersionId: deletedWorkflow.workflowVersionId },- );+ await activateCoreWorkflowVersion({+ coreWorkflowVersionId: deletedWorkflow.coreWorkflowVersionId,+ });const executeSpy = mockLogicFunctionExecution();try {- completedRunId = await runWorkflowVersion({- workflowVersionId: deletedWorkflow.workflowVersionId,- });+ completedRunId = await runWorkflowVersion(+ deletedWorkflow.coreWorkflowVersionId,+ );await waitForTestWorkflowRun(completedRunId,({ state }) => state?.stepInfos?.[formStepId]?.status === 'PENDING',@@ -307,17 +223,17 @@ describe('workflow deletion cleanup', () => {({ status }) => status === 'COMPLETED',);- waitingRunId = await runWorkflowVersion({- workflowVersionId: deletedWorkflow.workflowVersionId,- });+ waitingRunId = await runWorkflowVersion(+ deletedWorkflow.coreWorkflowVersionId,+ );await waitForTestWorkflowRun(waitingRunId,({ state }) => state?.stepInfos?.[formStepId]?.status === 'PENDING',);- keptRunId = await runWorkflowVersion({- workflowVersionId: keptWorkflow.workflowVersionId,- });+ keptRunId = await runWorkflowVersion(+ keptWorkflow.coreWorkflowVersionId,+ );await waitForTestWorkflowRun(keptRunId,({ status }) => status === 'COMPLETED',@@ -333,19 +249,21 @@ describe('workflow deletion cleanup', () => {[[completedRunId, waitingRunId, keptRunId, draftRunId]],);- for (const { workflowId } of [deletedWorkflow, keptWorkflow]) {- await workflowGraphqlRequest(- 'mutation Destroy($id: ID!) { destroyWorkflow(id: $id) { id } }',- { id: workflowId },- );- }+ await deleteCoreWorkflows({+ coreWorkflowIds: [+ deletedWorkflow.coreWorkflowId,+ keptWorkflow.coreWorkflowId,+ ],+ });});it('discarding a draft deletes its core version, its runs and the CODE functions only it uses', async () => {- const { createDraftFromWorkflowVersion } = await graphql(+ const { createDraftFromCoreWorkflowVersion } = await graphql(`- mutation CreateDraft($input: CreateDraftFromWorkflowVersionInput!) {- createDraftFromWorkflowVersion(input: $input) {+ mutation CreateDraft(+ $input: CreateDraftFromCoreWorkflowVersionInput!+ ) {+ createDraftFromCoreWorkflowVersion(input: $input) {idsteps}@@ -353,29 +271,24 @@ describe('workflow deletion cleanup', () => {`,{input: {- workflowId: deletedWorkflow.workflowId,- workflowVersionIdToCopy: deletedWorkflow.workflowVersionId,+ coreWorkflowId: deletedWorkflow.coreWorkflowId,+ coreWorkflowVersionIdToCopy: deletedWorkflow.coreWorkflowVersionId,},},);const draftCodeLogicFunctionId =- createDraftFromWorkflowVersion.steps.find(+ createDraftFromCoreWorkflowVersion.steps.find((step: WorkflowVersionStep) => step.type === 'CODE',).settings.input.logicFunctionId;- const { coreWorkflowVersionId: draftCoreWorkflowVersionId } =- await waitForCoreLink({- workflowId: deletedWorkflow.workflowId,- workflowVersionId: createDraftFromWorkflowVersion.id,- });+ const draftCoreWorkflowVersionId: string =+ createDraftFromCoreWorkflowVersion.id;expect(draftCodeLogicFunctionId).not.toBe(codeLogicFunctionId);const executeSpy = mockLogicFunctionExecution();try {- draftRunId = await runWorkflowVersion({- workflowVersionId: createDraftFromWorkflowVersion.id,- });+ draftRunId = await runWorkflowVersion(draftCoreWorkflowVersionId);await waitForTestWorkflowRun(draftRunId,({ state }) => state?.stepInfos?.[formStepId]?.status === 'PENDING',@@ -427,7 +340,7 @@ describe('workflow deletion cleanup', () => {),).toBe(1);- const { deleteCoreWorkflows } = await graphql(+ const { deleteCoreWorkflows: deletedCoreWorkflows } = await graphql(`mutation Delete($input: DeleteCoreWorkflowsInput!) {deleteCoreWorkflows(input: $input) {@@ -438,7 +351,7 @@ describe('workflow deletion cleanup', () => {{ input: { coreWorkflowIds: [deletedWorkflow.coreWorkflowId] } },);- expect(deleteCoreWorkflows).toEqual([+ expect(deletedCoreWorkflows).toEqual([{ id: deletedWorkflow.coreWorkflowId },]);expect(@@ -523,45 +436,33 @@ describe('workflow deletion cleanup', () => {const deferredWorkflow = await createWorkspaceWorkflow(`${PREFIX} deferred cleanup`,);- const deferredFormStep = await createStep({- workflowVersionId: deferredWorkflow.workflowVersionId,+ const deferredFormStep = await createCoreWorkflowVersionStep({+ coreWorkflowVersionId: deferredWorkflow.coreWorkflowVersionId,stepType: 'FORM',- parentStepId: 'trigger',});- await graphql(- `- mutation UpdateStep($input: UpdateWorkflowVersionStepInput!) {- updateWorkflowVersionStep(input: $input) {- id- }- }- `,- {- input: {- workflowVersionId: deferredWorkflow.workflowVersionId,- step: {- ...deferredFormStep,- settings: {- ...deferredFormStep.settings,- input: [- {- id: randomUUID(),- name: 'note',- label: 'Note',- type: 'TEXT',- },- ],+ await updateCoreWorkflowVersionStep({+ coreWorkflowVersionId: deferredWorkflow.coreWorkflowVersionId,+ step: {+ ...deferredFormStep,+ settings: {+ ...deferredFormStep.settings,+ input: [+ {+ id: randomUUID(),+ name: 'note',+ label: 'Note',+ type: 'TEXT',},- },+ ],},},- );-- const deferredRunId = await runWorkflowVersion({- workflowVersionId: deferredWorkflow.workflowVersionId,});+ const deferredRunId = await runWorkflowVersion(+ deferredWorkflow.coreWorkflowVersionId,+ );+await waitForTestWorkflowRun(deferredRunId,({ state }) =>@@ -606,10 +507,9 @@ describe('workflow deletion cleanup', () => {value: false,expectToFail: false,});- await workflowGraphqlRequest(- 'mutation Destroy($id: ID!) { destroyWorkflow(id: $id) { id } }',- { id: deferredWorkflow.workflowId },- );+ await deleteCoreWorkflows({+ coreWorkflowIds: [deferredWorkflow.coreWorkflowId],+ });}}, 120000);});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-lifecycle-core-mirror.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-lifecycle-core-mirror.integration-spec.tsindex cbc4d675ef3..903fc468d21 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-lifecycle-core-mirror.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-lifecycle-core-mirror.integration-spec.ts@@ -1,64 +1,27 @@-import request from 'supertest';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';+import {+ activateCoreWorkflowVersion,+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';-const client = request(`http://localhost:${APP_PORT}`);--const graphql = (query: string, variables?: object) =>- client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({ query, variables });-describe('workflow lifecycle core mirror with an active version (e2e)', () => {- let workflowId: string;- let alreadyDestroyed = false;-- const coreVersionRowCount = async (): Promise<number> => {- const rows = await global.testDataSource.query(- `SELECT "id" FROM core."workflowVersion"- WHERE "workspaceId" = $1 AND "workflowId" = $2`,- [SEED_APPLE_WORKSPACE_ID, workflowId],- );-- return rows.length;- };+ let coreWorkflowId: string;beforeAll(async () => {- const createResponse = await graphql(`- mutation {- createWorkflow(data: { name: "Lifecycle Mirror" }) {- id- }- }- `);-- expect(createResponse.body.errors).toBeUndefined();- workflowId = createResponse.body.data.createWorkflow.id;+ const createdCoreWorkflow = await createCoreWorkflow({+ name: 'Lifecycle Mirror',+ });- const getResponse = await graphql(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: workflowId },- );+ coreWorkflowId = createdCoreWorkflow.coreWorkflowId;- const workflowVersionId =- getResponse.body.data.workflow.versions.edges[0].node.id;+ const coreWorkflowVersionId = createdCoreWorkflow.coreWorkflowVersionId;- await updateWorkflowVersionTrigger({- workflowVersionId,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -68,53 +31,17 @@ describe('workflow lifecycle core mirror with an active version (e2e)', () => {},});- const stepResponse = await graphql(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId,- stepType: 'FIND_RECORDS',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- );-- expect(stepResponse.body.errors).toBeUndefined();-- const activateResponse = await graphql(- `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- { workflowVersionId },- );+ await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'FIND_RECORDS',+ });- expect(activateResponse.body.errors).toBeUndefined();- expect(activateResponse.body.data.activateWorkflowVersion).toBe(true);+ await activateCoreWorkflowVersion({ coreWorkflowVersionId });});afterAll(async () => {- if (workflowId && !alreadyDestroyed) {- await graphql(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workflowId },- );+ if (coreWorkflowId) {+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });}});@@ -126,65 +53,11 @@ describe('workflow lifecycle core mirror with an active version (e2e)', () => {LEFT JOIN core."workflowVersion" publishedON published.id = cw."lastPublishedCoreWorkflowVersionId"WHERE cw."workspaceId" = $1- AND cw.id IN (- SELECT cv."coreWorkflowId"- FROM core."workflowVersion" cv- WHERE cv."workspaceId" = $1- AND cv."workflowId" = $2- AND cv."coreWorkflowId" IS NOT NULL- )`,- [SEED_APPLE_WORKSPACE_ID, workflowId],+ AND cw.id = $2`,+ [SEED_APPLE_WORKSPACE_ID, coreWorkflowId],);expect(typeof rows[0]?.coreVersionId).toBe('string');expect(rows[0]?.resolves).toBe(true);});-- it('removes the core version row on delete, recreates it on restore, removes it on destroy', async () => {- // the v1 version created with the workflow is mirrored to core- expect(await coreVersionRowCount()).toBeGreaterThan(0);-- const deleteResponse = await graphql(- `- mutation DeleteWorkflow($id: ID!) {- deleteWorkflow(id: $id) {- id- }- }- `,- { id: workflowId },- );-- expect(deleteResponse.body.errors).toBeUndefined();- expect(await coreVersionRowCount()).toBe(0);-- const restoreResponse = await graphql(- `- mutation RestoreWorkflow($id: ID!) {- restoreWorkflow(id: $id) {- id- }- }- `,- { id: workflowId },- );-- expect(restoreResponse.body.errors).toBeUndefined();- expect(await coreVersionRowCount()).toBeGreaterThan(0);-- const destroyResponse = await graphql(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workflowId },- );-- expect(destroyResponse.body.errors).toBeUndefined();- alreadyDestroyed = true;- expect(await coreVersionRowCount()).toBe(0);- });});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-synchronous-parent-creation.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-synchronous-parent-creation.integration-spec.tsdeleted file mode 100644index 517da9410e6..00000000000--- a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-synchronous-parent-creation.integration-spec.ts+++ /dev/null@@ -1,66 +0,0 @@-import { randomUUID } from 'node:crypto';--import { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/get-workspace-schema-name.util';-import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';-import { workflowGraphqlRequest } from 'test/integration/graphql/suites/workflow/utils/workflow-graphql-request.util';--const schema = getWorkspaceSchemaName(SEED_APPLE_WORKSPACE_ID);--describe('synchronous workflow parent creation (e2e)', () => {- it.each(['one', 'many'] as const)(- 'creates the parent before the initial draft through create %s',- async (operation) => {- const name = `Synchronous parent ${randomUUID()}`;- const response = await workflowGraphqlRequest(- operation === 'one'- ? 'mutation Create($name: String!) { createWorkflow(data: { name: $name }) { id } }'- : 'mutation Create($name: String!) { createWorkflows(data: [{ name: $name }, { name: $name }]) { id } }',- { name },- );-- const workflows: { id: string }[] = await global.testDataSource.query(- `SELECT id FROM "${schema}".workflow WHERE name = $1`,- [name],- );-- try {- expect(response.body.errors).toBeUndefined();- expect(workflows).toHaveLength(operation === 'one' ? 1 : 2);-- for (const workflow of workflows) {- const rows = await global.testDataSource.query(- `SELECT w."coreWorkflowId", v.id AS "workspaceVersionId",- v."coreWorkflowVersionId", c."workspaceWorkflowId",- cv."coreWorkflowId" AS "versionParentId",- cv."workspaceWorkflowVersionId", cv.status- FROM "${schema}".workflow w- JOIN "${schema}"."workflowVersion" v ON v."workflowId" = w.id- LEFT JOIN core.workflow c ON c.id = w."coreWorkflowId"- LEFT JOIN core."workflowVersion" cv ON cv.id = v."coreWorkflowVersionId"- WHERE w.id = $1`,- [workflow.id],- );-- expect(rows).toHaveLength(1);- expect(rows[0].coreWorkflowId).toBeTruthy();- expect(rows[0].coreWorkflowVersionId).toBeTruthy();- expect(rows[0]).toMatchObject({- workspaceWorkflowId: workflow.id,- versionParentId: rows[0].coreWorkflowId,- workspaceWorkflowVersionId: rows[0].workspaceVersionId,- status: 'DRAFT',- });- }- } finally {- for (const workflow of workflows) {- const destroyed = await workflowGraphqlRequest(- 'mutation Destroy($id: UUID!) { destroyWorkflow(id: $id) { id } }',- { id: workflow.id },- );-- expect(destroyed.body.errors).toBeUndefined();- }- }- },- );-});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-activation-validation.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-activation-validation.integration-spec.tsindex ef2cd98c129..86c9d5a1502 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-activation-validation.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-activation-validation.integration-spec.ts@@ -1,79 +1,43 @@import request from 'supertest';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';+import {+ createCoreWorkflow,+ deleteCoreWorkflows,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';const client = request(`http://localhost:${APP_PORT}`);-const graphql = async (query: string, variables?: Record<string, unknown>) =>+const activateCoreWorkflowVersion = (coreWorkflowVersionId: string) =>client.post('/graphql').set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({ query, variables });--const graphqlOrFail = async (- query: string,- variables?: Record<string, unknown>,-) => {- const response = await graphql(query, variables);-- expect(response.body.errors).toBeUndefined();-- return response.body.data;-};--const validateWorkflowVersion = (workflowVersionId: string) =>- graphql(- `- mutation ValidateWorkflowVersion($workflowVersionId: UUID!) {- validateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- { workflowVersionId },- );--const activateWorkflowVersion = (workflowVersionId: string) =>- graphql(- `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- { workflowVersionId },- );+ .send({+ query: `+ mutation ActivateCoreWorkflowVersion($coreWorkflowVersionId: UUID!) {+ activateCoreWorkflowVersion(coreWorkflowVersionId: $coreWorkflowVersionId)+ }+ `,+ variables: { coreWorkflowVersionId },+ });describe('Workflow version activation validation (e2e)', () => {- let workflowVersionId: string;+ let coreWorkflowId: string;+ let coreWorkflowVersionId: string;beforeAll(async () => {- const createData = await graphqlOrFail(`- mutation CreateWorkflow {- createWorkflow(data: { name: "Activation validation test" }) {- id- }- }- `);+ const createdCoreWorkflow = await createCoreWorkflow({+ name: 'Activation validation test',+ });- const workflowData = await graphqlOrFail(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: createData.createWorkflow.id },- );+ coreWorkflowId = createdCoreWorkflow.coreWorkflowId;+ coreWorkflowVersionId = createdCoreWorkflow.coreWorkflowVersionId;+ });- workflowVersionId = workflowData.workflow.versions.edges[0].node.id;+ afterAll(async () => {+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });});- it('refuses to validate an empty draft, with the issues in the error', async () => {- const response = await validateWorkflowVersion(workflowVersionId);+ it('refuses to activate an empty draft, with the issues in the error', async () => {+ const response = await activateCoreWorkflowVersion(coreWorkflowVersionId);expect(response.body.errors).toBeDefined();expect(response.body.errors[0].extensions.code).toBe('BAD_USER_INPUT');@@ -82,64 +46,4 @@ describe('Workflow version activation validation (e2e)', () => {);expect(response.body.errors[0].message).toMatch(/trigger/i);});-- it('refuses activation with the same error as validation', async () => {- const response = await activateWorkflowVersion(workflowVersionId);-- expect(response.body.errors).toBeDefined();- expect(response.body.errors[0].extensions.subCode).toBe(- 'NON_ACTIVABLE_WORKFLOW_VERSION',- );- });-- it('validates a version whose trigger and steps are complete without activating it', async () => {- await updateWorkflowVersionTrigger({- workflowVersionId,- trigger: {- name: 'Manual Trigger',- type: 'MANUAL',- settings: { outputSchema: {} },- nextStepIds: [],- position: { x: 0, y: 0 },- },- });-- await graphqlOrFail(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId,- stepType: 'CREATE_RECORD',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- );-- const response = await validateWorkflowVersion(workflowVersionId);-- expect(response.body.errors).toBeUndefined();- expect(response.body.data.validateWorkflowVersion).toBe(true);-- const statusData = await graphqlOrFail(- `- query GetWorkflowVersion($id: UUID!) {- workflowVersion(filter: { id: { eq: $id } }) {- status- }- }- `,- { id: workflowVersionId },- );-- expect(statusData.workflowVersion.status).toBe('DRAFT');- });});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-content.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-content.integration-spec.tsdeleted file mode 100644index 3f0b5e4f8f0..00000000000--- a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-content.integration-spec.ts+++ /dev/null@@ -1,97 +0,0 @@-import request from 'supertest';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';--const client = request(`http://localhost:${APP_PORT}`);--const graphql = (query: string, variables?: object) =>- client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({ query, variables });--describe('workflowVersionContent (e2e)', () => {- let workflowId: string;- let workflowVersionId: string;-- beforeAll(async () => {- const createResponse = await graphql(`- mutation {- createWorkflow(data: { name: "Version Content Query" }) {- id- }- }- `);-- expect(createResponse.body.errors).toBeUndefined();- workflowId = createResponse.body.data.createWorkflow.id;-- const getResponse = await graphql(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: workflowId },- );-- workflowVersionId =- getResponse.body.data.workflow.versions.edges[0].node.id;-- await updateWorkflowVersionTrigger({- workflowVersionId,- trigger: {- name: 'Content Query Trigger',- type: 'MANUAL',- settings: { outputSchema: {} },- nextStepIds: [],- position: { x: 0, y: 0 },- },- });- });-- afterAll(async () => {- if (workflowId) {- await graphql(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workflowId },- );- }- });-- it('returns the version trigger and steps', async () => {- const contentResponse = await graphql(- `- query GetWorkflowVersionContent($workflowVersionId: UUID!) {- workflowVersionContent(workflowVersionId: $workflowVersionId) {- workflowVersionId- trigger- steps- }- }- `,- { workflowVersionId },- );-- expect(contentResponse.body.errors).toBeUndefined();-- const content = contentResponse.body.data.workflowVersionContent;-- expect(content.workflowVersionId).toBe(workflowVersionId);- expect(content.trigger.name).toBe('Content Query Trigger');- expect(content.trigger.type).toBe('MANUAL');- });-});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-core-workflow-id.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-core-workflow-id.integration-spec.tsdeleted file mode 100644index 968415a294b..00000000000--- a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-core-workflow-id.integration-spec.ts+++ /dev/null@@ -1,151 +0,0 @@-import request from 'supertest';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';-import { assertIsDefinedOrThrow, isDefined } from 'twenty-shared/utils';--import { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/get-workspace-schema-name.util';-import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';--const client = request(`http://localhost:${APP_PORT}`);--const graphql = (query: string, variables?: object) =>- client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({ query, variables });--const WORKSPACE_SCHEMA = getWorkspaceSchemaName(SEED_APPLE_WORKSPACE_ID);--const POLL_ATTEMPTS = 20;-const POLL_INTERVAL_MS = 250;--describe('workflow version core workflow id dual write (e2e)', () => {- let workflowId: string;- let workflowVersionId: string;-- const fetchWorkspaceCoreWorkflowId = async (): Promise<- string | null | undefined- > => {- const rows = await global.testDataSource.query(- `SELECT "coreWorkflowId" FROM "${WORKSPACE_SCHEMA}"."workflow" WHERE "id" = $1`,- [workflowId],- );-- return rows[0]?.coreWorkflowId;- };-- const waitForWorkspaceCoreWorkflowId = async (): Promise<- string | null | undefined- > => {- for (let attempt = 0; attempt < POLL_ATTEMPTS; attempt++) {- const coreWorkflowId = await fetchWorkspaceCoreWorkflowId();-- if (isDefined(coreWorkflowId)) {- return coreWorkflowId;- }-- await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));- }-- return fetchWorkspaceCoreWorkflowId();- };-- const countCoreVersionRowsPointingAt = async (- coreWorkflowId: string,- ): Promise<number> => {- const rows = await global.testDataSource.query(- `SELECT cv."id" FROM core."workflowVersion" cv- JOIN core."workflow" cw ON cw."id" = cv."coreWorkflowId"- WHERE cv."workspaceId" = $1- AND cv."workflowId" = $2- AND cv."coreWorkflowId" = $3`,- [SEED_APPLE_WORKSPACE_ID, workflowId, coreWorkflowId],- );-- return rows.length;- };-- const waitForCoreVersionRowsPointingAt = async (- coreWorkflowId: string,- ): Promise<number> => {- for (let attempt = 0; attempt < POLL_ATTEMPTS; attempt++) {- const count = await countCoreVersionRowsPointingAt(coreWorkflowId);-- if (count > 0) {- return count;- }-- await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));- }-- return countCoreVersionRowsPointingAt(coreWorkflowId);- };-- beforeAll(async () => {- const createResponse = await graphql(`- mutation {- createWorkflow(data: { name: "Core Workflow Id Dual Write" }) {- id- }- }- `);-- expect(createResponse.body.errors).toBeUndefined();- workflowId = createResponse.body.data.createWorkflow.id;-- const getResponse = await graphql(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: workflowId },- );-- workflowVersionId =- getResponse.body.data.workflow.versions.edges[0].node.id;- });-- afterAll(async () => {- if (workflowId) {- await graphql(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workflowId },- );- }- });-- it('stamps the core version row with the core workflow id on mirror writes', async () => {- const coreWorkflowId = await waitForWorkspaceCoreWorkflowId();-- assertIsDefinedOrThrow(coreWorkflowId);-- await updateWorkflowVersionTrigger({- workflowVersionId,- trigger: {- name: 'Manual Trigger',- type: 'MANUAL',- settings: { outputSchema: {} },- nextStepIds: [],- position: { x: 0, y: 0 },- },- });-- expect(- await waitForCoreVersionRowsPointingAt(coreWorkflowId),- ).toBeGreaterThan(0);- });-});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-discard-draft-core-mirror.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-discard-draft-core-mirror.integration-spec.tsindex 15da9efcc57..c1fc95fbbdd 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-discard-draft-core-mirror.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-discard-draft-core-mirror.integration-spec.ts@@ -1,62 +1,37 @@-import request from 'supertest';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';+import {+ activateCoreWorkflowVersion,+ coreWorkflowGraphqlRequest,+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';-const client = request(`http://localhost:${APP_PORT}`);--const graphql = (query: string, variables?: object) =>- client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({ query, variables });-describe('discard draft workflow version core mirror (e2e)', () => {- let workflowId: string;- let firstVersionId: string;+ let coreWorkflowId: string;let draftVersionId: string;const coreVersions = async (): Promise<{ id: string; status: string }[]> => {return global.testDataSource.query(`SELECT "id", "status" FROM core."workflowVersion"- WHERE "workspaceId" = $1 AND "workflowId" = $2`,- [SEED_APPLE_WORKSPACE_ID, workflowId],+ WHERE "workspaceId" = $1 AND "coreWorkflowId" = $2`,+ [SEED_APPLE_WORKSPACE_ID, coreWorkflowId],);};beforeAll(async () => {- const createResponse = await graphql(`- mutation {- createWorkflow(data: { name: "Discard Draft Mirror" }) {- id- }- }- `);-- expect(createResponse.body.errors).toBeUndefined();- workflowId = createResponse.body.data.createWorkflow.id;-- const getResponse = await graphql(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: workflowId },- );+ const createdCoreWorkflow = await createCoreWorkflow({+ name: 'Discard Draft Mirror',+ });++ coreWorkflowId = createdCoreWorkflow.coreWorkflowId;- firstVersionId = getResponse.body.data.workflow.versions.edges[0].node.id;+ const firstVersionId = createdCoreWorkflow.coreWorkflowVersionId;- await updateWorkflowVersionTrigger({- workflowVersionId: firstVersionId,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId: firstVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -66,76 +41,46 @@ describe('discard draft workflow version core mirror (e2e)', () => {},});- const stepResponse = await graphql(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId: firstVersionId,- stepType: 'FIND_RECORDS',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- );-- expect(stepResponse.body.errors).toBeUndefined();-- const activateResponse = await graphql(- `- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)- }- `,- { workflowVersionId: firstVersionId },- );+ await createCoreWorkflowVersionStep({+ coreWorkflowVersionId: firstVersionId,+ stepType: 'FIND_RECORDS',+ });- expect(activateResponse.body.errors).toBeUndefined();+ await activateCoreWorkflowVersion({+ coreWorkflowVersionId: firstVersionId,+ });- const draftResponse = await graphql(- `- mutation CreateDraft($input: CreateDraftFromWorkflowVersionInput!) {- createDraftFromWorkflowVersion(input: $input) {- id+ const { createDraftFromCoreWorkflowVersion: draftVersion } =+ await coreWorkflowGraphqlRequest<{+ createDraftFromCoreWorkflowVersion: { id: string };+ }>({+ query: `+ mutation CreateDraft(+ $input: CreateDraftFromCoreWorkflowVersionInput!+ ) {+ createDraftFromCoreWorkflowVersion(input: $input) {+ id+ }}- }- `,- {- input: {- workflowId,- workflowVersionIdToCopy: firstVersionId,+ `,+ variables: {+ input: {+ coreWorkflowId,+ coreWorkflowVersionIdToCopy: firstVersionId,+ },},- },- );+ });- expect(draftResponse.body.errors).toBeUndefined();- draftVersionId = draftResponse.body.data.createDraftFromWorkflowVersion.id;+ draftVersionId = draftVersion.id;});afterAll(async () => {- if (workflowId) {- await graphql(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workflowId },- );+ if (coreWorkflowId) {+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });}});it('removes only the discarded draft core row, keeping the active version', async () => {- // the active version and the new draft are both mirrored to coreconst versionsBefore = await coreVersions();expect(versionsBefore.map((version) => version.status).sort()).toEqual([@@ -151,20 +96,18 @@ describe('discard draft workflow version core mirror (e2e)', () => {)?.id;expect(activeCoreId).toBeDefined();- expect(draftCoreId).toBeDefined();+ expect(draftCoreId).toBe(draftVersionId);- const deleteResponse = await graphql(- `- mutation DeleteWorkflowVersion($id: ID!) {- deleteWorkflowVersion(id: $id) {+ await coreWorkflowGraphqlRequest({+ query: `+ mutation Discard($input: DiscardCoreWorkflowDraftInput!) {+ discardCoreWorkflowDraft(input: $input) {id}}`,- { id: draftVersionId },- );-- expect(deleteResponse.body.errors).toBeUndefined();+ variables: { input: { coreWorkflowVersionId: draftVersionId } },+ });const versionsAfter = await coreVersions();diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-malformed-validation.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-malformed-validation.integration-spec.tsindex 868c0164a78..4e4d22e5439 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-malformed-validation.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-malformed-validation.integration-spec.ts@@ -1,23 +1,18 @@import request from 'supertest';-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';+import {+ createCoreWorkflow,+ createCoreWorkflowVersionStep,+ deleteCoreWorkflows,+ findCoreWorkflowVersion,+ updateCoreWorkflowVersionTrigger,+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';import { makeGraphqlApiRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';import { updateOneOperationFactory } from 'test/integration/graphql/utils/update-one-operation-factory.util';const client = request(`http://localhost:${APP_PORT}`);-const graphql = async (query: string, variables?: Record<string, unknown>) => {- const response = await client- .post('/graphql')- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)- .send({ query, variables });-- expect(response.body.errors).toBeUndefined();-- return response.body.data;-};-const updateStepResponse = (- workflowVersionId: string,+ coreWorkflowVersionId: string,step: Record<string, unknown>,) =>client@@ -25,19 +20,21 @@ const updateStepResponse = (.set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`).send({query: `- mutation UpdateWorkflowVersionStep(- $input: UpdateWorkflowVersionStepInput!+ mutation UpdateCoreWorkflowVersionStep(+ $input: UpdateCoreWorkflowVersionStepInput!) {- updateWorkflowVersionStep(input: $input) {+ updateCoreWorkflowVersionStep(input: $input) {id}}`,- variables: { input: { workflowVersionId, step } },+ variables: { input: { coreWorkflowVersionId, step } },});describe('Workflow version malformed validation (e2e)', () => {- let workflowVersionId: string;+ let coreWorkflowId: string;+ let coreWorkflowVersionId: string;+ let workspaceWorkflowVersionId: string | null;let createRecordStep: {id: string;settings: { input: Record<string, unknown> };@@ -48,35 +45,15 @@ describe('Workflow version malformed validation (e2e)', () => {};beforeAll(async () => {- const createData = await graphql(`- mutation CreateWorkflow {- createWorkflow(data: { name: "Malformed validation test" }) {- id- }- }- `);-- const workflowData = await graphql(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: createData.createWorkflow.id },- );+ const createdCoreWorkflow = await createCoreWorkflow({+ name: 'Malformed validation test',+ });- workflowVersionId = workflowData.workflow.versions.edges[0].node.id;+ coreWorkflowId = createdCoreWorkflow.coreWorkflowId;+ coreWorkflowVersionId = createdCoreWorkflow.coreWorkflowVersionId;- await updateWorkflowVersionTrigger({- workflowVersionId,+ await updateCoreWorkflowVersionTrigger({+ coreWorkflowVersionId,trigger: {name: 'Manual Trigger',type: 'MANUAL',@@ -86,63 +63,26 @@ describe('Workflow version malformed validation (e2e)', () => {},});- await graphql(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId,- stepType: 'CREATE_RECORD',- parentStepId: 'trigger',- position: { x: 200, y: 0 },- },- },- );+ createRecordStep = await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'CREATE_RECORD',+ });- await graphql(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- {- input: {- workflowVersionId,- stepType: 'SEND_EMAIL',- parentStepId: 'trigger',- position: { x: 400, y: 0 },- },- },- );+ sendEmailStep = await createCoreWorkflowVersionStep({+ coreWorkflowVersionId,+ stepType: 'SEND_EMAIL',+ position: { x: 400, y: 0 },+ });- const stepsData = await graphql(- `- query GetWorkflowVersion($id: UUID!) {- workflowVersion(filter: { id: { eq: $id } }) {- steps- }- }- `,- { id: workflowVersionId },- );+ const coreWorkflowVersion = await findCoreWorkflowVersion({+ coreWorkflowVersionId,+ });- createRecordStep = stepsData.workflowVersion.steps.find(- (step: { type: string }) => step.type === 'CREATE_RECORD',- );- sendEmailStep = stepsData.workflowVersion.steps.find(- (step: { type: string }) => step.type === 'SEND_EMAIL',- );+ workspaceWorkflowVersionId = coreWorkflowVersion.workspaceWorkflowVersionId;+ });++ afterAll(async () => {+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });});const sendEmailStepWithBody = (body: string) => ({@@ -156,14 +96,12 @@ describe('Workflow version malformed validation (e2e)', () => {it('rejects an email body saved as HTML or plain text', async () => {for (const body of ['<p>Hello</p>', 'Hello {{trigger.name}},\n\nBye']) {const response = await updateStepResponse(- workflowVersionId,+ coreWorkflowVersionId,sendEmailStepWithBody(body),);expect(response.body.errors).toBeDefined();- expect(response.body.errors[0].extensions.subCode).toBe(- 'MALFORMED_WORKFLOW_VERSION',- );+ expect(response.body.errors[0].extensions.code).toBe('FORBIDDEN');expect(response.body.errors[0].message).toContain('must be a serialized email document',);@@ -172,7 +110,7 @@ describe('Workflow version malformed validation (e2e)', () => {it('accepts an email body saved as an email document', async () => {const response = await updateStepResponse(- workflowVersionId,+ coreWorkflowVersionId,sendEmailStepWithBody(JSON.stringify({type: 'doc',@@ -194,7 +132,7 @@ describe('Workflow version malformed validation (e2e)', () => {it('rejects a bare-string rich text value at write time', async () => {const response = await updateStepResponse(- workflowVersionId,+ coreWorkflowVersionId,stepWithInput({objectName: 'note',objectRecord: { bodyV2: 'a plain string' },@@ -202,29 +140,24 @@ describe('Workflow version malformed validation (e2e)', () => {);expect(response.body.errors).toBeDefined();- expect(response.body.errors[0].extensions.code).toBe('BAD_USER_INPUT');- expect(response.body.errors[0].extensions.subCode).toBe(- 'MALFORMED_WORKFLOW_VERSION',- );+ expect(response.body.errors[0].extensions.code).toBe('FORBIDDEN');expect(response.body.errors[0].message).toMatch(/rich text/i);});it('rejects a record step targeting an unknown object', async () => {const response = await updateStepResponse(- workflowVersionId,+ coreWorkflowVersionId,stepWithInput({ objectName: 'ghost', objectRecord: {} }),);expect(response.body.errors).toBeDefined();- expect(response.body.errors[0].extensions.subCode).toBe(- 'MALFORMED_WORKFLOW_VERSION',- );+ expect(response.body.errors[0].extensions.code).toBe('FORBIDDEN');expect(response.body.errors[0].message).toContain('does not exist');});it('accepts a valid rich text object', async () => {const response = await updateStepResponse(- workflowVersionId,+ coreWorkflowVersionId,stepWithInput({objectName: 'note',objectRecord: { bodyV2: { markdown: 'hello', blocknote: null } },@@ -232,14 +165,14 @@ describe('Workflow version malformed validation (e2e)', () => {);expect(response.body.errors).toBeUndefined();- expect(response.body.data.updateWorkflowVersionStep.id).toBe(+ expect(response.body.data.updateCoreWorkflowVersionStep.id).toBe(createRecordStep.id,);});it('accepts an incomplete record step whose fields are not filled in yet', async () => {const response = await updateStepResponse(- workflowVersionId,+ coreWorkflowVersionId,stepWithInput({ objectName: 'note', objectRecord: {} }),);@@ -250,7 +183,7 @@ describe('Workflow version malformed validation (e2e)', () => {const operation = updateOneOperationFactory({objectMetadataSingularName: 'workflowVersion',gqlFields: 'id',- recordId: workflowVersionId,+ recordId: workspaceWorkflowVersionId!,data: { steps: [] },});diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-step-type-change.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-step-type-change.integration-spec.tsindex 67111ff6363..e521b7d06d0 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-step-type-change.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-version-step-type-change.integration-spec.ts@@ -1,4 +1,3 @@-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';import { workflowGraphqlRequest } from 'test/integration/graphql/suites/workflow/utils/workflow-graphql-request.util';import { isDefined } from 'twenty-shared/utils';import { v4 } from 'uuid';@@ -20,7 +19,6 @@ type CreateStepInput = {};type WorkflowBuilderApi = {- name: string;createDraftVersion: () => Promise<{ workflowId: string; versionId: string }>;getSteps: (versionId: string) => Promise<WorkflowStep[]>;createStep: (versionId: string, input: CreateStepInput) => Promise<void>;@@ -43,125 +41,10 @@ const expectNoErrors = (body: { errors?: unknown }) => {expect(body.errors).toBeUndefined();};-const buildWorkspaceApi = (): WorkflowBuilderApi => {- const workflowIds: string[] = [];-- return {- name: 'workspace workflow version API',- createDraftVersion: async () => {- const createResponse = await workflowGraphqlRequest(`- mutation CreateWorkflow {- createWorkflow(data: { name: "Step type change test" }) {- id- }- }- `);-- expectNoErrors(createResponse.body);-- const workflowId = createResponse.body.data.createWorkflow.id;-- workflowIds.push(workflowId);-- const workflowResponse = await workflowGraphqlRequest(- `- query GetWorkflow($id: UUID!) {- workflow(filter: { id: { eq: $id } }) {- versions {- edges {- node {- id- }- }- }- }- }- `,- { id: workflowId },- );-- expectNoErrors(workflowResponse.body);-- const versionId =- workflowResponse.body.data.workflow.versions.edges[0].node.id;-- await updateWorkflowVersionTrigger({- workflowVersionId: versionId,- trigger: MANUAL_TRIGGER,- });-- return { workflowId, versionId };- },- getSteps: async (versionId) => {- const response = await workflowGraphqlRequest(- `- query GetWorkflowVersion($id: UUID!) {- workflowVersion(filter: { id: { eq: $id } }) {- steps- }- }- `,- { id: versionId },- );-- expectNoErrors(response.body);-- return response.body.data.workflowVersion.steps;- },- createStep: async (versionId, input) => {- const response = await workflowGraphqlRequest(- `- mutation CreateWorkflowVersionStep(- $input: CreateWorkflowVersionStepInput!- ) {- createWorkflowVersionStep(input: $input) {- stepsDiff- }- }- `,- { input: { workflowVersionId: versionId, ...input } },- );-- expectNoErrors(response.body);- },- updateStep: async (versionId, step) => {- const response = await workflowGraphqlRequest(- `- mutation UpdateWorkflowVersionStep(- $input: UpdateWorkflowVersionStepInput!- ) {- updateWorkflowVersionStep(input: $input) {- id- }- }- `,- { input: { workflowVersionId: versionId, step } },- );-- return response.body;- },- cleanup: async () => {- for (const workflowId of workflowIds) {- await workflowGraphqlRequest(- `- mutation DestroyWorkflow($id: ID!) {- destroyWorkflow(id: $id) {- id- }- }- `,- { id: workflowId },- );- }- },- };-};-const buildCoreApi = (): WorkflowBuilderApi => {const coreWorkflowIds: string[] = [];return {- name: 'core workflow version API',createDraftVersion: async () => {const createResponse = await workflowGraphqlRequest(`mutation {@@ -315,62 +198,61 @@ const changeStepTypeToIterator = async (expect(loopPlaceholderStep.nextStepIds).toEqual([existingStep.id]);};-describe.each([buildWorkspaceApi(), buildCoreApi()])(- 'Workflow version step type change through the $name (e2e)',- (api) => {- afterAll(async () => {- await api.cleanup();- });+describe('Workflow version step type change into Iterator (e2e)', () => {+ const api = buildCoreApi();- it('converts an If/Else branch placeholder into an Iterator', async () => {- const { versionId } = await api.createDraftVersion();- const ifElseStepId = v4();-- await api.createStep(versionId, {- id: ifElseStepId,- stepType: 'IF_ELSE',- parentStepId: 'trigger',- position: { x: 0, y: 200 },- });-- const steps = await api.getSteps(versionId);- const ifElseStep = findStepOrThrow(steps, ifElseStepId);- const branches = ifElseStep.settings.input.branches as {- nextStepIds: string[];- }[];- const branchPlaceholderStep = findStepOrThrow(- steps,- branches[0].nextStepIds[0],- );+ afterAll(async () => {+ await api.cleanup();+ });- expect(branchPlaceholderStep.type).toBe('EMPTY');+ it('converts an If/Else branch placeholder into an Iterator', async () => {+ const { versionId } = await api.createDraftVersion();+ const ifElseStepId = v4();- await changeStepTypeToIterator(api, versionId, branchPlaceholderStep);+ await api.createStep(versionId, {+ id: ifElseStepId,+ stepType: 'IF_ELSE',+ parentStepId: 'trigger',+ position: { x: 0, y: 200 },});- it('changes an existing step into an Iterator', async () => {- const { versionId } = await api.createDraftVersion();- const delayStepId = v4();+ const steps = await api.getSteps(versionId);+ const ifElseStep = findStepOrThrow(steps, ifElseStepId);+ const branches = ifElseStep.settings.input.branches as {+ nextStepIds: string[];+ }[];+ const branchPlaceholderStep = findStepOrThrow(+ steps,+ branches[0].nextStepIds[0],+ );- await api.createStep(versionId, {- id: delayStepId,- stepType: 'DELAY',- parentStepId: 'trigger',- position: { x: 0, y: 200 },- });+ expect(branchPlaceholderStep.type).toBe('EMPTY');- const delayStep = findStepOrThrow(- await api.getSteps(versionId),- delayStepId,- );+ await changeStepTypeToIterator(api, versionId, branchPlaceholderStep);+ });++ it('changes an existing step into an Iterator', async () => {+ const { versionId } = await api.createDraftVersion();+ const delayStepId = v4();- await changeStepTypeToIterator(api, versionId, delayStep);+ await api.createStep(versionId, {+ id: delayStepId,+ stepType: 'DELAY',+ parentStepId: 'trigger',+ position: { x: 0, y: 200 },});- },-);++ const delayStep = findStepOrThrow(+ await api.getSteps(versionId),+ delayStepId,+ );++ await changeStepTypeToIterator(api, versionId, delayStep);+ });+});describe('Workflow version step type change into Code (e2e)', () => {- const api = buildWorkspaceApi();+ const api = buildCoreApi();afterAll(async () => {await api.cleanup();@@ -390,32 +272,39 @@ describe('Workflow version step type change into Code (e2e)', () => {const activateResponse = await workflowGraphqlRequest(`- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {- activateWorkflowVersion(workflowVersionId: $workflowVersionId)+ mutation ActivateCoreWorkflowVersion($coreWorkflowVersionId: UUID!) {+ activateCoreWorkflowVersion(+ coreWorkflowVersionId: $coreWorkflowVersionId+ )}`,- { workflowVersionId: publishedVersionId },+ { coreWorkflowVersionId: publishedVersionId },);expectNoErrors(activateResponse.body);const draftResponse = await workflowGraphqlRequest(`- mutation CreateDraftFromWorkflowVersion(- $input: CreateDraftFromWorkflowVersionInput!+ mutation CreateDraftFromCoreWorkflowVersion(+ $input: CreateDraftFromCoreWorkflowVersionInput!) {- createDraftFromWorkflowVersion(input: $input) {+ createDraftFromCoreWorkflowVersion(input: $input) {id}}`,- { input: { workflowId, workflowVersionIdToCopy: publishedVersionId } },+ {+ input: {+ coreWorkflowId: workflowId,+ coreWorkflowVersionIdToCopy: publishedVersionId,+ },+ },);expectNoErrors(draftResponse.body);const draftVersionId =- draftResponse.body.data.createDraftFromWorkflowVersion.id;+ draftResponse.body.data.createDraftFromCoreWorkflowVersion.id;const draftCodeStep = findStepOrThrow(await api.getSteps(draftVersionId),diff --git a/packages/twenty-server/test/integration/utils/create-workflow-test-services.ts b/packages/twenty-server/test/integration/utils/create-workflow-test-services.tsindex 3053cc69693..a85c330b467 100644--- a/packages/twenty-server/test/integration/utils/create-workflow-test-services.ts+++ b/packages/twenty-server/test/integration/utils/create-workflow-test-services.ts@@ -4,7 +4,6 @@ import { type DataSource } from 'typeorm';import { WorkspaceService } from 'src/engine/core-modules/workspace/services/workspace.service';import { ApplicationService } from 'src/engine/core-modules/application/application.service';import { UserWorkspaceService } from 'src/engine/core-modules/user-workspace/user-workspace.service';-import { FeatureFlagService } from 'src/engine/core-modules/feature-flag/services/feature-flag.service';import { type INestApplication } from '@nestjs/common';import { BillingUsageService } from 'src/engine/core-modules/billing/services/billing-usage.service';@@ -24,7 +23,6 @@ export const createWorkflowTestServices = (app: INestApplication) => ({workspace: app.get(WorkspaceService),application: app.get(ApplicationService),userWorkspace: app.get(UserWorkspaceService),- flags: app.get(FeatureFlagService),workspaceCache: app.get(WorkspaceCacheService),upgradeState: UpgradeAwareRepositoryState.getInstance(),backfill: app.get(BackfillWorkflowExecutionCoreIdsCommand),