mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 20:14:36 +00:00
Add initial unit tests for Phase 1 of test coverage improvement: - telemetry: test initialization, payload sanitization, early returns (14.3% → 62.9%) - plugin: test _parse_plugin_id static method - rag: test _to_i18n_name static method - persistence: test serialize_model with datetime handling Overall core coverage: 41.9% → 42.2% Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
78 lines
3.2 KiB
Python
78 lines
3.2 KiB
Python
"""Unit tests for plugin connector static methods.
|
|
|
|
Tests cover:
|
|
- _parse_plugin_id() parsing and validation
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from importlib import import_module
|
|
|
|
|
|
def get_connector_module():
|
|
"""Lazy import to avoid circular import issues."""
|
|
return import_module('langbot.pkg.plugin.connector')
|
|
|
|
|
|
class TestParsePluginId:
|
|
"""Tests for _parse_plugin_id static method."""
|
|
|
|
def test_valid_plugin_id_simple(self):
|
|
"""Test parsing valid plugin ID with simple format."""
|
|
connector = get_connector_module()
|
|
author, name = connector.PluginRuntimeConnector._parse_plugin_id('langbot/rag-engine')
|
|
assert author == 'langbot'
|
|
assert name == 'rag-engine'
|
|
|
|
def test_valid_plugin_id_with_slash_in_name(self):
|
|
"""Test parsing plugin ID where name contains additional slashes."""
|
|
connector = get_connector_module()
|
|
# split('/', 1) only splits on first slash
|
|
author, name = connector.PluginRuntimeConnector._parse_plugin_id('author/name/with/slashes')
|
|
assert author == 'author'
|
|
assert name == 'name/with/slashes'
|
|
|
|
def test_invalid_plugin_id_no_slash(self):
|
|
"""Test that ValueError is raised when no slash present."""
|
|
connector = get_connector_module()
|
|
with pytest.raises(ValueError) as exc_info:
|
|
connector.PluginRuntimeConnector._parse_plugin_id('invalid-plugin-id')
|
|
assert 'Invalid plugin_id format' in str(exc_info.value)
|
|
assert 'invalid-plugin-id' in str(exc_info.value)
|
|
|
|
def test_invalid_plugin_id_empty_string(self):
|
|
"""Test that ValueError is raised for empty string."""
|
|
connector = get_connector_module()
|
|
with pytest.raises(ValueError) as exc_info:
|
|
connector.PluginRuntimeConnector._parse_plugin_id('')
|
|
assert 'Invalid plugin_id format' in str(exc_info.value)
|
|
|
|
def test_valid_plugin_id_single_character_parts(self):
|
|
"""Test parsing plugin ID with single character author and name."""
|
|
connector = get_connector_module()
|
|
author, name = connector.PluginRuntimeConnector._parse_plugin_id('a/b')
|
|
assert author == 'a'
|
|
assert name == 'b'
|
|
|
|
def test_valid_plugin_id_with_hyphens_and_underscores(self):
|
|
"""Test parsing plugin ID with hyphens and underscores."""
|
|
connector = get_connector_module()
|
|
author, name = connector.PluginRuntimeConnector._parse_plugin_id('lang-bot/my_rag_engine')
|
|
assert author == 'lang-bot'
|
|
assert name == 'my_rag_engine'
|
|
|
|
def test_valid_plugin_id_author_only(self):
|
|
"""Test that plugin ID with only author (trailing slash) is parsed."""
|
|
connector = get_connector_module()
|
|
# 'author/' - split returns ('author', '')
|
|
author, name = connector.PluginRuntimeConnector._parse_plugin_id('author/')
|
|
assert author == 'author'
|
|
assert name == ''
|
|
|
|
def test_valid_plugin_id_name_only(self):
|
|
"""Test that plugin ID with only name (leading slash) is parsed."""
|
|
connector = get_connector_module()
|
|
# '/name' - split returns ('', 'name')
|
|
author, name = connector.PluginRuntimeConnector._parse_plugin_id('/name')
|
|
assert author == ''
|
|
assert name == 'name' |