test(core): Fix a typo and add an additional test (#12725)

This commit is contained in:
Danny Martini 2025-01-20 16:56:12 +01:00 committed by GitHub
parent 967ee4b89b
commit d25817c5cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 1 deletions

View file

@ -123,6 +123,7 @@ describe('cleanRunData', () => {
});
});
// ►
// ┌─────┐ ┌────────┐
// │node1├─────►rootNode│
// └─────┘ └───▲────┘
@ -156,6 +157,7 @@ describe('cleanRunData', () => {
});
});
// ►
// ┌─────┐ ┌─────┐ ┌────────┐
// │node1├───►node2├────►rootNode│
// └─────┘ └─────┘ └───▲────┘
@ -191,4 +193,42 @@ describe('cleanRunData', () => {
[node1.name]: [toITaskData([{ data: { value: 1 } }])],
});
});
// ►
// ┌─────┐ ┌────────┐ ┌────────┐
// │node1├──►rootNode├──►rootNode│
// └─────┘ └───▲────┘ └───▲────┘
// │ │
// │ ┌───┴───┐
// └───────┤subNode│
// └───────┘
test('removes run data of sub nodes as well if the sub node is shared between multiple root nodes', () => {
// ARRANGE
const node1 = createNodeData({ name: 'Node1' });
const rootNode1 = createNodeData({ name: 'Root Node 1' });
const rootNode2 = createNodeData({ name: 'Root Node 2' });
const subNode = createNodeData({ name: 'Sub Node' });
const graph = new DirectedGraph()
.addNodes(node1, rootNode1, rootNode2, subNode)
.addConnections(
{ from: node1, to: rootNode1 },
{ from: rootNode1, to: rootNode2 },
{ from: subNode, to: rootNode1, type: NodeConnectionType.AiLanguageModel },
{ from: subNode, to: rootNode2, type: NodeConnectionType.AiLanguageModel },
);
const runData: IRunData = {
[node1.name]: [toITaskData([{ data: { value: 1 } }])],
[rootNode1.name]: [toITaskData([{ data: { value: 1 } }])],
[rootNode2.name]: [toITaskData([{ data: { value: 2 } }])],
[subNode.name]: [toITaskData([{ data: { value: 3 } }])],
};
// ACT
const newRunData = cleanRunData(runData, graph, new Set([rootNode1]));
// ASSERT
expect(newRunData).toEqual({
[node1.name]: [toITaskData([{ data: { value: 1 } }])],
});
});
});

View file

@ -24,7 +24,7 @@ export function cleanRunData(
// Delete runData for subNodes
const subNodeConnections = graph.getParentConnections(node);
for (const subNodeConnection of subNodeConnections) {
// Sub nodes never use the Main connection type, so this filters our
// Sub nodes never use the Main connection type, so this filters out
// the connection that goes upstream of the startNode.
if (subNodeConnection.type === NodeConnectionType.Main) {
continue;