Test_Agent/docs/ARCHITECTURE.md
jiawei.chen 6f6053ff51 feat: TestAgent 智能测试平台 v1.0
- CLI + Web 双平台,基于 LLM 的 TDD+DDD 自动化测试生成
- 集成 unified-test-platform 903 个 D-Cloud 用例 + 13 个 Robogo 场景
- Agent 5 步流水线: 扫描 -> DDD -> LLM 生成测试
- 精确回归 + UI 变更检查
- 可视化 HTML 测试报告
- 暗色/亮色主题切换
- 19 个 API 端点 + 6 个 SPA 页面
- 15/15 项 TDD+DDD 合规
2026-07-08 11:27:38 +08:00

140 lines
6.7 KiB
Markdown
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.

# TestAgent 平台架构
## 一、架构总览
```
┌──────────────────────────────────────┐
│ React SPA (Vite 8) │
│ Dashboard / Repos / Tasks / Reports │
│ /existing (已有用例) │
└────────────────┬─────────────────────┘
│ HTTP + SSE
┌────────────────▼─────────────────────┐
│ Flask Backend (端口 5002) │
│ API 路由 / 任务调度 / SSE 日志流 │
└────────────────┬─────────────────────┘
│
┌──────────────────────┼──────────────────────┐
│ │ │
┌─────────▼─────────┐ ┌────────▼────────┐ ┌─────────▼─────────┐
│ agent/ (引擎) │ │ tests/ + │ │ main.py (CLI) │
│ LLM + Git + AST │ │ framework/ │ │ run/diff/analyze │
│ DDD + 测试生成 │ │ 900+ 已有用例 │ │ │
└───────────────────┘ └─────────────────┘ └───────────────────┘
```
## 二、项目目录
```
test-agent/
├── main.py # CLI 入口 (Click)
├── config.yaml # 全局配置
├── SOUL.md # Agent 角色定义
├── .env # 环境变量
├── requirements.txt # Python 依赖
│
├── agent/ # 核心引擎
│ ├── app.py # 编排器 (5 步流水线)
│ ├── llm_client.py # LLM 客户端 (OpenAI 兼容)
│ ├── git_ops.py # Git 仓库操作
│ ├── code_analyzer.py # AST 代码分析
│ ├── domain_extractor.py # DDD 领域模型提取
│ ├── prompt_builder.py # Prompt 组装
│ ├── test_generator.py # 测试生成 + 解析
│ └── ui_analyzer.py # UI 选择器变更分析
│
├── backend/ # Flask 后端
│ ├── app.py # API 路由 + 任务调度 + SSE
│ └── __main__.py # 启动入口
│
├── frontend/ # React SPA
│ ├── src/
│ │ ├── App.tsx # 路由配置
│ │ ├── components/
│ │ │ ├── layout/ # Layout + Sidebar + navConfig
│ │ │ ├── dashboard/ # 控制台
│ │ │ ├── repos/ # 仓库管理
│ │ │ ├── tasks/ # 任务管理
│ │ │ ├── reports/ # 测试报告
│ │ │ └── existing/ # 已有用例
│ │ ├── hooks/useTaskLogs.ts # SSE 日志流
│ │ └── context/ThemeContext.tsx # 暗色/亮色主题
│ └── dist/ # 生产构建产物
│
├── skills/ # 知识库
│ ├── tdd-methodology/SKILL.md # TDD 方法论
│ ├── ddd-patterns/SKILL.md # DDD 领域模式
│ ├── test-framework/SKILL.md # 测试框架规范
│ └── language-patterns/SKILL.md # 多语言测试模式
│
├── plugins/ # 插件系统
│ ├── pylint_analyzer/ # 代码静态分析
│ └── test_runner/ # 测试运行 + 门禁检查
│
├── tests/ # D-Cloud 测试用例 (22 模块)
├── framework/ # Robogo 场景脚本 (13 个)
├── config/ # 配置管理
├── templates/ # 测试模板
├── output/ # LLM 生成的测试
├── work/ # Git 仓库克隆目录
├── platform_reports/ # 测试报告存储
└── platform_artifacts/ # 截图等制品
```
## 三、技术栈
| 层 | 技术 | 版本 |
|----|------|------|
| 前端框架 | React | 19 |
| 类型系统 | TypeScript | 6 |
| 构建工具 | Vite | 8 |
| CSS 框架 | TailwindCSS | 4 |
| 路由 | React Router | 7 |
| 图标 | Lucide React | 1.23 |
| 后端框架 | Flask | 3 |
| 实时通信 | Server-Sent Events (SSE) | - |
| LLM | DeepSeek V4 Pro (LiteLLM Gateway) | - |
| 测试框架 | Pytest + Playwright | - |
| 代码分析 | Python AST | stdlib |
| Git 操作 | GitPython | 3.1 |
| 模板引擎 | Jinja2 | 3.1 |
| CLI 框架 | Click + Rich | 8.1 |
## 四、代码量统计
| 层 | 语言 | 行数 | 文件数 |
|----|------|------|--------|
| Agent 引擎 | Python | 1,200+ | 8 |
| 后端 API | Python | 920+ | 1 |
| 前端组件 | TypeScript | 3,000+ | 15 组件 |
| 知识库 | Markdown | 200+ | 4 |
| 测试模板 | Jinja2 | 50+ | 2 |
| 已有测试 | Python | 30,000+ | 73 文件 |
## 四、数据持久化
| 数据 | 存储位置 | 格式 |
|------|---------|------|
| 任务/仓库/报告 | `platform_db.json` | JSON |
| 任务日志 | `platform_reports/<task_id>.json` | JSON |
| 生成测试 | `output/<repo_id>/` | Python 文件 |
| 截图 | `platform_artifacts/screenshots/` | PNG |
| 前端构建产物 | `frontend/dist/` | HTML/JS/CSS |
| Git 仓库 | `work/` | 原始文件 |
## 五、核心设计模式
### 5.1 插件系统
仿照 hermes-bot 的插件架构,支持 `pre_analysis` 和 `post_generation` 钩子。
### 5.2 知识库 (Skills)
Skill 文件采用 Markdown 格式,与 hermes-bot 的 SKILL.md 模式一致,作为 LLM 的上下文注入。
### 5.3 SSE 实时日志
后端通过 `queue.Queue` 收集任务日志,前端通过 `EventSource` 实时接收,支持 PING 心跳保活。
### 5.4 任务调度
- 支持 `once` / `continuous` / `hourly` / `daily` / `weekly` 调度类型
- 30 秒轮询检查
- 窗口时间门控(如 `09:00-18:00`)
- 自动清理超过 100 个旧任务