fix(editor): Fix issue that double incoming connection often does not resolve expression (no-changelog) (#7257)

Cherry-picked from AI Tool Creation branch

---------

Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Alex Grozav 2023-09-26 14:33:42 +01:00 committed by GitHub
parent 4b014286cf
commit 0824800dff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 238 additions and 8 deletions

View file

@ -0,0 +1,232 @@
import { createPinia, setActivePinia } from 'pinia';
import { useSettingsStore, useWorkflowsStore } from '@/stores';
import { setupServer } from '@/__tests__/server';
import { executeData } from '@/mixins/workflowHelpers';
import type { IExecutionResponse } from '@/Interface';
describe('workflowHelpers', () => {
let server: ReturnType<typeof setupServer>;
let pinia: ReturnType<typeof createPinia>;
let workflowsStore: ReturnType<typeof useWorkflowsStore>;
let settingsStore: ReturnType<typeof useSettingsStore>;
beforeAll(() => {
server = setupServer();
});
beforeEach(async () => {
pinia = createPinia();
setActivePinia(pinia);
workflowsStore = useWorkflowsStore();
settingsStore = useSettingsStore();
await settingsStore.getSettings();
});
afterAll(() => {
server.shutdown();
});
describe('executeData()', () => {
it('should return empty execute data if no parent nodes', () => {
const parentNodes: string[] = [];
const currentNode = 'Set';
const inputName = 'main';
const runIndex = 0;
const result = executeData(parentNodes, currentNode, inputName, runIndex);
expect(result).toEqual({
node: {},
data: {},
source: null,
});
});
it('should return the correct execution data with one parent node', () => {
const parentNodes = ['Start'];
const currentNode = 'Set';
const inputName = 'main';
const runIndex = 0;
const jsonData = {
name: 'Test',
};
workflowsStore.workflowExecutionData = {
data: {
resultData: {
runData: {
[parentNodes[0]]: [
{
startTime: 0,
executionTime: 0,
data: {
main: [
{
json: jsonData,
index: 0,
},
],
},
source: [],
},
],
},
},
},
} as unknown as IExecutionResponse;
const result = executeData(parentNodes, currentNode, inputName, runIndex);
expect(result).toEqual({
node: {},
data: {
main: [
{
index: 0,
json: jsonData,
},
],
},
source: {
main: [
{
previousNode: parentNodes[0],
},
],
},
});
});
it('should return the correct execution data with multiple parent nodes, only one with execution data', () => {
const parentNodes = ['Parent A', 'Parent B'];
const currentNode = 'Set';
const inputName = 'main';
const runIndex = 0;
const jsonData = {
name: 'Test',
};
workflowsStore.workflowExecutionData = {
data: {
resultData: {
runData: {
[parentNodes[1]]: [
{
startTime: 0,
executionTime: 0,
data: {
main: [
{
json: jsonData,
index: 0,
},
],
},
source: [],
},
],
},
},
},
} as unknown as IExecutionResponse;
const result = executeData(parentNodes, currentNode, inputName, runIndex);
expect(result).toEqual({
node: {},
data: {
main: [
{
index: 0,
json: jsonData,
},
],
},
source: {
main: [
{
previousNode: parentNodes[1],
},
],
},
});
});
it('should return the correct execution data with multiple parent nodes, all with execution data', () => {
const parentNodes = ['Parent A', 'Parent B'];
const currentNode = 'Set';
const inputName = 'main';
const runIndex = 0;
const jsonDataA = {
name: 'Test A',
};
const jsonDataB = {
name: 'Test B',
};
workflowsStore.workflowExecutionData = {
data: {
resultData: {
runData: {
[parentNodes[0]]: [
{
startTime: 0,
executionTime: 0,
data: {
main: [
{
json: jsonDataA,
index: 0,
},
],
},
source: [],
},
],
[parentNodes[1]]: [
{
startTime: 0,
executionTime: 0,
data: {
main: [
{
json: jsonDataB,
index: 0,
},
],
},
source: [],
},
],
},
},
},
} as unknown as IExecutionResponse;
const result = executeData(parentNodes, currentNode, inputName, runIndex);
expect(result).toEqual({
node: {},
data: {
main: [
{
index: 0,
json: jsonDataA,
},
],
},
source: {
main: [
{
previousNode: parentNodes[0],
},
],
},
});
});
});
});

View file

@ -305,8 +305,8 @@ function connectionInputData(
return connectionInputData; return connectionInputData;
} }
function executeData( export function executeData(
parentNode: string[], parentNodes: string[],
currentNode: string, currentNode: string,
inputName: string, inputName: string,
runIndex: number, runIndex: number,
@ -317,12 +317,10 @@ function executeData(
source: null, source: null,
} as IExecuteData; } as IExecuteData;
if (parentNode.length) {
// Add the input data to be able to also resolve the short expression format
// which does not use the node name
const parentNodeName = parentNode[0];
const workflowsStore = useWorkflowsStore(); const workflowsStore = useWorkflowsStore();
// Find the parent node which has data
for (const parentNodeName of parentNodes) {
if (workflowsStore.shouldReplaceInputDataWithPinData) { if (workflowsStore.shouldReplaceInputDataWithPinData) {
const parentPinData = workflowsStore.getPinData![parentNodeName]; const parentPinData = workflowsStore.getPinData![parentNodeName];
@ -337,7 +335,6 @@ function executeData(
} }
// populate `executeData` from `runData` // populate `executeData` from `runData`
const workflowRunData = workflowsStore.getWorkflowRunData; const workflowRunData = workflowsStore.getWorkflowRunData;
if (workflowRunData === null) { if (workflowRunData === null) {
return executeData; return executeData;
@ -368,6 +365,7 @@ function executeData(
], ],
}; };
} }
return executeData;
} }
} }