"""Regression tests for EXP-002: Shrinking electorate: serial expulsions manufacture a supermajority. Simple-majority expulsions remove opposing voters one by one until a kernel amendment passes with only 55% support of the original roll. Severity: critical | Capture objective: entrench_power | Found by detector: entrenchment 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-002.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_002_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-002 no longer reproduces against its discovery kernel" ) def test_exp_002_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-002 succeeds under kernel v0.2: regression" ) def test_exp_002_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}" )