Files
cobol-java-v3/hina/gate.py
hangshuo652 bc1d56d1a4 feat: Phase 2 complete — 13 Phases of COBOL type classification and test benchmark
P0.6: gcov infrastructure
P1: extract_structure output expansion (11 new feature fields)
P2: Confusion group rule engine (8 pairs + contradiction + backtrack)
P3: 4-factor confidence calculation + quality gate update
P4: 33+2 COBOL program type test samples (22 files, 7 categories)
P5: parametrized/ test data generation engine
P6: japanese_data.py lookup tables
P7-10: Type-specific test suites (~159 parametrized tests)
P11: Full classification pipeline (classify_program) + orchestrator integration
P12: Documentation (module-interfaces, test-plan v3.0, coverage-matrix)

Architecture decisions:
- classification_pipeline/ merged to hina/pipeline/
- parametrized/ as independent module
- japanese_data.py as root-level file
- hina/__all__ only exports classify_program()

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-19 23:51:55 +08:00

107 lines
3.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
质量门禁 — 执行前检查测试数据是否满足覆盖率和边界要求。
Phase 1 可用: 决策点覆盖、段落覆盖
Phase 2 启用: HINA 必须项、字段覆盖
"""
from __future__ import annotations
from typing import Any
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)
def compute_quality_score(
static_coverage: dict[str, Any],
gcov_coverage: dict[str, Any] | None = None,
confidence: float = 0.5,
) -> float:
"""双模式质量评分。
模式 1 — gcov 未启用 (gcov_coverage is None):
score = branch_rate × 0.5 + paragraph_rate × 0.5 + confidence × 0.4
其中 confidence 作为加分项(最高 +0.4
模式 2 — gcov 启用:
score = static_cov × 0.3 + gcov_cov × 0.4 + confidence × 0.3
其中 static_cov = branch_rate × 0.5 + paragraph_rate × 0.5
Args:
static_coverage: 静态覆盖率数据
{"branch_rate": float, "paragraph_rate": float, ...}
gcov_coverage: gcov 动态覆盖率数据,None 表示未启用
{"gcov_cov": float, ...} 或 None
confidence: 确信度 (0.0 ~ 1.0)
Returns:
float: 质量评分 (0.0 ~ 1.0)
"""
branch_rate = static_coverage.get("branch_rate", 0.0)
paragraph_rate = static_coverage.get("paragraph_rate", 0.0)
static_cov = branch_rate * 0.5 + paragraph_rate * 0.5
if gcov_coverage is not None:
# 模式 2: gcov 启用
gcov_cov = gcov_coverage.get("gcov_cov", 0.0)
score = static_cov * 0.3 + gcov_cov * 0.4 + confidence * 0.3
else:
# 模式 1: gcov 未启用 — confidence 作为加分
score = branch_rate * 0.5 + paragraph_rate * 0.5 + confidence * 0.4
return round(min(score, 1.0), 4)