refactor(core): Move single node check outside of the nodes loop (#16959)

This commit is contained in:
Ioannis Canellos
2025-07-11 16:32:26 +03:00
committed by GitHub
parent a34b30acc7
commit f928c58042
2 changed files with 25 additions and 3 deletions

View File

@@ -900,13 +900,16 @@ export class Workflow {
// Check if there are any trigger or poll nodes and then return the first one // Check if there are any trigger or poll nodes and then return the first one
let node: INode; let node: INode;
let nodeType: INodeType; let nodeType: INodeType;
for (const nodeName of nodeNames) {
node = this.nodes[nodeName];
if (nodeNames.length === 1 && !node.disabled) { if (nodeNames.length === 1) {
node = this.nodes[nodeNames[0]];
if (node && !node.disabled) {
return node; return node;
} }
}
for (const nodeName of nodeNames) {
node = this.nodes[nodeName];
nodeType = this.nodeTypes.getByNameAndVersion(node.type, node.typeVersion); nodeType = this.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
// TODO: Identify later differently // TODO: Identify later differently

View File

@@ -2586,6 +2586,25 @@ describe('Workflow', () => {
expect(workflow.getStartNode()).toBeUndefined(); expect(workflow.getStartNode()).toBeUndefined();
}); });
test('returns the single node when only one non-disabled node exists', () => {
const singleNode = {
name: 'SingleNode',
type: 'test.set',
typeVersion: 1,
id: 'uuid-single',
position: [0, 0],
parameters: {},
} as INode;
const workflow = new Workflow({
nodes: [singleNode],
connections: {},
active: false,
nodeTypes,
});
expect(workflow.getStartNode()).toBe(singleNode);
});
}); });
describe('getNode', () => { describe('getNode', () => {