from __future__ import annotations

from datetime import datetime

from v1.agent.service import build_session_title


def test_build_session_title_truncates_first_message() -> None:
    now = datetime(2026, 2, 25, 10, 30)

    title = build_session_title(
        "这是一个非常长的标题会被截断到二十四个可见字符用于会话摘要", now=now
    )

    assert len(title) == 24


def test_build_session_title_falls_back_when_message_empty() -> None:
    now = datetime(2026, 2, 25, 10, 30)

    title = build_session_title("\n  ", now=now)

    assert title == "新对话 2026-02-25 10:30"
