from __future__ import annotations from control_plane.agents.models import AgentVersion from control_plane.projects.models import Project, Task from control_plane.verification.models import Verification, VerificationLevel, VerificationResult class Judge: def judge(self, project: Project, task: Task, judge: AgentVersion, diff: str, test_status: str) -> Verification: evidence: list[dict[str, object]] = [{"type": "test_status", "status": test_status}] passed = test_status == "PASS" goal = task.goal.lower() expects_health_endpoint = "/health" in goal or "health endpoint" in goal or "health route" in goal if expects_health_endpoint: has_route = "/health" in diff or "path('health'" in diff or 'path("health"' in diff passed = passed and has_route and '"status": "ok"' in diff evidence.append({"type": "acceptance_check", "requirement": "health endpoint returns ok", "passed": passed}) if "description field" in goal: passed = passed and "description" in diff and "admin.py" in diff and "migrations" in diff evidence.append({"type": "acceptance_check", "requirement": "description field migration/admin/tests", "passed": passed}) return Verification.objects.create( project=project, task=task, level=VerificationLevel.TASK, judge=judge, result=VerificationResult.PASS if passed else VerificationResult.FAIL, contract={"acceptance_criteria": task.acceptance_criteria}, evidence=evidence, summary="Acceptance contract satisfied" if passed else "Acceptance contract failed", )