test: 前后端对齐—容器复跑验证+清理僵尸测试

- test_main: FastAPI 0.139 _IncludedRouter 不再 flatten,改用 TestClient 探测路由
- datareader: 文件名(sh600000_daily)/patch target(vnpy.trader.database) 对齐 lazy import 实现
- alpha_lab/analyzer/data_adapter: vnpy.alpha/alphalens 容器专用本地 skip
- 删 4 个测废弃 sanguo_web 的僵尸测试(-1267 行死代码)
- pytest.ini: asyncio_mode=auto
- frontend: package.json 加 test script(npm test 可跑)
- NAS 容器 309 passed 全绿验证(Python 3.10,本机 303+6skip)
This commit is contained in:
2026-07-11 11:45:26 +08:00
parent 928a52b96f
commit a1048690c1
11 changed files with 38 additions and 1267 deletions
+15 -4
View File
@@ -3,6 +3,8 @@
Covers Task S0.1: build_app(config_path, static_dir) loads backtest.yaml and
mounts SPA static files when the directory exists.
"""
from fastapi.testclient import TestClient
from sanguo_api.main import build_app
@@ -17,10 +19,20 @@ def _cfg(tmp_path) -> str:
return str(cfg)
def _has_route(app, path: str, method: str = "GET") -> bool:
"""路由存在性探测(FastAPI 0.139+ 兼容)。
FastAPI 0.139 起 include_router 的子路由包成 _IncludedRouter,不再 flatten
到 app.routes 顶层,因此 [r.path for r in app.routes] 看不到 /api/v1/* 路由。
用 TestClient 实际探测:404 = 路由不存在,其他状态码(405/401/200)= 存在。
前后端对齐的真实验证:前端能打的端点,后端确实挂载。
"""
return TestClient(app).request(method, path).status_code != 404
def test_build_app_has_api_routes(tmp_path):
app = build_app(_cfg(tmp_path))
paths = [getattr(r, "path", "") for r in app.routes]
assert "/api/v1/auth/login" in paths
assert _has_route(app, "/api/v1/auth/login", "POST")
def test_build_app_mounts_spa_when_static_exists(tmp_path):
@@ -35,5 +47,4 @@ def test_build_app_mounts_spa_when_static_exists(tmp_path):
def test_build_app_no_static_skips_mount(tmp_path):
"""When static dir absent, build must still succeed (no SPA mount)."""
app = build_app(_cfg(tmp_path), static_dir=str(tmp_path / "nope"))
paths = [getattr(r, "path", "") for r in app.routes]
assert "/api/v1/auth/login" in paths
assert _has_route(app, "/api/v1/auth/login", "POST")