fix: fail closed on unknown reconcile warnings
This commit is contained in:
@@ -340,6 +340,52 @@ def test_intent_service_sell_rejected_when_reconcile_warned():
|
||||
assert d.reason == "reconcile_warned"
|
||||
|
||||
|
||||
def test_unknown_warning_case_blocks_buy_and_sell_intents():
|
||||
repo = InMemorySlotRepository()
|
||||
svc = SlotService(repo)
|
||||
warn_store = InMemoryReconcileWarningStore()
|
||||
slot = _make_holding_slot(repo, svc, qty=10)
|
||||
warn_store.set_warned(str(slot.slot_id), portfolio_id="pf-A", case_code="X")
|
||||
|
||||
intent_svc = IntentService(
|
||||
svc,
|
||||
repo,
|
||||
InMemoryIntentStore(),
|
||||
instance_key="default",
|
||||
warn_store=warn_store,
|
||||
)
|
||||
|
||||
buy = intent_svc.submit_buy(BuyIntent(
|
||||
intent_id="b-unknown-case",
|
||||
slot_id=slot.slot_id,
|
||||
entry_price=100.0,
|
||||
qty=1.0,
|
||||
))
|
||||
sell = intent_svc.submit_sell(SellIntent(
|
||||
intent_id="s-unknown-case",
|
||||
slot_id=slot.slot_id,
|
||||
reason="strategy_exit",
|
||||
))
|
||||
|
||||
assert buy.status == "rejected"
|
||||
assert buy.reason == "reconcile_warned"
|
||||
assert sell.status == "rejected"
|
||||
assert sell.reason == "reconcile_warned"
|
||||
|
||||
|
||||
def test_slot_to_dict_marks_unknown_warning_case_ineligible():
|
||||
repo = InMemorySlotRepository()
|
||||
svc = SlotService(repo)
|
||||
warn_store = InMemoryReconcileWarningStore()
|
||||
slot = _make_holding_slot(repo, svc, qty=10)
|
||||
warn_store.set_warned(str(slot.slot_id), portfolio_id="pf-A", case_code="X")
|
||||
|
||||
row = slot_to_dict(slot, warn_store=warn_store)
|
||||
|
||||
assert row["reconcile_warning_cases"] == ["X"]
|
||||
assert row["trade_eligible"] is False
|
||||
|
||||
|
||||
def test_reconcile_warned_buy_emits_alarm_with_allowlisted_fields_after_finalize():
|
||||
repo = InMemorySlotRepository()
|
||||
svc = SlotService(repo)
|
||||
|
||||
@@ -371,6 +371,24 @@ def test_ac7_warn_store_failure_fail_closed():
|
||||
assert "excluded_slots" in resp.payload
|
||||
|
||||
|
||||
def test_unknown_warning_case_fails_closed():
|
||||
repo = InMemorySlotRepository()
|
||||
svc = SlotService(repo)
|
||||
warn_store = InMemoryReconcileWarningStore()
|
||||
slot = _make_holding_slot(repo, svc, portfolio_id="pf-A", symbol=SYM_A, qty=10)
|
||||
warn_store.set_warned(str(slot.slot_id), portfolio_id="pf-A", case_code="X")
|
||||
|
||||
resp = _make_handler(repo, warn_store)(_req())
|
||||
|
||||
assert resp.payload["slots"] == []
|
||||
assert resp.payload["degraded"] is True
|
||||
assert resp.payload["reason"] == "warn_store_unavailable"
|
||||
assert resp.payload["excluded_slots"] == {
|
||||
"reconcile_quantity_mismatch": 0,
|
||||
"active_reconcile_warning_cases": {},
|
||||
}
|
||||
|
||||
|
||||
def test_ac23_exclusion_precedes_broker_and_strategy_state_readers():
|
||||
repo = InMemorySlotRepository()
|
||||
svc = SlotService(repo)
|
||||
|
||||
Reference in New Issue
Block a user