mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
Merge remote-tracking branch 'origin/fix/plugin-parse-plugin-id-validation' into validation/test-build-with-fixes
This commit is contained in:
@@ -633,11 +633,12 @@ 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.
|
||||||
"""
|
"""
|
||||||
if '/' not in plugin_id:
|
segments = plugin_id.split('/')
|
||||||
|
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 plugin_id.split('/', 1)
|
return segments[0], segments[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.
|
||||||
|
|||||||
25
tests/unit_tests/plugin/test_plugin_id_parsing.py
Normal file
25
tests/unit_tests/plugin/test_plugin_id_parsing.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
"""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