merge: pull remote Black-white-box-Merge (resolve conflicts, accept remote)

This commit is contained in:
hangshuo652
2026-08-24 20:52:27 +08:00
72 changed files with 9495 additions and 517 deletions
+106 -137
View File
@@ -1,6 +1,6 @@
# V3系统总体设计
> 版本: v2.0 | 日期: 2026-08-23
> 版本: v1.0 | 日期: 2026-08-22
> 本文档描述COBOL迁移验证平台V3的总体架构和模块设计。
---
@@ -15,23 +15,21 @@ COBOL迁移验证平台V3是一个AI辅助的自动化测试工具,用于验
| 能力 | 说明 |
|------|------|
| COBOL源码解析 | 自动解析DATA DIVISION和PROCEDURE DIVISION(支持新旧双解析器) |
| 测试数据生成 | 基于分支覆盖的测试数据自动生成(规则引擎 + LLM双模式) |
| COBOL源码解析 | 自动解析DATA DIVISION和PROCEDURE DIVISION |
| 测试数据生成 | 基于分支覆盖的测试数据自动生成 |
| 双管道验证 | 支持非DBflat file)和DBSQLite)两种验证模式 |
| 全流程入口 | `run.py` 一键执行白盒+黑盒全流程 |
| 黑盒LLM生成 | `black-box-data-create` 基于设计书的LLM测试数据生成 |
| 覆盖率分析 | 静态分支覆盖 + 动态gcov覆盖,生成HTML报告 |
| AI辅助 | LLM驱动的程序分类、测试策略生成、诊断建议 |
| 覆盖率分析 | 静态分支覆盖 + 动态gcov覆盖 |
| AI辅助 | LLM驱动的程序分类和测试策略生成 |
### 1.3 技术栈
| 组件 | 技术 |
|------|------|
| 语言 | Python 3.12+ |
| 解析器 | Lark (Earley parser) + 新fast parser (line-based state machine) |
| 解析器 | Lark (Earley parser) |
| COBOL编译 | GnuCOBOL 3.2.0 |
| DB管道 | gixsql + SQLite |
| AI模型 | DeepSeek (deepseek-v4-flash) |
| AI模型 | DeepSeek |
| 测试框架 | pytest |
---
@@ -41,44 +39,39 @@ COBOL迁移验证平台V3是一个AI辅助的自动化测试工具,用于验
### 2.1 架构图
```
┌─────────────────────────────────────────────────────────────────────
V3系统架构
├─────────────────────────────────────────────────────────────────────
│ ┌──────────────┐ ┌──────────────┐
│ │ run.py │ │ main.py
│ │ 全流程入口 │ │ CLI入口 │
│ └──────┬───────┘ └──────┬───────┘
│ │ │
▼ ▼
┌──────────────┐ ┌──────────────────────────────────────────┐
│ Step1: │ 编排层 (Orchestrator)
│ cobol_testgen│ │ orchestrator.py (非DB) │
│ │ (白盒) orchestrator_db.py (DB, 6步) │ │
│ │ Step2: │ └──────────────────────────────────────────┘
│ black-box │ │
│ (黑盒LLM)
─────────────┘ │
│ │ ┌────────────┼────────────┐
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ │ 核心引擎 │ │ 运行引擎 AI代理
│ cobol_testgen│ │ runners/ │ │ agents/ │
└──────────────┘ └──────────────┘ └──────────────┘
│ │ │
│ ▼ ▼
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ │ 比对模块 │ │ 报告模块 │ │ 配置模块 │
│ │ comparator/ │ │ report/ │ │ config/ │
│ └──────────────┘ └──────────────┘ └──────────────┘
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ black-box-data-create/ (黑盒LLM模块) │ │
│ │ InputParser → RuleLoader → PromptBuilder → APIClient → Writer│ │
│ └──────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ V3系统架构 │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ │ CLI入口 │ │ Web界面│ API接口
│ │ main.py │ │ web/ __init__
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
└────────────────────┼────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ │ 编排层 (Orchestrator) │ │
│ │ orchestrator.py (非DB) orchestrator_db.py (DB) │
└─────────────────────────────────────────────────────────┘
│ │
────────────────────┼────────────────────┐
│ │
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ 核心引擎 │ │ 运行引擎 │ AI代理
│ │ cobol_testgen│ │ runners/ │ │ agents/
└──────────────┘ └──────────────┘ └──────────────┘
│ │ │
│ │
│ ▼
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ │ 比对模块 │ │ 报告模块 │ │ 配置模块 │ │
│ │ comparator/ │ │ report/ │ │ config/ │ │
│ └──────────────┘ └──────────────┘ └──────────────┘
│ │
─────────────────────────────────────────────────────────────────┘
```
### 2.2 分层架构
@@ -89,7 +82,7 @@ COBOL迁移验证平台V3是一个AI辅助的自动化测试工具,用于验
| **L2 核心层** | cobol_testgen/, config/ | COBOL解析、配置管理 |
| **L3 业务层** | hina/, agents/, comparator/ | 分类、AI代理、比对 |
| **L4 编排层** | orchestrator*, runners/ | 流程编排、执行 |
| **L5 接口层** | run.py, main.py, black-box-data-create/ | 用户接口 |
| **L5 接口层** | main.py, web/, __init__.py | 用户接口 |
---
@@ -99,15 +92,13 @@ COBOL迁移验证平台V3是一个AI辅助的自动化测试工具,用于验
| 模块 | 文件数 | 行数 | 职责 |
|------|--------|------|------|
| cobol_testgen/ | 22 | ~10000 | COBOL解析、测试数据生成 |
| black-box-data-create/ | 12 | ~1500 | 黑盒LLM测试数据生成 |
| orchestrator_db.py | 1 | ~1000 | DB管道6步编排 |
| orchestrator.py | 1 | ~500 | 非DB管道编排 |
| runners/ | 7 | ~600 | 编译运行引擎 |
| hina/ | 12 | ~2600 | HINA程序分类 |
| agents/ | 7 | ~1100 | LLM代理 |
| cobol_testgen/ | 22 | ~8000 | COBOL解析、测试数据生成 |
| orchestrator_db.py | 1 | 1334 | DB管道6步编排 |
| runners/ | 8 | ~600 | 编译运行引擎 |
| hina/ | 11 | ~2000 | HINA程序分类 |
| agents/ | 6 | ~800 | LLM代理 |
| comparator/ | 6 | ~400 | 字段比对 |
| config/ | 4 | ~400 | 配置管理 |
| config/ | 5 | ~300 | 配置管理 |
| report/ | 1 | ~200 | 报告生成 |
### 3.2 模块依赖关系
@@ -118,16 +109,12 @@ models.py (零依赖)
├── read.py (lark)
├── cond.py (stdlib)
├── core.py (cond)
├── procedure_parser.py (re) [新]
├── pipeline_bridge.py (procedure_parser, core) [新]
├── design.py (models, cond, core)
├── design_mcdc.py (models, cond) [新]
├── coverage.py (models, cond)
├── output.py (file_io)
├── to_sql.py (stdlib)
├── flatfile.py (read, file_io) [新]
├── data_merger.py (generate_data, design_data) [新]
├── gcov.py [新]
├── runner.py (file_io)
├── flatfile.py (read, file_io)
└── __init__.py (所有上层模块)
```
@@ -136,44 +123,59 @@ models.py (零依赖)
## 四、数据流
### 4.1 全流程入口 (run.py)
### 4.1 非DB管道数据流
```
run.py
├── Step1: python -m cobol_testgen --gcov <source> <output>
│ │
│ ├── read.py: preprocess() + parse_data_division()
│ ├── core.py / procedure_parser.py: build_branch_tree()
│ ├── design.py / design_mcdc.py: enum_paths() + generate_records()
│ ├── output.py: output_json() + output_input_files()
│ └── coverage.py: HTML覆盖率报告
└── Step2: black-box-data-create/main.py
├── InputParser: 解析设计书 + COPYBOOK + DB定义
├── RuleLoader: PGM模式匹配 → 规则文件
├── PromptBuilder: 组装LLM提示词
├── APIClient: DeepSeek API调用
└── OutputWriter: JSON/SQL输出
COBOL源码
read.py: preprocess() + parse_data_division()
core.py: build_branch_tree()
design.py: enum_paths() + generate_records()
output.py: output_json() + output_input_files()
runners/cobol_runner.py: compile() + run()
comparator/: compare_field()
report/generator.py: generate_report()
```
### 4.2 DB管道数据流
### 4.2 DB管道数据流
```
COBOL源码 → read.py → core.py → design.py → output.py → cobol_runner.py → comparator/ → report/
```
### 4.3 DB管道数据流
```
COBOL源码 → gixsql_runner.py → orchestrator_db.py (6步)
Step1: gixpp + cobc编译
Step2: generate_data → flatfile.write_all_files + DB初始化 + JSON输出
Step3: gixsql_runner.run (COBOL + SQLite)
Step4: SQLite → JSON中间数据
Step5: Java执行 (可选)
Step6: 结果比对
COBOL源码 (含EXEC SQL)
gixsql_runner.py: preprocess() + compile()
orchestrator_db.py: step2_generate_inputs()
├── cobol_testgen: extract_structure + generate_data
├── to_sql.py: build_db_input()
└── flatfile.py: write_all_files()
orchestrator_db.py: step3_run_cobol()
orchestrator_db.py: step4_extract_intermediate()
orchestrator_db.py: step5_run_java() (可选)
orchestrator_db.py: step6_verify()
```
---
@@ -189,7 +191,7 @@ def extract_structure(
cobol_source: str,
copybook_dirs: list[str] = None
) -> dict:
"""解析COBOL源码,返回结构信息(段落、决策点、分支树、文件信息等)"""
"""解析COBOL源码,返回结构信息"""
pass
def generate_data(
@@ -197,15 +199,7 @@ def generate_data(
structure: dict,
copybook_dirs: list[str] = None
) -> list[dict]:
"""基于分支覆盖生成测试数据"""
pass
def incremental_supplement(
branch_tree: list,
gaps: list,
data_fields: list
) -> list[dict]:
"""增量补充未覆盖分支的测试数据"""
"""生成分支覆盖测试数据"""
pass
def main():
@@ -213,35 +207,14 @@ def main():
pass
```
### 5.2 黑盒LLM API
```python
# black-box-data-create/agent/__init__.py
def generate(
design_md: str, # 詳細設計書パス
source_cbl: str, # COBOLソースパス
file_db_md: str, # COPY句定義書パス
cpy_dir: str, # COPYBOOKディレクトリ
db_md: str, # DB定義書パス
output_dir: str, # 出力ディレクトリ
api_key: str, # DeepSeek API Key
api_model: str, # モデル名 (default: deepseek-v4-flash)
rules_dir: str, # ルールディレクトリ
max_tokens: int, # トークン上限 (default: 32768)
) -> dict:
"""黑盒LLM测试数据生成主入口"""
pass
```
### 5.3 配置接口
### 5.2 配置接口
```python
# config/__init__.py
@dataclass
class Config:
"""全局配置(从TOML加载)"""
"""全局配置"""
project_name: str
copybook_paths: list[str]
dialect: str
@@ -262,15 +235,13 @@ class Config:
| 编译错误 | cobc编译失败 | 记录日志,跳过该程序 |
| 运行错误 | 程序执行异常 | 捕获异常,标记失败 |
| 超时错误 | 执行超时 | 强制终止,记录超时 |
| API错误 | DeepSeek调用失败 | 3次重试后回退到规则引擎 |
### 6.2 容错机制
- **解析器超时**pipeline_bridge 3秒超时回退(新parser → 旧parser
- **LLM失败**black-box-data-create 回退到空结果
- **解析器超时**pipeline_bridge 3秒超时回退
- **LLM失败**回退到规则引擎
- **gcov失败**:跳过覆盖率收集
- **DB连接失败**:重试或跳过
- **API重试**:3次指数退避重试
---
@@ -284,14 +255,12 @@ class Config:
| 测试数据生成 | < 30秒 |
| 编译运行 | < 60秒 |
| 覆盖率报告 | < 10秒 |
| 全流程 (run.py) | < 120秒 |
### 7.2 优化策略
- **路径枚举**O(N)线性算法procedure_parser替代O(2^N)
- **新解析器**line-based state machine10-50ms完成解析
- **路径枚举**O(N)线性算法替代O(2^N)
- **并行执行**:多场景gcov并行收集
- **缓存机制**LLM结果SHA256缓存
- **缓存机制**LLM结果缓存
- **增量补充**:质量门循环最多4次
---
@@ -326,7 +295,7 @@ class Config:
- 43个COBOL基准程序
- 33+2种程序类型
- 14个程序YAML schema
- 58个电信测试程序
---
@@ -345,7 +314,7 @@ class Config:
```bash
# 1. 安装Python依赖
pip install lark pathlib pyyaml requests
pip install lark pathlib pyyaml
# 2. 安装GnuCOBOL
# 下载GC32-BDB-SP1,添加到PATH
+12 -12
View File
@@ -282,11 +282,11 @@ class Agent3Diagnostic:
## 7. 式样书驱动测试数据生成器(DesignDataGenerator
### 7.1 职责
### 6.1 职责
从日文详细设计书(.md)中提取程序元信息(`ProgramMeta`),结合 COBOL 源码、COPYBOOK 结构和 DB 定义,通过 LLM 生成有业务意义的机能测试数据。
### 7.2 数据流
### 6.2 数据流
```
设计书 .md + COBOL 源码
@@ -300,7 +300,7 @@ JSON: {"records": [{field_name: value}]}
list[dict]
```
### 7.3 核心类
### 6.3 核心类
```python
class DesignDataGenerator:
@@ -309,7 +309,7 @@ class DesignDataGenerator:
db_md_text=None, replacing_rules=None, v3_field_names=None) -> list[dict]
```
### 7.4 式样书解析器(DesignDataInputParser
### 6.4 式样书解析器(DesignDataInputParser
解析日文详细设计书 Markdown 文档,提取以下结构化信息:
@@ -323,7 +323,7 @@ class DesignDataGenerator:
解析通过 Markdown 标题匹配(`## 基本情報``## 使用ファイル一覧` 等)和表格解析实现,不依赖外部 Markdown 解析库。
### 7.5 输入类型自动判定
### 6.5 输入类型自动判定
`_determine_input_type` 根据输入文件的媒体类型自动判定:
@@ -333,7 +333,7 @@ class DesignDataGenerator:
| 仅 DB(数据库) | `db` |
| 混合或无输入 | `mixed` / `file` |
### 7.6 字段名映射(_resolve_field_names
### 6.6 字段名映射(_resolve_field_names
外部 Agent 生成的字段名可能与 V3 内部字段名不一致,映射规则:
@@ -344,21 +344,21 @@ class DesignDataGenerator:
5. **去下划线匹配**`R01_EMP_ID``R01EMPID`
6. **无法映射的字段丢弃**
### 7.7 规则加载
### 6.7 规则加载
`_load_rules``rules/pgm_pattern/``rules/special_feature/` 目录加载所有 `.md` 规则文件,作为 LLM 上下文的一部分。
### 7.8 记录去重(_dedup
### 6.8 记录去重(_dedup
支持按指定键字段去重,`additional_records` 优先保留。
## 8. LLM 接口封装(LLMClient
### 8.1 职责
### 7.1 职责
封装 LLM API 调用,提供文件缓存、自动重试、多模型兼容能力。所有 Agent 通过此客户端与 LLM 交互。
### 8.2 核心类
### 7.2 核心类
```python
class LLMClient:
@@ -369,14 +369,14 @@ class LLMClient:
def _set(self, k: str, v: str) -> None # 缓存写入
```
### 8.3 缓存机制
### 7.3 缓存机制
- **键生成**:对消息列表进行 JSON 序列化后取 SHA256 哈希
- **存储**:以 `{hash}.json` 文件存储在 `.cache/llm/` 目录
- **格式**`{"response": "..."}`
- **效果**:相同输入直接返回缓存结果,避免重复调用 LLM
### 8.4 重试机制
### 7.4 重试机制
- 默认重试 1 次(共 2 次尝试)
- 使用 `httpx.post` 发送 HTTP 请求
+6 -6
View File
@@ -613,7 +613,7 @@ Path 是一条完整执行路径的所有约束集合。
### 5.1 非 DB 管道完整流程 (Mermaid)
```mermaid
`mermaid
flowchart TD
A[COBOL 源码 .cbl] --> B[read.py preprocess]
B --> C[read.py parse_data_division]
@@ -652,11 +652,11 @@ flowchart TD
Y --> Z[report/generator generate_html]
Z --> AA[HTML 验证报告]
```
`
### 5.2 DB 管道完整流程 (Mermaid)
```mermaid
`mermaid
flowchart TD
A[COBOL 源码 含 EXEC SQL] --> B[Step 1: 环境整备]
B --> B1[gixpp 预处理]
@@ -695,11 +695,11 @@ flowchart TD
D2 --> G
G --> G1[VerificationRun]
G1 --> G2[PASS / MISMATCH]
```
`
### 5.3 数据流关键节点汇总
```mermaid
`mermaid
flowchart LR
subgraph 输入层
A1[COBOL 源码]
@@ -754,7 +754,7 @@ flowchart LR
E3 --> F1
F1 --> F2 --> F4
B3 --> F3 --> F4
```
`
---