Files
RuoYi-Vue3-FastAPI/ruoyi-fastapi-backend/tests/module_plugin/controller/test_plugin_diagnostics_controller.py
T
insistence 4bd83bc7cd feat: 支持 v2 插件、独立前端和签名制品发布 (#130)
* feat: 支持 v2 插件、原生扩展与签名发布

* fix: 修复测试

* feat: 增强宿主 SDK、运行观测与制品维护能力

* feat: 增强文件传输、配置观测与本地开发能力

* feat: 支持 SSE 实时事件流并完善开发脚手架

* feat: 完善长连接鉴权复核与关闭回收

* feat: 增强生命周期与任务关闭可靠性

* feat: 收紧健康检查契约并补齐前端与真实网络验收

* feat: 增加SDK溯源与离线更新工具并验证跨版本兼容

* feat: 增加持久化业务示例与受控 Python 交付

* feat: 增加统一运行诊断与多worker状态观测

* feat: 增加固定目标发布等待与自动验收

* fix: 修复多环境插件部署前缀与代理配置不一致

* fix: 修复测试
2026-10-09 23:49:45 +08:00

57 lines
2.6 KiB
Python

import json
from types import SimpleNamespace
from unittest.mock import AsyncMock
import pytest
from fastapi import FastAPI, Request
from module_plugin.controller.plugin_controller import diagnose_system_plugin
@pytest.mark.asyncio
async def test_diagnose_api_attaches_runtime_without_changing_static_ok(monkeypatch: pytest.MonkeyPatch) -> None:
app = FastAPI()
reporter = object()
app.state.plugin_diagnostics_reporter = reporter
app.state.redis = object()
app.state.plugin_application_runtime = SimpleNamespace(ready_key='isolated:ready')
operation = SimpleNamespace(
diagnose_plugin_with_audit_services=AsyncMock(
return_value={
'ok': True,
'pluginId': 'demo',
'message': '插件诊断包生成完成',
'audit': {'available': True},
}
)
)
read = AsyncMock(return_value={'state': 'unavailable', 'observedTotals': None})
monkeypatch.setattr('module_plugin.controller.plugin_controller.get_plugin_operation_service', lambda: operation)
monkeypatch.setattr('plugins.core.runtime.diagnostics_query.read_plugin_runtime_diagnostics', read)
response = await diagnose_system_plugin(Request({'type': 'http', 'app': app}), object(), 'demo')
payload = json.loads(response.body)['data']
assert payload['ok'] is True
assert payload['runtime'] == {'state': 'unavailable', 'observedTotals': None}
read.assert_awaited_once_with('demo', reporter=reporter, redis=app.state.redis, ready_key='isolated:ready')
@pytest.mark.asyncio
@pytest.mark.parametrize('complete', [True, False])
async def test_failed_check_remains_visible_but_generation_failure_keeps_error_envelope(
monkeypatch: pytest.MonkeyPatch, complete: bool
) -> None:
payload = {'ok': False, 'message': '插件诊断包生成完成,发现问题', 'info': {'pluginId': 'demo'}}
if complete:
payload.update(check={'ok': False}, config={}, menuPlan={}, audit={})
operation = SimpleNamespace(diagnose_plugin_with_audit_services=AsyncMock(return_value=payload))
monkeypatch.setattr('module_plugin.controller.plugin_controller.get_plugin_operation_service', lambda: operation)
monkeypatch.setattr(
'plugins.core.runtime.diagnostics_query.read_plugin_runtime_diagnostics',
AsyncMock(return_value={'state': 'observed'}),
)
response = await diagnose_system_plugin(Request({'type': 'http', 'app': FastAPI()}), object(), 'demo')
result = json.loads(response.body)
assert result['code'] == (200 if complete else 601)
assert result['data']['ok'] is False
assert result['data']['runtime'] == {'state': 'observed'}