AICEPAICEP AICEP 0.1 — Public Draft (RFC)
AICEP is an experimental public draft, provided “as is” and without warranty. Use it at your own risk. We test it extensively, but testing is not a guarantee. Full disclaimer

← AICEP home · Runbook index

reference/tests/test_review_r2.py

Download test_review_r2.py

"""design review v2.4 re-review: real bugs pinned as xfail(strict=True). Remove a marker when its fix lands."""
import os, sys
import pytest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from aicep_common import Ledger, Reject
from test_tamper import env, pub, sub, NOW  # noqa: F401

BUG = pytest.mark.xfail  # unused since v2.4 fixes:(strict=True, reason="design review v2.4 finding (open)")


# W1: no max expiry window. A backdated created + a huge expires is accepted (V7 gap).
def test_backdated_long_expiry_rejected(env):
    d = pub(env, now=NOW - 86400 * 365, ttl=86400 * 3650, prev_batch_id="genesis")
    with pytest.raises(Reject):
        sub(env, d)


# W2: append() silently re-anchors a tail-truncated ledger, so the truncation is laundered.
def test_append_after_truncation_does_not_reanchor(tmp_path):
    p = str(tmp_path / "l.jsonl"); L = Ledger(p)
    for i in range(3):
        L.append("e", i=i)
    lines = open(p).read().splitlines(True)
    open(p, "w").writelines(lines[:1])          # attacker drops the tail
    try:
        L.append("e", i=9)                       # next normal append
    except Exception:
        return                                   # refusing to append is a valid fix
    assert not Ledger(p).verify()


# W3: a legacy (no-anchor) ledger is "re-anchored" by any append, not by a human step.
def test_legacy_ledger_not_auto_reanchored(tmp_path):
    p = str(tmp_path / "l.jsonl"); L = Ledger(p)
    L.append("e", i=0); L.append("e", i=1)
    os.remove(L.anchor_path)                     # legacy ledger: no anchor
    assert not L.verify()
    try:
        L.append("e", i=2)
    except Exception:
        return
    assert not Ledger(p).verify()