from pathlib import Path

SCRIPT = Path("scripts/audit_operator_page_consistency.py")


def test_operator_page_consistency_audit_script_exists_and_is_read_only():
    text = SCRIPT.read_text(encoding="utf-8")
    assert "def main()" in text
    assert "Auditoria de coerência concluída" in text
    assert "clientflow_operator_page_consistency.csv" in text
    assert "INSERT INTO" not in text.upper()
    assert "UPDATE " not in text.upper()
    assert "DELETE FROM" not in text.upper()


def test_operator_page_consistency_rules_cover_known_inconsistencies():
    text = SCRIPT.read_text(encoding="utf-8")
    for rule in [
        "next_action_mismatch",
        "odoo_delivery_done_but_production_active",
        "wait_production_after_delivery_done",
        "send_invoice_action_after_invoice_done",
        "after_delivery_invoice_task_too_early",
        "old_invoice_candidate_same_customer_not_same_process",
        "odoo_delivery_line_not_in_jasmin_invoice",
        "public_domain_identity_is_weak",
        "linked_chatwoot_conversation_without_local_messages",
        "raw_events_processing_error_for_linked_conversation",
    ]:
        assert rule in text
