63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
"""
|
|
质量门禁 — 执行前检查测试数据是否满足覆盖率和边界要求。
|
|
|
|
Phase 1 可用: 决策点覆盖、段落覆盖
|
|
Phase 2 启用: HINA 必须项、字段覆盖
|
|
"""
|
|
|
|
|
|
def check(
|
|
complete_tests: list,
|
|
hina_result: dict,
|
|
coverage: dict,
|
|
decision_threshold: float = 0.90,
|
|
paragraph_threshold: float = 1.0,
|
|
) -> dict:
|
|
"""质量门禁检查。
|
|
|
|
Args:
|
|
complete_tests: 完整的测试数据集
|
|
hina_result: HINA 分类结果
|
|
coverage: check_coverage() 输出的覆盖率数据
|
|
decision_threshold: 决策点覆盖率阈值
|
|
paragraph_threshold: 段落覆盖率阈值
|
|
|
|
Returns:
|
|
dict with: passed, score, issues
|
|
"""
|
|
issues = {}
|
|
|
|
branch_rate = coverage.get("branch_rate", 0.0)
|
|
if branch_rate < decision_threshold:
|
|
issues["decision_gaps"] = coverage.get("uncovered_decision_ids", [])
|
|
|
|
paragraph_rate = coverage.get("paragraph_rate", 0.0)
|
|
if paragraph_rate < paragraph_threshold:
|
|
issues.setdefault("paragraph_gaps", []).append(
|
|
f"段落覆盖率不足: {paragraph_rate:.0%}"
|
|
)
|
|
|
|
if not complete_tests:
|
|
issues["no_data"] = True
|
|
|
|
passed = len(issues) == 0
|
|
score = _compute_score(coverage, hina_result)
|
|
|
|
return {"passed": passed, "score": score, "issues": issues}
|
|
|
|
|
|
def _compute_score(coverage: dict, hina_result: dict) -> float:
|
|
"""质量评分公式(COBOL 版)。
|
|
|
|
评分 = 覆盖质量 × 0.6 + 边界质量 × 0.4
|
|
覆盖质量 = 段落覆盖率 × 0.5 + 分支覆盖率 × 0.5
|
|
边界质量 = HINA 必须项覆盖率(Phase 2 后启用,默认 1.0)
|
|
"""
|
|
paragraph_rate = coverage.get("paragraph_rate", 0.0)
|
|
branch_rate = coverage.get("branch_rate", 0.0)
|
|
|
|
coverage_quality = paragraph_rate * 0.5 + branch_rate * 0.5
|
|
boundary_quality = 1.0
|
|
|
|
return round(coverage_quality * 0.6 + boundary_quality * 0.4, 2)
|