"""The reply engine offers chatChannels only when the v2 brain gave the turn a chat backend.""" from contextlib import nullcontext from unittest.mock import Mock, patch import pytest from src.jarvis.memory.conversation import DialogueMemory from src.jarvis.reply import turn_state from src.jarvis.reply.engine import run_reply_engine from tests.test_ollama_num_predict import _mock_cfg def _offered(chat, strategy="all"): cfg = _mock_cfg(512) cfg.tool_selection_strategy = strategy turn_state.reset() turn_state.set_chat(chat) try: with patch("src.jarvis.reply.engine.plan_query", return_value=[]), \ patch("src.jarvis.reply.engine.select_tools", return_value=["getWeather"]) if strategy == "routed" else nullcontext(), \ patch("src.jarvis.reply.engine.extract_search_params_for_memory", return_value={}), \ patch("src.jarvis.reply.engine.extract_text_from_response", return_value="Hello."), \ patch("src.jarvis.reply.engine.chat_with_messages") as mock_chat: mock_chat.return_value = {"message": {"content": "Hello."}} run_reply_engine(db=Mock(), cfg=cfg, tts=None, text="채팅 채널에 오늘 할 일 올려 줘", dialogue_memory=DialogueMemory()) tools = mock_chat.call_args.kwargs.get("tools") or [] return {t["function"]["name"] for t in tools} finally: turn_state.reset() @pytest.mark.unit def test_not_offered_without_a_chat_backend(): assert "chatChannels" not in _offered(None) @pytest.mark.unit def test_offered_with_a_backend_even_when_the_router_did_not_pick_it(): assert "chatChannels" in _offered(object(), strategy="routed")