feat(orchestration): implement atomic claims, root task selection and truthful completion gates
This commit is contained in:
1 parent
ee90284129
commit
344f79039f
3 files changed
+184
-139
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import json
|
||||
import unittest
|
||||
from unittest.mock import Mock
|
||||
|
||||
from orchestration_worker import (
|
||||
claim_sql, complete_sql, execute_next_task, reconcile_parent_states,
|
||||
determine_parent_status, verify_artifact,
|
||||
)
|
||||
|
||||
|
||||
class ContractTests(unittest.TestCase):
|
||||
def test_claim_is_atomic_priority_first_and_includes_roots(self):
|
||||
sql = claim_sql("token-1")
|
||||
self.assertIn("FOR UPDATE SKIP LOCKED", sql)
|
||||
self.assertIn("CEO_EXPEDITE", sql)
|
||||
self.assertIn("updated_at ASC", sql)
|
||||
self.assertNotIn("parentTaskCode' IS NOT NULL", sql)
|
||||
self.assertIn("RETURNING", sql)
|
||||
|
||||
def test_completion_is_fenced_by_claim_token(self):
|
||||
sql = complete_sql("task-id", "token-1", "TEST", {"status": "QA_PENDING"})
|
||||
self.assertIn("IN_PROGRESS", sql)
|
||||
self.assertIn("token-1", sql)
|
||||
self.assertIn("RETURNING", sql)
|
||||
self.assertIn("claim_token", sql)
|
||||
self.assertIn("updated_at >= NOW() - INTERVAL '15 minutes'", sql)
|
||||
|
||||
def test_model_verified_url_cannot_mark_done(self):
|
||||
self.assertEqual(determine_parent_status(has_children=False, deliverable_url="https://canina.ir/fake", verified=True), "TEST")
|
||||
|
||||
def test_independent_qa_rejects_unverified_claimed_url(self):
|
||||
self.assertFalse(verify_artifact({"url": "https://canina.ir/fake", "verified": True}, {"passed": True}).passed)
|
||||
|
||||
def test_unapproved_content_publish_is_not_attempted(self):
|
||||
db = Mock()
|
||||
db.claim_next.return_value = {"id": "1", "code": "CEO-2", "department": "CONTENT", "title": "Draft", "description": "Do", "acceptance_criteria": {}, "claim_token": "abc"}
|
||||
db.finish_claim.return_value = True
|
||||
model = Mock()
|
||||
model.complete.return_value = json.dumps({"deliverable": {"type": "draft", "content": "clinical " * 200, "url": "https://canina.ir/blog/fake", "verified": True}, "verification": {"passed": True}})
|
||||
self.assertTrue(execute_next_task(db, model))
|
||||
self.assertEqual(db.finish_claim.call_args.args[2], "TEST")
|
||||
self.assertNotIn("published", db.finish_claim.call_args.args[1])
|
||||
|
||||
def test_root_executes_without_live_side_effects(self):
|
||||
db = Mock()
|
||||
db.claim_next.return_value = {"id": "1", "code": "CEO-1", "department": "PMO", "title": "Plan", "description": "Do", "acceptance_criteria": {}, "claim_token": "abc"}
|
||||
db.finish_claim.return_value = True
|
||||
model = Mock()
|
||||
model.complete.return_value = json.dumps({"deliverable": {"url": "https://canina.ir/fake", "verified": True}, "verification": {"passed": True}, "child_tasks": []})
|
||||
self.assertTrue(execute_next_task(db, model))
|
||||
db.finish_claim.assert_called_once()
|
||||
self.assertEqual(db.finish_claim.call_args.args[2], "TEST")
|
||||
db.insert_children.assert_not_called()
|
||||
|
||||
def test_rejected_child_never_unblocks_parent(self):
|
||||
db = Mock()
|
||||
db.rows_json.return_value = []
|
||||
self.assertFalse(reconcile_parent_states(db))
|
||||
# REJECTED is not DONE, therefore the anti-join still blocks the parent.
|
||||
self.assertIn("NOT IN ('DONE')", db.rows_json.call_args.args[0])
|
||||
self.assertNotIn("NOT IN ('DONE', 'REJECTED')", db.rows_json.call_args.args[0])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user