and more good stuff
this time its... jus look at the test diff
This commit is contained in:
@@ -184,9 +184,11 @@ class WorkflowBuilder:
|
|||||||
"""
|
"""
|
||||||
return execute_workflow(self.compile(), workflow_input, self.registry())
|
return execute_workflow(self.compile(), workflow_input, self.registry())
|
||||||
|
|
||||||
def condition(self, *, id: str, check: CoreCondition | Expr) -> ConditionNode:
|
def condition(
|
||||||
|
self, *, id: str | None = None, check: CoreCondition | Expr
|
||||||
|
) -> ConditionNode:
|
||||||
node = ConditionNode(
|
node = ConditionNode(
|
||||||
id=id,
|
id=id or self._next_step_id("condition"),
|
||||||
type="condition",
|
type="condition",
|
||||||
check=compile_condition(check),
|
check=compile_condition(check),
|
||||||
)
|
)
|
||||||
@@ -196,7 +198,7 @@ class WorkflowBuilder:
|
|||||||
def foreach(
|
def foreach(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
id: str,
|
id: str | None = None,
|
||||||
over: PathArg,
|
over: PathArg,
|
||||||
as_: str,
|
as_: str,
|
||||||
mode: Literal["serial", "parallel"] = "serial",
|
mode: Literal["serial", "parallel"] = "serial",
|
||||||
@@ -204,7 +206,7 @@ class WorkflowBuilder:
|
|||||||
) -> ForeachNode:
|
) -> ForeachNode:
|
||||||
node = ForeachNode.model_validate(
|
node = ForeachNode.model_validate(
|
||||||
{
|
{
|
||||||
"id": id,
|
"id": id or self._next_step_id(f"foreach_{_slug_id(as_)}"),
|
||||||
"type": "foreach",
|
"type": "foreach",
|
||||||
"over": _coerce_path(over),
|
"over": _coerce_path(over),
|
||||||
"as": as_,
|
"as": as_,
|
||||||
@@ -218,14 +220,14 @@ class WorkflowBuilder:
|
|||||||
def interrupt(
|
def interrupt(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
id: str,
|
id: str | None = None,
|
||||||
kind: str,
|
kind: str,
|
||||||
request_map: MapArg | None = None,
|
request_map: MapArg | None = None,
|
||||||
out_map: MapArg | None = None,
|
out_map: MapArg | None = None,
|
||||||
outcomes: list[str] | None = None,
|
outcomes: list[str] | None = None,
|
||||||
) -> InterruptNode:
|
) -> InterruptNode:
|
||||||
node = InterruptNode(
|
node = InterruptNode(
|
||||||
id=id,
|
id=id or self._next_step_id(f"interrupt_{_slug_id(kind)}"),
|
||||||
type="interrupt",
|
type="interrupt",
|
||||||
kind=kind,
|
kind=kind,
|
||||||
request_map=_normalize_mapping(request_map),
|
request_map=_normalize_mapping(request_map),
|
||||||
@@ -252,6 +254,7 @@ class WorkflowBuilder:
|
|||||||
Passing a NodeSpec creates a node use with auto-mapping and an auto id.
|
Passing a NodeSpec creates a node use with auto-mapping and an auto id.
|
||||||
Passing an existing step or id only wires edges. Empty branch maps are
|
Passing an existing step or id only wires edges. Empty branch maps are
|
||||||
allowed but warn because they usually indicate an unfinished router.
|
allowed but warn because they usually indicate an unfinished router.
|
||||||
|
The returned mapping is keyed by branch outcome, not generated target id.
|
||||||
"""
|
"""
|
||||||
if not branches:
|
if not branches:
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from pydantic import BaseModel, Field
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from wf_authoring import WorkflowBuilder, node, state_field
|
from wf_authoring import WorkflowBuilder, node, state, state_field
|
||||||
from wf_core import RunStatus, WorkflowExecutionError
|
from wf_core import RunStatus, WorkflowExecutionError
|
||||||
|
|
||||||
|
|
||||||
@@ -284,3 +284,22 @@ def test_builder_branch_warns_on_empty_branch_map() -> None:
|
|||||||
targets = builder.branch(router, {})
|
targets = builder.branch(router, {})
|
||||||
|
|
||||||
assert targets == {}
|
assert targets == {}
|
||||||
|
|
||||||
|
|
||||||
|
def test_builder_can_auto_id_condition_foreach_and_interrupt() -> None:
|
||||||
|
builder = WorkflowBuilder(
|
||||||
|
name="auto_id_control_demo",
|
||||||
|
input_schema=AutoBindInput,
|
||||||
|
state_schema=AutoBindState,
|
||||||
|
output_schema=AutoBindOutput,
|
||||||
|
)
|
||||||
|
|
||||||
|
first_condition = builder.condition(check=state("count").gt(0))
|
||||||
|
second_condition = builder.condition(check=state("count").gt(1))
|
||||||
|
foreach = builder.foreach(over="state.tags", as_="tag")
|
||||||
|
interrupt = builder.interrupt(kind="approval")
|
||||||
|
|
||||||
|
assert first_condition.id == "condition"
|
||||||
|
assert second_condition.id == "condition_2"
|
||||||
|
assert foreach.id == "foreach_tag"
|
||||||
|
assert interrupt.id == "interrupt_approval"
|
||||||
|
|||||||
Reference in New Issue
Block a user