mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
fix: Increment runIndex in WorkflowToolV2 tool executions to avoid reusing out of date inputs (#13008)
This commit is contained in:
parent
fdcff9082b
commit
cc907fbca9
|
@ -11,9 +11,14 @@ import type {
|
||||||
|
|
||||||
import { WorkflowToolService } from './utils/WorkflowToolService';
|
import { WorkflowToolService } from './utils/WorkflowToolService';
|
||||||
|
|
||||||
|
type ISupplyDataFunctionsWithRunIndex = ISupplyDataFunctions & { runIndex: number };
|
||||||
|
|
||||||
// Mock ISupplyDataFunctions interface
|
// Mock ISupplyDataFunctions interface
|
||||||
function createMockContext(overrides?: Partial<ISupplyDataFunctions>): ISupplyDataFunctions {
|
function createMockContext(
|
||||||
|
overrides?: Partial<ISupplyDataFunctions>,
|
||||||
|
): ISupplyDataFunctionsWithRunIndex {
|
||||||
return {
|
return {
|
||||||
|
runIndex: 0,
|
||||||
getNodeParameter: jest.fn(),
|
getNodeParameter: jest.fn(),
|
||||||
getWorkflowDataProxy: jest.fn(),
|
getWorkflowDataProxy: jest.fn(),
|
||||||
getNode: jest.fn(),
|
getNode: jest.fn(),
|
||||||
|
@ -35,11 +40,11 @@ function createMockContext(overrides?: Partial<ISupplyDataFunctions>): ISupplyDa
|
||||||
warn: jest.fn(),
|
warn: jest.fn(),
|
||||||
},
|
},
|
||||||
...overrides,
|
...overrides,
|
||||||
} as ISupplyDataFunctions;
|
} as ISupplyDataFunctionsWithRunIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('WorkflowTool::WorkflowToolService', () => {
|
describe('WorkflowTool::WorkflowToolService', () => {
|
||||||
let context: ISupplyDataFunctions;
|
let context: ISupplyDataFunctionsWithRunIndex;
|
||||||
let service: WorkflowToolService;
|
let service: WorkflowToolService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -93,6 +98,7 @@ describe('WorkflowTool::WorkflowToolService', () => {
|
||||||
|
|
||||||
expect(result).toBe(JSON.stringify(TEST_RESPONSE, null, 2));
|
expect(result).toBe(JSON.stringify(TEST_RESPONSE, null, 2));
|
||||||
expect(context.addOutputData).toHaveBeenCalled();
|
expect(context.addOutputData).toHaveBeenCalled();
|
||||||
|
expect(context.runIndex).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle errors during tool execution', async () => {
|
it('should handle errors during tool execution', async () => {
|
||||||
|
|
|
@ -90,6 +90,9 @@ export class WorkflowToolService {
|
||||||
const errorResponse = `There was an error: "${executionError.message}"`;
|
const errorResponse = `There was an error: "${executionError.message}"`;
|
||||||
void this.context.addOutputData(NodeConnectionType.AiTool, index, executionError);
|
void this.context.addOutputData(NodeConnectionType.AiTool, index, executionError);
|
||||||
return errorResponse;
|
return errorResponse;
|
||||||
|
} finally {
|
||||||
|
// @ts-expect-error this accesses a private member on the actual implementation to fix https://linear.app/n8n/issue/ADO-3186/bug-workflowtool-v2-always-uses-first-row-of-input-data
|
||||||
|
this.context.runIndex++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue