fix: validate interrupt request payloads

This commit is contained in:
lda
2026-07-01 05:54:34 +07:00 Verified
parent 32831e5b13
commit b56f492d80
2 changed files with 42 additions and 0 deletions
+36
View File
@@ -20,6 +20,7 @@ from wf_core import (
resume_workflow_async,
resume_workflow_result_async,
)
from wf_core.models.steps import InputValueBinding
async def explode(_payload: dict[str, Any], _context: RuntimeContext) -> dict[str, Any]:
@@ -120,3 +121,38 @@ def _interrupt_then_fail_workflow() -> Workflow:
def _schema() -> SchemaRef:
return SchemaRef(type="object", properties={})
async def test_interrupt_request_payload_validates_against_schema() -> None:
workflow = Workflow(
name="bad_interrupt_request",
input_schema=_schema(),
state_schema=StateSchema.from_field_map({}),
output_schema=_schema(),
outcomes=["ok"],
start="ask",
nodes=[
InterruptNode(
id="ask",
type="interrupt",
kind="approval",
request=[
InputValueBinding(target="count", value="not a number") # type: ignore[arg-type]
],
request_schema={
"type": "object",
"properties": {"count": {"type": "number"}},
"required": ["count"],
"additionalProperties": False,
},
),
],
edges=[Edge.model_validate({"from": "ask", "outcome": "submitted", "to": END})],
)
run = await execute_workflow_result_async(workflow, {}, {})
assert run.status == RunStatus.FAILED
assert run.interrupt is None
assert run.error is not None
assert "interrupt request for ask" in run.error