test: 接入覆盖率工具并在 CI 强制 ≥80% 门禁

后端: 加 pytest-cov + [tool.coverage] 配置, pytest --cov-fail-under=80 (基线~88%)。
前端: 加 @vitest/coverage-v8, vitest.config.ts 设 80% 阈值, 新增 test:coverage 脚本 (基线~93%)。
前端覆盖范围限定 lib/** 纯逻辑层; hooks(use*.ts)待 jsdom 测试栈接入后纳入。
CI backend/frontend job 改跑覆盖率门禁命令。CLAUDE.md 同步 DoD 与 Toolchain。
This commit is contained in:
Yaojia Wang
2026-06-26 21:11:57 +02:00
parent e9477d84d8
commit a02c6b6e4f
7 changed files with 562 additions and 68 deletions

View File

@@ -14,6 +14,7 @@ members = [
dev = [
"pytest>=8",
"pytest-asyncio>=0.24",
"pytest-cov>=5",
"ruff>=0.6",
"mypy>=1.11",
"httpx>=0.27",
@@ -51,3 +52,23 @@ exclude = ["(^|/)conftest\\.py$"]
[tool.pytest.ini_options]
asyncio_mode = "auto"
testpaths = ["tests", "apps", "packages"]
[tool.coverage.run]
branch = true
source = ["apps", "packages"]
omit = [
"*/tests/*",
"*/conftest.py",
"*/migrations/*",
"*/alembic/*",
]
[tool.coverage.report]
show_missing = true
# 排除无需覆盖的纯防御/类型分支
exclude_lines = [
"pragma: no cover",
"raise NotImplementedError",
"if TYPE_CHECKING:",
"@(abc\\.)?abstractmethod",
]