fix(reconcile): symbol을 슬롯 생성 시 함께 저장 + NULL 슬롯 backfill

reconcile_universe 시그니처를 set[str] → dict[str, str] (portfolio_id→symbol)로 변경.
기존 symbol=NULL 슬롯은 다음 reconcile 실행 시 자동 backfill.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 21:08:46 +09:00
co-authored by Claude Sonnet 4.6
parent 221a16342e
commit 24a6017457
29 changed files with 92 additions and 68 deletions
@@ -54,7 +54,7 @@ def test_intent_admission_rpc_dedups_duplicate_correlation_id_over_rabbitmq(mq_u
svc = SlotService(repo)
intents = IntentService(svc, repo, InMemoryIntentStore(),
resolve_symbol=lambda pid: "005930") # dcy-011: universe resolve
repo.reconcile_universe("default", {"PF-1"})
repo.reconcile_universe("default", {"PF-1": "SYM"})
handler = make_intent_rpc_handler(intents)
queue = f"trex.test.intent.{uuid.uuid4().hex[:8]}"
@@ -29,22 +29,22 @@ def test_universe_reconcile_pg(pg_clean):
# partial-index upsert + find_slot_by_portfolio/count_active.
repo = PostgreSQLSlotRepository(pg_clean)
inst = "inst-pg"
r1 = repo.reconcile_universe(inst, {"pf-a", "pf-b"})
r1 = repo.reconcile_universe(inst, {"pf-a": "SYM", "pf-b": "SYM"})
assert r1["created"] == 2
r2 = repo.reconcile_universe(inst, {"pf-a", "pf-b"}) # idempotent (ON CONFLICT)
r2 = repo.reconcile_universe(inst, {"pf-a": "SYM", "pf-b": "SYM"}) # idempotent (ON CONFLICT)
assert r2["created"] == 0
slot_a = repo.find_slot_by_portfolio(inst, "pf-a")
assert slot_a is not None and slot_a.status is SlotState.INACTIVE
assert repo.count_active(inst) == 0
# pf-b leaves universe while inactive -> soft-retire
r3 = repo.reconcile_universe(inst, {"pf-a"})
r3 = repo.reconcile_universe(inst, {"pf-a": "SYM"})
assert r3["retired"] == 1
assert repo.find_slot_by_portfolio(inst, "pf-b").retired_at is not None
def test_capacity_instance_scoped(pg_clean):
repo, svc, _ = _wire(pg_clean)
repo.reconcile_universe(INST, set(_SYMS))
repo.reconcile_universe(INST, _SYMS)
cap = svc.compute_slot_capacity()
assert cap.inactive_count == 3 and cap.available_count == 3
cap_m = svc.compute_slot_capacity(max_active_slots=2)
@@ -54,7 +54,7 @@ def test_capacity_instance_scoped(pg_clean):
def test_buy_intent_persists_transition(pg_clean):
repo, svc, intents = _wire(pg_clean)
repo.reconcile_universe(INST, set(_SYMS))
repo.reconcile_universe(INST, _SYMS)
d = intents.submit_buy(BuyIntent(intent_id="pg-buy-1", qty=10, portfolio_id="PF-1"))
assert d.admitted
slot = repo.fetch_slot(d.slot_id)
@@ -63,7 +63,7 @@ def test_buy_intent_persists_transition(pg_clean):
def test_buy_intent_idempotent_on_pg(pg_clean):
repo, svc, intents = _wire(pg_clean)
repo.reconcile_universe(INST, set(_SYMS))
repo.reconcile_universe(INST, _SYMS)
d1 = intents.submit_buy(BuyIntent(intent_id="pg-dup", portfolio_id="PF-1"))
d2 = intents.submit_buy(BuyIntent(intent_id="pg-dup", portfolio_id="PF-1"))
assert d1.slot_id == d2.slot_id and d2.status == "admitted"
@@ -74,7 +74,7 @@ def test_buy_intent_idempotent_on_pg(pg_clean):
def test_buy_by_slot_id_contract_pg(pg_clean):
# dcy-020/REQ-061: slot_id is the canonical buy key against real PG.
repo, svc, intents = _wire(pg_clean)
repo.reconcile_universe(INST, set(_SYMS))
repo.reconcile_universe(INST, _SYMS)
slot = repo.find_slot_by_portfolio(INST, "PF-2")
d = intents.submit_buy(BuyIntent(intent_id="pg-sid", slot_id=slot.slot_id))
assert d.admitted and d.slot_id == slot.slot_id
@@ -85,7 +85,7 @@ def test_full_lifecycle_returns_to_inactive_and_reuses(pg_clean):
# dcy-020 (BAT-030): sell fill -> inactive (occupancy cleared, asset
# binding kept); the same permanent slot activates again.
repo, svc, intents = _wire(pg_clean)
repo.reconcile_universe(INST, set(_SYMS))
repo.reconcile_universe(INST, _SYMS)
d = intents.submit_buy(BuyIntent(intent_id="pg-life", portfolio_id="PF-1"))
sid = d.slot_id
svc.transit_slot(sid, SlotState.PENDING_BUY, SlotState.HOLDING,
@@ -106,8 +106,8 @@ def test_dispatch_queue_instance_scoped(pg_clean):
# dcy-020/REQ-056 (BAT-030): list_undispatched_pending / list_dispatched_pending
# never cross instance boundaries in a shared DB.
repo_a = PostgreSQLSlotRepository(pg_clean)
repo_a.reconcile_universe("inst-a", {"pf-x"})
repo_a.reconcile_universe("inst-b", {"pf-x"})
repo_a.reconcile_universe("inst-a", {"pf-x": "SYM"})
repo_a.reconcile_universe("inst-b", {"pf-x": "SYM"})
svc_a = SlotService(repo_a, instance_key="inst-a")
slot_a = repo_a.find_slot_by_portfolio("inst-a", "pf-x")
svc_a.transit_slot(slot_a.slot_id, SlotState.INACTIVE, SlotState.PENDING_BUY,