import json from pathlib import Path import unittest from src.workflow import MockBitrix, WorkflowError, create_verified_task class WorkflowTests(unittest.TestCase): def setUp(self): self.case = json.loads((Path(__file__).parents[1] / "examples/case.json").read_text()) def test_verified_creation_and_handoff(self): result = create_verified_task(MockBitrix(), self.case) self.assertTrue(result["creation_verified"]) self.assertEqual(result["handoff"]["acceptance"], "pending human review") def test_api_failure_stops(self): with self.assertRaisesRegex(WorkflowError, "creation failed"): create_verified_task(MockBitrix(fail=True), self.case) def test_readback_mismatch_stops_without_duplicate(self): api = MockBitrix(corrupt=True) with self.assertRaisesRegex(WorkflowError, "mismatch"): create_verified_task(api, self.case) self.assertEqual(len(api.tasks), 1) def test_approval_required(self): self.case["human_approved"] = False api = MockBitrix() with self.assertRaisesRegex(WorkflowError, "approval"): create_verified_task(api, self.case) self.assertEqual(api.tasks, {}) def test_uncertain_creation_stops(self): class Uncertain: def call(self, method, params): return {"result": {}} with self.assertRaisesRegex(WorkflowError, "Uncertain"): create_verified_task(Uncertain(), self.case)