docs: 更新设计文档以匹配Black-white-box-Merge分支最新代码
- 00-overview.md: 重写架构图(移除web/入口)、更新模块清单、更新API签名 - 05-agents-llm.md: 修复章节编号(Section 7/8子节编号错误) - 08-data-flow.md: 修复Mermaid代码块格式(单反引号→三反引号) - 09-run-pipeline.md: 新增run.py全流程入口+black-box-data-create详细设计 - DESIGN.md: 重写为竞赛要求格式(场景价值、范式图、Agent架构、工具清单) - README.md: 添加项目性质声明(新规)、团队分工、技术难度评估
This commit is contained in:
+137
-106
@@ -1,6 +1,6 @@
|
||||
# V3系统总体设计
|
||||
|
||||
> 版本: v1.0 | 日期: 2026-08-22
|
||||
> 版本: v2.0 | 日期: 2026-08-23
|
||||
> 本文档描述COBOL迁移验证平台V3的总体架构和模块设计。
|
||||
|
||||
---
|
||||
@@ -15,21 +15,23 @@ COBOL迁移验证平台V3是一个AI辅助的自动化测试工具,用于验
|
||||
|
||||
| 能力 | 说明 |
|
||||
|------|------|
|
||||
| COBOL源码解析 | 自动解析DATA DIVISION和PROCEDURE DIVISION |
|
||||
| 测试数据生成 | 基于分支覆盖的测试数据自动生成 |
|
||||
| COBOL源码解析 | 自动解析DATA DIVISION和PROCEDURE DIVISION(支持新旧双解析器) |
|
||||
| 测试数据生成 | 基于分支覆盖的测试数据自动生成(规则引擎 + LLM双模式) |
|
||||
| 双管道验证 | 支持非DB(flat file)和DB(SQLite)两种验证模式 |
|
||||
| 覆盖率分析 | 静态分支覆盖 + 动态gcov覆盖 |
|
||||
| AI辅助 | LLM驱动的程序分类和测试策略生成 |
|
||||
| 全流程入口 | `run.py` 一键执行白盒+黑盒全流程 |
|
||||
| 黑盒LLM生成 | `black-box-data-create` 基于设计书的LLM测试数据生成 |
|
||||
| 覆盖率分析 | 静态分支覆盖 + 动态gcov覆盖,生成HTML报告 |
|
||||
| AI辅助 | LLM驱动的程序分类、测试策略生成、诊断建议 |
|
||||
|
||||
### 1.3 技术栈
|
||||
|
||||
| 组件 | 技术 |
|
||||
|------|------|
|
||||
| 语言 | Python 3.12+ |
|
||||
| 解析器 | Lark (Earley parser) |
|
||||
| 解析器 | Lark (Earley parser) + 新fast parser (line-based state machine) |
|
||||
| COBOL编译 | GnuCOBOL 3.2.0 |
|
||||
| DB管道 | gixsql + SQLite |
|
||||
| AI模型 | DeepSeek |
|
||||
| AI模型 | DeepSeek (deepseek-v4-flash) |
|
||||
| 测试框架 | pytest |
|
||||
|
||||
---
|
||||
@@ -39,39 +41,44 @@ COBOL迁移验证平台V3是一个AI辅助的自动化测试工具,用于验
|
||||
### 2.1 架构图
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ V3系统架构 │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
|
||||
│ │ CLI入口 │ │ Web界面 │ │ API接口 │ │
|
||||
│ │ main.py │ │ web/ │ │ __init__ │ │
|
||||
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
|
||||
│ │ │ │ │
|
||||
│ └────────────────────┼────────────────────┘ │
|
||||
│ │ │
|
||||
│ ▼ │
|
||||
│ ┌─────────────────────────────────────────────────────────┐ │
|
||||
│ │ 编排层 (Orchestrator) │ │
|
||||
│ │ orchestrator.py (非DB) orchestrator_db.py (DB) │ │
|
||||
│ └─────────────────────────────────────────────────────────┘ │
|
||||
│ │ │
|
||||
│ ┌────────────────────┼────────────────────┐ │
|
||||
│ │ │ │ │
|
||||
│ ▼ ▼ ▼ │
|
||||
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
|
||||
│ │ 核心引擎 │ │ 运行引擎 │ │ AI代理 │ │
|
||||
│ │ cobol_testgen│ │ runners/ │ │ agents/ │ │
|
||||
│ └──────────────┘ └──────────────┘ └──────────────┘ │
|
||||
│ │ │ │ │
|
||||
│ │ │ │ │
|
||||
│ ▼ ▼ ▼ │
|
||||
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
|
||||
│ │ 比对模块 │ │ 报告模块 │ │ 配置模块 │ │
|
||||
│ │ comparator/ │ │ report/ │ │ config/ │ │
|
||||
│ └──────────────┘ └──────────────┘ └──────────────┘ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
┌─────────────────────────────────────────────────────────────────────┐
|
||||
│ 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│ │
|
||||
│ └──────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### 2.2 分层架构
|
||||
@@ -82,7 +89,7 @@ COBOL迁移验证平台V3是一个AI辅助的自动化测试工具,用于验
|
||||
| **L2 核心层** | cobol_testgen/, config/ | COBOL解析、配置管理 |
|
||||
| **L3 业务层** | hina/, agents/, comparator/ | 分类、AI代理、比对 |
|
||||
| **L4 编排层** | orchestrator*, runners/ | 流程编排、执行 |
|
||||
| **L5 接口层** | main.py, web/, __init__.py | 用户接口 |
|
||||
| **L5 接口层** | run.py, main.py, black-box-data-create/ | 用户接口 |
|
||||
|
||||
---
|
||||
|
||||
@@ -92,13 +99,15 @@ COBOL迁移验证平台V3是一个AI辅助的自动化测试工具,用于验
|
||||
|
||||
| 模块 | 文件数 | 行数 | 职责 |
|
||||
|------|--------|------|------|
|
||||
| cobol_testgen/ | 22 | ~8000 | COBOL解析、测试数据生成 |
|
||||
| orchestrator_db.py | 1 | 1334 | DB管道6步编排 |
|
||||
| runners/ | 8 | ~600 | 编译运行引擎 |
|
||||
| hina/ | 11 | ~2000 | HINA程序分类 |
|
||||
| agents/ | 6 | ~800 | LLM代理 |
|
||||
| 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代理 |
|
||||
| comparator/ | 6 | ~400 | 字段比对 |
|
||||
| config/ | 5 | ~300 | 配置管理 |
|
||||
| config/ | 4 | ~400 | 配置管理 |
|
||||
| report/ | 1 | ~200 | 报告生成 |
|
||||
|
||||
### 3.2 模块依赖关系
|
||||
@@ -109,12 +118,16 @@ 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)
|
||||
├── runner.py (file_io)
|
||||
├── flatfile.py (read, file_io)
|
||||
├── flatfile.py (read, file_io) [新]
|
||||
├── data_merger.py (generate_data, design_data) [新]
|
||||
├── gcov.py [新]
|
||||
│
|
||||
└── __init__.py (所有上层模块)
|
||||
```
|
||||
@@ -123,59 +136,44 @@ models.py (零依赖)
|
||||
|
||||
## 四、数据流
|
||||
|
||||
### 4.1 非DB管道数据流
|
||||
### 4.1 全流程入口 (run.py)
|
||||
|
||||
```
|
||||
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()
|
||||
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输出
|
||||
```
|
||||
|
||||
### 4.2 DB管道数据流
|
||||
### 4.2 非DB管道数据流
|
||||
|
||||
```
|
||||
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()
|
||||
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: 结果比对
|
||||
```
|
||||
|
||||
---
|
||||
@@ -191,7 +189,7 @@ def extract_structure(
|
||||
cobol_source: str,
|
||||
copybook_dirs: list[str] = None
|
||||
) -> dict:
|
||||
"""解析COBOL源码,返回结构信息"""
|
||||
"""解析COBOL源码,返回结构信息(段落、决策点、分支树、文件信息等)"""
|
||||
pass
|
||||
|
||||
def generate_data(
|
||||
@@ -199,7 +197,15 @@ 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():
|
||||
@@ -207,14 +213,35 @@ def main():
|
||||
pass
|
||||
```
|
||||
|
||||
### 5.2 配置接口
|
||||
### 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 配置接口
|
||||
|
||||
```python
|
||||
# config/__init__.py
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
"""全局配置"""
|
||||
"""全局配置(从TOML加载)"""
|
||||
project_name: str
|
||||
copybook_paths: list[str]
|
||||
dialect: str
|
||||
@@ -235,13 +262,15 @@ class Config:
|
||||
| 编译错误 | cobc编译失败 | 记录日志,跳过该程序 |
|
||||
| 运行错误 | 程序执行异常 | 捕获异常,标记失败 |
|
||||
| 超时错误 | 执行超时 | 强制终止,记录超时 |
|
||||
| API错误 | DeepSeek调用失败 | 3次重试后回退到规则引擎 |
|
||||
|
||||
### 6.2 容错机制
|
||||
|
||||
- **解析器超时**:pipeline_bridge 3秒超时回退
|
||||
- **LLM失败**:回退到规则引擎
|
||||
- **解析器超时**:pipeline_bridge 3秒超时回退(新parser → 旧parser)
|
||||
- **LLM失败**:black-box-data-create 回退到空结果
|
||||
- **gcov失败**:跳过覆盖率收集
|
||||
- **DB连接失败**:重试或跳过
|
||||
- **API重试**:3次指数退避重试
|
||||
|
||||
---
|
||||
|
||||
@@ -255,12 +284,14 @@ class Config:
|
||||
| 测试数据生成 | < 30秒 |
|
||||
| 编译运行 | < 60秒 |
|
||||
| 覆盖率报告 | < 10秒 |
|
||||
| 全流程 (run.py) | < 120秒 |
|
||||
|
||||
### 7.2 优化策略
|
||||
|
||||
- **路径枚举**:O(N)线性算法替代O(2^N)
|
||||
- **路径枚举**:O(N)线性算法(procedure_parser)替代O(2^N)
|
||||
- **新解析器**:line-based state machine,10-50ms完成解析
|
||||
- **并行执行**:多场景gcov并行收集
|
||||
- **缓存机制**:LLM结果缓存
|
||||
- **缓存机制**:LLM结果SHA256缓存
|
||||
- **增量补充**:质量门循环最多4次
|
||||
|
||||
---
|
||||
@@ -295,7 +326,7 @@ class Config:
|
||||
|
||||
- 43个COBOL基准程序
|
||||
- 33+2种程序类型
|
||||
- 58个电信测试程序
|
||||
- 14个程序YAML schema
|
||||
|
||||
---
|
||||
|
||||
@@ -314,7 +345,7 @@ class Config:
|
||||
|
||||
```bash
|
||||
# 1. 安装Python依赖
|
||||
pip install lark pathlib pyyaml
|
||||
pip install lark pathlib pyyaml requests
|
||||
|
||||
# 2. 安装GnuCOBOL
|
||||
# 下载GC32-BDB-SP1,添加到PATH
|
||||
|
||||
Reference in New Issue
Block a user