# TestAgent API 文档 Base URL: `http://localhost:5002` --- ## 系统 ### GET /api/health 健康检查。 **响应:** ```json { "status": "ok", "version": "1.0.0", "tasks_count": 10, "reports_count": 8, "repos_count": 0 } ``` --- ## 控制台 ### GET /api/dashboard/stats 获取控制台统计概览。 **响应:** ```json { "tasks": { "total": 10, "pass": 5, "fail": 3, "running": 2, "pass_rate": 50.0 }, "reports": { "total": 8, "pass": 5, "pass_rate": 62.5 }, "repos": { "total": 0 }, "existing_tests": { "modules": 35 } } ``` --- ## 仓库管理 ### GET /api/repos 获取所有已扫描仓库列表。 ### POST /api/repos 扫描新仓库(clone + AST 分析 + DDD 建模)。 **请求体:** ```json { "url": "https://github.com/user/repo.git", "branch": "main", "api_key": "sk-xxx" } ``` ### DELETE /api/repos/ 删除仓库。 ### POST /api/repos//analyze DDD 领域分析。 ### POST /api/repos//generate 生成测试用例。 **请求体:** ```json { "api_key": "sk-xxx", "test_types": ["smoke", "unit", "integration"] } ``` ### POST /api/repos//diff 精确回归(仅对 git diff 变更文件生成测试)。 **请求体:** ```json { "api_key": "sk-xxx", "against": "HEAD~1" } ``` ### POST /api/repos//full 全流程(扫描 + 分析 + 生成)。 ### POST /api/repos/check-ui UI 变更检查(克隆前端仓库,比对 Robogo 脚本中的 UI 选择器)。 **请求体:** ```json { "url": "https://gitea.d-robotics.cc/d-cloud/d_cloud_artificer_frontend", "branch": "main", "api_key": "sk-xxx" } ``` --- ## 任务管理 ### GET /api/tasks 获取所有任务列表。支持 `?product=` 过滤。 ### POST /api/tasks 创建并启动任务。 **请求体:** ```json { "name": "任务名称", "task_type": "run_existing", "platform": "dcloud", "module": "data_space", "test_marker": "smoke", "test_file": "tests/data_space/tests/test_data_space_e2e.py", "headless": "false", "env": "PROD", "scope": "all", "account": "user", "password": "pass" } ``` **任务类型 (task_type):** | 值 | 说明 | |----|------| | `scan` | 扫描仓库 | | `analyze` | DDD 分析 | | `generate` | 生成测试 | | `repo_full` | 全流程 | | `diff` | 精确回归 | | `run_existing` | 运行已有用例 | | `ui_check` | UI 变更检查 | ### DELETE /api/tasks/ 删除任务。 ### POST /api/tasks//stop 停止运行中的任务(发送 SIGKILL)。 ### GET /api/tasks//logs SSE 日志流。实时推送任务执行日志。 **Event 格式:** ``` data: {"ts":"14:21:11","level":"INFO","msg":"执行: pytest ..."} data: {"ts":"14:21:11","level":"SUCCESS","msg":"测试通过"} data: {"level":"PING","msg":"","ts":"--:--:--"} data: {"level":"DONE","msg":"","ts":"--:--:--"} ``` --- ## 测试报告 ### GET /api/reports 获取所有报告列表。 ### GET /api/reports/ 获取报告详情(含日志、结果、截图)。 --- ## 已有用例 ### GET /api/existing-tests/modules 获取已有用例模块列表。 **响应:** ```json { "dcloud": [ { "name": "data_space", "path": "tests/data_space", "test_files": [ { "name": "test_data_space_e2e.py", "tests": [ { "name": "test_dataspace_full_pipeline", "readable": "dataspace full pipeline", "doc": "创建→列表→文件→文件夹→删除" } ], "count": 10 } ], "test_count": 80 } ], "robogo": [ { "name": "robogo", "label": "Robogo 全量巡检", "description": "串行运行全部 13 个场景脚本", "section": "product" } ] } ``` ### GET /api/existing-tests/markers 获取所有 pytest 标记列表。 **响应:** ```json ["smoke", "e2e", "api", "ui", "flow", "data_space", "dataspace", ...] ``` --- ## 静态资源 ### GET /artifacts/screenshots/ 获取测试截图。 ### GET / SPA 前端(所有非 API 路径自动 fallback 到 index.html)。