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:
2026-06-08 12:57:51 +09:00
co-authored by Claude Opus 4.8
parent a24ebb242e
commit aee3512383
27 changed files with 729 additions and 33 deletions
@@ -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) == []