mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-03 04:24:36 +00:00
Compare commits
1 Commits
fix/plugin
...
fix/utils-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa4d46fd87 |
@@ -35,10 +35,6 @@ 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"""
|
||||||
|
|
||||||
@@ -196,7 +192,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 PluginRuntimeNotConnectedError('Plugin runtime is not connected')
|
raise Exception('Plugin runtime is not connected')
|
||||||
|
|
||||||
return await self.handler.ping()
|
return await self.handler.ping()
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ def get_func_schema(function: typing.Callable) -> dict:
|
|||||||
|
|
||||||
parameters['properties'][param.name] = {
|
parameters['properties'][param.name] = {
|
||||||
'type': param_type,
|
'type': param_type,
|
||||||
'description': args_doc[param.name],
|
'description': args_doc.get(param.name, ''),
|
||||||
}
|
}
|
||||||
|
|
||||||
# add schema for array
|
# add schema for array
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
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()
|
|
||||||
15
tests/unit_tests/utils/test_funcschema.py
Normal file
15
tests/unit_tests/utils/test_funcschema.py
Normal 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'] == ''
|
||||||
Reference in New Issue
Block a user