fix: drop obsolete eval_condition context_data parameter
This commit is contained in:
+10
-18
@@ -20,43 +20,36 @@ def eval_condition(
|
|||||||
condition: Condition,
|
condition: Condition,
|
||||||
state: Mapping[str, Any],
|
state: Mapping[str, Any],
|
||||||
workflow_input: Mapping[str, Any],
|
workflow_input: Mapping[str, Any],
|
||||||
context_data: str | None,
|
|
||||||
*,
|
*,
|
||||||
context: Mapping[str, Any] | None = None,
|
context: Mapping[str, Any],
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Evaluate a condition against state, input, and context.
|
"""Evaluate a condition against state, input, and context.
|
||||||
|
|
||||||
``context`` is the frame's structured context graph (see
|
``context`` is the frame's structured context graph (see
|
||||||
``frame_context_view``); when omitted, evaluation falls back to the
|
``frame_context_view``); it always carries ``prior_outcome`` alongside the
|
||||||
legacy ``{"prior_outcome": context_data}`` stub so direct unit callers
|
structured ``foreach`` entries, aliases, and loop keys.
|
||||||
keep working. The graph always carries ``prior_outcome``, so passing it
|
|
||||||
preserves legacy behavior while also resolving structured paths such as
|
|
||||||
``context.foreach.<id>.item``.
|
|
||||||
"""
|
"""
|
||||||
resolved = context if context is not None else {"prior_outcome": context_data}
|
|
||||||
if isinstance(condition, ExistsCondition):
|
if isinstance(condition, ExistsCondition):
|
||||||
return path_exists(
|
return path_exists(
|
||||||
condition.path,
|
condition.path,
|
||||||
state=state,
|
state=state,
|
||||||
workflow_input=workflow_input,
|
workflow_input=workflow_input,
|
||||||
context=resolved,
|
context=context,
|
||||||
)
|
)
|
||||||
if isinstance(condition, NotCondition):
|
if isinstance(condition, NotCondition):
|
||||||
return not eval_condition(
|
return not eval_condition(
|
||||||
condition.arg, state, workflow_input, context_data, context=resolved
|
condition.arg, state, workflow_input, context=context
|
||||||
)
|
)
|
||||||
if isinstance(condition, VariadicCondition):
|
if isinstance(condition, VariadicCondition):
|
||||||
values = [
|
values = [
|
||||||
eval_condition(arg, state, workflow_input, context_data, context=resolved)
|
eval_condition(arg, state, workflow_input, context=context)
|
||||||
for arg in condition.args
|
for arg in condition.args
|
||||||
]
|
]
|
||||||
return all(values) if condition.op == "and" else any(values)
|
return all(values) if condition.op == "and" else any(values)
|
||||||
if isinstance(condition, BinaryCondition):
|
if isinstance(condition, BinaryCondition):
|
||||||
left = resolve_operand(
|
left = resolve_operand(condition.left, state, workflow_input, context=context)
|
||||||
condition.left, state, workflow_input, context_data, context=resolved
|
|
||||||
)
|
|
||||||
right = resolve_operand(
|
right = resolve_operand(
|
||||||
condition.right, state, workflow_input, context_data, context=resolved
|
condition.right, state, workflow_input, context=context
|
||||||
)
|
)
|
||||||
if condition.op == "eq":
|
if condition.op == "eq":
|
||||||
return left == right
|
return left == right
|
||||||
@@ -77,9 +70,8 @@ def resolve_operand(
|
|||||||
operand: PathOperand | LiteralOperand,
|
operand: PathOperand | LiteralOperand,
|
||||||
state: Mapping[str, Any],
|
state: Mapping[str, Any],
|
||||||
workflow_input: Mapping[str, Any],
|
workflow_input: Mapping[str, Any],
|
||||||
context_data: str | None,
|
|
||||||
*,
|
*,
|
||||||
context: Mapping[str, Any] | None = None,
|
context: Mapping[str, Any],
|
||||||
) -> Any:
|
) -> Any:
|
||||||
if isinstance(operand, LiteralOperand):
|
if isinstance(operand, LiteralOperand):
|
||||||
return operand.value
|
return operand.value
|
||||||
@@ -87,7 +79,7 @@ def resolve_operand(
|
|||||||
str(operand.path),
|
str(operand.path),
|
||||||
state=state,
|
state=state,
|
||||||
workflow_input=workflow_input,
|
workflow_input=workflow_input,
|
||||||
context=context if context is not None else {"prior_outcome": context_data},
|
context=context,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ def handle_condition_step(
|
|||||||
step.check,
|
step.check,
|
||||||
state_view_for_frame(run, frame),
|
state_view_for_frame(run, frame),
|
||||||
scope_input_for_frame(run, frame),
|
scope_input_for_frame(run, frame),
|
||||||
frame.prior_outcome,
|
|
||||||
# Structured context must match what validation blesses: conditions
|
# Structured context must match what validation blesses: conditions
|
||||||
# inside a foreach body can read context.foreach.* / loop aliases.
|
# inside a foreach body can read context.foreach.* / loop aliases.
|
||||||
context=frame_context_view(run, frame).graph,
|
context=frame_context_view(run, frame).graph,
|
||||||
|
|||||||
@@ -45,5 +45,5 @@ def test_condition_dsl_supports_not_ge_and_ne() -> None:
|
|||||||
compiled,
|
compiled,
|
||||||
state={"score": 7, "status": "ready"},
|
state={"score": 7, "status": "ready"},
|
||||||
workflow_input={},
|
workflow_input={},
|
||||||
context_data=None,
|
context={"prior_outcome": None},
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user