mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-21 11:49:59 +00:00
fix(editor): Implement dirty nodes for partial executions (#11739)
Co-authored-by: Danny Martini <danny@n8n.io>
This commit is contained in:
committed by
GitHub
parent
57d3269e40
commit
b8da4ff9ed
@@ -200,6 +200,7 @@ export interface IStartRunData {
|
||||
startNodes?: StartNodeData[];
|
||||
destinationNode?: string;
|
||||
runData?: IRunData;
|
||||
dirtyNodeNames?: string[];
|
||||
}
|
||||
|
||||
export interface ITableData {
|
||||
|
||||
@@ -2,7 +2,13 @@ import { setActivePinia } from 'pinia';
|
||||
import { createTestingPinia } from '@pinia/testing';
|
||||
import { useRouter } from 'vue-router';
|
||||
import type router from 'vue-router';
|
||||
import { ExpressionError, type IPinData, type IRunData, type Workflow } from 'n8n-workflow';
|
||||
import {
|
||||
ExpressionError,
|
||||
type IPinData,
|
||||
type IRunData,
|
||||
type Workflow,
|
||||
type IExecuteData,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { useRootStore } from '@/stores/root.store';
|
||||
import { useRunWorkflow } from '@/composables/useRunWorkflow';
|
||||
@@ -28,6 +34,8 @@ vi.mock('@/stores/workflows.store', () => ({
|
||||
getNodeByName: vi.fn(),
|
||||
getExecution: vi.fn(),
|
||||
nodeIssuesExit: vi.fn(),
|
||||
checkIfNodeHasChatParent: vi.fn(),
|
||||
getParametersLastUpdate: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
@@ -69,6 +77,7 @@ vi.mock('@/composables/useWorkflowHelpers', () => ({
|
||||
saveCurrentWorkflow: vi.fn(),
|
||||
getWorkflowDataToSave: vi.fn(),
|
||||
setDocumentTitle: vi.fn(),
|
||||
executeData: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
@@ -262,6 +271,60 @@ describe('useRunWorkflow({ router })', () => {
|
||||
expect(result).toEqual(mockExecutionResponse);
|
||||
});
|
||||
|
||||
it('should send dirty nodes for partial executions', async () => {
|
||||
vi.mocked(useLocalStorage).mockReturnValueOnce(ref(1));
|
||||
const composable = useRunWorkflow({ router });
|
||||
const parentName = 'When clicking';
|
||||
const executeName = 'Code';
|
||||
vi.mocked(workflowsStore).getWorkflowRunData = {
|
||||
[parentName]: [
|
||||
{
|
||||
startTime: 1,
|
||||
executionTime: 0,
|
||||
source: [],
|
||||
},
|
||||
],
|
||||
[executeName]: [
|
||||
{
|
||||
startTime: 1,
|
||||
executionTime: 8,
|
||||
source: [
|
||||
{
|
||||
previousNode: parentName,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
vi.mocked(workflowHelpers).getCurrentWorkflow.mockReturnValue({
|
||||
name: 'Test Workflow',
|
||||
getParentNodes: () => [parentName],
|
||||
nodes: { [parentName]: {} },
|
||||
} as unknown as Workflow);
|
||||
vi.mocked(workflowHelpers).getWorkflowDataToSave.mockResolvedValue({
|
||||
nodes: [],
|
||||
} as unknown as IWorkflowData);
|
||||
vi.mocked(workflowHelpers).executeData.mockResolvedValue({
|
||||
data: {},
|
||||
node: {},
|
||||
source: null,
|
||||
} as IExecuteData);
|
||||
|
||||
vi.mocked(workflowsStore).checkIfNodeHasChatParent.mockReturnValue(false);
|
||||
vi.mocked(workflowsStore).getParametersLastUpdate.mockImplementation((name: string) => {
|
||||
if (name === executeName) return 2;
|
||||
return undefined;
|
||||
});
|
||||
|
||||
const { runWorkflow } = composable;
|
||||
|
||||
await runWorkflow({ destinationNode: 'Code 1', source: 'Node.executeNode' });
|
||||
|
||||
expect(workflowsStore.runWorkflow).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ dirtyNodeNames: [executeName] }),
|
||||
);
|
||||
});
|
||||
|
||||
it('does not use the original run data if `PartialExecution.version` is set to 0', async () => {
|
||||
// ARRANGE
|
||||
const mockExecutionResponse = { executionId: '123' };
|
||||
|
||||
@@ -37,6 +37,25 @@ import { get } from 'lodash-es';
|
||||
import { useExecutionsStore } from '@/stores/executions.store';
|
||||
import { useLocalStorage } from '@vueuse/core';
|
||||
|
||||
const getDirtyNodeNames = (
|
||||
runData: IRunData,
|
||||
getParametersLastUpdate: (nodeName: string) => number | undefined,
|
||||
): string[] | undefined => {
|
||||
const dirtyNodeNames = Object.entries(runData).reduce<string[]>((acc, [nodeName, tasks]) => {
|
||||
if (!tasks.length) return acc;
|
||||
|
||||
const updatedAt = getParametersLastUpdate(nodeName) ?? 0;
|
||||
|
||||
if (updatedAt > tasks[0].startTime) {
|
||||
acc.push(nodeName);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
return dirtyNodeNames.length ? dirtyNodeNames : undefined;
|
||||
};
|
||||
|
||||
export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof useRouter> }) {
|
||||
const nodeHelpers = useNodeHelpers();
|
||||
const workflowHelpers = useWorkflowHelpers({ router: useRunWorkflowOpts.router });
|
||||
@@ -244,6 +263,13 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
|
||||
startRunData.destinationNode = options.destinationNode;
|
||||
}
|
||||
|
||||
if (startRunData.runData) {
|
||||
startRunData.dirtyNodeNames = getDirtyNodeNames(
|
||||
startRunData.runData,
|
||||
workflowsStore.getParametersLastUpdate,
|
||||
);
|
||||
}
|
||||
|
||||
// Init the execution data to represent the start of the execution
|
||||
// that data which gets reused is already set and data of newly executed
|
||||
// nodes can be added as it gets pushed in
|
||||
|
||||
@@ -618,6 +618,51 @@ describe('useWorkflowsStore', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('setNodeValue()', () => {
|
||||
it('should update a node', () => {
|
||||
const nodeName = 'Edit Fields';
|
||||
workflowsStore.addNode({
|
||||
parameters: {},
|
||||
id: '554c7ff4-7ee2-407c-8931-e34234c5056a',
|
||||
name: nodeName,
|
||||
type: 'n8n-nodes-base.set',
|
||||
position: [680, 180],
|
||||
typeVersion: 3.4,
|
||||
});
|
||||
|
||||
expect(workflowsStore.nodeMetadata[nodeName].parametersLastUpdatedAt).toBe(undefined);
|
||||
|
||||
workflowsStore.setNodeValue({ name: 'Edit Fields', key: 'executeOnce', value: true });
|
||||
|
||||
expect(workflowsStore.workflow.nodes[0].executeOnce).toBe(true);
|
||||
expect(workflowsStore.nodeMetadata[nodeName].parametersLastUpdatedAt).toEqual(
|
||||
expect.any(Number),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setNodePositionById()', () => {
|
||||
it('should NOT update parametersLastUpdatedAt', () => {
|
||||
const nodeName = 'Edit Fields';
|
||||
const nodeId = '554c7ff4-7ee2-407c-8931-e34234c5056a';
|
||||
workflowsStore.addNode({
|
||||
parameters: {},
|
||||
id: nodeId,
|
||||
name: nodeName,
|
||||
type: 'n8n-nodes-base.set',
|
||||
position: [680, 180],
|
||||
typeVersion: 3.4,
|
||||
});
|
||||
|
||||
expect(workflowsStore.nodeMetadata[nodeName].parametersLastUpdatedAt).toBe(undefined);
|
||||
|
||||
workflowsStore.setNodePositionById(nodeId, [0, 0]);
|
||||
|
||||
expect(workflowsStore.workflow.nodes[0].position).toStrictEqual([0, 0]);
|
||||
expect(workflowsStore.nodeMetadata[nodeName].parametersLastUpdatedAt).toBe(undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function getMockEditFieldsNode() {
|
||||
|
||||
@@ -1200,6 +1200,10 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => {
|
||||
updateNodeAtIndex(nodeIndex, {
|
||||
[updateInformation.key]: updateInformation.value,
|
||||
});
|
||||
|
||||
if (updateInformation.key !== 'position') {
|
||||
nodeMetadata.value[workflow.value.nodes[nodeIndex].name].parametersLastUpdatedAt = Date.now();
|
||||
}
|
||||
}
|
||||
|
||||
function setNodeParameters(updateInformation: IUpdateInformation, append?: boolean): void {
|
||||
|
||||
Reference in New Issue
Block a user