feat(core): Support executing single nodes not part of a graph as a partial execution (#13529)

This commit is contained in:
Danny Martini
2025-02-27 09:35:52 +01:00
committed by GitHub
parent 223ec2d9c9
commit 8a34f027c5
4 changed files with 135 additions and 15 deletions
@@ -33,6 +33,27 @@ describe('findSubgraph', () => {
expect(subgraph).toEqual(graph);
});
// ►►
// ┌──────┐
// │orphan│
// └──────┘
// ┌───────┐ ┌───────────┐
// │trigger├────►│destination│
// └───────┘ └───────────┘
test('works with a single node', () => {
const trigger = createNodeData({ name: 'trigger' });
const destination = createNodeData({ name: 'destination' });
const orphan = createNodeData({ name: 'orphan' });
const graph = new DirectedGraph()
.addNodes(trigger, destination, orphan)
.addConnections({ from: trigger, to: destination });
const subgraph = findSubgraph({ graph, destination: orphan, trigger: orphan });
expect(subgraph).toEqual(new DirectedGraph().addNode(orphan));
});
// ►►
// ┌───────┐ ┌───────────┐
// │ ├────────►│ │
@@ -13,6 +13,12 @@ function findSubgraphRecursive(
) {
// If the current node is the chosen trigger keep this branch.
if (current === trigger) {
// If this graph consists of only one node there won't be any connections
// and the loop below won't add anything.
// We're adding the trigger here so that graphs with one node and no
// connections are handled correctly.
newGraph.addNode(trigger);
for (const connection of currentBranch) {
newGraph.addNodes(connection.from, connection.to);
newGraph.addConnection(connection);