fix(core): Error in partial execution of vector stores (#15019)

This commit is contained in:
Benjamin Schroth
2025-05-01 00:54:02 +02:00
committed by GitHub
parent 154153d86f
commit 5fa41bd73a
2 changed files with 12 additions and 9 deletions
@@ -93,14 +93,15 @@ describe('rewireGraph()', () => {
expect(tool.rewireOutputLogTo).toBe(NodeConnectionTypes.AiTool);
});
it('fails when the tool has no incoming connections', () => {
it('should not rewire when the tool has no root', () => {
const tool = createNodeData({ name: 'tool', type: 'n8n-nodes-base.ai-tool' });
const root = createNodeData({ name: 'root' });
const graph = new DirectedGraph();
graph.addNodes(root, tool);
const result = rewireGraph(tool, graph);
expect(() => rewireGraph(tool, graph)).toThrow();
expect(result).toStrictEqual(graph);
});
it('removes the root node from the graph', () => {
@@ -4,26 +4,28 @@ import { type INode, NodeConnectionTypes } from 'n8n-workflow';
import { type DirectedGraph } from './directed-graph';
export function rewireGraph(tool: INode, graph: DirectedGraph): DirectedGraph {
graph = graph.clone();
const children = graph.getChildren(tool);
const modifiedGraph = graph.clone();
const children = modifiedGraph.getChildren(tool);
a.ok(children.size > 0, 'Tool must be connected to a root node');
if (children.size === 0) {
return graph;
}
const rootNode = [...children][0];
a.ok(rootNode);
const allIncomingConnection = graph
const allIncomingConnection = modifiedGraph
.getDirectParentConnections(rootNode)
.filter((cn) => cn.type === NodeConnectionTypes.Main);
tool.rewireOutputLogTo = NodeConnectionTypes.AiTool;
for (const cn of allIncomingConnection) {
graph.addConnection({ from: cn.from, to: tool });
modifiedGraph.addConnection({ from: cn.from, to: tool });
}
graph.removeNode(rootNode);
modifiedGraph.removeNode(rootNode);
return graph;
return modifiedGraph;
}