Files
gitea-agent/harness/tests/common/test_delegation_consumers.py
T

47 lines
2.1 KiB
Python

import importlib.util
import unittest
from pathlib import Path
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[3]
PATH = ROOT / "harness/agents/impl/skills/gitea-issue-implementation/scripts/delivery_adoption.py"
spec = importlib.util.spec_from_file_location("delivery_adoption", PATH)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
class DeliveryConsumerTests(unittest.TestCase):
def test_delivery_requires_adoption_then_calls_adapter_once(self):
calls = []
with patch.object(mod, "require_adoption", return_value={"status": "pass"}) as adopted:
result = mod.deliver(lambda: {"adapter": "actual"}, head="a" * 40,
declaration={"mode": "delegated"})
adopted.assert_called_once_with({"mode": "delegated"}, expected_source={"kind": "git_tree", "revision": "a" * 40}, expected_stage="implementation-delivery")
self.assertEqual(result, {"adapter": "actual"})
def test_rejected_adoption_blocks_adapter(self):
calls = []
with patch.object(mod, "require_adoption", side_effect=mod.AdoptionError("no")):
with self.assertRaises(mod.AdoptionError):
mod.deliver(lambda: calls.append("called"), head="a" * 40,
declaration={"mode": "delegated"})
self.assertEqual(calls, [])
def test_missing_declaration_blocks_adapter(self):
calls = []
with self.assertRaises(mod.AdoptionError):
mod.deliver(lambda: calls.append("called"), head="a" * 40, declaration=None)
self.assertEqual(calls, [])
def test_explicit_none_still_validates_head_and_calls_adapter(self):
calls = []
with patch.object(mod, "require_adoption", return_value={"status": "none"}):
with self.assertRaises(mod.AdoptionError):
mod.deliver(lambda: calls.append("called"), head="bad", declaration={"mode": "none"})
mod.deliver(lambda: calls.append("called"), head="a" * 40, declaration={"mode": "none"})
self.assertEqual(calls, ["called"])
if __name__ == "__main__":
unittest.main()