@@ -1486,6 +1486,186 @@ def test_context_run_id_string_interpolation(self):
14861486 result = evaluate_expression ("RUN_ID={{ context.run_id }}" , ctx )
14871487 assert result == "RUN_ID=deadbeef"
14881488
1489+ def test_comparison_greater_equal_and_less_equal (self ):
1490+ """``>=``/``<=`` evaluate like ``>``/``<``, for every operand shape.
1491+
1492+ The operators were in ``_COMPARISON_OPERATORS`` and handed to
1493+ ``_safe_compare``, but no test evaluated them, so the ``>=``/``<=``
1494+ branches and their ordering relative to the single-char operators were
1495+ unpinned.
1496+ """
1497+ from specify_cli .workflows .expressions import evaluate_expression
1498+ from specify_cli .workflows .base import StepContext
1499+
1500+ ctx = StepContext (inputs = {"n" : 5 , "s10" : "10" , "s9" : "9" , "lo" : "alpha" , "hi" : "beta" })
1501+ assert evaluate_expression ("{{ inputs.n >= 5 }}" , ctx ) is True
1502+ assert evaluate_expression ("{{ inputs.n <= 5 }}" , ctx ) is True
1503+ assert evaluate_expression ("{{ inputs.n >= 6 }}" , ctx ) is False
1504+ assert evaluate_expression ("{{ inputs.n <= 4 }}" , ctx ) is False
1505+ # Numeric strings still compare as numbers ("10" >= "9", not lexically).
1506+ assert evaluate_expression ("{{ inputs.s10 >= inputs.s9 }}" , ctx ) is True
1507+ assert evaluate_expression ("{{ inputs.s9 <= inputs.s10 }}" , ctx ) is True
1508+ # Non-numeric strings compare lexicographically.
1509+ assert evaluate_expression ("{{ inputs.hi >= inputs.lo }}" , ctx ) is True
1510+ assert evaluate_expression ("{{ inputs.lo <= inputs.hi }}" , ctx ) is True
1511+ # A number against a non-numeric string is incomparable -> False.
1512+ assert evaluate_expression ("{{ inputs.n >= 'abc' }}" , ctx ) is False
1513+ assert evaluate_expression ("{{ inputs.n <= 'abc' }}" , ctx ) is False
1514+
1515+ def test_boolean_literals_are_case_insensitive (self ):
1516+ """``{{ True }}``/``{{ TRUE }}`` resolve as booleans, as the ``.lower()``
1517+ branch intends; only lowercase was pinned before."""
1518+ from specify_cli .workflows .expressions import evaluate_expression
1519+ from specify_cli .workflows .base import StepContext
1520+
1521+ ctx = StepContext ()
1522+ for literal in ("True" , "TRUE" ):
1523+ assert evaluate_expression ("{{ " + literal + " }}" , ctx ) is True , literal
1524+ for literal in ("False" , "FALSE" ):
1525+ assert evaluate_expression ("{{ " + literal + " }}" , ctx ) is False , literal
1526+
1527+ def test_null_literals (self ):
1528+ """``none``/``null`` (any case) resolve to ``None``, not to a path."""
1529+ from specify_cli .workflows .expressions import evaluate_expression
1530+ from specify_cli .workflows .base import StepContext
1531+
1532+ ctx = StepContext ()
1533+ for literal in ("none" , "null" , "None" , "NULL" , "nUlL" ):
1534+ assert evaluate_expression ("{{ " + literal + " }}" , ctx ) is None , literal
1535+
1536+ def test_filter_map_dot_path_attribute (self ):
1537+ """``map('a.b')`` walks nested dicts, not just a top-level key."""
1538+ from specify_cli .workflows .expressions import evaluate_expression
1539+ from specify_cli .workflows .base import StepContext
1540+
1541+ ctx = StepContext (
1542+ inputs = {"rows" : [{"result" : {"status" : "ok" }}, {"result" : {"status" : "bad" }}]}
1543+ )
1544+ assert evaluate_expression (
1545+ "{{ inputs.rows | map('result.status') }}" , ctx
1546+ ) == ["ok" , "bad" ]
1547+ # A missing branch of the path yields None for that element, as for a
1548+ # missing top-level key.
1549+ ctx_missing = StepContext (inputs = {"rows" : [{"result" : {"status" : "ok" }}, {}]})
1550+ assert evaluate_expression (
1551+ "{{ inputs.rows | map('result.status') }}" , ctx_missing
1552+ ) == ["ok" , None ]
1553+
1554+ def test_filter_default_on_empty_string (self ):
1555+ """``default`` fires for an empty string too, not only for ``None``.
1556+
1557+ ``_filter_default`` treats both as absent; only the ``None`` half was
1558+ covered.
1559+ """
1560+ from specify_cli .workflows .expressions import evaluate_expression
1561+ from specify_cli .workflows .base import StepContext
1562+
1563+ ctx = StepContext (inputs = {"empty" : "" , "value" : "kept" , "missing" : None })
1564+ assert evaluate_expression ("{{ inputs.empty | default('fb') }}" , ctx ) == "fb"
1565+ assert evaluate_expression ("{{ inputs.missing | default('fb') }}" , ctx ) == "fb"
1566+ # A non-empty value is passed through unchanged.
1567+ assert evaluate_expression ("{{ inputs.value | default('fb') }}" , ctx ) == "kept"
1568+
1569+ def test_filter_from_json_returns_non_object_types (self ):
1570+ """``from_json`` yields the parsed value for every JSON type, not only
1571+ objects: arrays, numbers, booleans and ``null``."""
1572+ from specify_cli .workflows .expressions import evaluate_expression
1573+ from specify_cli .workflows .base import StepContext
1574+
1575+ ctx = StepContext (
1576+ inputs = {"arr" : "[1, 2, 3]" , "num" : "42" , "fnum" : "1.5" , "t" : "true" , "nl" : "null" }
1577+ )
1578+ assert evaluate_expression ("{{ inputs.arr | from_json }}" , ctx ) == [1 , 2 , 3 ]
1579+ assert evaluate_expression ("{{ inputs.num | from_json }}" , ctx ) == 42
1580+ assert evaluate_expression ("{{ inputs.fnum | from_json }}" , ctx ) == 1.5
1581+ assert evaluate_expression ("{{ inputs.t | from_json }}" , ctx ) is True
1582+ assert evaluate_expression ("{{ inputs.nl | from_json }}" , ctx ) is None
1583+
1584+ def test_filter_argument_resolved_from_namespace (self ):
1585+ """A filter argument may be a namespace path, not only a literal."""
1586+ from specify_cli .workflows .expressions import evaluate_expression
1587+ from specify_cli .workflows .base import StepContext
1588+
1589+ ctx = StepContext (inputs = {"tags" : ["a" , "b" ], "sep" : "-" , "missing" : None })
1590+ assert evaluate_expression ("{{ inputs.tags | join(inputs.sep) }}" , ctx ) == "a-b"
1591+ assert evaluate_expression ("{{ inputs.missing | default(inputs.sep) }}" , ctx ) == "-"
1592+
1593+ def test_boolean_precedence_without_parentheses (self ):
1594+ """``and`` binds tighter than ``or``, so grouping is only needed to
1595+ override it. With a=True, b=False, c=False: ``a or (b and c)`` is True;
1596+ the wrong left-to-right reading ``(a or b) and c`` would be False."""
1597+ from specify_cli .workflows .expressions import evaluate_expression
1598+ from specify_cli .workflows .base import StepContext
1599+
1600+ ctx = StepContext (inputs = {"a" : True , "b" : False , "c" : False })
1601+ assert evaluate_expression ("{{ inputs.a or inputs.b and inputs.c }}" , ctx ) is True
1602+ # Explicit grouping overrides the default and flips the result.
1603+ assert evaluate_expression ("{{ (inputs.a or inputs.b) and inputs.c }}" , ctx ) is False
1604+
1605+ def test_item_and_fan_in_namespace (self ):
1606+ """The ``item`` and ``fan_in`` roots resolve inside fan-out/fan-in, like
1607+ ``inputs``/``steps``/``context``. Only the diagnostics probed them."""
1608+ from specify_cli .workflows .expressions import evaluate_expression
1609+ from specify_cli .workflows .base import StepContext
1610+
1611+ ctx = StepContext (
1612+ inputs = {"x" : "y" }, item = {"name" : "n1" }, fan_in = {"results" : [1 , 2 ]}
1613+ )
1614+ assert evaluate_expression ("{{ item.name }}" , ctx ) == "n1"
1615+ assert evaluate_expression ("{{ item }}" , ctx ) == {"name" : "n1" }
1616+ assert evaluate_expression ("{{ fan_in.results }}" , ctx ) == [1 , 2 ]
1617+ assert evaluate_expression ("{{ fan_in.results | join(', ') }}" , ctx ) == "1, 2"
1618+ # An item that is itself a list indexes like any other list root.
1619+ list_ctx = StepContext (inputs = {"x" : 1 }, item = ["x" , "y" ])
1620+ assert evaluate_expression ("{{ item[0] }}" , list_ctx ) == "x"
1621+ assert evaluate_expression ("{{ item[-1] }}" , list_ctx ) == "y"
1622+
1623+ def test_interpolation_with_steps_and_item (self ):
1624+ """Interpolation resolves every root, not only ``inputs``/``context``."""
1625+ from specify_cli .workflows .expressions import evaluate_expression
1626+ from specify_cli .workflows .base import StepContext
1627+
1628+ ctx = StepContext (
1629+ steps = {"emit" : {"output" : {"file" : "a.md" }}}, item = "row-1"
1630+ )
1631+ assert evaluate_expression ("file={{ steps.emit.output.file }}" , ctx ) == "file=a.md"
1632+ assert evaluate_expression ("item={{ item }}" , ctx ) == "item=row-1"
1633+
1634+ def test_empty_expression_block_is_empty_string (self ):
1635+ """A block with no expression interpolates to ``""`` (and in a condition
1636+ coerces to False), rather than raising."""
1637+ from specify_cli .workflows .expressions import (
1638+ evaluate_condition ,
1639+ evaluate_expression ,
1640+ )
1641+ from specify_cli .workflows .base import StepContext
1642+
1643+ ctx = StepContext ()
1644+ assert evaluate_expression ("{{ }}" , ctx ) == ""
1645+ assert evaluate_condition ("{{ }}" , ctx ) is False
1646+
1647+ def test_missing_intermediate_path_resolves_to_none (self ):
1648+ """A path whose intermediate segment is absent resolves to ``None``
1649+ rather than raising."""
1650+ from specify_cli .workflows .expressions import evaluate_expression
1651+ from specify_cli .workflows .base import StepContext
1652+
1653+ ctx = StepContext (inputs = {"a" : {}})
1654+ assert evaluate_expression ("{{ inputs.a.b }}" , ctx ) is None
1655+ assert evaluate_expression ("{{ inputs.zzz.deep }}" , ctx ) is None
1656+
1657+ def test_whitespace_inside_and_around_block (self ):
1658+ """Arbitrary whitespace around tokens is insignificant; none inside a
1659+ quoted operand is not."""
1660+ from specify_cli .workflows .expressions import evaluate_expression
1661+ from specify_cli .workflows .base import StepContext
1662+
1663+ ctx = StepContext (inputs = {"n" : 5 , "missing" : None })
1664+ assert evaluate_expression ("{{inputs.n}}" , ctx ) == 5
1665+ assert evaluate_expression ("{{ inputs.n }}" , ctx ) == 5
1666+ assert evaluate_expression ("{{ inputs.missing | default( 'y' ) }}" , ctx ) == "y"
1667+ assert evaluate_expression ("{{ inputs.missing|default('y') }}" , ctx ) == "y"
1668+
14891669
14901670# ===== Integration Dispatch Tests =====
14911671
@@ -3351,6 +3531,23 @@ def test_execute_returns_paused(self):
33513531 assert result .output ["message" ] == "Review the spec."
33523532 assert result .output ["options" ] == ["approve" , "reject" ]
33533533
3534+ def test_message_expression_is_interpolated (self ):
3535+ """A gate ``message`` containing ``{{ }}`` is evaluated against the
3536+ context before it is persisted, not shown verbatim."""
3537+ from specify_cli .workflows .step .gate import GateStep
3538+ from specify_cli .workflows .base import StepContext , StepStatus
3539+
3540+ result = GateStep ().execute (
3541+ {
3542+ "id" : "review" ,
3543+ "message" : "Approve {{ inputs.feature }}?" ,
3544+ "options" : ["approve" , "reject" ],
3545+ },
3546+ StepContext (inputs = {"feature" : "login" }),
3547+ )
3548+ assert result .status == StepStatus .PAUSED
3549+ assert result .output ["message" ] == "Approve login?"
3550+
33543551 @pytest .mark .parametrize (
33553552 "inputs" , [{}, {"spec_verdict" : None }, {"spec_verdict" : "" }]
33563553 )
0 commit comments