fix 插件恢复前先装配插件市场、包管理、依赖安装等外部服务

This commit is contained in:
jxxghp
2026-08-18 09:42:58 +08:00
parent 4dc713f02f
commit 17499e5ac9
3 changed files with 37 additions and 5 deletions
+21
View File
@@ -33,6 +33,7 @@ def _patch_lifespan(monkeypatch, *, failing_step: str | None = None) -> dict:
"init_workflow",
):
monkeypatch.setattr(lifecycle, name, MagicMock())
monkeypatch.setattr(lifecycle, "configure_plugin_services", MagicMock())
monkeypatch.setattr(lifecycle, "init_modules", AsyncMock())
# 启动期的引擎预热与额度核算也要打桩。不打的话这些用例会走真实的引擎创建,在测试
@@ -124,6 +125,7 @@ def test_lifespan_normal_mode_starts_full_runtime(monkeypatch):
asyncio.run(run_lifespan())
lifecycle.init_modules.assert_awaited_once_with()
lifecycle.configure_plugin_services.assert_called_once_with()
for name in (
"init_plugins",
"init_scheduler",
@@ -137,6 +139,25 @@ def test_lifespan_normal_mode_starts_full_runtime(monkeypatch):
_assert_completed_once(step)
def test_lifespan_configures_plugin_services_before_restore(monkeypatch):
"""插件恢复依赖的外部系统服务必须先于恢复阶段完成装配。"""
shutdown_steps = _patch_lifespan(monkeypatch)
order = []
lifecycle.configure_plugin_services.side_effect = lambda: order.append("configure")
lifecycle.SystemChain.return_value.restore_plugins.side_effect = (
lambda: order.append("restore")
)
async def run_lifespan():
async with lifecycle.lifespan(FastAPI()):
pass
asyncio.run(run_lifespan())
assert order == ["configure", "restore"]
_assert_completed_once(shutdown_steps["close_http"])
def test_lifespan_safe_mode_skips_optional_runtime(monkeypatch):
"""安全模式只启动基础模块,并跳过插件及可选后台服务。"""
shutdown_steps = _patch_lifespan(monkeypatch)