feat: add bounded KIS account read recovery

This commit is contained in:
jordan
2026-07-29 17:40:01 +09:00
parent 3dd8eefc92
commit 0266992238
29 changed files with 970 additions and 26 deletions
@@ -0,0 +1,37 @@
"""PostgreSQL account snapshot persistence contract."""
from __future__ import annotations
from datetime import datetime, timezone
from trex_core.adapters.persistence.account_snapshot import (
PostgreSQLAccountSnapshotStore,
)
from trex_core.application.account_snapshot import AccountSnapshot
from trex_core.application.broker_port import BalanceItem
def test_round_trip_keeps_independent_capture_times(pg_clean):
store = PostgreSQLAccountSnapshotStore(pg_clean)
holdings_at = datetime(2026, 7, 29, 0, 0, tzinfo=timezone.utc)
cash_at = datetime(2026, 7, 28, 23, 59, tzinfo=timezone.utc)
expected = AccountSnapshot(
account_hash="d" * 64,
holdings=(BalanceItem("005930", 2),),
holdings_captured_at=holdings_at,
available_cash=300_000,
cash_captured_at=cash_at,
)
store.save(expected)
assert store.load(expected.account_hash) == expected
def test_refresh_guard_is_account_scoped_and_released(pg_clean):
store = PostgreSQLAccountSnapshotStore(pg_clean)
with store.refresh_guard("e" * 64) as first:
assert first is True
with store.refresh_guard("e" * 64) as second:
assert second is False
with store.refresh_guard("e" * 64) as after_release:
assert after_release is True
@@ -18,6 +18,7 @@ _EXPECTED_TABLES = {
"intent_log",
"ledger_outbox", # BAT-006 / REQ-019
"snapshot_pause", # BAT-008 / REQ-032
"broker_account_snapshot", # dcy-041 / GitHub #45
}