fix: P1 - complete_tests now feeds DataWriter; P2 - loop syncs complete_tests; P5 - machine_json gets coverage fields

This commit is contained in:
hangshuo652
2026-06-18 16:47:21 +08:00
parent c93104e6bf
commit 2e64f208ea
2 changed files with 33 additions and 16 deletions
+26 -14
View File
@@ -51,7 +51,17 @@ def run_pipeline(cfg: Config, cpath: str, cbl: str, java: str, map_path: str) ->
# ── Phase 1+2: cobol_testgen + HINA Agent + 策略 Agent + 质量门禁 ── # ── Phase 1+2: cobol_testgen + HINA Agent + 策略 Agent + 质量门禁 ──
try: try:
cobol_src_text = Path(cbl).read_text(encoding="utf-8") cobol_src_text = Path(cbl).read_text(encoding="utf-8")
structure = extract_structure(cobol_src_text) structure = extract_structure(cobol_src_text, source_dir=str(Path(cbl).parent))
# cobol_testgen 路径枚举 + 基础数据生成
base_records = generate_data(cobol_src_text, structure, source_dir=str(Path(cbl).parent))
vr.debug["cobol_testgen_records"] = len(base_records)
vr.debug["total_branches"] = structure.get("total_branches", 0)
# 转换为 TestCase 列表(增强管线的基础数据集)
complete_tests = []
for i, rec in enumerate(base_records):
complete_tests.append(TestCase(id=f"CTG-{i+1:04d}", fields=dict(rec)))
# HINA Agent 类型判定 # HINA Agent 类型判定
hina_result = {} hina_result = {}
@@ -68,18 +78,13 @@ def run_pipeline(cfg: Config, cpath: str, cbl: str, java: str, map_path: str) ->
vr.debug["hina_agent_error"] = str(e) vr.debug["hina_agent_error"] = str(e)
logger.warning(f"[orchestrator] HINA Agent 判定失败: {e}") logger.warning(f"[orchestrator] HINA Agent 判定失败: {e}")
# cobol_testgen 路径枚举 + 基础数据生成 # 策略 Agent 补充(追加标记记录,统一为 TestCase 格式)
base_records = generate_data(cobol_src_text, structure) for m in strategy_supplement([], hina_result):
vr.debug["cobol_testgen_records"] = len(base_records) complete_tests.append(TestCase(
vr.debug["total_branches"] = structure.get("total_branches", 0) id=m.get("id", f"STG-{len(complete_tests)+1:04d}"),
fields=m.get("fields", {}),
base_testcases = [] coverage_targets=m.get("coverage_targets", []),
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) cov = check_coverage(structure, base_records)
@@ -95,11 +100,17 @@ def run_pipeline(cfg: Config, cpath: str, cbl: str, java: str, map_path: str) ->
if gaps and structure.get("branch_tree_obj"): if gaps and structure.get("branch_tree_obj"):
delta = incremental_supplement(structure["branch_tree_obj"], gaps) delta = incremental_supplement(structure["branch_tree_obj"], gaps)
base_records.extend(delta) base_records.extend(delta)
# 同步更新 complete_tests
for i, d in enumerate(delta):
complete_tests.append(TestCase(
id=f"CTG-S{attempt+1}-{i+1:04d}",
fields=dict(d),
))
cov = check_coverage(structure, base_records) cov = check_coverage(structure, base_records)
else: else:
break break
vr.paragraph_rate = cov.get("paragraph_rate", 0.0) vr.paragraph_rate = 0.0 # Phase 3 通过 gcov 获取精确值
vr.branch_rate = cov.get("branch_rate", 0.0) vr.branch_rate = cov.get("branch_rate", 0.0)
vr.decision_rate = cov.get("decision_rate", 0.0) vr.decision_rate = cov.get("decision_rate", 0.0)
@@ -112,6 +123,7 @@ def run_pipeline(cfg: Config, cpath: str, cbl: str, java: str, map_path: str) ->
suite = Agent2Data(llm).design(tree, cfg.coverage_default, cfg.runner_mode == "spark") suite = Agent2Data(llm).design(tree, cfg.coverage_default, cfg.runner_mode == "spark")
vr.llm_cost += 0.002 vr.llm_cost += 0.002
suite.test_cases = complete_tests # 替换为增强管线数据(P1/P2 修复)
vr.debug["test_cases"] = [{"id":tc.id,"fields":tc.fields,"targets":tc.coverage_targets} for tc in suite.test_cases] vr.debug["test_cases"] = [{"id":tc.id,"fields":tc.fields,"targets":tc.coverage_targets} for tc in suite.test_cases]
vr.debug["spark_config"] = {"records":suite.spark_config.num_records} if suite.has_spark else None vr.debug["spark_config"] = {"records":suite.spark_config.num_records} if suite.has_spark else None
+6 -1
View File
@@ -95,6 +95,11 @@ table{{border-collapse:collapse}} td,th{{padding:6px 12px}}
def generate_machine_json(self, run: VerificationRun, p: Path) -> Path: def generate_machine_json(self, run: VerificationRun, p: Path) -> Path:
d = {"program": run.program, "status": run.status, "exit_code": run.exit_code, d = {"program": run.program, "status": run.status, "exit_code": run.exit_code,
"timestamp": run.timestamp, "duration_s": run.duration_s, "runner": run.runner} "timestamp": run.timestamp, "duration_s": run.duration_s, "runner": run.runner,
"branch_rate": run.branch_rate, "paragraph_rate": run.paragraph_rate,
"decision_rate": run.decision_rate, "quality_score": run.quality_score,
"hina_type": run.hina_type, "hina_confidence": run.hina_confidence,
"heal_retry": run.heal_retry, "simple_retry": run.simple_retry,
"total_retry": run.total_retry}
p.write_text(json.dumps(d)) p.write_text(json.dumps(d))
return p return p