|
| 1 | +""" |
| 2 | +Replay-after-denial synthetic test. |
| 3 | +
|
| 4 | +This test proves deterministic replay refusal behaviour inside the synthetic |
| 5 | +enterprise-shaped harness. |
| 6 | +It does not prove production persistence or path-universal replay protection. |
| 7 | +""" |
| 8 | + |
| 9 | +from __future__ import annotations |
| 10 | + |
| 11 | +import importlib.util |
| 12 | +from pathlib import Path |
| 13 | + |
| 14 | + |
| 15 | +ROOT = Path(__file__).resolve().parents[1] |
| 16 | +LEDGER_PATH = ROOT / "adapters" / "replay_ledger.py" |
| 17 | + |
| 18 | +spec = importlib.util.spec_from_file_location("replay_ledger", LEDGER_PATH) |
| 19 | +replay_ledger = importlib.util.module_from_spec(spec) |
| 20 | +assert spec.loader is not None |
| 21 | +spec.loader.exec_module(replay_ledger) |
| 22 | +ReplayLedger = replay_ledger.ReplayLedger |
| 23 | + |
| 24 | + |
| 25 | +NONCE = "esp-001-replay-test" |
| 26 | + |
| 27 | + |
| 28 | +def synthetic_gate(*, nonce: str, ledger: ReplayLedger) -> str: |
| 29 | + if ledger.contains(nonce): |
| 30 | + return "DENY:NONCE_REPLAYED" |
| 31 | + |
| 32 | + ledger.record( |
| 33 | + nonce=nonce, |
| 34 | + decision_id="decision-esp-001", |
| 35 | + result_code="DENY:NO_DECISION_RECORD", |
| 36 | + ) |
| 37 | + |
| 38 | + return "DENY:NO_DECISION_RECORD" |
| 39 | + |
| 40 | + |
| 41 | +def test_replay_after_denial_is_deterministically_refused() -> None: |
| 42 | + ledger = ReplayLedger() |
| 43 | + |
| 44 | + first = synthetic_gate(nonce=NONCE, ledger=ledger) |
| 45 | + second = synthetic_gate(nonce=NONCE, ledger=ledger) |
| 46 | + |
| 47 | + assert first == "DENY:NO_DECISION_RECORD" |
| 48 | + assert second == "DENY:NONCE_REPLAYED" |
| 49 | + assert ledger.count() == 1 |
0 commit comments