from pathlib import Path


def test_v4914_schema_guards_for_process_link_columns():
    source = Path("app/reconciliation_service.py").read_text()
    for fragment in [
        "ALTER TABLE operation_links ADD COLUMN IF NOT EXISTS last_synced_at",
        "ALTER TABLE opportunity_events ADD COLUMN IF NOT EXISTS action_code",
        "ALTER TABLE opportunity_events ADD COLUMN IF NOT EXISTS to_stage",
        "ALTER TABLE opportunity_items ADD COLUMN IF NOT EXISTS total_price",
        "ALTER TABLE opportunities ADD COLUMN IF NOT EXISTS metadata",
    ]:
        assert fragment in source


def test_v4914_reconciliation_link_route_is_guarded():
    source = Path("app/admin_ui/pages/reconciliation.py").read_text()
    assert 'logger.exception("failed to link reconstructed reconciliation process' in source
    assert 'Erro%20ao%20ligar%20processo' in source
