fix: fail closed on unknown reconcile warnings

This commit is contained in:
Hermes Agent
2026-09-12 22:58:11 +09:00
parent 310b6f6dec
commit 853943f676
7 changed files with 92 additions and 7 deletions
@@ -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)