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:
@@ -52,7 +52,8 @@ def test_intent_admission_rpc_dedups_duplicate_correlation_id_over_rabbitmq(mq_u
|
||||
"""REQ-023 AC-1: same correlation_id processed twice ⇒ slot transitions ONCE."""
|
||||
repo = InMemorySlotRepository()
|
||||
svc = SlotService(repo)
|
||||
intents = IntentService(svc, repo, InMemoryIntentStore())
|
||||
intents = IntentService(svc, repo, InMemoryIntentStore(),
|
||||
resolve_symbol=lambda pid: "005930") # dcy-011: universe resolve
|
||||
svc.preallocate_daily_slots(DAY, 3)
|
||||
handler = make_intent_rpc_handler(intents)
|
||||
|
||||
@@ -77,7 +78,7 @@ def test_intent_admission_rpc_dedups_duplicate_correlation_id_over_rabbitmq(mq_u
|
||||
cid = "buy-dup-rmq"
|
||||
payload = {
|
||||
"intent_type": "buy", "intent_id": cid,
|
||||
"trading_date": DAY.isoformat(), "symbol": "005930", "qty": 10,
|
||||
"trading_date": DAY.isoformat(), "portfolio_id": "PF-1", "qty": 10,
|
||||
}
|
||||
r1 = client.call_rpc(queue, payload, correlation_id=cid, timeout=3.0)
|
||||
r2 = client.call_rpc(queue, payload, correlation_id=cid, timeout=3.0)
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
"""Ledger-gap operational check tests (REQ-055 / dcy-011 FR-5, issue #11).
|
||||
|
||||
PostgreSQL-gated (TREX_POSTGRESQL_TEST_DSN). Inserts closed slots + outbox rows
|
||||
directly and asserts find_ledger_gap_slots detects only the gaps.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
from datetime import date
|
||||
|
||||
from trex_core.adapters.persistence.ops_checks import find_ledger_gap_slots
|
||||
|
||||
_DAY = date(2026, 6, 8)
|
||||
|
||||
|
||||
def _insert_slot(conn, *, status, portfolio_id, symbol="005930"):
|
||||
sid = str(uuid.uuid4())
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"INSERT INTO daily_slot (slot_id, trading_date, status, symbol, portfolio_id) "
|
||||
"VALUES (%s, %s, %s, %s, %s)",
|
||||
(sid, _DAY, status, symbol, portfolio_id),
|
||||
)
|
||||
return sid
|
||||
|
||||
|
||||
def _insert_outbox(conn, *, asset_id, order_id="O1", execution_id="E1"):
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"INSERT INTO ledger_outbox (correlation_id, asset_id, order_id, execution_id, "
|
||||
"side, qty, price) VALUES (%s, %s, %s, %s, 'buy', 1, 1000)",
|
||||
(f"{asset_id}:{order_id}:{execution_id}", asset_id, order_id, execution_id),
|
||||
)
|
||||
|
||||
|
||||
def test_detects_only_gap_slots(pg_clean):
|
||||
import psycopg
|
||||
dsn = pg_clean
|
||||
with psycopg.connect(dsn, autocommit=True) as conn:
|
||||
gap_null = _insert_slot(conn, status="closed", portfolio_id=None) # gap (no pf)
|
||||
gap_no_outbox = _insert_slot(conn, status="closed", portfolio_id="PF-GAP") # gap (no outbox row)
|
||||
ok = _insert_slot(conn, status="closed", portfolio_id="PF-OK") # not a gap
|
||||
_insert_outbox(conn, asset_id="PF-OK")
|
||||
_insert_slot(conn, status="holding", portfolio_id=None) # not closed → ignored
|
||||
|
||||
gaps = find_ledger_gap_slots(dsn, trading_date=_DAY)
|
||||
gap_ids = {str(g["slot_id"]) for g in gaps}
|
||||
assert gap_null in gap_ids
|
||||
assert gap_no_outbox in gap_ids
|
||||
assert ok not in gap_ids
|
||||
|
||||
|
||||
def test_no_gaps_when_all_recorded(pg_clean):
|
||||
import psycopg
|
||||
dsn = pg_clean
|
||||
with psycopg.connect(dsn, autocommit=True) as conn:
|
||||
_insert_slot(conn, status="closed", portfolio_id="PF-1")
|
||||
_insert_outbox(conn, asset_id="PF-1")
|
||||
assert find_ledger_gap_slots(dsn, trading_date=_DAY) == []
|
||||
@@ -32,7 +32,7 @@ def test_preallocate_and_capacity(pg_clean):
|
||||
def test_buy_intent_persists_transition(pg_clean):
|
||||
repo, svc, intents = _wire(pg_clean)
|
||||
svc.preallocate_daily_slots(DAY, 3)
|
||||
d = intents.submit_buy(BuyIntent(intent_id="pg-buy-1", trading_date=DAY, symbol="005930", qty=10))
|
||||
d = intents.submit_buy(BuyIntent(intent_id="pg-buy-1", trading_date=DAY, symbol="005930", qty=10, portfolio_id="PF-1"))
|
||||
assert d.admitted
|
||||
slot = repo.fetch_slot(d.slot_id)
|
||||
assert slot.status is SlotState.PENDING_BUY and slot.symbol == "005930"
|
||||
@@ -41,8 +41,8 @@ def test_buy_intent_persists_transition(pg_clean):
|
||||
def test_buy_intent_idempotent_on_pg(pg_clean):
|
||||
repo, svc, intents = _wire(pg_clean)
|
||||
svc.preallocate_daily_slots(DAY, 3)
|
||||
d1 = intents.submit_buy(BuyIntent(intent_id="pg-dup", trading_date=DAY, symbol="005930"))
|
||||
d2 = intents.submit_buy(BuyIntent(intent_id="pg-dup", trading_date=DAY, symbol="005930"))
|
||||
d1 = intents.submit_buy(BuyIntent(intent_id="pg-dup", trading_date=DAY, symbol="005930", portfolio_id="PF-1"))
|
||||
d2 = intents.submit_buy(BuyIntent(intent_id="pg-dup", trading_date=DAY, symbol="005930", portfolio_id="PF-1"))
|
||||
assert d1.slot_id == d2.slot_id and d2.status == "admitted"
|
||||
pending = [s for s in repo.list_slots(DAY) if s.status is SlotState.PENDING_BUY]
|
||||
assert len(pending) == 1 # no double transition
|
||||
@@ -51,7 +51,7 @@ def test_buy_intent_idempotent_on_pg(pg_clean):
|
||||
def test_full_lifecycle_recovery_bumps_entry_count(pg_clean):
|
||||
repo, svc, intents = _wire(pg_clean)
|
||||
svc.preallocate_daily_slots(DAY, 1)
|
||||
d = intents.submit_buy(BuyIntent(intent_id="pg-life", trading_date=DAY, symbol="005930"))
|
||||
d = intents.submit_buy(BuyIntent(intent_id="pg-life", trading_date=DAY, symbol="005930", portfolio_id="PF-1"))
|
||||
sid = d.slot_id
|
||||
svc.transit_slot(sid, SlotState.PENDING_BUY, SlotState.HOLDING, reason="filled", actor="t")
|
||||
intents.submit_sell(SellIntent(intent_id="pg-sell", slot_id=sid))
|
||||
|
||||
Reference in New Issue
Block a user