test(phase2): add unit tests for core, persistence, plugin, utils

- Add test_handler_helpers.py for plugin handler helpers (7 tests)
- Add test_mgr_methods.py for persistence manager (5 tests)
- Add test_app_config_validation.py for core app config (12 tests)
- Add test_knowledge_service.py for API knowledge service (22 tests)
- Add test_kbmgr.py for RAG knowledge base manager (39 tests)
- Add test_survey_manager.py for survey manager (22 tests)
- Add test_connector_methods.py for plugin connector (24 tests)
- Add test_funcschema.py for utils function schema (9 tests)
- Add test_platform.py for utils platform detection (7 tests)
- Add test_extract_deps.py for plugin deps extraction (7 tests)
- Add test_database_decorator.py for persistence decorator (7 tests)
- Add test_load_config.py for core config loading (19 tests)
- Add COVERAGE_EXCLUSIONS.md documenting external adapter exclusions
- Fix test_chat_session_limit.py path for portability

Coverage: core 28% → 30%, persistence 24% → 24.4%, plugin 27% → 28%
Total: 1082 tests passed, core module coverage 45.5%

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
huanghuoguoguo
2026-05-10 20:43:54 +08:00
parent ea6ed9b7fd
commit 3872e3e1ac
17 changed files with 4041 additions and 444 deletions

View File

@@ -0,0 +1,493 @@
"""Unit tests for plugin connector methods.
Tests cover:
- list_plugins() with filtering and sorting
- list_knowledge_engines() and list_parsers()
- RAG methods (ingest, retrieve, schema)
- Disabled plugin early returns
"""
from __future__ import annotations
import pytest
from unittest.mock import Mock, AsyncMock
from importlib import import_module
def get_connector_module():
"""Lazy import to avoid circular import issues."""
return import_module('langbot.pkg.plugin.connector')
def create_mock_app():
"""Create mock Application for testing."""
mock_app = Mock()
mock_app.logger = Mock()
mock_app.instance_config = Mock()
mock_app.instance_config.data = {'plugin': {'enable': True}}
mock_app.persistence_mgr = AsyncMock()
mock_app.persistence_mgr.execute_async = AsyncMock()
return mock_app
def create_mock_connector():
"""Create mock PluginRuntimeConnector instance for testing."""
connector = get_connector_module()
async def mock_disconnect_callback(conn):
pass
return connector.PluginRuntimeConnector(create_mock_app(), mock_disconnect_callback)
class TestListPlugins:
"""Tests for list_plugins method."""
@pytest.mark.asyncio
async def test_returns_empty_when_plugin_disabled(self):
"""Test returns empty list when plugin system disabled."""
connector_module = get_connector_module()
async def mock_disconnect(conn):
pass
mock_app = create_mock_app()
mock_app.instance_config.data = {'plugin': {'enable': False}}
connector = connector_module.PluginRuntimeConnector(mock_app, mock_disconnect)
result = await connector.list_plugins()
assert result == []
@pytest.mark.asyncio
async def test_calls_handler_list_plugins(self):
"""Test that handler.list_plugins is called."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.list_plugins = AsyncMock(
return_value=[{'manifest': {'manifest': {'metadata': {'author': 'test', 'name': 'plugin'}}}}]
)
result = await connector.list_plugins()
connector.handler.list_plugins.assert_called_once()
assert len(result) == 1
@pytest.mark.asyncio
async def test_filters_by_component_kinds(self):
"""Test that plugins are filtered by component kinds."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.list_plugins = AsyncMock(
return_value=[
{
'manifest': {'manifest': {'metadata': {'author': 'a', 'name': 'p1'}}},
'components': [
{'manifest': {'manifest': {'kind': 'Command'}}}
],
'debug': False,
},
{
'manifest': {'manifest': {'metadata': {'author': 'b', 'name': 'p2'}}},
'components': [
{'manifest': {'manifest': {'kind': 'Tool'}}}
],
'debug': False,
},
]
)
result = await connector.list_plugins(component_kinds=['Command'])
assert len(result) == 1
assert result[0]['manifest']['manifest']['metadata']['name'] == 'p1'
@pytest.mark.asyncio
async def test_sorts_debug_plugins_first(self):
"""Test that debug plugins are sorted first."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.list_plugins = AsyncMock(
return_value=[
{
'manifest': {'manifest': {'metadata': {'author': 'a', 'name': 'normal'}}},
'components': [],
'debug': False,
},
{
'manifest': {'manifest': {'metadata': {'author': 'b', 'name': 'debug'}}},
'components': [],
'debug': True,
},
]
)
connector.ap.persistence_mgr.execute_async = AsyncMock(
return_value=Mock(__iter__=lambda self: iter([]))
)
result = await connector.list_plugins()
# Debug plugin should be first
assert result[0]['debug'] is True
class TestListKnowledgeEngines:
"""Tests for list_knowledge_engines method."""
@pytest.mark.asyncio
async def test_returns_empty_when_plugin_disabled(self):
"""Test returns empty list when plugin system disabled."""
connector_module = get_connector_module()
async def mock_disconnect(conn):
pass
mock_app = create_mock_app()
mock_app.instance_config.data = {'plugin': {'enable': False}}
connector = connector_module.PluginRuntimeConnector(mock_app, mock_disconnect)
result = await connector.list_knowledge_engines()
assert result == []
@pytest.mark.asyncio
async def test_calls_handler_list_knowledge_engines(self):
"""Test that handler method is called."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.list_knowledge_engines = AsyncMock(
return_value=[{'plugin_id': 'author/engine', 'name': 'Engine'}]
)
result = await connector.list_knowledge_engines()
connector.handler.list_knowledge_engines.assert_called_once()
assert len(result) == 1
class TestListParsers:
"""Tests for list_parsers method."""
@pytest.mark.asyncio
async def test_returns_empty_when_plugin_disabled(self):
"""Test returns empty list when plugin system disabled."""
connector_module = get_connector_module()
async def mock_disconnect(conn):
pass
mock_app = create_mock_app()
mock_app.instance_config.data = {'plugin': {'enable': False}}
connector = connector_module.PluginRuntimeConnector(mock_app, mock_disconnect)
result = await connector.list_parsers()
assert result == []
@pytest.mark.asyncio
async def test_calls_handler_list_parsers(self):
"""Test that handler method is called."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.list_parsers = AsyncMock(
return_value=[{'plugin_id': 'author/parser', 'supported_mime_types': ['text/plain']}]
)
result = await connector.list_parsers()
connector.handler.list_parsers.assert_called_once()
assert len(result) == 1
class TestCallParser:
"""Tests for call_parser method."""
@pytest.mark.asyncio
async def test_calls_handler_parse_document(self):
"""Test that handler.parse_document is called with correct args."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.parse_document = AsyncMock(return_value={'content': 'parsed'})
result = await connector.call_parser(
'author/parser',
{'mime_type': 'text/plain', 'filename': 'test.txt'},
b'file content',
)
connector.handler.parse_document.assert_called_once_with(
'author', 'parser',
{'mime_type': 'text/plain', 'filename': 'test.txt'},
b'file content',
)
assert result['content'] == 'parsed'
class TestRAGMethods:
"""Tests for RAG-related methods."""
@pytest.mark.asyncio
async def test_call_rag_ingest(self):
"""Test call_rag_ingest calls handler with parsed plugin ID."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.rag_ingest_document = AsyncMock(return_value={'status': 'success'})
result = await connector.call_rag_ingest('author/engine', {'file': 'test.pdf'})
connector.handler.rag_ingest_document.assert_called_once_with(
'author', 'engine', {'file': 'test.pdf'}
)
assert result['status'] == 'success'
@pytest.mark.asyncio
async def test_call_rag_retrieve(self):
"""Test call_rag_retrieve calls handler."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.retrieve_knowledge = AsyncMock(
return_value={'results': [{'id': 'doc1', 'content': [{'type': 'text', 'text': 'test'}], 'metadata': {}, 'distance': 0.1}]}
)
result = await connector.call_rag_retrieve('author/engine', {'query': 'test'})
connector.handler.retrieve_knowledge.assert_called_once()
assert 'results' in result
@pytest.mark.asyncio
async def test_get_rag_creation_schema(self):
"""Test get_rag_creation_schema calls handler."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.get_rag_creation_schema = AsyncMock(
return_value={'properties': {'name': {'type': 'string'}}}
)
result = await connector.get_rag_creation_schema('author/engine')
connector.handler.get_rag_creation_schema.assert_called_once_with('author', 'engine')
assert 'properties' in result
@pytest.mark.asyncio
async def test_get_rag_retrieval_schema(self):
"""Test get_rag_retrieval_schema calls handler."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.get_rag_retrieval_schema = AsyncMock(
return_value={'properties': {'top_k': {'type': 'integer'}}}
)
result = await connector.get_rag_retrieval_schema('author/engine')
connector.handler.get_rag_retrieval_schema.assert_called_once_with('author', 'engine')
assert 'properties' in result
@pytest.mark.asyncio
async def test_rag_on_kb_create(self):
"""Test rag_on_kb_create calls handler."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.rag_on_kb_create = AsyncMock(return_value={'status': 'ok'})
await connector.rag_on_kb_create('author/engine', 'kb-uuid', {'model': 'test'})
connector.handler.rag_on_kb_create.assert_called_once_with(
'author', 'engine', 'kb-uuid', {'model': 'test'}
)
@pytest.mark.asyncio
async def test_rag_on_kb_delete(self):
"""Test rag_on_kb_delete calls handler."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.rag_on_kb_delete = AsyncMock(return_value={'status': 'ok'})
await connector.rag_on_kb_delete('author/engine', 'kb-uuid')
connector.handler.rag_on_kb_delete.assert_called_once_with('author', 'engine', 'kb-uuid')
@pytest.mark.asyncio
async def test_call_rag_delete_document(self):
"""Test call_rag_delete_document calls handler."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.rag_delete_document = AsyncMock(return_value=True)
result = await connector.call_rag_delete_document('author/engine', 'doc-uuid', 'kb-uuid')
connector.handler.rag_delete_document.assert_called_once_with(
'author', 'engine', 'doc-uuid', 'kb-uuid'
)
assert result is True
class TestRetrieveKnowledge:
"""Tests for retrieve_knowledge method."""
@pytest.mark.asyncio
async def test_returns_empty_results_when_plugin_disabled(self):
"""Test returns empty when plugin disabled."""
connector_module = get_connector_module()
async def mock_disconnect(conn):
pass
mock_app = create_mock_app()
mock_app.instance_config.data = {'plugin': {'enable': False}}
connector = connector_module.PluginRuntimeConnector(mock_app, mock_disconnect)
result = await connector.retrieve_knowledge('author', 'engine', 'retriever', {})
assert result == {'results': []}
class TestDisabledPluginEarlyReturns:
"""Tests for early returns when plugin system is disabled."""
@pytest.mark.asyncio
async def test_list_tools_returns_empty(self):
"""Test list_tools returns empty when disabled."""
connector_module = get_connector_module()
async def mock_disconnect(conn):
pass
mock_app = create_mock_app()
mock_app.instance_config.data = {'plugin': {'enable': False}}
connector = connector_module.PluginRuntimeConnector(mock_app, mock_disconnect)
result = await connector.list_tools()
assert result == []
@pytest.mark.asyncio
async def test_list_commands_returns_empty(self):
"""Test list_commands returns empty when disabled."""
connector_module = get_connector_module()
async def mock_disconnect(conn):
pass
mock_app = create_mock_app()
mock_app.instance_config.data = {'plugin': {'enable': False}}
connector = connector_module.PluginRuntimeConnector(mock_app, mock_disconnect)
result = await connector.list_commands()
assert result == []
@pytest.mark.asyncio
async def test_get_debug_info_returns_empty(self):
"""Test get_debug_info returns empty dict when disabled."""
connector_module = get_connector_module()
async def mock_disconnect(conn):
pass
mock_app = create_mock_app()
mock_app.instance_config.data = {'plugin': {'enable': False}}
connector = connector_module.PluginRuntimeConnector(mock_app, mock_disconnect)
result = await connector.get_debug_info()
assert result == {}
class TestGetPluginInfo:
"""Tests for get_plugin_info method."""
@pytest.mark.asyncio
async def test_calls_handler_get_plugin_info(self):
"""Test that handler.get_plugin_info is called."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.get_plugin_info = AsyncMock(
return_value={'manifest': {'metadata': {'name': 'plugin'}}}
)
result = await connector.get_plugin_info('author', 'plugin')
connector.handler.get_plugin_info.assert_called_once_with('author', 'plugin')
assert 'manifest' in result
class TestSetPluginConfig:
"""Tests for set_plugin_config method."""
@pytest.mark.asyncio
async def test_calls_handler_set_plugin_config(self):
"""Test that handler.set_plugin_config is called."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.set_plugin_config = AsyncMock(return_value={'status': 'ok'})
await connector.set_plugin_config('author', 'plugin', {'setting': 'value'})
connector.handler.set_plugin_config.assert_called_once_with(
'author', 'plugin', {'setting': 'value'}
)
class TestPingPluginRuntime:
"""Tests for ping_plugin_runtime method."""
@pytest.mark.asyncio
async def test_raises_when_handler_not_set(self):
"""Test that exception is raised when handler not initialized."""
get_connector_module()
connector = create_mock_connector()
# handler is not set
with pytest.raises(Exception) as exc_info:
await connector.ping_plugin_runtime()
assert 'not connected' in str(exc_info.value)
@pytest.mark.asyncio
async def test_calls_handler_ping(self):
"""Test that handler.ping is called."""
get_connector_module()
connector = create_mock_connector()
connector.handler = AsyncMock()
connector.handler.ping = AsyncMock(return_value={'status': 'ok'})
await connector.ping_plugin_runtime()
connector.handler.ping.assert_called_once()

View File

@@ -0,0 +1,210 @@
"""Unit tests for plugin connector _extract_deps_metadata method.
Tests cover:
- Extracting requirements.txt from ZIP
- Parsing dependency lines
- Handling missing requirements.txt
- Handling empty/malformed requirements.txt
"""
from __future__ import annotations
import zipfile
import io
from unittest.mock import Mock
from importlib import import_module
def get_connector_module():
"""Lazy import to avoid circular import issues."""
return import_module('langbot.pkg.plugin.connector')
def create_mock_connector():
"""Create a mock PluginRuntimeConnector instance for testing."""
connector = get_connector_module()
mock_app = Mock()
mock_app.logger = Mock()
mock_app.instance_config = Mock()
mock_app.instance_config.data = {'plugin': {'enable': True}}
# Mock disconnect callback
async def mock_disconnect_callback(connector):
pass
return connector.PluginRuntimeConnector(mock_app, mock_disconnect_callback)
def create_zip_with_requirements(requirements_content: str) -> bytes:
"""Create a ZIP file containing requirements.txt with given content."""
buf = io.BytesIO()
with zipfile.ZipFile(buf, 'w') as zf:
zf.writestr('requirements.txt', requirements_content)
return buf.getvalue()
def create_zip_with_nested_requirements(requirements_content: str) -> bytes:
"""Create a ZIP file with requirements.txt in nested directory."""
buf = io.BytesIO()
with zipfile.ZipFile(buf, 'w') as zf:
zf.writestr('plugin/requirements.txt', requirements_content)
return buf.getvalue()
def create_zip_without_requirements() -> bytes:
"""Create a ZIP file without requirements.txt."""
buf = io.BytesIO()
with zipfile.ZipFile(buf, 'w') as zf:
zf.writestr('main.py', 'print("hello")')
zf.writestr('manifest.yaml', 'name: test')
return buf.getvalue()
class TestExtractDepsMetadata:
"""Tests for _extract_deps_metadata method."""
def test_extract_simple_requirements(self):
"""Test extracting simple requirements.txt."""
connector_instance = create_mock_connector()
# Create test ZIP
zip_bytes = create_zip_with_requirements('requests>=2.0\nflask==1.0\nnumpy')
# Create task context
task_context = Mock()
task_context.metadata = {}
connector_instance._extract_deps_metadata(zip_bytes, task_context)
assert task_context.metadata.get('deps_total') == 3
assert task_context.metadata.get('deps_list') == ['requests>=2.0', 'flask==1.0', 'numpy']
def test_extract_requirements_with_comments_and_empty_lines(self):
"""Test that comments and empty lines are filtered."""
connector_instance = create_mock_connector()
requirements = '''# This is a comment
requests>=2.0
# Another comment
flask==1.0
numpy'''
zip_bytes = create_zip_with_requirements(requirements)
task_context = Mock()
task_context.metadata = {}
connector_instance._extract_deps_metadata(zip_bytes, task_context)
assert task_context.metadata.get('deps_total') == 3
assert '# This is a comment' not in task_context.metadata.get('deps_list', [])
def test_extract_nested_requirements(self):
"""Test extracting requirements.txt from nested directory."""
connector_instance = create_mock_connector()
zip_bytes = create_zip_with_nested_requirements('requests\nflask')
task_context = Mock()
task_context.metadata = {}
connector_instance._extract_deps_metadata(zip_bytes, task_context)
# Should find nested requirements.txt (ends with 'requirements.txt')
assert task_context.metadata.get('deps_total') == 2
def test_no_requirements_in_zip(self):
"""Test handling ZIP without requirements.txt."""
connector_instance = create_mock_connector()
zip_bytes = create_zip_without_requirements()
task_context = Mock()
task_context.metadata = {}
connector_instance._extract_deps_metadata(zip_bytes, task_context)
# metadata should remain empty (no deps found)
assert task_context.metadata.get('deps_total') is None
assert task_context.metadata.get('deps_list') is None
def test_empty_requirements_file(self):
"""Test handling empty requirements.txt."""
connector_instance = create_mock_connector()
zip_bytes = create_zip_with_requirements('')
task_context = Mock()
task_context.metadata = {}
connector_instance._extract_deps_metadata(zip_bytes, task_context)
# deps_total should be 0 (empty list after filtering)
assert task_context.metadata.get('deps_total') == 0
assert task_context.metadata.get('deps_list') == []
def test_requirements_only_comments(self):
"""Test handling requirements.txt with only comments."""
connector_instance = create_mock_connector()
requirements = '''# Comment 1
# Comment 2
# Comment 3'''
zip_bytes = create_zip_with_requirements(requirements)
task_context = Mock()
task_context.metadata = {}
connector_instance._extract_deps_metadata(zip_bytes, task_context)
assert task_context.metadata.get('deps_total') == 0
assert task_context.metadata.get('deps_list') == []
def test_task_context_none_returns_early(self):
"""Test that method returns early when task_context is None."""
connector_instance = create_mock_connector()
zip_bytes = create_zip_with_requirements('requests')
# Should return without error when task_context is None
connector_instance._extract_deps_metadata(zip_bytes, None)
# No exception should be raised
def test_malformed_zip_handling(self):
"""Test handling malformed ZIP bytes."""
connector_instance = create_mock_connector()
# Invalid ZIP bytes
invalid_bytes = b'not a valid zip file'
task_context = Mock()
task_context.metadata = {}
# Should silently handle exception (pass in try/except)
connector_instance._extract_deps_metadata(invalid_bytes, task_context)
# metadata should remain unchanged
assert task_context.metadata == {}
def test_requirements_with_unicode_decode_error(self):
"""Test handling requirements.txt with non-UTF8 content."""
connector_instance = create_mock_connector()
# Create ZIP with non-UTF8 content in requirements.txt
buf = io.BytesIO()
with zipfile.ZipFile(buf, 'w') as zf:
# Write bytes that will cause decode issues
# \x80 is invalid UTF-8, but errors='ignore' will skip it
zf.writestr('requirements.txt', b'requests\nflask\n\x80invalid')
zip_bytes = buf.getvalue()
task_context = Mock()
task_context.metadata = {}
# errors='ignore' will decode \x80invalid as 'invalid' (skipping \x80)
connector_instance._extract_deps_metadata(zip_bytes, task_context)
# All 3 lines will be parsed (requests, flask, invalid)
assert task_context.metadata.get('deps_total') == 3
assert 'invalid' in task_context.metadata.get('deps_list', [])

View File

@@ -0,0 +1,127 @@
"""Unit tests for plugin handler helper functions and methods.
Tests cover:
- _make_rag_error_response() helper function
- RuntimeConnectionHandler cleanup_plugin_data method
"""
from __future__ import annotations
import pytest
from unittest.mock import Mock, AsyncMock
from importlib import import_module
def get_handler_module():
"""Lazy import to avoid circular import issues."""
return import_module('langbot.pkg.plugin.handler')
class TestMakeRagErrorResponse:
"""Tests for _make_rag_error_response helper function."""
def test_creates_error_response_with_exception(self):
"""Test basic error response creation."""
handler = get_handler_module()
error = ValueError("test error message")
result = handler._make_rag_error_response(error, 'TestError')
# ActionResponse.error() returns code=1 (error status)
assert result.code == 1
assert 'TestError' in result.message
assert 'ValueError' in result.message
assert 'test error message' in result.message
def test_includes_error_type_in_message(self):
"""Test that error type is included in message."""
handler = get_handler_module()
error = RuntimeError("something went wrong")
result = handler._make_rag_error_response(error, 'VectorStoreError')
assert '[VectorStoreError/RuntimeError]' in result.message
def test_includes_extra_context_in_message(self):
"""Test that extra context fields are included."""
handler = get_handler_module()
error = Exception("embedding failed")
result = handler._make_rag_error_response(
error,
'EmbeddingError',
embedding_model_uuid='test-uuid-123',
collection_id='collection-456',
)
assert 'embedding_model_uuid=test-uuid-123' in result.message
assert 'collection_id=collection-456' in result.message
def test_handles_exception_with_no_message(self):
"""Test handling exception with empty message."""
handler = get_handler_module()
error = Exception()
result = handler._make_rag_error_response(error, 'GenericError')
# ActionResponse.error() returns code=1 (error status)
assert result.code == 1
assert '[GenericError/Exception]' in result.message
def test_formats_context_with_multiple_fields(self):
"""Test multiple context fields are comma separated."""
handler = get_handler_module()
error = IOError("file not found")
result = handler._make_rag_error_response(
error,
'FileServiceError',
storage_path='/data/file.pdf',
kb_id='kb-001',
)
assert '[storage_path=/data/file.pdf, kb_id=kb-001]' in result.message
class TestCleanupPluginData:
"""Tests for cleanup_plugin_data method."""
@pytest.mark.asyncio
async def test_deletes_plugin_settings(self):
"""Test that plugin settings are deleted."""
handler_module = get_handler_module()
mock_app = Mock()
mock_app.persistence_mgr = AsyncMock()
mock_app.persistence_mgr.execute_async = AsyncMock()
# Mock the handler without connection (we only need ap)
handler_instance = Mock(spec=handler_module.RuntimeConnectionHandler)
handler_instance.ap = mock_app
# Call cleanup_plugin_data
await handler_module.RuntimeConnectionHandler.cleanup_plugin_data(
handler_instance, 'test-author', 'test-plugin'
)
# Verify plugin settings delete was called
calls = mock_app.persistence_mgr.execute_async.call_args_list
assert len(calls) >= 1
@pytest.mark.asyncio
async def test_deletes_binary_storage(self):
"""Test that binary storage is deleted."""
handler_module = get_handler_module()
mock_app = Mock()
mock_app.persistence_mgr = AsyncMock()
mock_app.persistence_mgr.execute_async = AsyncMock()
handler_instance = Mock(spec=handler_module.RuntimeConnectionHandler)
handler_instance.ap = mock_app
await handler_module.RuntimeConnectionHandler.cleanup_plugin_data(
handler_instance, 'author', 'plugin-name'
)
# Should have at least 2 calls: one for settings, one for binary storage
assert mock_app.persistence_mgr.execute_async.call_count >= 2