fix: preserve sell event routing owner
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
"""Runtime SELL event owner routing defenses (REQ-0011 / AC-0039)."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, cast
|
||||
from uuid import uuid4
|
||||
|
||||
from trex_core.domain.slot import Slot, SlotState
|
||||
from trex_core.runtime.daemon import Daemon
|
||||
|
||||
|
||||
class _Publisher:
|
||||
def __init__(self) -> None:
|
||||
self.calls: list[tuple[str, dict]] = []
|
||||
self.failure: Exception | None = None
|
||||
|
||||
def publish_event(self, routing_key: str, payload: dict) -> None:
|
||||
if self.failure is not None:
|
||||
raise self.failure
|
||||
self.calls.append((routing_key, payload))
|
||||
|
||||
|
||||
def _daemon_with_publisher() -> tuple[Daemon, _Publisher]:
|
||||
daemon = object.__new__(Daemon)
|
||||
publisher = _Publisher()
|
||||
daemon.event_publisher = cast(Any, publisher)
|
||||
return daemon, publisher
|
||||
|
||||
|
||||
def test_runtime_emitter_blocks_ownerless_sell_without_synthetic_owner(caplog):
|
||||
daemon, publisher = _daemon_with_publisher()
|
||||
slot = Slot(slot_id=uuid4(), status=SlotState.INACTIVE, symbol="005930")
|
||||
|
||||
daemon._make_event_emitter()("slot_filled_sell", slot, None)
|
||||
|
||||
assert publisher.calls == []
|
||||
assert "reason=sell_event_owner_missing" in caplog.text
|
||||
|
||||
|
||||
def test_runtime_emitter_routes_sell_with_explicit_owner():
|
||||
daemon, publisher = _daemon_with_publisher()
|
||||
slot = Slot(slot_id=uuid4(), status=SlotState.INACTIVE, symbol="005930")
|
||||
|
||||
daemon._make_event_emitter()("slot_filled_sell", slot, "SELL-B")
|
||||
|
||||
assert len(publisher.calls) == 1
|
||||
assert publisher.calls[0][0] == "slot_filled_sell.SELL-B.005930"
|
||||
|
||||
|
||||
def test_runtime_publish_failure_log_excludes_raw_exception(caplog):
|
||||
daemon, publisher = _daemon_with_publisher()
|
||||
publisher.failure = RuntimeError("SENTINEL_SECRET_CONNECTION_TEXT")
|
||||
slot = Slot(slot_id=uuid4(), status=SlotState.INACTIVE, symbol="005930")
|
||||
|
||||
daemon._make_event_emitter()("slot_filled_sell", slot, "SELL-B")
|
||||
|
||||
assert publisher.calls == []
|
||||
assert "reason=event_publish_failed" in caplog.text
|
||||
assert "exc_type=RuntimeError" in caplog.text
|
||||
assert "SENTINEL_SECRET_CONNECTION_TEXT" not in caplog.text
|
||||
assert not any(record.exc_info for record in caplog.records)
|
||||
Reference in New Issue
Block a user