"""Regression tests for EXP-001: Salami drain: serial sub-cap spends exhaust the treasury. A 55% faction drains the commons with a series of individually modest spend proposals, each legal under kernel v0.1. Severity: critical | Capture objective: drain_treasury | Found by detector: treasury_drain 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-001.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_001_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-001 no longer reproduces against its discovery kernel" ) def test_exp_001_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-001 succeeds under kernel v0.2: regression" ) def test_exp_001_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}" )