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/plugin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
779cf9899f |
@@ -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()
|
||||||
|
|
||||||
@@ -633,12 +637,11 @@ class PluginRuntimeConnector:
|
|||||||
Raises:
|
Raises:
|
||||||
ValueError: If plugin_id is not in the expected 'author/name' format.
|
ValueError: If plugin_id is not in the expected 'author/name' format.
|
||||||
"""
|
"""
|
||||||
segments = plugin_id.split('/')
|
if '/' not in plugin_id:
|
||||||
if len(segments) != 2 or not all(segments):
|
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Invalid plugin_id format: '{plugin_id}'. Expected 'author/name' format (e.g. 'langbot/rag-engine')."
|
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]:
|
async def call_rag_ingest(self, plugin_id: str, context_data: dict[str, Any]) -> dict[str, Any]:
|
||||||
"""Call plugin to ingest document.
|
"""Call plugin to ingest document.
|
||||||
|
|||||||
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()
|
||||||
@@ -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