feat: Phase 2 - HINA Agent + Strategy Agent + classifier

This commit is contained in:
hangshuo652
2026-06-18 16:10:38 +08:00
parent c021dfe01e
commit de506d9c31
4 changed files with 530 additions and 3 deletions
+27 -3
View File
@@ -21,6 +21,9 @@ from config import Config
from cobol_testgen import extract_structure, generate_data, incremental_supplement
from cobol_testgen.coverage import check_coverage
from hina.gate import check as gate_check
from hina.classifier import compute_confidence
from hina.hina_agent import classify_with_llm
from hina.strategy import supplement as strategy_supplement
logger = logging.getLogger(__name__)
@@ -45,10 +48,27 @@ def run_pipeline(cfg: Config, cpath: str, cbl: str, java: str, map_path: str) ->
if vr.llm_cost > cfg.max_llm_cost:
return _done(vr, t0, "BLOCKED", 3)
# ── Phase 1: cobol_testgen 结构提取 + 路径覆盖 + 质量门禁 ──
# ── Phase 1+2: cobol_testgen + HINA Agent + 策略 Agent + 质量门禁 ──
try:
cobol_src_text = Path(cbl).read_text(encoding="utf-8")
structure = extract_structure(cobol_src_text)
# HINA Agent 类型判定
hina_result = {}
try:
hina_result = compute_confidence(cobol_src_text, structure)
if hina_result.get("confidence", 0) < 0.7 and structure:
llm_hina = classify_with_llm(structure, llm)
if llm_hina.get("confidence", 0) > hina_result.get("confidence", 0):
hina_result = llm_hina
vr.hina_type = hina_result.get("category", "")
vr.hina_confidence = hina_result.get("confidence", 0.0)
vr.debug["hina_result"] = hina_result
except Exception as e:
vr.debug["hina_agent_error"] = str(e)
logger.warning(f"[orchestrator] HINA Agent 判定失败: {e}")
# cobol_testgen 路径枚举 + 基础数据生成
base_records = generate_data(cobol_src_text, structure)
vr.debug["cobol_testgen_records"] = len(base_records)
vr.debug["total_branches"] = structure.get("total_branches", 0)
@@ -57,11 +77,15 @@ def run_pipeline(cfg: Config, cpath: str, cbl: str, java: str, map_path: str) ->
for i, rec in enumerate(base_records):
base_testcases.append(TestCase(id=f"CTG-{i+1:04d}", fields=dict(rec)))
# 策略 Agent 补充
strategy_tests = strategy_supplement(base_testcases, hina_result)
complete_tests = base_testcases + strategy_tests
# 质量门禁循环
cov = check_coverage(structure, base_records)
for attempt in range(cfg.max_quality_retries):
gate_result = gate_check(
base_testcases, {},
cov,
complete_tests, hina_result, cov,
decision_threshold=cfg.quality_gate_decision_threshold,
paragraph_threshold=cfg.quality_gate_paragraph_threshold,
)