import json import unittest from orchestration_worker import ( build_child_tasks, determine_parent_status, parse_structured_response, ) class OrchestrationWorkerTests(unittest.TestCase): def test_unverified_model_response_can_never_be_done(self): self.assertEqual( determine_parent_status(has_children=False, deliverable_url=None, verified=False), "TEST", ) self.assertEqual( determine_parent_status(has_children=False, deliverable_url="https://canina.ir/x", verified=False), "TEST", ) def test_model_claimed_live_deliverable_still_requires_independent_qa(self): self.assertEqual( determine_parent_status(has_children=False, deliverable_url="https://canina.ir/x", verified=True), "TEST", ) def test_children_force_waiting_dependencies(self): self.assertEqual( determine_parent_status(has_children=True, deliverable_url=None, verified=False), "WAITING_DEPENDENCIES", ) def test_parse_json_code_fence(self): payload = parse_structured_response('```json\n{"summary":"ok","child_tasks":[]}\n```') self.assertEqual(payload["summary"], "ok") def test_parse_json_with_raw_control_character(self): payload = parse_structured_response('{"summary":"line one\nline two","child_tasks":[]}') self.assertEqual(payload["summary"], "line one\nline two") def test_child_task_codes_are_deterministic_and_include_parent(self): proposal = { "child_tasks": [ { "department": "CONTENT", "title": "تدوین مقاله", "description": "مقاله مستند", "priority": "HIGH", "acceptance_criteria": ["پیش‌نویس موجود باشد"], } ] } first = build_child_tasks("TSK-390939", proposal, depth=0) second = build_child_tasks("TSK-390939", proposal, depth=0) self.assertEqual(first[0]["code"], second[0]["code"]) self.assertEqual(first[0]["acceptanceCriteria"]["parentTaskCode"], "TSK-390939") self.assertEqual(first[0]["acceptanceCriteria"]["depth"], 1) def test_depth_limit_blocks_recursive_fanout(self): proposal = {"child_tasks": [{"department": "SEO", "title": "x"}]} self.assertEqual(build_child_tasks("TSK-1", proposal, depth=2), []) if __name__ == "__main__": unittest.main()