feat(intents): dcy-011 buy intent portfolio_id 필수 계약 + ledger skip 가시화 (BAT-015)
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>
This commit is contained in:
@@ -22,18 +22,21 @@ DAY = date(2026, 6, 5)
|
||||
def _wire():
|
||||
repo = InMemorySlotRepository()
|
||||
svc = SlotService(repo)
|
||||
intents = IntentService(svc, repo, InMemoryIntentStore())
|
||||
# dcy-011 / REQ-007: buy resolves symbol from the universe via resolver.
|
||||
intents = IntentService(svc, repo, InMemoryIntentStore(),
|
||||
resolve_symbol=lambda pid: "005930")
|
||||
svc.preallocate_daily_slots(DAY, 3)
|
||||
return repo, svc, intents
|
||||
|
||||
|
||||
def _buy_req(intent_id: str, symbol: str = "005930") -> RpcRequest:
|
||||
def _buy_req(intent_id: str, portfolio_id: str = "PF-1") -> RpcRequest:
|
||||
# dcy-011 / REQ-021: buy payload carries portfolio_id (required); no symbol.
|
||||
return RpcRequest(
|
||||
payload={
|
||||
"intent_type": "buy",
|
||||
"intent_id": intent_id,
|
||||
"trading_date": DAY.isoformat(),
|
||||
"symbol": symbol,
|
||||
"portfolio_id": portfolio_id,
|
||||
"qty": 10,
|
||||
},
|
||||
correlation_id=intent_id,
|
||||
@@ -119,7 +122,7 @@ def test_correlation_id_is_used_as_intent_id_when_missing_in_payload():
|
||||
payload={
|
||||
"intent_type": "buy",
|
||||
"trading_date": DAY.isoformat(),
|
||||
"symbol": "005930",
|
||||
"portfolio_id": "PF-1",
|
||||
"qty": 5,
|
||||
},
|
||||
correlation_id="cid-only",
|
||||
@@ -130,3 +133,43 @@ def test_correlation_id_is_used_as_intent_id_when_missing_in_payload():
|
||||
assert r1.payload == r2.payload
|
||||
pending = [s for s in repo.list_slots(DAY) if s.status is SlotState.PENDING_BUY]
|
||||
assert len(pending) == 1
|
||||
|
||||
|
||||
# ---- dcy-011 / REQ-007/021: portfolio_id required + symbol resolve ----------
|
||||
|
||||
def test_buy_without_portfolio_id_rejected():
|
||||
"""FR-1 / S-1: missing portfolio_id → portfolio_id_required reject."""
|
||||
repo, _, intents = _wire()
|
||||
handler = make_intent_rpc_handler(intents)
|
||||
req = RpcRequest(
|
||||
payload={"intent_type": "buy", "intent_id": "no-pf",
|
||||
"trading_date": DAY.isoformat(), "qty": 5},
|
||||
correlation_id="no-pf",
|
||||
)
|
||||
resp = handler(req)
|
||||
assert resp.payload["status"] == "rejected"
|
||||
assert resp.payload["reason"] == "portfolio_id_required"
|
||||
|
||||
|
||||
def test_buy_unknown_portfolio_rejected():
|
||||
"""FR-3 / S-1: portfolio_id absent from universe → unknown_portfolio reject."""
|
||||
repo = InMemorySlotRepository()
|
||||
svc = SlotService(repo)
|
||||
intents = IntentService(svc, repo, InMemoryIntentStore(),
|
||||
resolve_symbol=lambda pid: None) # universe empty
|
||||
svc.preallocate_daily_slots(DAY, 3)
|
||||
handler = make_intent_rpc_handler(intents)
|
||||
resp = handler(_buy_req("u1", portfolio_id="PF-X"))
|
||||
assert resp.payload["status"] == "rejected"
|
||||
assert resp.payload["reason"] == "unknown_portfolio"
|
||||
|
||||
|
||||
def test_buy_symbol_resolved_from_universe():
|
||||
"""FR-2 / S-1: symbol is resolved server-side from portfolio_id (no client symbol)."""
|
||||
repo, _, intents = _wire() # resolver → "005930"
|
||||
handler = make_intent_rpc_handler(intents)
|
||||
resp = handler(_buy_req("r1", portfolio_id="PF-9"))
|
||||
assert resp.payload["status"] == "admitted"
|
||||
from uuid import UUID
|
||||
slot = repo.fetch_slot(UUID(resp.payload["slot_id"]))
|
||||
assert slot.symbol == "005930" and slot.portfolio_id == "PF-9"
|
||||
|
||||
Reference in New Issue
Block a user