Compare commits

..

1 Commits

Author SHA1 Message Date
huanghuoguoguo
aa4d46fd87 fix(utils): handle missing funcschema parameter docs 2026-05-16 10:37:01 +08:00
4 changed files with 16 additions and 44 deletions

View File

@@ -275,7 +275,6 @@ 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:

View File

@@ -83,7 +83,7 @@ def get_func_schema(function: typing.Callable) -> dict:
parameters['properties'][param.name] = {
'type': param_type,
'description': args_doc[param.name],
'description': args_doc.get(param.name, ''),
}
# add schema for array

View File

@@ -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'

View File

@@ -0,0 +1,15 @@
from langbot.pkg.utils.funcschema import get_func_schema
def test_get_func_schema_uses_empty_description_for_undocumented_parameter():
def sample_function(documented: str, undocumented: int):
"""Sample function.
Args:
documented(str): documented parameter description
"""
schema = get_func_schema(sample_function)
assert schema['parameters']['properties']['documented']['description'] == 'documented parameter description'
assert schema['parameters']['properties']['undocumented']['description'] == ''