from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def read(path: str) -> str:
    return (ROOT / path).read_text(encoding="utf-8")


def test_send_reply_swaps_full_task_detail_panel_on_success():
    tasks = read("app/admin_ui/pages/tasks.py")
    assert 'hx-post="/tasks/{esc(task_id)}/send-reply"' in tasks
    assert 'hx-target="#task-detail-panel"' in tasks
    assert "render_task_detail_partial(task_id, notice=notice)" in tasks
    assert "leaving the header showing stale Pendente/SEND_QUOTE" in tasks


def test_send_reply_errors_retarget_reply_panel_only():
    tasks = read("app/admin_ui/pages/tasks.py")
    assert 'response.headers["HX-Retarget"] = "#reply-assistant-panel"' in tasks
    assert 'response.headers["HX-Reswap"] = "outerHTML"' in tasks


def test_v4928_1_5_13_badge_is_visible():
    tasks = read("app/admin_ui/pages/tasks.py")
    assert "v4928.1.5.13" in tasks
