返回 Bug 清单
BUG-1378project-12中已修复test-flaky

后端 pytest 整体覆盖率 38% — services 层最薄 (data_quality 12%, search 20%)

发现:2026-10-15验证:2026-10-15置信度:70%

症状

pytest 跑 743 items 有 3 fail + 1 collection err;collection err 是 test_knowledge_freshness.py 依赖外部模块;3 个 fail 在 test_api_routes.py (2) 和 test_api_units.py (1);services 层最容易出 bug 但最没测试覆盖

根因

后端有 743 个测试 items 但整体覆盖率 38%。分层看: models 100%(8 个 ORM model 都测了)→ schemas 88%(只有 Pydantic validator 边角)→ api/v1 22-65% → services 12-38% → core/middleware 14-54%。最薄的是 services/data_quality.py (12%), services/search.py (20%), core/ai_router.py (14%)。这说明测试重 endpoint 轻 service——API 层有 httpx AsyncClient 测路由,service 层的纯业务逻辑没单测。根因是 BUG-0576 那次 production schema 变更 conftest 被打断后,service 层 fixture 没有补回。

修复方案

当前状态已摸清。优先级: 1) 修复 test_knowledge_freshness.py collection err(删或补依赖); 2) 给 services/data_quality.py 加 pytest unit test (12% → 至少 60%); 3) 3 个 failing test 定位修复(当前 session 时间不够,先记下来)。models 100% 不用动。schemas 88% 够用。

错误签名

TOTAL 4256 2635 38% (pytest --cov=app)

技术信息

来源项目

project-12

涉及文件

scripts/_run_pytest.ps1

标签

project-12, mcp-reported, source-agent