from pathlib import Path


def test_workflow_guard_does_not_select_missing_tasks_completed_at_column():
    text = Path("app/workflow_guard.py").read_text()
    assert "SELECT id::text, action_code, action, note, status, metadata" in text
    assert "SELECT id::text, action_code, action, note, status, completed_at, metadata" not in text


def test_completed_send_invoice_task_evidence_still_uses_done_status():
    from app.workflow_guard import _completed_send_invoice_task_evidence

    assert _completed_send_invoice_task_evidence(
        [
            {
                "action_code": "SEND_INVOICE",
                "status": "done",
                "action": "Enviar fatura",
                "note": "Enviar fatura FA.FA2026.134 ao cliente.",
                "metadata": {},
            }
        ],
        [{"id": "doc-1", "document_number": "FA.FA2026.134"}],
    ) is True
