feat: strengthen transactional audit delivery
This commit is contained in:
@@ -17,6 +17,11 @@ from govoplan_core.core.events import (
|
||||
EventActorRef,
|
||||
PlatformEvent,
|
||||
)
|
||||
from govoplan_core.core.institutional import (
|
||||
GovernedContextEnvelope,
|
||||
InstitutionalReference,
|
||||
TemporalRevision,
|
||||
)
|
||||
from govoplan_core.db.base import Base
|
||||
|
||||
|
||||
@@ -109,6 +114,60 @@ class AuditOutboxTests(unittest.TestCase):
|
||||
delivery.delivery_key,
|
||||
)
|
||||
|
||||
def test_outbox_preserves_institutional_context(self) -> None:
|
||||
Session = self._database()
|
||||
outbox = SqlAuditOutbox()
|
||||
seen: list[PlatformEvent] = []
|
||||
now = datetime.now(timezone.utc)
|
||||
context = GovernedContextEnvelope(
|
||||
tenant_id="tenant-1",
|
||||
temporal=TemporalRevision(revision="decision:7", recorded_at=now),
|
||||
decision_ref=InstitutionalReference(
|
||||
kind="decision",
|
||||
owner_module="committee",
|
||||
object_id="decision-7",
|
||||
tenant_id="tenant-1",
|
||||
version="7",
|
||||
valid_at=now,
|
||||
),
|
||||
approval_refs=(
|
||||
InstitutionalReference(
|
||||
kind="approval",
|
||||
owner_module="workflow",
|
||||
object_id="approval-3",
|
||||
tenant_id="tenant-1",
|
||||
version="3",
|
||||
valid_at=now,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
with Session() as session:
|
||||
outbox.enqueue(
|
||||
session,
|
||||
PlatformEvent(
|
||||
type="committee.decision.recorded",
|
||||
module_id="committee",
|
||||
institutional_context=context,
|
||||
),
|
||||
)
|
||||
outbox.dispatch_pending(
|
||||
session,
|
||||
consumers=(
|
||||
DurableEventConsumer(
|
||||
consumer_id="tests.institutional-context.v1",
|
||||
event_types=frozenset({"committee.decision.recorded"}),
|
||||
handler=lambda delivered, _key: seen.append(delivered),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
self.assertEqual("decision-7", seen[0].institutional_context.decision_ref.object_id)
|
||||
self.assertEqual(
|
||||
"approval-3",
|
||||
seen[0].institutional_context.approval_refs[0].object_id,
|
||||
)
|
||||
|
||||
def test_outbox_retries_then_quarantines_a_failed_consumer(self) -> None:
|
||||
Session = self._database()
|
||||
outbox = SqlAuditOutbox(max_attempts=2)
|
||||
|
||||
Reference in New Issue
Block a user