From 758ce40cc16969543feede665bed6ee465dc3ea2 Mon Sep 17 00:00:00 2001 From: Dt8333 <25431943+Dt8333@users.noreply.github.com> Date: Thu, 27 Nov 2025 14:02:42 +0800 Subject: [PATCH] chore: fix test (#3787) --- packages/session_controller/main.py | 2 +- tests/test_dashboard.py | 12 +++++++++++- tests/test_plugin_manager.py | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/session_controller/main.py b/packages/session_controller/main.py index 4d4a4252..9ea62ea3 100644 --- a/packages/session_controller/main.py +++ b/packages/session_controller/main.py @@ -14,7 +14,7 @@ from astrbot.core.utils.session_waiter import ( ) -class Waiter(Star): +class Main(Star): """会话控制""" def __init__(self, context: Context): diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index a2710c84..f5439e9d 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -21,7 +21,17 @@ async def core_lifecycle_td(tmp_path_factory): log_broker = LogBroker() core_lifecycle = AstrBotCoreLifecycle(log_broker, db) await core_lifecycle.initialize() - return core_lifecycle + try: + yield core_lifecycle + finally: + # 优先停止核心生命周期以释放资源(包括关闭 MCP 等后台任务) + try: + _stop_res = core_lifecycle.stop() + if asyncio.iscoroutine(_stop_res): + await _stop_res + except Exception: + # 停止过程中如有异常,不影响后续清理 + pass @pytest.fixture(scope="module") diff --git a/tests/test_plugin_manager.py b/tests/test_plugin_manager.py index 277f8fa4..1e4cd866 100644 --- a/tests/test_plugin_manager.py +++ b/tests/test_plugin_manager.py @@ -39,6 +39,7 @@ def plugin_manager_pm(tmp_path): message_history_manager = MagicMock() persona_manager = MagicMock() astrbot_config_mgr = MagicMock() + knowledge_base_manager = MagicMock() star_context = Context( event_queue, @@ -50,6 +51,7 @@ def plugin_manager_pm(tmp_path): message_history_manager, persona_manager, astrbot_config_mgr, + knowledge_base_manager=knowledge_base_manager, ) # Create the PluginManager instance