mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 12:05:54 +00:00
Compare commits
1 Commits
fix/plugin
...
fix/pipeli
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ceb0c6829 |
@@ -275,6 +275,7 @@ class MessageAggregator:
|
||||
message_chain=merged_chain,
|
||||
adapter=base_msg.adapter,
|
||||
pipeline_uuid=base_msg.pipeline_uuid,
|
||||
routed_by_rule=any(msg.routed_by_rule for msg in messages),
|
||||
)
|
||||
|
||||
async def flush_all(self) -> None:
|
||||
|
||||
@@ -633,12 +633,11 @@ class PluginRuntimeConnector:
|
||||
Raises:
|
||||
ValueError: If plugin_id is not in the expected 'author/name' format.
|
||||
"""
|
||||
segments = plugin_id.split('/')
|
||||
if len(segments) != 2 or not all(segments):
|
||||
if '/' not in plugin_id:
|
||||
raise ValueError(
|
||||
f"Invalid plugin_id format: '{plugin_id}'. Expected 'author/name' format (e.g. 'langbot/rag-engine')."
|
||||
)
|
||||
return segments[0], segments[1]
|
||||
return plugin_id.split('/', 1)
|
||||
|
||||
async def call_rag_ingest(self, plugin_id: str, context_data: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Call plugin to ingest document.
|
||||
|
||||
42
tests/unit_tests/pipeline/test_aggregator.py
Normal file
42
tests/unit_tests/pipeline/test_aggregator.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""
|
||||
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'
|
||||
@@ -1,25 +0,0 @@
|
||||
"""Test plugin ID parsing validation."""
|
||||
|
||||
import pytest
|
||||
|
||||
from src.langbot.pkg.plugin.connector import PluginRuntimeConnector
|
||||
|
||||
|
||||
def test_parse_plugin_id_accepts_author_name():
|
||||
assert PluginRuntimeConnector._parse_plugin_id('langbot/rag-engine') == ('langbot', 'rag-engine')
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'plugin_id',
|
||||
[
|
||||
'',
|
||||
'author',
|
||||
'author/',
|
||||
'/name',
|
||||
'author/name/extra',
|
||||
'/',
|
||||
],
|
||||
)
|
||||
def test_parse_plugin_id_rejects_malformed_ids(plugin_id):
|
||||
with pytest.raises(ValueError, match='Expected'):
|
||||
PluginRuntimeConnector._parse_plugin_id(plugin_id)
|
||||
Reference in New Issue
Block a user