tests/test_hermes_control.py
text
from pathlib import Path
from apps.whatsapp_control_api.app.core.config import get_settings
from apps.whatsapp_control_api.app.services.hermes_control import (
build_hermes_command_message,
parse_hermes_command,
read_hermes_model_config,
)
def test_parse_model_show_command() -> None:
command = parse_hermes_command("/model")
assert command is not None
assert command.command == "model"
assert command.action == "show"
def test_parse_model_set_command() -> None:
command = parse_hermes_command("/model set openrouter deepseek-v4-flash")
assert command is not None
assert command.action == "set"
assert command.provider == "openrouter"
assert command.model == "deepseek-v4-flash"
def test_model_set_updates_hermes_config(tmp_path: Path, monkeypatch) -> None:
hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()
(hermes_home / ".env").write_text("OPENROUTER_API_KEY=test\n", encoding="utf-8")
(hermes_home / "config.yaml").write_text(
"\n".join(
[
"model:",
" model: old-model",
" provider: openrouter",
" default: old-model",
" base_url: https://openrouter.ai/api/v1",
" api_mode: chat_completions",
"agent:",
" max_turns: 90",
]
)
+ "\n",
encoding="utf-8",
)
monkeypatch.setenv("HERMES_WORKSPACE_ROOT", str(tmp_path))
get_settings.cache_clear()
command = parse_hermes_command("/model set openrouter deepseek-v4-flash")
assert command is not None
message = build_hermes_command_message(command)
config = read_hermes_model_config()
assert "Model Hermes berhasil diubah" in message
assert config.provider == "openrouter"
assert config.model == "deepseek-v4-flash"
assert config.default == "deepseek-v4-flash"