重构: 迁移后端代码到 app 目录,前端移动到 WebUI,添加完整测试套件
主要变更: - 后端代码从根目录迁移到 app/ 目录 - 前端代码从 frontend/ 重命名为 WebUI/ - 更新所有导入路径以适配新结构 - 提取公共 API 响应函数到 app/api/common.py - 精简验证器服务代码 - 更新启动脚本和文档 测试: - 新增完整测试套件 (tests/) - 单元测试: 模型、仓库层 - 集成测试: 覆盖所有 22+ API 端点 - E2E 测试: 4个完整工作流场景 - 添加 pytest 配置和测试运行脚本
This commit is contained in:
45
app/api/deps.py
Normal file
45
app/api/deps.py
Normal file
@@ -0,0 +1,45 @@
|
||||
"""依赖注入"""
|
||||
from fastapi import Request
|
||||
from app.services.proxy_service import ProxyService
|
||||
from app.services.plugin_service import PluginService
|
||||
from app.services.scheduler_service import SchedulerService
|
||||
from app.services.validator_service import ValidatorService
|
||||
from app.repositories.proxy_repo import ProxyRepository
|
||||
from app.core.tasks.queue import ValidationQueue
|
||||
from app.core.config import settings as app_settings
|
||||
|
||||
|
||||
def get_proxy_service() -> ProxyService:
|
||||
return ProxyService()
|
||||
|
||||
|
||||
def get_plugin_service() -> PluginService:
|
||||
return PluginService()
|
||||
|
||||
|
||||
def get_scheduler_service(request: Request) -> SchedulerService:
|
||||
return request.app.state.scheduler_service
|
||||
|
||||
|
||||
def get_validation_queue(request: Request) -> ValidationQueue:
|
||||
return request.app.state.validation_queue
|
||||
|
||||
|
||||
def create_scheduler_service() -> SchedulerService:
|
||||
"""在应用启动时创建 SchedulerService(非请求上下文)"""
|
||||
validator = ValidatorService(
|
||||
timeout=app_settings.validator_timeout,
|
||||
connect_timeout=app_settings.validator_connect_timeout,
|
||||
max_concurrency=app_settings.validator_max_concurrency,
|
||||
)
|
||||
proxy_repo = ProxyRepository()
|
||||
queue = ValidationQueue(
|
||||
validator=validator,
|
||||
proxy_repo=proxy_repo,
|
||||
worker_count=app_settings.validator_max_concurrency,
|
||||
score_valid=app_settings.score_valid,
|
||||
score_invalid=app_settings.score_invalid,
|
||||
score_min=app_settings.score_min,
|
||||
score_max=app_settings.score_max,
|
||||
)
|
||||
return SchedulerService(validation_queue=queue, proxy_repo=proxy_repo)
|
||||
Reference in New Issue
Block a user