Files
RuoYi-Vue3-FastAPI/ruoyi-fastapi-backend/tests/cli/runtime/plugin/conftest.py
T
insistence 025b0822df refactor: 统一多前端工程架构、插件配置与 CI (#131)
* refactor: 重构项目架构

* refactor: 重构ci和测试

* fix: 修复测试

* feat: 新增更多E2E测试

* fix: 修复E2E测试
2026-10-10 21:15:22 +08:00

114 lines
3.9 KiB
Python

import sys
from pathlib import Path
from subprocess import CompletedProcess
from cli.runtime.plugin.service import CliPluginRuntimeService
from plugins.core.environment import PluginRuntimeEnvironmentService
from plugins.core.frontend import PluginFrontendFrameworkResolver
from plugins.core.validation.dependencies import (
NpmDependencyInspector,
PluginDependencyChecker,
PythonDependencyInspector,
)
EXPECTED_FRONTEND_BUILD_TIMEOUT = 300
class FakeRuntimeEnvironment:
"""
测试用插件 CLI 运行时环境服务。
"""
def __init__(self, backend_dir: Path, frontend_dir: Path | None = None) -> None:
"""初始化测试用插件 CLI 运行时环境服务。"""
self.backend_dir = backend_dir
self.frontend_dir = frontend_dir or Path(
PluginRuntimeEnvironmentService(backend_root=backend_dir).get_frontend_dir()
)
def get_backend_dir(self) -> str:
"""获取后端项目根目录。"""
return str(self.backend_dir)
def get_backend_plugins_dir(self) -> str:
"""获取后端插件根目录。"""
return str(self.backend_dir / 'plugins')
def get_frontend_dir(self) -> str:
"""获取前端项目根目录。"""
return str(self.frontend_dir)
def get_frontend_framework(self, frontend_root: Path | None = None) -> str:
"""获取指定测试前端工程的框架标识。"""
return PluginFrontendFrameworkResolver.resolve(frontend_root or self.frontend_dir)
def get_frontend_plugins_dir(self) -> str:
"""获取前端插件根目录。"""
return str(self.frontend_dir / 'plugins')
@staticmethod
def get_frontend_mode() -> str:
"""获取测试用前端运行模式。"""
return 'dev'
@staticmethod
def get_backend_runtime_mode() -> str:
"""获取测试用后端运行模式。"""
return 'dev'
@staticmethod
def get_python_executable() -> str:
"""获取测试用 Python 解释器。"""
return sys.executable
class FakePluginRuntimeGateway:
"""
测试用插件 CLI 运行时适配器。
"""
def __init__(self) -> None:
"""初始化测试用插件 CLI 运行时适配器。"""
self.completed_process = CompletedProcess(args=[], returncode=0, stdout='1 passed\n', stderr='')
self.commands: list[tuple[list[str], str, int | None]] = []
def run_command(
self,
command: list[str],
workdir: str,
*,
timeout: int | None = None,
) -> CompletedProcess[str]:
"""记录测试用系统命令。"""
self.commands.append((command, workdir, timeout))
return self.completed_process
def build_runtime(backend_root: Path, frontend_root: Path | None = None) -> CliPluginRuntimeService:
"""构建测试用插件 CLI 运行时服务。"""
return CliPluginRuntimeService(
runtime_environment=FakeRuntimeEnvironment(backend_root, frontend_root),
dependency_checker=PluginDependencyChecker(
python_inspector=PythonDependencyInspector(installed_packages={'openai': '2.17.0'}),
npm_inspector=NpmDependencyInspector(installed_packages={'vue': '3.5.26'}),
),
)
def build_runtime_with_gateway(
backend_root: Path,
gateway: FakePluginRuntimeGateway,
frontend_root: Path | None = None,
) -> CliPluginRuntimeService:
"""构建带测试运行时适配器的插件 CLI 运行时服务。"""
return CliPluginRuntimeService(
runtime_environment=FakeRuntimeEnvironment(backend_root, frontend_root),
dependency_checker=PluginDependencyChecker(
python_inspector=PythonDependencyInspector(installed_packages={'openai': '2.17.0'}),
npm_inspector=NpmDependencyInspector(installed_packages={'vue': '3.5.26'}),
),
management_gateway=gateway,
model_gateway=gateway,
command_gateway=gateway,
)