from pathlib import Path


def test_recent_chatwoot_context_sql_casts_nullable_current_event_id():
    src = Path("app/persistence.py").read_text(encoding="utf-8")
    assert "CAST(:current_source_event_id AS TEXT) IS NULL" in src
    assert "source_event_id <> CAST(:current_source_event_id AS TEXT)" in src
    assert ":current_source_event_id IS NULL OR source_event_id <> :current_source_event_id" not in src


def test_audit_allow_list_includes_operational_actions():
    src = Path("scripts/audit_system_health.py").read_text(encoding="utf-8")
    assert "PREPARE_ORDER" in src
    assert "REVIEW_RECONCILIATION" in src
    assert "processing_exception:" in src
