feat: Sprint 1 - 数据正确性整改

P2-01: 移除 lifespan create_all,改为仅验证连接
       新增 /health/ready 就绪检查
P0-04: LLM 输出严格 Pydantic 校验
       - Agent 输出越界/非法 → parse_error
       - 预测输出自动修正 1X2 与比分一致性
P0-01: injuries cutoff 修复
       - get_injuries_for_match 增加 as_of 参数
       - injuries_slice 使用 as_of 过滤 retrieved_at
       - 防止回测时未来采集数据泄漏
P1-12: 批量入库优化
       - 预加载 teams 到内存 dict
       - 预加载 existing matches 到内存 set
       - 消灭 N+1 查询
This commit is contained in:
shangfangjian
2026-09-14 23:36:35 +08:00
parent 9b44905192
commit f3160e3062
11 changed files with 326 additions and 69 deletions
+9 -1
View File
@@ -96,16 +96,24 @@ class TestReportParsing:
parsed = {
"data_sufficiency": "bogus", # 非法 → medium
"home_edge": "very strong", # 非法 → None
"home_edge": "very strong", # 非法 → None (宽容降级)
"confidence": None,
"key_evidence": "单字符串", # → [str]
}
resp = LLMResponse(content="{}", parsed=parsed)
r = _parse_report("form", parsed, resp, "m")
# 宽容降级: 不抛异常,非法字段变 None 或默认值
assert r.status == "ok"
assert r.data_sufficiency == "medium"
assert r.home_edge is None
assert r.key_evidence == ["单字符串"]
# 验证范围约束: confidence > 1 会被截断或拒绝
parsed2 = {"confidence": 1.5, "home_edge": 2.0}
r2 = _parse_report("form", parsed2, resp, "m")
# Pydantic 会拒绝越界值 → parse_error
assert r2.status == "parse_error"
class TestRunAgent:
"""run_agent 执行器: 门控 + fail-open。"""