
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x11efb2ea0>

    @pytest.mark.unit
    def test_risk_veto_persistence_writes_a_row_for_a_live_ruling(monkeypatch):
        """THE LIVE PATH. A consult through the unified _SeamBoundPolicy body (ReplayPolicy is used
        here because it has the explicit ask_fn seam; LivePolicy and ReplayPolicy share the SAME
        body — the bug's parity pin) must produce ONE insert into RiskVetoRulings with the schema the
        bug names: trading_day, et, origin, mech_decision, forbid, why, reasoning, prompt_sha256,
        judges_block_sha256, prompt_chars, latency_s, dead_call, full sensor list."""
        from rtrader.services import risk_veto as RV
        monkeypatch.setattr(DP, "_judges_block_for_veto", lambda _llm: "")  # no judges paragraph
        monkeypatch.setattr("rtrader.services.combined_engine_live._llm_catch_budget_s",
                            lambda: 30.0, raising=False)
        monkeypatch.setattr("rtrader.services.feature_flags.hot_flag", _flag_pair(persist=True))
    
        def stub_ask(_prompt):
            return "FORBID: short\nWHY: wave says no\nREASONING: 87 is not 13"
        fake_db = _PersistFakeDb()
        policy = DP.ReplayPolicy(
            series_provider=lambda _s, _d: ([], [], []),
            rail_supported_fn=lambda *a: RAIL_REFUSAL,
            source_db_factory=lambda: fake_db,
            ask_fn=stub_ask,
            spawn=_inline)
        review = _join(policy.start_risk_review(
            _inputs(origin="backtest", signal_source="rollover_up",
                    account_nick="cuixia", run_id="run-123"),
            MECH_UP))
        assert review.tier == RV.TIER_RM
        assert sorted(review.forbidden) == ["short"]
        assert review.rationale == "wave says no"
        assert review.reasoning_review == "87 is not 13"
    
        coll = fake_db["RiskVetoRulings"]
>       assert len(coll.inserts) == 1, f"expected exactly one row, got {len(coll.inserts)}"
E       AssertionError: expected exactly one row, got 0
E       assert 0 == 1
E        +  where 0 = len([])
E        +    where [] = <test_decision_policy._PersistFakeColl object at 0x11ef9a780>.inserts

tests/services/test_decision_policy.py:1142: AssertionError
