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}, ), ]