#!/usr/bin/env python3
"""Assert new label style for talk history replay.

Requirement: replay output shows "You > ..." / "Agent > ..."
             NOT "Turn N [[You]]" / "Turn N [[Agent]]"
"""

import io
from typing import Any, cast
from types import SimpleNamespace

from rich.console import Console
from returns.result import Success


def test_new_label_format():
    """Assert replay uses 'You >' and 'Agent >' labels, not 'Turn N [[...]]'."""
    from anima.shell.cli_commands.talk_session import replay_talk_history

    # Setup: mock log with user + agent messages
    mock_entries = [
        {
            "event": "user_message",
            "details": {"message_text": "Hello user", "turn_number": 1},
        },
        {
            "event": "response",
            "details": {"response_text": "Hello agent", "turn_number": 1},
        },
    ]

    captured = io.StringIO()
    console = Console(file=captured, force_terminal=True, width=200)

    deps = cast(Any, SimpleNamespace(read_log=lambda _agent_id: Success(mock_entries)))
    replay_talk_history(
        agent_id="test-agent",
        json_output=False,
        console=console,
        deps=deps,
    )

    output = captured.getvalue()
    print(f"Output:\n{output}")

    # Assert NEW format is present
    assert "You >" in output, f"Expected 'You >' label, got: {output}"
    assert "Agent >" in output, f"Expected 'Agent >' label, got: {output}"

    # Assert OLD format is ABSENT
    assert "[[You]]" not in output, (
        f"OLD format '[[You]]' should NOT appear, got: {output}"
    )
    assert "[[Agent]]" not in output, (
        f"OLD format '[[Agent]]' should NOT appear, got: {output}"
    )

    print("✓ NEW label style asserted successfully")


if __name__ == "__main__":
    test_new_label_format()
