Bot & Automation

AI Assistants

/root/hermes-projects/AI Assistants

tests/test_chat_routing.py text
from apps.whatsapp_control_api.app.api.main import (
    _clean_hermes_summary,
    _format_task_completed,
    _format_task_progress,
    _is_unusable_final_summary,
    _is_task_intent,
    _parse_task_query,
    _should_route_to_hermes,
)
from apps.whatsapp_control_api.app.services.chat import REMOTE_CHAT_PROVIDERS, local_assistant_reply
from apps.whatsapp_control_api.app.services.hermes_control import parse_hermes_command
from apps.whatsapp_control_api.app.services.settings_control import parse_control_command


def test_greeting_is_not_task_intent() -> None:
    assert _is_task_intent("halo") is False


def test_work_instruction_is_task_intent() -> None:
    assert _is_task_intent("buat project company profile | website") is True


def test_pdf_document_request_routes_to_hermes() -> None:
    text = "Buatkan saya dokumen PDF profesional tentang Artificial Intelligence / AI."
    assert _is_task_intent(text) is True
    assert _should_route_to_hermes(text) is True


def test_generic_create_file_request_routes_to_hermes() -> None:
    text = "Buatkan struktur storyboard produk AI dalam format PDF yang bisa saya download."
    assert _is_task_intent(text) is True
    assert _should_route_to_hermes(text) is True


def test_general_question_is_not_task_intent() -> None:
    assert _is_task_intent("Apa itu Gemini AI?") is False


def test_greeting_does_not_route_to_hermes() -> None:
    assert _should_route_to_hermes("haii") is False


def test_general_question_does_not_route_to_hermes() -> None:
    assert _should_route_to_hermes("Apa itu Gemini AI?") is False


def test_how_to_create_project_question_does_not_route_to_hermes() -> None:
    text = "Cara buat project di Hermes agent bagaimana?"
    assert _is_task_intent(text) is False
    assert _should_route_to_hermes(text) is False


def test_hermes_agent_question_does_not_route_to_hermes() -> None:
    assert _should_route_to_hermes("hermes agent di buat kapan?") is False


def test_systemctl_command_routes_to_hermes() -> None:
    assert _should_route_to_hermes("systemctl restart ai-assistants-whatsapp-control") is True


def test_clean_summary_removes_generic_closer() -> None:
    summary = "Ringkasan utama.\n\nKalau kamu ingin saya bantu eksplor lebih lanjut, bilang aja."
    assert _clean_hermes_summary(summary) == "Ringkasan utama."


def test_completed_message_starts_with_answer() -> None:
    message = _format_task_completed("abc123", "Ini jawaban utama.")
    assert message.startswith("Ini jawaban utama.")


def test_too_short_final_summary_is_unusable() -> None:
    assert _is_unusable_final_summary("Ba") is True


def test_progress_message_includes_model_status_line() -> None:
    message = _format_task_progress("abc123", 30, "Hermes is working", 84)
    assert "[" in message
    assert "30%" in message
    assert "/1M" in message or "/--" in message
    assert "1m 24s" in message


def test_settings_command_is_parsed() -> None:
    command = parse_control_command("settings set CHAT_PROVIDER=openrouter")
    assert command is not None
    assert command.scope == "app"


def test_model_slash_command_is_parsed_as_hermes_control() -> None:
    command = parse_hermes_command("/model")
    assert command is not None
    assert command.command == "model"


def test_openai_is_supported_provider() -> None:
    assert "openai" in REMOTE_CHAT_PROVIDERS


def test_status_command_maps_to_latest_task_query() -> None:
    query = _parse_task_query("task terakhir")
    assert query is not None
    assert query["type"] == "latest"


def test_local_reply_for_greeting_is_short() -> None:
    reply = local_assistant_reply("halo")
    assert reply == "Hai. Ada yang bisa saya bantu?"