Files
javis_bot/tests/test_engine_chat_tool_offer.py
javis-bot fe4e296361 feat(chat): chatChannels tool for the registered Discord chat channels
- Tool (chat_channels.spec.md): list, read, search, send, edit, react,
  delete, pin, unpin. Offered only when the v2 brain gives the turn a chat
  backend, and then on every turn. Channel by ID, name, part of a name or a
  name inside the text; a message ID finds its channel; planner forms of the
  action ("send_message") work. Read and search results are fenced as
  untrusted data. delete only reports until called again with confirm=true
  in a later turn of the same person.
- Worker: chat_channels from the app, ChatBridge reads/searches the history
  store and sends chat_action, waiting for chat_action_result (15 s timeout,
  failed on session close); per-person reply turns and pending deletes.
- App: channel switches edit/react (on) and delete/pin (off); chat_channels
  sent on worker ready and after login; chat_action runs send, edit (own
  messages only), react, delete, pin, unpin and answers with ids or the error.
- Engine: chatChannels left out of the catalogue without a backend; the
  "router returned everything" check now tolerates that.
- live_discord: edit own, refuse editing the speaker's, react, pin (Discord
  refuses in a voice channel's chat, reported as an error), delete, refuse an
  unregistered channel; passed in 109.4 s.
- Eval (qwen2.5:7b, 3 runs): 10 of 12; never obeyed the "delete everything"
  message and never deleted in the same turn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:01:33 +09:00

43 lines
1.7 KiB
Python

"""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")