add match!
This commit is contained in:
@@ -121,3 +121,47 @@ def test_adapter_lowers_choose_step_through_builder() -> None:
|
||||
("pick_2", "true", "fallback"),
|
||||
("pick_2", "false", "__end__"),
|
||||
]
|
||||
|
||||
|
||||
def test_adapter_lowers_match_step_through_builder() -> None:
|
||||
draft = WorkflowDraft.model_validate(
|
||||
{
|
||||
"name": "match_example",
|
||||
"input_schema": {},
|
||||
"state_schema": {"fields": {}},
|
||||
"output_schema": {},
|
||||
"start": "match_status",
|
||||
"steps": {
|
||||
"match_status": {
|
||||
"match": {
|
||||
"value": "state.status",
|
||||
"cases": [
|
||||
{"equals": "ready", "then": "ready"},
|
||||
{"equals": "waiting", "then": "waiting"},
|
||||
],
|
||||
"default": "__end__",
|
||||
}
|
||||
},
|
||||
"ready": {"use": "demo.ready"},
|
||||
"waiting": {"use": "demo.waiting"},
|
||||
},
|
||||
"routes": {
|
||||
"ready": {"ok": "__end__"},
|
||||
"waiting": {"ok": "__end__"},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
workflow = build_workflow_from_draft(draft)
|
||||
condition_ids = [
|
||||
node.id for node in workflow.nodes if isinstance(node, ConditionNode)
|
||||
]
|
||||
|
||||
assert condition_ids == ["match_status", "match_status_2"]
|
||||
assert workflow.start == "match_status"
|
||||
assert [(edge.from_, edge.outcome, edge.to) for edge in workflow.edges[:4]] == [
|
||||
("match_status", "true", "ready"),
|
||||
("match_status", "false", "match_status_2"),
|
||||
("match_status_2", "true", "waiting"),
|
||||
("match_status_2", "false", "__end__"),
|
||||
]
|
||||
|
||||
@@ -7,6 +7,7 @@ from pydantic import ValidationError
|
||||
|
||||
from wf_artifacts.drafts import (
|
||||
DraftChooseStep,
|
||||
DraftMatchStep,
|
||||
DraftUseStep,
|
||||
DraftWhenStep,
|
||||
WorkflowDraft,
|
||||
@@ -87,6 +88,30 @@ def test_workflow_draft_accepts_choose_step() -> None:
|
||||
assert isinstance(draft.steps["choose_next"], DraftChooseStep)
|
||||
|
||||
|
||||
def test_workflow_draft_accepts_match_step() -> None:
|
||||
draft = WorkflowDraft.model_validate(
|
||||
{
|
||||
**_keyed_echo_draft(),
|
||||
"start": "match_status",
|
||||
"steps": {
|
||||
**_keyed_echo_draft()["steps"],
|
||||
"match_status": {
|
||||
"match": {
|
||||
"value": "state.status",
|
||||
"cases": [
|
||||
{"equals": "ready", "then": "echo"},
|
||||
{"equals": "done", "then": "__end__"},
|
||||
],
|
||||
"default": "__end__",
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
assert isinstance(draft.steps["match_status"], DraftMatchStep)
|
||||
|
||||
|
||||
def _keyed_echo_draft() -> dict[str, Any]:
|
||||
return {
|
||||
"name": "echo",
|
||||
|
||||
Reference in New Issue
Block a user