dcy-011 전 주기 delivery. issue #6(buy 식별자 정정) + issue #11(ledger silent skip) 흡수. 거버넌스: 기존 Implemented REQ는 change-req, 신규 기능만 신규 REQ(OQ-3). - REQ-007 (change-req): buy admission portfolio_id 필수화 + SnapshotStore symbol resolve + unknown_portfolio 거부 (hard cutover, OQ-1/OQ-2) - REQ-021 (change-req): buy 메시지 payload symbol 제거 - REQ-018 (change-req): _record_ledger skip 가시화 (WARN + ledger_skipped 카운터) - REQ-055 (신규): closed↔ledger_outbox anti-join 운영 점검 find_ledger_gap_slots 코드: intents.py(BuyIntent portfolio_id 필수 + resolve_symbol 주입 + _admit_buy reject 분기), messaging_handlers.py, runtime/daemon.py(_resolve_symbol 배선), execution.py(skip WARN 로그), adapters/persistence/ops_checks.py(신규 anti-join). 검증: 단위 282 passed/32 skipped, 인프라 게이트(PG+RabbitMQ) 314 passed, ruff clean. BAT-015(standard) release-candidate. srs/index Next ID → REQ-056. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
78 lines
2.7 KiB
Python
78 lines
2.7 KiB
Python
"""Snapshot RPC handler tests (REQ-021 AC-2, BAT-007 stub-shape)."""
|
|
from __future__ import annotations
|
|
|
|
from datetime import date
|
|
|
|
from trex_core.adapters.persistence.in_memory_intent_store import InMemoryIntentStore
|
|
from trex_core.application.intents import BuyIntent, IntentService
|
|
from trex_core.application.messaging import RpcRequest
|
|
from trex_core.application.messaging_handlers import make_snapshot_rpc_handler
|
|
from trex_core.domain.slot import SlotService
|
|
from trex_core.domain.slot.in_memory_repository import InMemorySlotRepository
|
|
|
|
DAY = date(2026, 6, 5)
|
|
|
|
|
|
def _wire():
|
|
repo = InMemorySlotRepository()
|
|
svc = SlotService(repo)
|
|
intents = IntentService(svc, repo, InMemoryIntentStore())
|
|
svc.preallocate_daily_slots(DAY, 3)
|
|
return repo, svc, intents
|
|
|
|
|
|
def _req(view="all", strategy_id=None):
|
|
return RpcRequest(
|
|
payload={
|
|
"view": view,
|
|
"strategy_id": strategy_id,
|
|
"trading_date": DAY.isoformat(),
|
|
},
|
|
correlation_id="snap-cid",
|
|
)
|
|
|
|
|
|
def test_snapshot_returns_all_slots_and_capacity():
|
|
repo, svc, intents = _wire()
|
|
intents.submit_buy(BuyIntent(
|
|
intent_id="b1", trading_date=DAY, symbol="005930", qty=10,
|
|
strategy_id="A", portfolio_id="PF-1",
|
|
))
|
|
handler = make_snapshot_rpc_handler(repo, svc)
|
|
resp = handler(_req())
|
|
assert resp.payload["trading_date"] == DAY.isoformat()
|
|
assert resp.payload["view"] == "all"
|
|
assert len(resp.payload["slots"]) == 3 # all 3 slots returned
|
|
cap = resp.payload["capacity"]
|
|
assert cap["pending_count"] == 1 and cap["idle_count"] == 2
|
|
|
|
|
|
def test_snapshot_open_view_filters_to_active_slots():
|
|
repo, svc, intents = _wire()
|
|
intents.submit_buy(BuyIntent(
|
|
intent_id="b1", trading_date=DAY, symbol="005930", qty=10, strategy_id="A",
|
|
portfolio_id="PF-1",
|
|
))
|
|
handler = make_snapshot_rpc_handler(repo, svc)
|
|
resp = handler(_req(view="open"))
|
|
statuses = {s["status"] for s in resp.payload["slots"]}
|
|
assert "idle" not in statuses
|
|
assert statuses == {"pending_buy"}
|
|
|
|
|
|
def test_snapshot_strategy_id_filter():
|
|
repo, svc, intents = _wire()
|
|
intents.submit_buy(BuyIntent(
|
|
intent_id="b1", trading_date=DAY, symbol="005930", qty=10, strategy_id="A",
|
|
portfolio_id="PF-1",
|
|
))
|
|
intents.submit_buy(BuyIntent(
|
|
intent_id="b2", trading_date=DAY, symbol="000660", qty=5, strategy_id="B",
|
|
portfolio_id="PF-2",
|
|
))
|
|
handler = make_snapshot_rpc_handler(repo, svc)
|
|
resp = handler(_req(view="open", strategy_id="A"))
|
|
assert len(resp.payload["slots"]) == 1
|
|
assert resp.payload["slots"][0]["strategy_id"] == "A"
|
|
assert resp.payload["slots"][0]["symbol"] == "005930"
|