Files
planManage/app/main.py
congsh 37d282c0a2 test: 添加测试框架和全面的单元测试
- 添加 pytest 配置和测试依赖到 requirements.txt
- 创建测试包结构和 fixtures (conftest.py)
- 添加数据库模块的 CRUD 操作测试 (test_database.py)
- 添加 Provider 插件系统测试 (test_providers.py)
- 添加调度器模块测试 (test_scheduler.py)
- 添加 API 路由测试 (test_api.py)
- 添加回归测试覆盖边界条件和错误处理 (test_regressions.py)
- 添加健康检查端点用于容器监控
- 修复调度器中的日历计算逻辑和任务执行参数处理
- 更新数据库函数以返回操作结果状态
2026-03-31 22:36:18 +08:00

59 lines
1.6 KiB
Python

"""FastAPI 应用入口"""
from contextlib import asynccontextmanager
from pathlib import Path
from fastapi import FastAPI
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from app.config import settings
from app.database import get_db, close_db, seed_from_config
@asynccontextmanager
async def lifespan(app: FastAPI):
await get_db()
await seed_from_config()
from app.services.scheduler import start_scheduler
await start_scheduler()
Path(settings.storage.path).mkdir(parents=True, exist_ok=True)
yield
from app.services.scheduler import stop_scheduler
await stop_scheduler()
await close_db()
app = FastAPI(
title="Plan Manager",
description="多平台 Coding Plan 统一管理系统",
version="0.1.0",
lifespan=lifespan,
)
# 挂载 API / 代理路由
from app.routers import plans, quota, queue, proxy # noqa: E402
app.include_router(plans.router, prefix="/api/plans", tags=["Plans"])
app.include_router(quota.router, prefix="/api/quota", tags=["Quota"])
app.include_router(queue.router, prefix="/api/queue", tags=["Queue"])
app.include_router(proxy.router, tags=["Proxy"])
# 前端: 用显式路由而非 mount("/") 以避免遮盖 /docs, /api, /v1
_static_dir = Path(__file__).parent / "static"
@app.get("/", include_in_schema=False)
async def serve_index():
return FileResponse(_static_dir / "index.html")
@app.get("/health", tags=["Health"])
async def health_check():
"""健康检查端点,用于容器健康检查"""
return {"status": "healthy", "service": "plan-manager"}