"""REQ-100/101: design docs are up to date with the shipped platform.
Asserts no stale 'dev-only spike' / 'v1.2 wires the gates' / 'Phases 08-10
implement' framing, and that the audit ledger deferral is clearly labeled.
"""
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
HITL = ROOT / "core" / "hitl_matrix_design.md"
AUDIT = ROOT / "core" / "audit_ledger_design.md"


def _read(path):
    return Path(path).read_text()


def test_hitl_matrix_design_no_stale_dev_only_spike_framing():
    text = _read(HITL)
    low = text.lower()
    assert "the spike is dev-only" not in low, "stale 'spike is dev-only' framing"
    assert "hitl is not exercised" not in low, "stale 'HITL is not exercised' framing"


def test_hitl_matrix_design_no_stale_v1_2_wires_language():
    text = _read(HITL)
    assert "v1.2 wires the gates" not in text.lower(), "stale 'v1.2 wires the gates' framing"


def test_hitl_matrix_design_references_v1_9_implementation():
    text = _read(HITL)
    assert "attestation_matrix.py" in text, "must reference the v1.9 attestation_matrix.py"
    assert "hitl_gates.py" in text, "must reference the v1.9 hitl_gates.py"
    assert "v1.9" in text, "must reference v1.9 wiring"


def test_hitl_matrix_design_marks_offline_testable_subset_implemented():
    text = _read(HITL)
    low = text.lower()
    assert "offline-testable" in low, "must distinguish offline-testable concerns"
    assert "operator-supplied" in low, "must distinguish operator-supplied concerns"


def test_audit_ledger_design_no_stale_phases_08_10_implement():
    text = _read(AUDIT)
    low = text.lower()
    assert "phases 08-10 implement" not in low, "stale 'Phases 08-10 implement' framing"


def test_audit_ledger_design_marks_outbox_shipped():
    text = _read(AUDIT)
    low = text.lower()
    assert "shipped + production since v1.8" in low, "must mark the outbox as shipped + production"


def test_audit_ledger_design_deferred_section_exists():
    text = _read(AUDIT)
    assert "Deferred to a future milestone" in text, "must have a clearly-labeled deferred section"
    assert "D-083" in text, "deferred section must reference decision D-083"


def test_audit_ledger_design_approver_fields_note_v1_9():
    text = _read(AUDIT)
    assert "approver_dr" in text, "must note approver_dr (v1.9 hitl_gates.attest)"
    assert "hitl_gates.attest" in text, "must reference v1.9 hitl_gates.attest"


def test_hitl_matrix_decision_trail_includes_d084():
    text = _read(HITL)
    assert "D-084" in text, "decision trail must include D-084 (attestation matrix)"


def test_audit_ledger_decision_trail_includes_d083():
    text = _read(AUDIT)
    assert "D-083" in text, "decision trail must include D-083 (deferral)"