sched: address R1 findings on shared traversal and resolver threading

This commit is contained in:
lda
2026-09-08 10:15:36 +07:00 Verified
parent 0ded9b0d40
commit 46c2763b66
8 changed files with 232 additions and 124 deletions
+66 -2
View File
@@ -111,6 +111,53 @@ def test_graph_only_path_is_invalid_in_schedule_bindings() -> None:
)
def test_nested_graph_path_is_invalid_in_schedule_bindings() -> None:
with pytest.raises(ValidationError):
ScheduleInputBinding.model_validate(
{
"target": "x",
"expression": {
"kind": "object",
"fields": {
"nested": {"kind": "path", "path": "input.a"},
},
},
}
)
with pytest.raises(ValidationError):
ScheduleInputBinding.model_validate(
{
"target": "x",
"expression": {
"kind": "array",
"items": [{"kind": "path", "path": "state.b"}],
},
}
)
def test_nested_occurrence_is_invalid_in_graph_bindings() -> None:
from wf_core.models.input_bindings import (
ArrayExpression,
ObjectExpression,
)
with pytest.raises(ValidationError):
ArrayExpression.model_validate(
{
"kind": "array",
"items": [{"kind": "occurrence", "field": "scheduled_at"}],
}
)
with pytest.raises(ValidationError):
ObjectExpression.model_validate(
{
"kind": "object",
"fields": {"when": {"kind": "occurrence", "field": "scheduled_at"}},
}
)
def test_invalid_field_rejected() -> None:
with pytest.raises(ValidationError):
ScheduleInputBinding.model_validate(
@@ -153,7 +200,7 @@ def test_invalid_resolved_input_fails_schema_check() -> None:
resolved = resolve_schedule_input_bindings(
[binding], occurrence=OCC, label="schedule s"
)
with pytest.raises(Exception, match="count"):
with pytest.raises(WorkflowExecutionError, match="count"):
validate_payload_against_schema(
{"type": "object", "properties": {"count": {"type": "integer"}}},
resolved,
@@ -161,10 +208,27 @@ def test_invalid_resolved_input_fails_schema_check() -> None:
)
def test_direct_schedule_expression_resolution_rejects_graph_paths() -> None:
def test_direct_schedule_expression_resolves_literal() -> None:
expr = ScheduleInputBinding.model_validate(
{"target": "x", "expression": {"kind": "literal", "value": 1}}
).expression
assert (
resolve_schedule_expression(expr, occurrence=OCC, label="s", location="x") == 1
)
def test_graph_path_leaf_rejected_inside_schedule_traversal() -> None:
from wf_core.models.input_bindings import PathExpression
from wf_core.runtime.input_sources import MappingSourceResolver
graph_leaf = PathExpression.model_validate(
{"kind": "path", "path": "input.a"}
)
with pytest.raises(WorkflowExecutionError, match="graph paths are invalid"):
resolve_schedule_expression(
graph_leaf, # type: ignore[arg-type]
occurrence=MappingSourceResolver(OCC),
label="s",
location="x",
)