TBC/docs/API.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

4.0 KiB
Raw Blame History

TestAgent API 文档

Base URL: http://localhost:5002


系统

GET /api/health

健康检查。

响应:

{
  "status": "ok",
  "version": "1.0.0",
  "tasks_count": 10,
  "reports_count": 8,
  "repos_count": 0
}

控制台

GET /api/dashboard/stats

获取控制台统计概览。

响应:

{
  "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 建模)。

请求体:

{
  "url": "https://github.com/user/repo.git",
  "branch": "main",
  "api_key": "sk-xxx"
}

DELETE /api/repos/<repo_id>

删除仓库。

POST /api/repos/<repo_id>/analyze

DDD 领域分析。

POST /api/repos/<repo_id>/generate

生成测试用例。

请求体:

{
  "api_key": "sk-xxx",
  "test_types": ["smoke", "unit", "integration"]
}

POST /api/repos/<repo_id>/diff

精确回归(仅对 git diff 变更文件生成测试)。

请求体:

{
  "api_key": "sk-xxx",
  "against": "HEAD~1"
}

POST /api/repos/<repo_id>/full

全流程(扫描 + 分析 + 生成)。

POST /api/repos/check-ui

UI 变更检查(克隆前端仓库,比对 Robogo 脚本中的 UI 选择器)。

请求体:

{
  "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

创建并启动任务。

请求体:

{
  "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

获取已有用例模块列表。

响应:

{
  "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 标记列表。

响应:

["smoke", "e2e", "api", "ui", "flow", "data_space", "dataspace", ...]

静态资源

GET /artifacts/screenshots/

获取测试截图。

GET /

SPA 前端(所有非 API 路径自动 fallback 到 index.html)。