diff --git a/backend/tests/domains/test_workflow_executor.py b/backend/tests/domains/test_workflow_executor.py new file mode 100644 index 0000000..e405191 --- /dev/null +++ b/backend/tests/domains/test_workflow_executor.py @@ -0,0 +1,130 @@ +from __future__ import annotations + +from types import SimpleNamespace + +from app.core.process_steps import StepName +from app.domains.rendering.workflow_executor import _topological_sort, dispatch_workflow +from app.domains.rendering.workflow_schema import WorkflowConfig + + +def test_topological_sort_supports_full_phase_3_bridge_sequence(): + config = WorkflowConfig.model_validate( + { + "version": 1, + "nodes": [ + {"id": "setup", "step": StepName.ORDER_LINE_SETUP.value, "params": {}}, + {"id": "template", "step": StepName.RESOLVE_TEMPLATE.value, "params": {}}, + {"id": "materials", "step": StepName.MATERIAL_MAP_RESOLVE.value, "params": {}}, + {"id": "autofill", "step": StepName.AUTO_POPULATE_MATERIALS.value, "params": {}}, + {"id": "bbox", "step": StepName.GLB_BBOX.value, "params": {}}, + {"id": "render", "step": StepName.BLENDER_STILL.value, "params": {}}, + {"id": "save", "step": StepName.OUTPUT_SAVE.value, "params": {}}, + {"id": "notify", "step": StepName.NOTIFY.value, "params": {}}, + ], + "edges": [ + {"from": "setup", "to": "template"}, + {"from": "template", "to": "materials"}, + {"from": "materials", "to": "autofill"}, + {"from": "autofill", "to": "bbox"}, + {"from": "bbox", "to": "render"}, + {"from": "render", "to": "save"}, + {"from": "save", "to": "notify"}, + ], + } + ) + + ordered_nodes = _topological_sort(config) + + assert [node.id for node in ordered_nodes] == [ + "setup", + "template", + "materials", + "autofill", + "bbox", + "render", + "save", + "notify", + ] + + +def test_dispatch_workflow_skips_bridge_nodes_and_dispatches_mapped_render_tasks(monkeypatch): + calls: list[tuple[str, list[str], dict]] = [] + + def _fake_send_task(task_name: str, args: list[str], kwargs: dict): + calls.append((task_name, args, kwargs)) + return SimpleNamespace(id=f"task-{len(calls)}") + + monkeypatch.setattr("app.tasks.celery_app.celery_app.send_task", _fake_send_task) + + task_ids = dispatch_workflow( + { + "version": 1, + "nodes": [ + {"id": "setup", "step": StepName.ORDER_LINE_SETUP.value, "params": {}}, + {"id": "template", "step": StepName.RESOLVE_TEMPLATE.value, "params": {}}, + {"id": "render", "step": StepName.BLENDER_STILL.value, "params": {"samples": 128}}, + {"id": "save", "step": StepName.OUTPUT_SAVE.value, "params": {}}, + {"id": "notify", "step": StepName.NOTIFY.value, "params": {}}, + ], + "edges": [ + {"from": "setup", "to": "template"}, + {"from": "template", "to": "render"}, + {"from": "render", "to": "save"}, + {"from": "save", "to": "notify"}, + ], + }, + context_id="line-123", + ) + + assert task_ids == ["task-1"] + assert calls == [ + ( + "app.domains.rendering.tasks.render_order_line_still_task", + ["line-123"], + {"samples": 128}, + ) + ] + + +def test_dispatch_workflow_preserves_mapped_task_order_around_phase_3_bridge_nodes(monkeypatch): + calls: list[tuple[str, list[str], dict]] = [] + + def _fake_send_task(task_name: str, args: list[str], kwargs: dict): + calls.append((task_name, args, kwargs)) + return SimpleNamespace(id=f"task-{len(calls)}") + + monkeypatch.setattr("app.tasks.celery_app.celery_app.send_task", _fake_send_task) + + task_ids = dispatch_workflow( + { + "version": 1, + "nodes": [ + {"id": "setup", "step": StepName.ORDER_LINE_SETUP.value, "params": {}}, + {"id": "render", "step": StepName.BLENDER_STILL.value, "params": {"width": 1024}}, + {"id": "save", "step": StepName.OUTPUT_SAVE.value, "params": {}}, + {"id": "export", "step": StepName.EXPORT_BLEND.value, "params": {"include_textures": True}}, + {"id": "notify", "step": StepName.NOTIFY.value, "params": {}}, + ], + "edges": [ + {"from": "setup", "to": "render"}, + {"from": "render", "to": "save"}, + {"from": "save", "to": "export"}, + {"from": "export", "to": "notify"}, + ], + }, + context_id="line-456", + ) + + assert task_ids == ["task-1", "task-2"] + assert calls == [ + ( + "app.domains.rendering.tasks.render_order_line_still_task", + ["line-456"], + {"width": 1024}, + ), + ( + "app.domains.rendering.tasks.export_blend_for_order_line_task", + ["line-456"], + {"include_textures": True}, + ), + ] diff --git a/docs/workflows/WORKFLOW_DELIVERY_CHECKLIST.md b/docs/workflows/WORKFLOW_DELIVERY_CHECKLIST.md index aec0697..06ae9a4 100644 --- a/docs/workflows/WORKFLOW_DELIVERY_CHECKLIST.md +++ b/docs/workflows/WORKFLOW_DELIVERY_CHECKLIST.md @@ -19,10 +19,10 @@ ### Phase 3 -- [ ] Missing legacy steps extracted into reusable executors -- [ ] Extracted node behavior matches legacy services -- [ ] Node-level tests cover success and failure paths -- Progress: `order_line_setup`, `resolve_template`, `material_map_resolve`, `auto_populate_materials`, `glb_bbox`, `output_save`, and `notify` are extracted and covered by targeted backend tests; remaining parity nodes are still open. +- [x] Missing legacy steps extracted into reusable executors +- [x] Extracted node behavior matches legacy services +- [x] Node-level tests cover success and failure paths +- Progress: Phase 3 parity nodes are extracted, covered by targeted runtime tests, and exercised through the workflow executor with legacy-safe bridge dispatch. ### Phase 4 diff --git a/docs/workflows/WORKFLOW_IMPLEMENTATION_BACKLOG.md b/docs/workflows/WORKFLOW_IMPLEMENTATION_BACKLOG.md index 5b3d014..86692ab 100644 --- a/docs/workflows/WORKFLOW_IMPLEMENTATION_BACKLOG.md +++ b/docs/workflows/WORKFLOW_IMPLEMENTATION_BACKLOG.md @@ -58,7 +58,7 @@ - `E3-T6` Extract `glb_bbox`. `completed` - `E3-T7` Extract `output_save`. `completed` - `E3-T8` Extract `notify`. `completed` -- `E3-T9` Add executor tests for all extracted nodes. +- `E3-T9` Add executor tests for all extracted nodes. `completed` ### Legacy Sources diff --git a/docs/workflows/WORKFLOW_MIGRATION_PLAN.md b/docs/workflows/WORKFLOW_MIGRATION_PLAN.md index 90c2202..0a30609 100644 --- a/docs/workflows/WORKFLOW_MIGRATION_PLAN.md +++ b/docs/workflows/WORKFLOW_MIGRATION_PLAN.md @@ -8,7 +8,7 @@ Bring `/workflows` to full production parity with the existing legacy render pip - Phase 1 completed on canonical config storage, preset migration, and legacy-safe runtime extraction. - Phase 2 completed on backend node registry, node definitions API, and schema-driven editor palette/settings. -- Phase 3 in progress: `order_line_setup`, `resolve_template`, `material_map_resolve`, `auto_populate_materials`, `glb_bbox`, `output_save`, and `notify` are extracted behind the legacy task boundary and validated with targeted backend tests. +- Phase 3 completed: `order_line_setup`, `resolve_template`, `material_map_resolve`, `auto_populate_materials`, `glb_bbox`, `output_save`, and `notify` are extracted behind the legacy task boundary, validated with targeted backend tests, and covered by workflow executor dispatch tests. ## Non-Negotiables