69 lines
2.8 KiB
Python
69 lines
2.8 KiB
Python
import pytest
|
|
from workflows.engine import execute_flow_dag
|
|
|
|
def test_diamond_rejoin_execution():
|
|
"""
|
|
Graph Topology:
|
|
start -> decision
|
|
decision -> (winning handle) -> node_a -> join_node
|
|
decision -> (losing handle) -> node_b -> join_node
|
|
Both node_a and node_b connect to join_node.
|
|
join_node must execute when branch A is chosen.
|
|
node_b must NOT execute.
|
|
"""
|
|
graph = {
|
|
"nodes": [
|
|
{"id": "start", "type": "trigger", "data": {}},
|
|
{
|
|
"id": "decision",
|
|
"type": "decision",
|
|
"data": {
|
|
"outcomes": [
|
|
{
|
|
"id": "path_a",
|
|
"rules": [{"field": "status", "operator": "equals", "value": "A"}]
|
|
},
|
|
{
|
|
"id": "path_b",
|
|
"rules": [{"field": "status", "operator": "equals", "value": "B"}]
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"id": "node_a",
|
|
"type": "assignment",
|
|
"data": {"variable": "executed_a", "operator": "equals", "value": True}
|
|
},
|
|
{
|
|
"id": "node_b",
|
|
"type": "assignment",
|
|
"data": {"variable": "executed_b", "operator": "equals", "value": True}
|
|
},
|
|
{
|
|
"id": "join_node",
|
|
"type": "assignment",
|
|
"data": {"variable": "executed_join", "operator": "equals", "value": True}
|
|
}
|
|
],
|
|
"edges": [
|
|
{"source": "start", "target": "decision"},
|
|
{"source": "decision", "target": "node_a", "sourceHandle": "path_a"},
|
|
{"source": "decision", "target": "node_b", "sourceHandle": "path_b"},
|
|
{"source": "node_a", "target": "join_node"},
|
|
{"source": "node_b", "target": "join_node"}
|
|
]
|
|
}
|
|
|
|
result = execute_flow_dag(graph, initial_context={"status": "A"})
|
|
ctx = result if isinstance(result, dict) else result.context
|
|
assert ctx.get("executed_a") is True, "Branch A should have executed"
|
|
assert ctx.get("executed_b") is not True, "Branch B must NEVER execute"
|
|
assert ctx.get("executed_join") is True, "Diamond join node MUST execute when reached via Branch A"
|
|
|
|
# Opposite branch test: status == 'B'
|
|
result_b = execute_flow_dag(graph, initial_context={"status": "B"})
|
|
ctx_b = result_b if isinstance(result_b, dict) else result_b.context
|
|
assert ctx_b.get("executed_b") is True, "Branch B should have executed when status is B"
|
|
assert ctx_b.get("executed_a") is not True, "Branch A must NEVER execute when status is B"
|
|
assert ctx_b.get("executed_join") is True, "Diamond join node MUST execute when reached via Branch B"
|