65 行
2.7 KiB
Python
65 行
2.7 KiB
Python
"""Lightweight workflow review checks."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from backend.dto.image_dto import GenerationImage
|
|
from backend.dto.workflow_dto import ProfileWorkflow, WorkflowNode
|
|
|
|
|
|
class ReviewFlowEngine:
|
|
def review_node(self, node: WorkflowNode, images: list[GenerationImage]) -> dict[str, Any]:
|
|
warnings: list[dict[str, Any]] = []
|
|
errors: list[dict[str, Any]] = []
|
|
if not images:
|
|
warnings.append({"code": "NO_IMAGES", "message": "node has no generated images"})
|
|
if node.status in {"completed", "selected"} and not node.selected_image_id:
|
|
errors.append({"code": "MISSING_SELECTED_IMAGE", "message": "completed node has no selected image"})
|
|
if node.selected_image_id and node.selected_image_id not in {image.image_id for image in images}:
|
|
errors.append({"code": "SELECTED_IMAGE_NOT_FOUND", "message": "selected image is not in node images"})
|
|
if any(image.image_id == node.selected_image_id and image.is_archived for image in images):
|
|
errors.append({"code": "SELECTED_IMAGE_ARCHIVED", "message": "selected image is archived"})
|
|
return {
|
|
"target_type": "node",
|
|
"target_id": node.node_id,
|
|
"passed": not errors,
|
|
"warnings": warnings,
|
|
"errors": errors,
|
|
"summary": {
|
|
"image_count": len(images),
|
|
"selected_image_id": node.selected_image_id,
|
|
"node_status": node.status,
|
|
},
|
|
}
|
|
|
|
def review_workflow(
|
|
self,
|
|
workflow: ProfileWorkflow,
|
|
nodes: list[WorkflowNode],
|
|
node_results: list[dict[str, Any]],
|
|
) -> dict[str, Any]:
|
|
errors = [error for result in node_results for error in result["errors"]]
|
|
warnings = [warning for result in node_results for warning in result["warnings"]]
|
|
incomplete = [node.node_id for node in nodes if node.status not in {"completed", "selected", "skipped"}]
|
|
if incomplete:
|
|
warnings.append(
|
|
{
|
|
"code": "INCOMPLETE_NODES",
|
|
"message": "workflow has nodes that are not finished",
|
|
"node_ids": incomplete,
|
|
}
|
|
)
|
|
return {
|
|
"target_type": "workflow",
|
|
"target_id": workflow.workflow_id,
|
|
"passed": not errors,
|
|
"warnings": warnings,
|
|
"errors": errors,
|
|
"summary": {
|
|
"workflow_type": workflow.workflow_type,
|
|
"node_count": len(nodes),
|
|
"incomplete_count": len(incomplete),
|
|
},
|
|
"nodes": node_results,
|
|
}
|