Files
RuoYi-Vue3-FastAPI/ruoyi-fastapi-backend/tests/cli/root/test_plugin_diagnostics.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

47 lines
2.2 KiB
Python

from pathlib import Path
from types import SimpleNamespace
from unittest.mock import AsyncMock
import pytest
from cli.groups.plugin.payload import PluginCommandPayloadAdapter
from cli.groups.plugin.presenter import PluginCommandPresenter
from cli.runtime.plugin.service import CliPluginRuntimeService
@pytest.mark.asyncio
async def test_cli_diagnose_appends_runtime_without_changing_static_result(monkeypatch: pytest.MonkeyPatch) -> None:
read = AsyncMock(return_value={'state': 'unavailable', 'observedTotals': None})
monkeypatch.setattr('plugins.core.runtime.diagnostics_query.read_cli_runtime_diagnostics', read)
runtime = CliPluginRuntimeService(runtime_environment=SimpleNamespace(get_backend_dir=lambda: '/backend'))
runtime._core_runtime = SimpleNamespace(diagnose_plugin=AsyncMock(return_value={'ok': True, 'info': {'x': 1}}))
payload = await runtime.diagnose_plugin_with_runtime('demo')
assert payload['ok'] is True and payload['info'] == {'x': 1}
assert payload['runtime']['state'] == 'unavailable'
read.assert_awaited_once_with('demo', backend_root=Path('/backend'))
def test_runtime_shared_contract_and_unknown_text_are_preserved() -> None:
payload = {
'ok': True,
'runtime': {
'state': 'partial',
'scope': 'reporting_workers',
'observedWorkers': 0,
'expectedWorkers': 1,
'missingWorkers': 1,
'staleSnapshots': 1,
'invalidSnapshots': 0,
'sampleTtlSeconds': 60,
'release': {'summary': {'pluginId': 'demo', 'status': 'pending_restart', 'enabled': True}},
'workers': [{'workerId': 'a' * 32, 'freshness': 'stale', 'observation': 'stale', 'actual': None}],
},
}
adapted = PluginCommandPayloadAdapter.adapt(payload)
assert adapted['runtime'] == payload['runtime']
text = PluginCommandPresenter().build_diagnose_text(adapted)
assert 'runtime_state: partial' in text and 'freshness=stale' in text
assert 'jobs=unknown' in text and 'sse=unknown' in text and 'websocket=unknown' in text
assert 'ready=unknown' in text and 'worker_pending_cleanup=unknown' in text
assert 'jobs=0' not in text