from pathlib import Path

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


def test_audit_script_contains_core_flow_rules():
    text = SCRIPT.read_text(encoding="utf-8")
    assert "next_action_missing_pending_task" in text
    assert "obsolete_payment_task_pending" in text
    assert "payment_task_without_commercial_document" in text
    assert "obsolete_send_invoice_task_pending" in text
    assert "pending_task_on_terminal_opportunity" in text


def test_send_invoice_is_materialized_action():
    text = SCRIPT.read_text(encoding="utf-8")
    assert 'MATERIALIZED_NEXT_ACTIONS = {"SEND_INVOICE"}' in text
    assert "repair_missing_send_invoice_tasks.py --apply" in text


def test_audit_outputs_csv_markdown_json():
    text = SCRIPT.read_text(encoding="utf-8")
    assert ".csv" in text
    assert ".md" in text
    assert ".json" in text
    assert "clientflow_opportunity_task_flow_audit" in text
