Files
OpenJarvis/tests/channels/test_webchat.py
T
Jon Saad-FalconandClaude Opus 4.6 8d538cd1b0 Add orchestrator training, channels, LiteLLM engine, and simplify learning taxonomy
Major changes across parallel sessions:

- Add orchestrator SFT & GRPO training subpackage (learning/orchestrator/)
  with episode types, multi-objective reward, prompt registry, policy model,
  RL environment, and registered learning policies
- Add structured THOUGHT/TOOL/INPUT/FINAL_ANSWER mode to OrchestratorAgent
- Add 15 channel backends (Discord, Slack, Telegram, Email, Webhook, IRC,
  Matrix, Teams, WhatsApp, Signal, Mattermost, BlueBubbles, Feishu,
  Google Chat, Webchat) with channel tools and config
- Add LiteLLM engine backend for unified LLM provider access
- Add RLM agent and REPL tool
- Remove ToolLearningPolicy — learning taxonomy now only targets
  Intelligence (LM weights/routing) and Agents (logic/ICL/tool strategies)
- Rename SFTPolicy to SFTRouterPolicy (backward-compat alias kept)
- Remove OpenClaw agent infrastructure (openclaw*.py, openclaw_bridge.py)
- Fix async streaming tests (asyncio.run vs deprecated get_event_loop)
- Fix server channel route tests (pytest.importorskip for optional fastapi)
- Track uv.lock for reproducibility
- Update CLAUDE.md and docs to reflect all changes

1676 tests pass, 37 skipped.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 18:32:32 +00:00

104 lines
2.8 KiB
Python

"""Tests for the WebChatChannel adapter."""
from __future__ import annotations
from unittest.mock import MagicMock
import pytest
from openjarvis.channels._stubs import ChannelStatus
from openjarvis.channels.webchat import WebChatChannel
from openjarvis.core.events import EventBus, EventType
from openjarvis.core.registry import ChannelRegistry
@pytest.fixture(autouse=True)
def _register_webchat():
"""Re-register after any registry clear."""
if not ChannelRegistry.contains("webchat"):
ChannelRegistry.register_value("webchat", WebChatChannel)
class TestRegistration:
def test_registry_key(self):
assert ChannelRegistry.contains("webchat")
def test_channel_id(self):
ch = WebChatChannel()
assert ch.channel_id == "webchat"
class TestInit:
def test_defaults(self):
ch = WebChatChannel()
assert ch._messages == []
assert ch._handlers == []
assert ch._status == ChannelStatus.DISCONNECTED
class TestSend:
def test_send_success(self):
ch = WebChatChannel()
result = ch.send("user", "Hello!")
assert result is True
def test_send_publishes_event(self):
bus = EventBus(record_history=True)
ch = WebChatChannel(bus=bus)
ch.send("user", "Hello!")
event_types = [e.event_type for e in bus.history]
assert EventType.CHANNEL_MESSAGE_SENT in event_types
def test_get_messages(self):
ch = WebChatChannel()
ch.send("user1", "Hello!")
ch.send("user2", "World!")
ch.send("user1", "Again!")
messages = ch.get_messages()
assert len(messages) == 3
assert messages[0].content == "Hello!"
assert messages[1].content == "World!"
assert messages[2].content == "Again!"
def test_clear_messages(self):
ch = WebChatChannel()
ch.send("user1", "Hello!")
ch.send("user2", "World!")
assert len(ch.get_messages()) == 2
ch.clear_messages()
assert len(ch.get_messages()) == 0
class TestListChannels:
def test_list_channels(self):
ch = WebChatChannel()
assert ch.list_channels() == ["webchat"]
class TestStatus:
def test_disconnected_initially(self):
ch = WebChatChannel()
assert ch.status() == ChannelStatus.DISCONNECTED
def test_connected_after_connect(self):
ch = WebChatChannel()
ch.connect()
assert ch.status() == ChannelStatus.CONNECTED
class TestOnMessage:
def test_on_message(self):
ch = WebChatChannel()
handler = MagicMock()
ch.on_message(handler)
assert handler in ch._handlers
class TestDisconnect:
def test_disconnect(self):
ch = WebChatChannel()
ch._status = ChannelStatus.CONNECTED
ch.disconnect()
assert ch.status() == ChannelStatus.DISCONNECTED