"""Regression tests for EXP-003: Perpetual emergency: majority-declared emergency with no sunset. A bare majority declares an emergency that never expires and spends from the treasury without further votes. Severity: critical | Capture objective: entrench_power | Found by detector: emergency_abuse GENERATED by fable_selfplay.exploit_to_test. Do not edit by hand. Regenerate with: fable-selfplay exploit-to-test --exploits exploits --out tests/regression """ from pathlib import Path import pytest from fable_selfplay import replay from fable_selfplay.exploit_to_test import ExploitRecord _ROOT = Path(__file__).resolve().parents[2] RECORD_PATH = _ROOT / "exploits" / "EXP-003.json" KERNEL_V02_PATH = _ROOT / "kernel" / "kernel-v0.2.yaml" @pytest.fixture(scope="module") def record() -> ExploitRecord: return ExploitRecord.from_path(RECORD_PATH) def _run(record: ExploitRecord, params: dict) -> "replay.ReplayResult": return replay.run_trace( params, record.citizens, record.initial_treasury, record.action_trace, ) def test_exp_003_reproduces_under_discovery_kernel(record: ExploitRecord) -> None: """The exploit must still succeed under the kernel it was discovered against. If this fails, the archived record no longer reproduces and the exploit archive itself is corrupt; investigate before touching the kernel. """ result = _run(record, record.kernel_params_at_discovery) assert replay.evaluate_predicate(record.success_predicate, result), ( "EXP-003 no longer reproduces against its discovery kernel" ) def test_exp_003_blocked_under_kernel_v0_2(record: ExploitRecord) -> None: """The patched kernel must defeat the recorded exploit trace.""" params = replay.load_kernel_params(KERNEL_V02_PATH) result = _run(record, params) assert not replay.evaluate_predicate(record.success_predicate, result), ( "EXP-003 succeeds under kernel v0.2: regression" ) def test_exp_003_patched_invariants_hold(record: ExploitRecord) -> None: """Exploit-specific guarantees the patch is expected to provide.""" params = replay.load_kernel_params(KERNEL_V02_PATH) result = _run(record, params) for assertion in record.patched_assertions: assert replay.evaluate_predicate(assertion, result), ( f"patched invariant violated: {assertion}" )