mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-11 16:26:02 +00:00
Compare commits
1 Commits
fix/pipeli
...
fix/plugin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
779cf9899f |
@@ -275,7 +275,6 @@ class MessageAggregator:
|
|||||||
message_chain=merged_chain,
|
message_chain=merged_chain,
|
||||||
adapter=base_msg.adapter,
|
adapter=base_msg.adapter,
|
||||||
pipeline_uuid=base_msg.pipeline_uuid,
|
pipeline_uuid=base_msg.pipeline_uuid,
|
||||||
routed_by_rule=any(msg.routed_by_rule for msg in messages),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
async def flush_all(self) -> None:
|
async def flush_all(self) -> None:
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ from ..core import taskmgr
|
|||||||
from ..entity.persistence import plugin as persistence_plugin
|
from ..entity.persistence import plugin as persistence_plugin
|
||||||
|
|
||||||
|
|
||||||
|
class PluginRuntimeNotConnectedError(RuntimeError):
|
||||||
|
"""Raised when plugin runtime operations are requested before connection."""
|
||||||
|
|
||||||
|
|
||||||
class PluginRuntimeConnector:
|
class PluginRuntimeConnector:
|
||||||
"""Plugin runtime connector"""
|
"""Plugin runtime connector"""
|
||||||
|
|
||||||
@@ -192,7 +196,7 @@ class PluginRuntimeConnector:
|
|||||||
|
|
||||||
async def ping_plugin_runtime(self):
|
async def ping_plugin_runtime(self):
|
||||||
if not hasattr(self, 'handler'):
|
if not hasattr(self, 'handler'):
|
||||||
raise Exception('Plugin runtime is not connected')
|
raise PluginRuntimeNotConnectedError('Plugin runtime is not connected')
|
||||||
|
|
||||||
return await self.handler.ping()
|
return await self.handler.ping()
|
||||||
|
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
"""
|
|
||||||
MessageAggregator unit tests.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from importlib import import_module
|
|
||||||
|
|
||||||
import langbot_plugin.api.entities.builtin.platform.message as platform_message
|
|
||||||
import langbot_plugin.api.entities.builtin.provider.session as provider_session
|
|
||||||
|
|
||||||
|
|
||||||
def test_merge_messages_preserves_routed_by_rule_if_any_input_matches(sample_message_event, mock_adapter):
|
|
||||||
"""Merged PendingMessage should keep routed_by_rule when any input was rule-routed."""
|
|
||||||
aggregator = import_module('langbot.pkg.pipeline.aggregator')
|
|
||||||
message_aggregator = aggregator.MessageAggregator(ap=None)
|
|
||||||
|
|
||||||
first_message = aggregator.PendingMessage(
|
|
||||||
bot_uuid='test-bot-uuid',
|
|
||||||
launcher_type=provider_session.LauncherTypes.PERSON,
|
|
||||||
launcher_id=12345,
|
|
||||||
sender_id=12345,
|
|
||||||
message_event=sample_message_event,
|
|
||||||
message_chain=platform_message.MessageChain([platform_message.Plain(text='first')]),
|
|
||||||
adapter=mock_adapter,
|
|
||||||
pipeline_uuid='test-pipeline-uuid',
|
|
||||||
routed_by_rule=False,
|
|
||||||
)
|
|
||||||
second_message = aggregator.PendingMessage(
|
|
||||||
bot_uuid='test-bot-uuid',
|
|
||||||
launcher_type=provider_session.LauncherTypes.PERSON,
|
|
||||||
launcher_id=12345,
|
|
||||||
sender_id=12345,
|
|
||||||
message_event=sample_message_event,
|
|
||||||
message_chain=platform_message.MessageChain([platform_message.Plain(text='second')]),
|
|
||||||
adapter=mock_adapter,
|
|
||||||
pipeline_uuid='test-pipeline-uuid',
|
|
||||||
routed_by_rule=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
merged_message = message_aggregator._merge_messages([first_message, second_message])
|
|
||||||
|
|
||||||
assert merged_message.routed_by_rule is True
|
|
||||||
assert str(merged_message.message_chain) == 'first\nsecond'
|
|
||||||
32
tests/unit_tests/plugin/test_connector_ping.py
Normal file
32
tests/unit_tests/plugin/test_connector_ping.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from types import SimpleNamespace
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from langbot.pkg.plugin.connector import PluginRuntimeConnector, PluginRuntimeNotConnectedError
|
||||||
|
|
||||||
|
|
||||||
|
def make_connector() -> PluginRuntimeConnector:
|
||||||
|
app = SimpleNamespace(instance_config=SimpleNamespace(data={'plugin': {'enable': True}}))
|
||||||
|
return PluginRuntimeConnector(app, AsyncMock())
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_ping_plugin_runtime_raises_specific_error_when_not_connected():
|
||||||
|
connector = make_connector()
|
||||||
|
|
||||||
|
with pytest.raises(PluginRuntimeNotConnectedError, match='Plugin runtime is not connected'):
|
||||||
|
await connector.ping_plugin_runtime()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_ping_plugin_runtime_delegates_to_connected_handler():
|
||||||
|
connector = make_connector()
|
||||||
|
connector.handler = SimpleNamespace(ping=AsyncMock(return_value='pong'))
|
||||||
|
|
||||||
|
result = await connector.ping_plugin_runtime()
|
||||||
|
|
||||||
|
assert result == 'pong'
|
||||||
|
connector.handler.ping.assert_awaited_once()
|
||||||
Reference in New Issue
Block a user