|
1 | 1 | import pytest |
| 2 | +from typing import Any, cast |
2 | 3 |
|
3 | 4 | from deepdiff import DeepDiff |
4 | 5 |
|
|
23 | 24 | from vellum_ee.workflows.display.workflows.get_vellum_workflow_display_class import get_workflow_display |
24 | 25 |
|
25 | 26 | from tests.workflows.basic_conditional_node.workflow import CategoryWorkflow |
26 | | -from tests.workflows.basic_conditional_node.workflow_with_only_one_conditional_node import create_simple_workflow |
| 27 | +from tests.workflows.basic_conditional_node.workflow_with_only_one_conditional_node import ( |
| 28 | + Inputs as SimpleInputs, |
| 29 | + create_simple_workflow, |
| 30 | +) |
27 | 31 |
|
28 | 32 |
|
29 | 33 | def test_serialize_workflow(): |
@@ -924,3 +928,26 @@ def test_conditional_node_serialize_all_operators_with_value_and_start_and_end(d |
924 | 928 | conditional_node, |
925 | 929 | ignore_order=True, |
926 | 930 | ) |
| 931 | + |
| 932 | + |
| 933 | +def test_conditional_node_serialize_or_combinator_preserves_or(): |
| 934 | + """Regression test: OR conditions (A | B) must serialize with combinator 'OR', not 'AND'.""" |
| 935 | + # GIVEN a conditional node with an OR condition: text == "foo" OR text == "bar" |
| 936 | + or_condition = SimpleInputs.text.equals("foo") | SimpleInputs.text.equals("bar") |
| 937 | + workflow_cls = create_simple_workflow(or_condition) |
| 938 | + |
| 939 | + workflow_display = get_workflow_display(workflow_class=workflow_cls) |
| 940 | + serialized_workflow = cast(dict[str, Any], workflow_display.serialize()) |
| 941 | + |
| 942 | + # WHEN we extract the conditional node's IF condition |
| 943 | + conditional_node = next( |
| 944 | + n |
| 945 | + for n in serialized_workflow["workflow_raw_data"]["nodes"] |
| 946 | + if (n.get("base") or {}).get("name") == "ConditionalNode" |
| 947 | + ) |
| 948 | + if_condition = next(c for c in conditional_node["data"]["conditions"] if c["type"] == "IF") |
| 949 | + |
| 950 | + # THEN the combinator must be "OR" (not "AND") |
| 951 | + assert ( |
| 952 | + if_condition["data"]["combinator"] == "OR" |
| 953 | + ), "OR conditions were incorrectly serialized as AND - top-level OrExpression must produce combinator 'OR'" |
0 commit comments