"""Golden tests for MODEL_GOVERNANCE_KILL_SWITCH_V1 (governance/todo/v8_9_p1_adoption_plan.yaml P1-C.4). Maps to v8.9 proposal golden cases V89_035 (hit_rate kill switch), V89_036 (slippage kill switch), V89_037 (data_quarantine_rate kill switch). """ from __future__ import annotations import importlib.util from pathlib import Path ROOT = Path(__file__).resolve().parents[3] MODULE_PATH = ROOT / "tools" / "build_model_governance_kill_switch_v1.py" def _load_module(): spec = importlib.util.spec_from_file_location("build_model_governance_kill_switch_v1", MODULE_PATH) module = importlib.util.module_from_spec(spec) assert spec.loader is not None spec.loader.exec_module(module) return module def test_v89_035_low_hit_rate_with_sufficient_sample_demotes_one_rung() -> None: mod = _load_module() reasons = mod.evaluate_kill_switches({"t5_hit_rate_pct": 40.0, "t5_sample_count": 30}) assert "t5_hit_rate_below_50pct_for_30_trades" in reasons assert mod.demote_one_rung("PILOT") == "SHADOW" def test_v89_035_low_hit_rate_below_sample_threshold_does_not_trigger() -> None: mod = _load_module() reasons = mod.evaluate_kill_switches({"t5_hit_rate_pct": 40.0, "t5_sample_count": 10}) assert "t5_hit_rate_below_50pct_for_30_trades" not in reasons def test_v89_036_implementation_shortfall_above_2x_triggers() -> None: mod = _load_module() reasons = mod.evaluate_kill_switches({"implementation_shortfall_ratio": 2.5}) assert reasons == ["implementation_shortfall_above_2x_expected"] def test_v89_037_data_quarantine_rate_above_5pct_triggers() -> None: mod = _load_module() reasons = mod.evaluate_kill_switches({"data_quarantine_rate_pct": 7.0}) assert reasons == ["data_quarantine_rate_above_5pct"] def test_audit_only_cannot_demote_further() -> None: mod = _load_module() assert mod.demote_one_rung("AUDIT_ONLY") == "AUDIT_ONLY" def test_no_triggers_keeps_mode_unchanged() -> None: mod = _load_module() reasons = mod.evaluate_kill_switches({"data_quarantine_rate_pct": 1.0}) assert reasons == []