fix: normalize snapshot read failures to unavailable in slots RPC path

Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-08-25 12:25:39 +00:00
committed by GitHub
co-authored by genichin
parent f394f1560d
commit d4a968ee1a
3 changed files with 77 additions and 3 deletions
@@ -36,6 +36,11 @@ class FakeAccountBroker:
return self.cash
class BrokenLoadStore(InMemoryAccountSnapshotStore):
def load(self, account_hash: str) -> AccountSnapshot | None:
raise RuntimeError("db read failed")
def _wire():
now = [datetime(2026, 7, 29, tzinfo=UTC)]
broker = FakeAccountBroker()
@@ -177,3 +182,19 @@ def test_slots_rpc_uses_snapshot_only_with_sell_ttl_freshness():
with pytest.raises(AccountSnapshotUnavailable) as raised:
service.holdings_for_slots_rpc()
assert raised.value.code == "expired"
def test_slots_rpc_normalizes_snapshot_store_read_failure():
broker = FakeAccountBroker()
service = AccountSnapshotService(
broker=broker,
store=BrokenLoadStore(),
buy_max_age_sec=600,
sell_max_age_sec=3600,
clock=lambda: datetime(2026, 7, 29, tzinfo=UTC),
rng=lambda: 0.5,
)
with pytest.raises(AccountSnapshotUnavailable) as raised:
service.holdings_for_slots_rpc()
assert raised.value.code == "read_failed"