fix: preserve multi-cause reconcile warnings and align slot blocking
Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
co-authored by
genichin
parent
e47bebacaf
commit
45a5e4157d
@@ -313,6 +313,40 @@ def test_verify_c_case_clear_preserves_b_case_warning():
|
||||
assert b_info is not None and b_info["case_code"] == "B"
|
||||
|
||||
|
||||
def test_verify_c_case_clear_on_slot_with_b_and_c_keeps_b():
|
||||
sym = "005930"
|
||||
slot = _make_slot(status=SlotState.HOLDING, symbol=sym, pid="pf-c")
|
||||
|
||||
repo = InMemorySlotRepository()
|
||||
repo.add_slot(slot)
|
||||
|
||||
ws = InMemoryReconcileWarningStore()
|
||||
slot_id = str(slot.slot_id)
|
||||
ws.set_warned(slot_id, portfolio_id="pf-c", case_code="B")
|
||||
ws.set_warned(slot_id, portfolio_id="pf-c", case_code="C")
|
||||
|
||||
store = SnapshotStore()
|
||||
store.swap([
|
||||
PortfolioItem(portfolio_id="pf-c", symbol=sym, cash_balance=0.0, asset_quantity=10.0),
|
||||
])
|
||||
broker = FakeBroker({sym: 10})
|
||||
|
||||
result = verify_slot_reconcile(
|
||||
portfolio_id="pf-c",
|
||||
store=store,
|
||||
broker=broker,
|
||||
slot_repo=repo,
|
||||
instance_key=INSTANCE,
|
||||
warn_store=ws,
|
||||
)
|
||||
|
||||
assert result["result"] == "cleared"
|
||||
assert ws.is_warned(slot_id) is True
|
||||
info = ws.get_warning_info(slot_id)
|
||||
assert info is not None
|
||||
assert info["case_codes"] == ["B"]
|
||||
|
||||
|
||||
def test_verify_c_case_clear_non_holding_slot():
|
||||
"""A non-HOLDING slot with C-case warning for the same symbol must also be cleared."""
|
||||
sym = "005930"
|
||||
@@ -360,11 +394,11 @@ class _FailAfterNStore(InMemoryReconcileWarningStore):
|
||||
self._calls = 0
|
||||
self._fail_after = fail_after
|
||||
|
||||
def clear_warned(self, slot_id: str) -> None:
|
||||
def clear_warned(self, slot_id: str, *, case_code: str | None = None) -> None:
|
||||
self._calls += 1
|
||||
if self._calls > self._fail_after:
|
||||
raise RuntimeError("simulated DB error")
|
||||
super().clear_warned(slot_id)
|
||||
super().clear_warned(slot_id, case_code=case_code)
|
||||
|
||||
|
||||
def test_verify_partial_clear_failure_returns_clear_failed():
|
||||
|
||||
Reference in New Issue
Block a user