from pathlib import Path


def test_list_tasks_defines_customer_column_before_sql():
    text = Path("app/task_service.py").read_text(encoding="utf-8")
    start = text.index("def list_tasks(\n")
    end = text.index("\ndef get_task(", start)
    body = text[start:end]
    marker_pos = body.find("customer_column = opportunity_customer_column()")
    sql_pos = body.find('sql = text(f"""')
    assert marker_pos != -1, "list_tasks must define customer_column"
    assert sql_pos != -1, "list_tasks SQL f-string not found"
    assert marker_pos < sql_pos, "customer_column must be defined before SQL f-string interpolation"
    assert 'LEFT JOIN customers cu ON cu.id = o.{customer_column}' in body


def test_hotfix_marker_present_after_apply():
    text = Path("app/task_service.py").read_text(encoding="utf-8")
    assert "v4928.1.5.92: choose schema-supported opportunity customer for task list" in text
