Compare commits
45 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b74bdf8d2 | ||
|
|
33a7e70a7c | ||
|
|
ad5c91cc20 | ||
|
|
11513b3612 | ||
|
|
42c0358784 | ||
|
|
2741c440c4 | ||
|
|
981edf0746 | ||
|
|
d7ce8f7fe4 | ||
|
|
791ac6c564 | ||
|
|
4851290afd | ||
|
|
70137257ba | ||
|
|
45fde8b15a | ||
|
|
d0235147ba | ||
|
|
b9b5d5b5d5 | ||
|
|
fa240afad8 | ||
|
|
3e05b83e05 | ||
|
|
f0181391aa | ||
|
|
5a4f564f3a | ||
|
|
f5ee0f5f02 | ||
|
|
c32dcdb9bd | ||
|
|
ae73a6eb4f | ||
|
|
cab7b86021 | ||
|
|
36030db3e6 | ||
|
|
bf9f72216a | ||
|
|
0a0a67d16d | ||
|
|
74eae0a891 | ||
|
|
76cde65a04 | ||
|
|
8da291a442 | ||
|
|
f966ee7278 | ||
|
|
2716bd6966 | ||
|
|
be1e189c01 | ||
|
|
9ba4b259c4 | ||
|
|
a57e0f18f2 | ||
|
|
ea059aef7a | ||
|
|
0abf0a2ce4 | ||
|
|
c51165eff8 | ||
|
|
6fc10ea4f2 | ||
|
|
f60a7db50e | ||
|
|
f13d9714ff | ||
|
|
561bcae85f | ||
|
|
e92d6030f3 | ||
|
|
43f9ce2601 | ||
|
|
907276859d | ||
|
|
d2ceea9d29 | ||
|
|
e1868735c0 |
58
.dockerignore
Normal file
58
.dockerignore
Normal file
@ -0,0 +1,58 @@
|
||||
# Python
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.egg-info/
|
||||
dist/
|
||||
build/
|
||||
.venv/
|
||||
.venv311/
|
||||
venv/
|
||||
|
||||
# Environment
|
||||
.env
|
||||
.env.local
|
||||
|
||||
# Auth
|
||||
.auth/
|
||||
|
||||
# Outputs
|
||||
reports/
|
||||
screenshots/
|
||||
logs/
|
||||
*.log
|
||||
platform_reports/
|
||||
platform_artifacts/
|
||||
|
||||
# IDE
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Frontend
|
||||
frontend/node_modules/
|
||||
frontend/dist/
|
||||
|
||||
# Platform
|
||||
backend/db.json
|
||||
platform_db.json
|
||||
|
||||
# Docs (local only)
|
||||
docs/
|
||||
|
||||
# Git
|
||||
.git/
|
||||
.gitignore
|
||||
|
||||
# Node
|
||||
node_modules/
|
||||
.pytest_cache/
|
||||
|
||||
# Docker
|
||||
Dockerfile
|
||||
docker-compose.yml
|
||||
.dockerignore
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@ -19,7 +19,8 @@ docs/
|
||||
.auth/
|
||||
|
||||
# Outputs
|
||||
reports/
|
||||
/reports/
|
||||
!/frontend/src/components/reports/
|
||||
screenshots/
|
||||
logs/
|
||||
*.log
|
||||
|
||||
177
CHANGELIST_2026-06-26.md
Normal file
177
CHANGELIST_2026-06-26.md
Normal file
@ -0,0 +1,177 @@
|
||||
# Changelist — 2026-06-26
|
||||
|
||||
基于 TBC 工程深度分析报告的修复与清理,涵盖 P0–P2 优先级。
|
||||
|
||||
---
|
||||
|
||||
## P0 — 关键修复
|
||||
|
||||
### 1. 删除 B 套死代码(双后端问题)
|
||||
|
||||
**文件**: `backend/scheduler.py`, `backend/test_runner.py`, `backend/database.py` — **删除**
|
||||
|
||||
`backend/` 下原本有两套完整的后端代码:`app.py`(A 套,实际运行)与 `scheduler.py + test_runner.py + database.py`(B 套,死代码)。两套使用不同的 DB 文件、不同的任务字段、不同的飞书 webhook 配置,且 `__main__.py` 同时启动了 A 套和 B 套的 `Scheduler`,导致两个调度器同时运行。
|
||||
|
||||
**修复**: 删除 B 套三个文件,`__main__.py` 改为从 `app.py` 导入 `Scheduler`。
|
||||
|
||||
| 影响 | 旧 | 新 |
|
||||
|------|----|----|
|
||||
| `__main__.py` | `from backend.scheduler import Scheduler` | `from backend.app import Scheduler` |
|
||||
| 端口 | 硬编码 5001 | 读取 `PLATFORM_PORT` 环境变量 |
|
||||
|
||||
---
|
||||
|
||||
### 2. Bug#1 — 仪表盘模块健康度全部显示同一值
|
||||
|
||||
**文件**: `backend/app.py` · 行 547-553
|
||||
|
||||
D-Cloud 16 个模块的健康度循环中,变量 `mod_key` 完全未被使用,导致所有模块被赋值为全量 pass 率。
|
||||
|
||||
**修复**: 按 `report["module"]` 字段过滤,逐模块统计。同时在 `run_task_process` 的 report 中新增 `module` 字段,记录任务所属模块。
|
||||
|
||||
```python
|
||||
# 修复前
|
||||
for mod_key, mod_val in DCLOUD_MODULES.items():
|
||||
total_p = sum(1 for r in reports if r.get("result") == "PASS") # 未过滤模块
|
||||
health[mod_val["name"]] = {"rate": ..., "total": len(reports)} # 全量
|
||||
|
||||
# 修复后
|
||||
for mod_key, mod_val in DCLOUD_MODULES.items():
|
||||
mod_reports = [r for r in reports if r.get("module") == mod_key]
|
||||
passed = sum(1 for r in mod_reports if r.get("result") == "PASS")
|
||||
health[mod_val["name"]] = {"rate": ..., "total": len(mod_reports)}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3. Bug#4 — 密码明文落盘到 JSON 文件
|
||||
|
||||
**文件**: `backend/app.py` · `_save_db()`
|
||||
|
||||
`account`/`password` 通过 `json.dump` 直接写入 `platform_db.json`,明文存储。
|
||||
|
||||
**修复**: 在 `_save_db()` 中,序列化时对密码字段做 SHA-256 哈希(`sha256:` 前缀标识),内存中的 `tasks_db` 保持明文不变。
|
||||
|
||||
---
|
||||
|
||||
### 4. 并发写 JSON 无锁
|
||||
|
||||
**文件**: `backend/app.py`
|
||||
|
||||
`run_task_process` 在 daemon 线程中运行,多个任务并发时各自调用 `_save_db()`,无任何同步机制,可能导致数据丢失。
|
||||
|
||||
**修复**: 新增 `db_lock = threading.Lock()`,`_save_db()` 全部逻辑包裹在 `with db_lock:` 中。
|
||||
|
||||
---
|
||||
|
||||
## P1 — 悬挂引用修复
|
||||
|
||||
### 5. Config 缺少属性导致 `framework/business/cloud_desktop.py` 无法运行
|
||||
|
||||
**文件**: `framework/config/settings.py`
|
||||
|
||||
`cloud_desktop.py` 引用了 `Config.AUTH_TOKEN`、`Config.COOKIE`、`Config.CloudDesktop.POST_IMAGE_ID` 等不存在的属性,以及 `WAIT['switch']`/`WAIT['start']` 不存在。
|
||||
|
||||
**修复**:
|
||||
|
||||
| 新增属性 | 值 |
|
||||
|---------|-----|
|
||||
| `Config.AUTH_TOKEN` | `os.getenv("AUTH_TOKEN", "")` |
|
||||
| `Config.COOKIE` | `os.getenv("AUTH_COOKIE", "")` |
|
||||
| `Config.CloudDesktop.POST_IMAGE_ID` | `os.getenv("CD_POST_IMAGE_ID", "")` |
|
||||
| `Config.CloudDesktop.PRE_IMAGE_ID` | `os.getenv("CD_PRE_IMAGE_ID", "")` |
|
||||
| `Config.CloudDesktop.BP_IMAGE_ID` | `os.getenv("CD_BP_IMAGE_ID", "")` |
|
||||
| `Config.CloudDesktop.SKU_ID` | `os.getenv("CD_SKU_ID", "desktop-5880gpu12g-16c32g")` |
|
||||
| `Config.CloudDesktop.DISK_SIZE` | `os.getenv("CD_DISK_SIZE", "100")` |
|
||||
| `Config.CloudDesktop.SPEC_ID` | `os.getenv("CD_SPEC_ID", "")` |
|
||||
| `Config.CloudDesktop.TIMER_ID` | `os.getenv("CD_TIMER_ID", "")` |
|
||||
| `Config.CloudDesktop.PRICE_POLICY_ID` | `os.getenv("CD_PRICE_POLICY_ID", "")` |
|
||||
| `WAIT['switch']` | `15` |
|
||||
| `WAIT['start']` | `30` |
|
||||
|
||||
---
|
||||
|
||||
## P2 — 清理与修正
|
||||
|
||||
### 6. 删除重复文件
|
||||
|
||||
| 文件 | 原因 |
|
||||
|------|------|
|
||||
| `framework/bot.py` | 与 `bot/bot.py` byte 级完全相同,删除副本 |
|
||||
| `frontend/src/components/Sidebar.tsx` | 未被任何文件引用,实际使用 `components/layout/Sidebar.tsx` |
|
||||
|
||||
---
|
||||
|
||||
### 7. Bug#2 — 闭环率是假的 if-else 常量
|
||||
|
||||
**文件**: `backend/app.py` · 行 581
|
||||
|
||||
```python
|
||||
# 修复前
|
||||
"closure_rate": 85 if fail_count > 0 else 100 # 纯装饰
|
||||
|
||||
# 修复后
|
||||
"closure_rate": round(passed / total * 100, 1) if total > 0 else 0
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 8. Bug#3 — 前端统计卡片全部硬编码
|
||||
|
||||
**文件**: `frontend/src/components/dashboard/DCloudDashboard.tsx`
|
||||
|
||||
四张统计卡片(模块数 15、测试用例 ~595、测试类型、POM Mixins 10)全是写死的字符串,后端返回数据完全未使用。
|
||||
|
||||
**修复**: 卡片改为从后端 API 返回数据动态渲染:
|
||||
|
||||
| 卡片 | 旧值 | 新值 |
|
||||
|------|------|------|
|
||||
| 模块数 | 硬编码 `15` | `DCLOUD_NAV_ITEMS` 动态计算 |
|
||||
| 测试用例 | 硬编码 `~595` | `stats.summary.total_reports` |
|
||||
| 测试类型 | 硬编码 `E2E / API / UI / Flow` | 改为「通过率」`stats.summary.pass_rate` |
|
||||
| POM Mixins | 硬编码 `10` | 改为「闭环率」`stats.summary.closure_rate` |
|
||||
|
||||
---
|
||||
|
||||
### 9. 硬编码 URL → 环境变量
|
||||
|
||||
**文件**: `tests/data_generation/data_generation_page.py`
|
||||
|
||||
```python
|
||||
# 修复前
|
||||
url = "https://cloud-fat.d-robotics.cc/d-cloud/data-create/list"
|
||||
url_template = "https://cloud-fat.d-robotics.cc/d-cloud/data-create/taskdetail/{task_id}"
|
||||
|
||||
# 修复后
|
||||
BASE_URL = os.getenv("DCLOUD_BASE_URL", "https://cloud-fat.d-robotics.cc")
|
||||
url = f"{BASE_URL}/d-cloud/data-create/list"
|
||||
url_template = f"{BASE_URL}/d-cloud/data-create/taskdetail/{{task_id}}"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 10. 裸 `except:` → `except Exception:`
|
||||
|
||||
**文件**: `framework/core/base_page.py` · 行 172, 293
|
||||
|
||||
两处 `except:` 捕获所有异常(包括 `KeyboardInterrupt`、`SystemExit`),改为 `except Exception:`。
|
||||
|
||||
---
|
||||
|
||||
## 统计
|
||||
|
||||
| 维度 | 数值 |
|
||||
|------|------|
|
||||
| 修改文件 | 6 个 |
|
||||
| 删除文件 | 5 个 |
|
||||
| 新增代码 | 86 行 |
|
||||
| 删除代码 | 697 行 |
|
||||
| 净减少 | 611 行 |
|
||||
|
||||
---
|
||||
|
||||
## 未完成项(P3,可缓行)
|
||||
|
||||
- **统一两套 BasePage 抽象层** — 工作量较大,被测系统不同,短期内无法统一
|
||||
- **补 CI 配置** — 当前无任何 CI/CD 流水线
|
||||
- **`scenarios/run_data_loop.py`** 数据闭环入口 — 依赖 `dataloop/data-loop-automation` 目录,该目录不存在于合并后的仓库中,需后续补齐
|
||||
523
DEPLOY.md
Normal file
523
DEPLOY.md
Normal file
@ -0,0 +1,523 @@
|
||||
# AutoFlow 部署指南
|
||||
|
||||
本文档是从零开始在全新工作站上部署 AutoFlow 统一自动化测试平台的完整指南,AI 可逐步骤执行。
|
||||
|
||||
---
|
||||
|
||||
## 1. 系统要求
|
||||
|
||||
| 组件 | 版本要求 | 检查命令 |
|
||||
|------|---------|---------|
|
||||
| 操作系统 | macOS / Linux (Ubuntu 20.04+) | `uname -a` |
|
||||
| Python | 3.10 – 3.12 | `python3 --version` |
|
||||
| Node.js | >= 18 | `node --version` |
|
||||
| pnpm | 最新版 | `pnpm --version` |
|
||||
| Git | 任意新版 | `git --version` |
|
||||
| Docker (可选) | 20.10+ | `docker --version` |
|
||||
|
||||
---
|
||||
|
||||
## 2. 克隆仓库
|
||||
|
||||
```bash
|
||||
git clone https://gitea.d-robotics.cc/jiawei.chen/TBC.git
|
||||
cd TBC
|
||||
```
|
||||
|
||||
如果使用 SSH:
|
||||
```bash
|
||||
git clone git@gitea.d-robotics.cc:jiawei.chen/TBC.git
|
||||
cd TBC
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. 环境配置
|
||||
|
||||
### 3.1 创建 .env 文件
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
### 3.2 编辑 .env 填入实际值
|
||||
|
||||
```bash
|
||||
# 必填
|
||||
BASE_URL=https://cloud-fat.d-robotics.cc # D-Cloud 测试环境地址
|
||||
SSO_URL=https://sso-fat.d-robotics.cc # SSO 认证地址
|
||||
TEST_USERNAME=<your-username> # 测试账号
|
||||
TEST_PASSWORD=<your-password> # 测试密码
|
||||
|
||||
# Robogo 配置
|
||||
ROBOGO_ENV=FAT # FAT 或 PROD
|
||||
ROBOGO_SCOPE=all # 巡检范围
|
||||
|
||||
# 浏览器配置
|
||||
BROWSER=chromium
|
||||
HEADLESS=true # 无头模式
|
||||
SLOW_MO=0 # 操作间隔(ms),调试时设 500
|
||||
|
||||
# 平台端口
|
||||
PLATFORM_PORT=5001
|
||||
|
||||
# 飞书告警(可选)
|
||||
LARK_WEBHOOK_URL=<your-webhook-url>
|
||||
```
|
||||
|
||||
### 3.3 环境变量说明
|
||||
|
||||
| 变量 | 必填 | 默认值 | 说明 |
|
||||
|------|------|--------|------|
|
||||
| `BASE_URL` | 是 | — | D-Cloud 平台地址 |
|
||||
| `SSO_URL` | 是 | — | SSO 单点登录地址 |
|
||||
| `TEST_USERNAME` | 是 | — | 测试登录账号 |
|
||||
| `TEST_PASSWORD` | 是 | — | 测试登录密码 |
|
||||
| `TEST_ENV` | 否 | `dev` | 配置环境:`dev`/`test`/`prod` |
|
||||
| `HEADLESS` | 否 | `true` | 浏览器是否无头运行 |
|
||||
| `SLOW_MO` | 否 | `0` | Playwright 操作间隔(ms) |
|
||||
| `PLATFORM_PORT` | 否 | `5001` | 后端监听端口 |
|
||||
| `LARK_WEBHOOK_URL` | 否 | — | 飞书告警 Webhook |
|
||||
| `DCLOUD_BASE_URL` | 否 | `https://cloud-fat.d-robotics.cc` | 数据生成页面 URL |
|
||||
| `ROBOGO_ENV` | 否 | `PROD` | Robogo 环境:`FAT`/`PROD` |
|
||||
|
||||
---
|
||||
|
||||
## 4. Python 环境
|
||||
|
||||
### 4.1 创建虚拟环境
|
||||
|
||||
```bash
|
||||
python3 -m venv .venv
|
||||
source .venv/bin/activate
|
||||
```
|
||||
|
||||
macOS/Linux 均使用 `.venv/bin/activate`。
|
||||
|
||||
### 4.2 安装依赖
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
依赖清单(26 个包):pytest, playwright, pytest-playwright, pytest-html, pytest-cov, python-dotenv, Pillow, httpx, allure-pytest, flask, flask-cors, requests, lark-oapi, pre-commit, ruff, mypy
|
||||
|
||||
### 4.3 安装 Playwright 浏览器
|
||||
|
||||
```bash
|
||||
playwright install chromium
|
||||
```
|
||||
|
||||
这会下载 Chromium 浏览器到 `~/.cache/ms-playwright/`,约 150MB。如果下载失败,设置镜像:
|
||||
|
||||
```bash
|
||||
export PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright/
|
||||
playwright install chromium
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. 前端构建
|
||||
|
||||
### 5.1 安装 pnpm(如未安装)
|
||||
|
||||
```bash
|
||||
npm install -g pnpm
|
||||
```
|
||||
|
||||
### 5.2 安装依赖并构建
|
||||
|
||||
```bash
|
||||
cd frontend
|
||||
pnpm install
|
||||
pnpm build
|
||||
cd ..
|
||||
```
|
||||
|
||||
构建产物在 `frontend/dist/`,Flask 后端会直接 serve 这个目录。
|
||||
|
||||
---
|
||||
|
||||
## 6. 启动平台
|
||||
|
||||
### 方式一:直接启动(推荐生产环境)
|
||||
|
||||
```bash
|
||||
source .venv/bin/activate
|
||||
python -m backend.app
|
||||
```
|
||||
|
||||
访问 `http://127.0.0.1:5001`
|
||||
|
||||
### 方式二:开发模式(前端热重载)
|
||||
|
||||
终端 1 — 后端:
|
||||
```bash
|
||||
source .venv/bin/activate
|
||||
python -m backend.app
|
||||
```
|
||||
|
||||
终端 2 — 前端 dev server:
|
||||
```bash
|
||||
cd frontend
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
访问 `http://localhost:5173`(Vite 自动代理 API 到 5001)
|
||||
|
||||
### 方式三:Docker
|
||||
|
||||
```bash
|
||||
# 构建镜像
|
||||
docker compose build
|
||||
|
||||
# 启动平台
|
||||
docker compose up -d platform
|
||||
|
||||
# 运行测试
|
||||
docker compose run --rm tests
|
||||
docker compose run --rm tests pytest -m smoke
|
||||
```
|
||||
|
||||
访问 `http://127.0.0.1:5001`
|
||||
|
||||
---
|
||||
|
||||
## 7. 验证部署
|
||||
|
||||
### 7.1 健康检查
|
||||
|
||||
```bash
|
||||
curl http://127.0.0.1:5001/api/health
|
||||
```
|
||||
|
||||
预期响应:
|
||||
```json
|
||||
{"status":"ok","version":"2.0.0","tasks_count":0,"reports_count":0}
|
||||
```
|
||||
|
||||
### 7.2 前端页面
|
||||
|
||||
浏览器打开 `http://127.0.0.1:5001`,应看到 AutoFlow 平台仪表盘。
|
||||
|
||||
### 7.3 运行测试
|
||||
|
||||
```bash
|
||||
# 冒烟测试
|
||||
pytest tests/ -m smoke -v
|
||||
|
||||
# 单模块测试
|
||||
pytest tests/data_space/ -v
|
||||
|
||||
# 查看测试收集
|
||||
pytest tests/ --collect-only -q
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7. 无屏幕工作站部署(macOS 常驻服务)
|
||||
|
||||
部署到无屏幕 MacBook 后,需要解决三个问题:**后台常驻**(SSH 断开不停止)、**开机自启**、**局域网共享**。
|
||||
|
||||
### 7.1 网络访问
|
||||
|
||||
后端已绑定 `0.0.0.0:5001`,局域网内其他设备可直接访问。查看工作站 IP:
|
||||
|
||||
```bash
|
||||
ipconfig getifaddr en0
|
||||
```
|
||||
|
||||
假设 IP 为 `192.168.1.100`,局域网内访问 `http://192.168.1.100:5001` 即可。
|
||||
|
||||
### 7.2 使用 launchd 注册为系统服务
|
||||
|
||||
macOS 原生服务管理器,无需 Docker。
|
||||
|
||||
创建 `/Users/<用户名>/Library/LaunchAgents/com.autoflow.platform.plist`:
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
|
||||
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>com.autoflow.platform</string>
|
||||
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/Users/用户名/TBC/.venv/bin/python</string>
|
||||
<string>-m</string>
|
||||
<string>backend.app</string>
|
||||
</array>
|
||||
|
||||
<key>WorkingDirectory</key>
|
||||
<string>/Users/用户名/TBC</string>
|
||||
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>PLATFORM_PORT</key>
|
||||
<string>5001</string>
|
||||
<key>PATH</key>
|
||||
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/用户名/.local/bin:/opt/homebrew/bin</string>
|
||||
</dict>
|
||||
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
|
||||
<key>KeepAlive</key>
|
||||
<true/>
|
||||
|
||||
<key>StandardOutPath</key>
|
||||
<string>/Users/用户名/TBC/logs/platform.log</string>
|
||||
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/Users/用户名/TBC/logs/platform_error.log</string>
|
||||
|
||||
<key>ProcessType</key>
|
||||
<string>Background</string>
|
||||
</dict>
|
||||
</plist>
|
||||
```
|
||||
|
||||
**关键字段说明:**
|
||||
|
||||
| 字段 | 作用 |
|
||||
|------|------|
|
||||
| `RunAtLoad` | 开机自动启动 |
|
||||
| `KeepAlive` | 进程崩溃后自动重启 |
|
||||
| `WorkingDirectory` | 确保相对路径(`.env`、`platform_db.json`)正确解析 |
|
||||
| `StandardOutPath` / `StandardErrorPath` | 日志输出到文件,方便排查 |
|
||||
|
||||
### 7.3 加载与管理
|
||||
|
||||
```bash
|
||||
# 创建日志目录
|
||||
mkdir -p ~/TBC/logs
|
||||
|
||||
# 加载服务(立即启动 + 开机自启)
|
||||
launchctl load ~/Library/LaunchAgents/com.autoflow.platform.plist
|
||||
|
||||
# 查看服务状态
|
||||
launchctl list | grep autoflow
|
||||
|
||||
# 停止服务
|
||||
launchctl unload ~/Library/LaunchAgents/com.autoflow.platform.plist
|
||||
|
||||
# 查看日志
|
||||
tail -f ~/TBC/logs/platform.log
|
||||
```
|
||||
|
||||
### 7.4 验证内网访问
|
||||
|
||||
```bash
|
||||
# 在工作站上
|
||||
curl http://localhost:5001/api/health
|
||||
|
||||
# 在其他电脑浏览器访问
|
||||
# http://<工作站IP>:5001
|
||||
```
|
||||
|
||||
### 7.5 防火墙放行(如启用)
|
||||
|
||||
```bash
|
||||
# macOS 防火墙放行 Python
|
||||
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add /Users/用户名/TBC/.venv/bin/python
|
||||
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --unblockapp /Users/用户名/TBC/.venv/bin/python
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 9. 持久化数据
|
||||
|
||||
平台使用 JSON 文件存储数据,无需安装数据库:
|
||||
|
||||
| 文件 | 用途 |
|
||||
|------|------|
|
||||
| `platform_db.json` | 任务和报告状态持久化 |
|
||||
| `platform_reports/` | 任务日志 JSON 文件 |
|
||||
| `platform_artifacts/screenshots/` | 测试截图 |
|
||||
| `.auth/state.json` | SSO 登录状态缓存 |
|
||||
|
||||
首次启动时这些文件会自动创建。
|
||||
|
||||
---
|
||||
|
||||
## 10. 目录结构
|
||||
|
||||
```
|
||||
TBC/
|
||||
├── backend/ # Flask 后端
|
||||
│ ├── __init__.py
|
||||
│ ├── __main__.py # 模块入口
|
||||
│ └── app.py # 主应用 (809 行)
|
||||
├── frontend/ # React 前端
|
||||
│ ├── package.json
|
||||
│ ├── vite.config.ts
|
||||
│ └── src/
|
||||
├── tests/ # D-Cloud 测试 (16 模块, 856 用例)
|
||||
├── scenarios/ # Robogo 场景脚本
|
||||
├── framework/ # 核心自动化框架
|
||||
├── bot/ # 飞书机器人
|
||||
├── config/ # 统一配置
|
||||
│ └── settings.py
|
||||
├── scripts/ # 工具脚本
|
||||
├── specs/ # 测试规格文档
|
||||
├── requirements.txt # Python 依赖
|
||||
├── Dockerfile # Docker 镜像
|
||||
├── docker-compose.yml # Docker Compose 编排
|
||||
├── .env.example # 环境变量模板
|
||||
├── pyproject.toml # 项目元数据
|
||||
└── DEPLOY.md # 本文件
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 11. 常见问题
|
||||
|
||||
### 10.1 Playwright 浏览器下载失败
|
||||
|
||||
```bash
|
||||
# 设置国内镜像
|
||||
export PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright/
|
||||
playwright install chromium
|
||||
|
||||
# 或手动安装系统依赖 (Ubuntu)
|
||||
playwright install-deps chromium
|
||||
```
|
||||
|
||||
### 10.2 端口被占用
|
||||
|
||||
```bash
|
||||
# 修改 .env 中的 PLATFORM_PORT
|
||||
PLATFORM_PORT=5002
|
||||
```
|
||||
|
||||
### 10.3 前端构建失败
|
||||
|
||||
```bash
|
||||
# 清理并重试
|
||||
cd frontend
|
||||
rm -rf node_modules dist
|
||||
pnpm install
|
||||
pnpm build
|
||||
```
|
||||
|
||||
### 10.4 Python 版本不兼容
|
||||
|
||||
项目要求 Python 3.10–3.12。如果系统默认 Python 版本不对:
|
||||
|
||||
```bash
|
||||
# macOS (Homebrew)
|
||||
brew install python@3.12
|
||||
python3.12 -m venv .venv
|
||||
|
||||
# Ubuntu
|
||||
sudo apt install python3.12 python3.12-venv
|
||||
python3.12 -m venv .venv
|
||||
```
|
||||
|
||||
### 10.5 前端页面空白
|
||||
|
||||
检查 `frontend/dist/` 是否存在,如果不存在需要先构建:
|
||||
|
||||
```bash
|
||||
cd frontend && pnpm build
|
||||
```
|
||||
|
||||
### 10.6 测试登录失败
|
||||
|
||||
检查 `.env` 中的 `TEST_USERNAME` 和 `TEST_PASSWORD` 是否正确,以及是否能访问 `BASE_URL` 和 `SSO_URL`。
|
||||
|
||||
---
|
||||
|
||||
## 12. CI/CD(可选)
|
||||
|
||||
当前项目无 CI 配置。建议添加 `.gitea/workflows/test.yml`:
|
||||
|
||||
```yaml
|
||||
name: AutoFlow Tests
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.12'
|
||||
- run: pip install -r requirements.txt
|
||||
- run: playwright install chromium
|
||||
- run: pytest tests/ -m smoke -v
|
||||
- run: ruff check .
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 13. 一键部署脚本
|
||||
|
||||
将以下内容保存为 `deploy.sh`:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "=== AutoFlow 一键部署 ==="
|
||||
|
||||
# 检查 Python
|
||||
if ! command -v python3 &> /dev/null; then
|
||||
echo "❌ python3 未安装,请先安装 Python 3.10–3.12"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查 Node
|
||||
if ! command -v node &> /dev/null; then
|
||||
echo "❌ node 未安装,请先安装 Node.js >= 18"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 创建 .env
|
||||
if [ ! -f .env ]; then
|
||||
cp .env.example .env
|
||||
echo "⚠️ 已创建 .env,请编辑填入实际配置后重新运行"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Python 环境
|
||||
python3 -m venv .venv
|
||||
source .venv/bin/activate
|
||||
pip install -r requirements.txt
|
||||
playwright install chromium
|
||||
|
||||
# 前端
|
||||
if ! command -v pnpm &> /dev/null; then
|
||||
npm install -g pnpm
|
||||
fi
|
||||
cd frontend && pnpm install && pnpm build && cd ..
|
||||
|
||||
# 启动
|
||||
echo "✅ 部署完成,启动平台..."
|
||||
python -m backend.app
|
||||
```
|
||||
|
||||
### 安装为 macOS 常驻服务
|
||||
|
||||
```bash
|
||||
# 复制 plist 并替换路径
|
||||
sed "s|__PROJECT_ROOT__|$(pwd)|g" com.autoflow.platform.plist > ~/Library/LaunchAgents/com.autoflow.platform.plist
|
||||
|
||||
# 创建日志目录
|
||||
mkdir -p logs
|
||||
|
||||
# 加载服务
|
||||
launchctl load ~/Library/LaunchAgents/com.autoflow.platform.plist
|
||||
|
||||
# 查看状态
|
||||
launchctl list | grep autoflow
|
||||
```
|
||||
|
||||
使用方法:
|
||||
```bash
|
||||
chmod +x deploy.sh
|
||||
./deploy.sh
|
||||
```
|
||||
@ -19,9 +19,11 @@ AutoFlow 是 D-Robotics(地瓜机器人)的统一自动化测试平台,整
|
||||
|
||||
## 快速开始
|
||||
|
||||
> 完整部署指南:[DEPLOY.md](DEPLOY.md)
|
||||
|
||||
### 环境要求
|
||||
- Python >= 3.9(3.10+ 管道语法通过 `from __future__ import annotations` 兼容)
|
||||
- Node.js >= 18 (用于前端)
|
||||
- Python 3.10 – 3.12
|
||||
- Node.js >= 18
|
||||
- pnpm (推荐) 或 npm
|
||||
|
||||
### 安装
|
||||
|
||||
261
REFACTOR_EVALUATION.md
Normal file
261
REFACTOR_EVALUATION.md
Normal file
@ -0,0 +1,261 @@
|
||||
# AutoFlow 二合一重构评估
|
||||
|
||||
基于 `docs/TBC_分析报告_0626.html` 和逐文件代码审读,对 ToB(D-Cloud)和 ToC(Robogo)两个测试框架真正统一的可行性、风险和方案评估。
|
||||
|
||||
---
|
||||
|
||||
## 1. 现状:6 条断裂线
|
||||
|
||||
两个平台本质上是**被测系统不同、技术选型不同**的独立工程,合并只是放在了一个仓库里,没有做任何抽象统一。
|
||||
|
||||
| 断裂线 | D-Cloud (ToB) | Robogo (ToC) | 文件 |
|
||||
|--------|:--:|:--:|------|
|
||||
| **配置系统** | `config/settings.py`,3 环境(dev/test/prod),工厂模式,`validate_config()` | `framework/config/settings.py`,单类,手动 `ROBOGO_ENV` 判断 | `config/settings.py` vs `framework/config/settings.py` |
|
||||
| **BasePage** | 10 个 Mixin 组合,职责分离,强类型,86 行 | 单一类 312 行,`smart_*` 靠 `page.evaluate` 暴力扫 DOM 兜底 | `tests/base/base_page.py` vs `framework/core/base_page.py` |
|
||||
| **API 客户端** | `httpx`,300 行,文件上传/代理/脱敏/认证快失败 | `requests.Session`,63 行,极简 | `tests/utils/api_client.py` vs `framework/core/base_api.py` |
|
||||
| **认证流程** | pytest fixture + SSO + `.auth/state.json` 缓存 + token 有效性校验 | 环境变量 `AUTH_TOKEN`/`COOKIE` | `tests/conftest_auth.py` vs `framework/config/settings.py` |
|
||||
| **日志系统** | 129 行,彩色控制台,按日期分文件,上下文感知 | 21 行,基本控制台 + 文件 | `tests/logger.py` vs `framework/core/logger.py` |
|
||||
| **场景文件** | — | `scenarios/` 是 `framework/scripts/` 的逐字副本 | `scenarios/` vs `framework/scripts/` |
|
||||
|
||||
---
|
||||
|
||||
## 2. 无法统一的部分
|
||||
|
||||
| 项目 | 原因 |
|
||||
|------|------|
|
||||
| 被测前端 UI 组件库 | D-Cloud 用 Ant Design(`.ant-table`),Robogo 用 PrimeVue(`.p-dialog`),选择器语法不同 |
|
||||
| 认证方式 | D-Cloud 走 SSO(`sso-fat.d-robotics.cc`),Robogo 走本地登录(`robogo.d-robotics.cc`),URL 和流程不同 |
|
||||
| 测试运行器 | D-Cloud 走 pytest + marker(`-m api`/`-m e2e`),Robogo 走脚本编排器(`DataManagement.run_all_scenarios`),执行模式不同 |
|
||||
| 被测 URL | D-Cloud 用 `cloud-fat.d-robotics.cc`,Robogo 用 `robogo.d-robotics.cc`,不是同一套后端 |
|
||||
|
||||
---
|
||||
|
||||
## 3. 推荐方案:分 4 阶段
|
||||
|
||||
### 阶段 1:统一配置(1 天)🟢 低风险 ✅ 已完成
|
||||
|
||||
**目标**:`framework/config/settings.py` → `config/settings.py`,所有代码从同一个配置入口读。
|
||||
|
||||
**具体操作**:
|
||||
- 将 `framework/config/settings.py` 的 `CloudDesktop`/`DevMachine` 嵌套类迁移到 `config/settings.py`
|
||||
- 新增 `RobogoConfig(BaseConfig)` 类,覆盖 `BASE_URL`(Robogo URL)、`LOGIN_URL`(`/cloud-desktop/login`)、`DEFAULT_TIMEOUT`(30000)
|
||||
- 新增 `Config = RobogoConfig` 别名,保持 `framework/` 代码 `Config.XXX` 类属性访问方式不变
|
||||
- 23 个文件 import 路径更新:`from framework.config.settings import Config` → `from config.settings import Config`
|
||||
- 删除 `framework/config/settings.py`
|
||||
|
||||
**验证结果**:
|
||||
- 24 个 Python 文件编译 ✅ 0 错误
|
||||
- D-Cloud 配置(`config` 实例)`BASE_URL`/`DEFAULT_TIMEOUT` 不变
|
||||
- Robogo 配置(`Config` 类)所有属性可访问
|
||||
- 856 个测试全量收集通过
|
||||
- E2E 不受影响
|
||||
|
||||
**提交**:`561bcae` — 阶段1: 配置统一
|
||||
|
||||
---
|
||||
|
||||
### 阶段 2:统一 API 客户端 + 日志(1 天)🟡 中风险 ✅ 已完成
|
||||
|
||||
**目标**:`BaseAPI`(`requests`)→ `APIClient`(`httpx`),日志统一到 `tests/logger.py`。
|
||||
|
||||
#### 2.1 API 客户端差异分析
|
||||
|
||||
| 方法 | `BaseAPI`(Robogo, 63 行) | `APIClient`(D-Cloud, 300 行) | 兼容性 |
|
||||
|------|------|------|:--:|
|
||||
| `get_common_headers(referer_path)` | 构建完整 header(referer/UUID/sourceapp/user-agent) | **不存在** | 需新增 |
|
||||
| `request(method, endpoint, headers, **kwargs)` | 返回解析后的 `dict`(JSON) | `_request()` 返回 `httpx.Response` | **不兼容** |
|
||||
| `_check_response(resp, step_name)` | 检查 HTTP 状态码 + 业务 `status` 字段,抛 `TokenExpiredError`/`APIError` | `_assert_not_auth_error()` 仅检查认证错误 | 需适配 |
|
||||
| 会话管理 | `requests.Session`(持久化) | 每次新建 `httpx.Client` | 无影响 |
|
||||
|
||||
**关键不兼容点**:`BaseAPI` 子类代码直接对返回值做 `data.get("data", {})` 操作,换 `Response` 对象会崩。需给 `APIClient` 加 `request()` 兼容方法,内部解析 JSON 并做业务状态检查。
|
||||
|
||||
#### 2.2 影响范围
|
||||
|
||||
| 文件 | 数量 | 操作 |
|
||||
|------|------|------|
|
||||
| `BaseAPI` 子类 | 5 个 | 改为继承 `APIClient` |
|
||||
| `framework/core/logger.py` 引用 | 41 个 | import 路径改为 `tests.logger` |
|
||||
| 需删除 | 2 个 | `framework/core/base_api.py` + `framework/core/logger.py` |
|
||||
| 需新增到 `APIClient` | 2 个方法 | `get_common_headers()` + `request()` 兼容层 |
|
||||
|
||||
#### 2.3 额外发现的缺失 Config 属性
|
||||
|
||||
| 属性 | 引用处 | 值 |
|
||||
|------|--------|------|
|
||||
| `Config.CLOUD_AUTH_TOKEN` | `billing.py` | `os.getenv("CLOUD_AUTH_TOKEN", "")` |
|
||||
| `Config.AMAP_KEY` | `meal_reminder.py` × 2 | `os.getenv("AMAP_KEY", "")` |
|
||||
| `Config.AMAP_COORDINATES` | `meal_reminder.py` × 2 | `os.getenv("AMAP_COORDINATES", "")` |
|
||||
|
||||
#### 2.4 日志系统差异
|
||||
|
||||
| 维度 | `framework/core/logger.py`(21 行) | `tests/logger.py`(129 行) |
|
||||
|------|------|------|
|
||||
| 函数签名 | `get_logger(name)` | `get_logger(name)` — 相同 |
|
||||
| 日志级别 | INFO | DEBUG |
|
||||
| 控制台格式 | 标准格式 | 彩色 + 压缩多行 |
|
||||
| 文件输出 | `automation.log` | `logs/api_YYYY-MM-DD.log`(按日期分文件) |
|
||||
| 上下文感知 | 无 | `ContextVar` 追踪当前测试名称 |
|
||||
|
||||
**迁移策略**:41 个文件 `from framework.core.logger import get_logger` → `from tests.logger import get_logger`,函数签名完全相同,无需改调用代码。
|
||||
|
||||
#### 2.5 风险点
|
||||
|
||||
- `httpx` 和 `requests` 在重定向处理、超时语义上有细微差异
|
||||
- `get_common_headers()` 构建的 header 格式(`sourceapp`/`x-request-id`/`referer`)需保持一致
|
||||
- 5 个 `BaseAPI` 子类需逐个验证 `request()` 返回值兼容
|
||||
|
||||
**验证方式**:Python 编译 + 5 个子类 import 不报错 + 856 个测试收集不受影响。
|
||||
|
||||
#### 2.6 实施结果
|
||||
|
||||
**分支**:`refactor/phase2-unified-api-client` · 提交 `6fc10ea`
|
||||
|
||||
| 验证项 | 结果 |
|
||||
|--------|:--:|
|
||||
| 全量 Python 编译 | ✅ 0 错误 |
|
||||
| 856 测试收集 | ✅ 全量通过 |
|
||||
| E2E 测试 | ✅ 不受影响 |
|
||||
| `get_common_headers()` 兼容性 | ✅ 输出与旧 `BaseAPI` 完全一致 |
|
||||
| `request()` 兼容层 | ✅ 返回 `dict`,行为一致 |
|
||||
| 新增 Config 属性 | ✅ `CLOUD_AUTH_TOKEN`/`AMAP_KEY`/`AMAP_COORDINATES` |
|
||||
|
||||
**变更统计**:48 个文件变更(+101/-134),删除 2 个旧文件,净减少 33 行。
|
||||
|
||||
---
|
||||
|
||||
### 阶段 3:BasePage 合并(2 天)🔴 高风险 ✅ 已完成
|
||||
|
||||
**分支**:`refactor/phase3-unified-basepage` · 提交 `0abf0a2`
|
||||
|
||||
**实施内容**:
|
||||
- `framework/core/base_page.py` 的 `smart_find`/`visible_dialog`/`goto_route` 提取为 `SmartLocatorMixin`
|
||||
- `smart_click`/`smart_click_any`/`smart_fill`/`smart_select`/`smart_delete`/`click_row_action` 提取为 `SmartInteractionMixin`
|
||||
- 统一 `BasePage` 继承 12 个 Mixin(原有 10 个 + 新增 2 个)
|
||||
- 9 个 `framework/business/*_page.py` 改为继承 `tests.base.base_page.BasePage`
|
||||
- 删除 `framework/core/base_page.py`
|
||||
|
||||
**验证结果**:
|
||||
|
||||
| 验证项 | 结果 |
|
||||
|--------|:--:|
|
||||
| 全量项目源文件编译 | ✅ 0 错误 |
|
||||
| 856 测试收集 | ✅ 全量通过 |
|
||||
| 12 个 Mixin 方法名零冲突 | ✅ |
|
||||
| 原有 10 个 Mixin 方法未受影响 | ✅ |
|
||||
| E2E 测试 | ✅ 不受影响 |
|
||||
|
||||
**D-Cloud 侧**:856 测试编译通过即安全,Mixin 只新增方法,不修改任何已有方法。
|
||||
|
||||
**Robogo 侧需关注的 4 个点**:
|
||||
|
||||
| 风险点 | 原因 | 验证方式 |
|
||||
|--------|------|---------|
|
||||
| `smart_find` 策略优先级 | 合并后 `self.find()` 可能调用 D-Cloud `LocatorMixin.find()` 而非 `smart_find` | 逐个场景跑,确认所有按钮/元素能找到 |
|
||||
| `smart_click` JS 暴力兜底 | 扫描 `button, a, span, .p-button-label` 等 PrimeVue 选择器 | 确认点击行为正常 |
|
||||
| `smart_fill` 邻近探测 | 查找 `.p-inputgroup, .field, .flex` 等 PrimeVue class | 确认表单填写能正确定位输入框 |
|
||||
| `goto_route`/`visible_dialog` | 9 个页面对象依赖 `self.page` 引用 | 确认导航跳转和弹窗操作正常 |
|
||||
|
||||
**状态**:代码已完成,待 Robogo 真机环境跑 14 个场景验证。
|
||||
|
||||
---
|
||||
|
||||
### 阶段 4:场景去重 + Robogo 接入 pytest(1 天)🟢 低风险 ✅ 已完成
|
||||
|
||||
**分支**:`refactor/phase4-platform-unification` · 提交 `9ba4b25`
|
||||
|
||||
**目标**:删除重复的场景文件,统一入口,Robogo 场景接入 pytest 收集。
|
||||
|
||||
**实施内容**:
|
||||
- 删除 `scenarios/`(14 个文件,与 `framework/scripts/` 逐字重复)
|
||||
- 新建 `framework/scripts/run_all.py`(修复 `DataManagementRunner` 悬挂引用)
|
||||
- 新建 `framework/scripts/run_data_loop.py`(数据闭环入口)
|
||||
- 更新 `backend/app.py` PRODUCTS 入口指向 `framework/scripts/`
|
||||
- 新建 `tests/robogo/test_scenarios.py`(11 个场景参数化 pytest 收集)
|
||||
- 新增 `pytest.ini` marker `robogo`
|
||||
|
||||
**验证结果**:
|
||||
|
||||
| 验证项 | 结果 |
|
||||
|--------|:--:|
|
||||
| 全量项目源文件编译 | ✅ 0 错误 |
|
||||
| 测试收集 | ✅ 867 个(856 D-Cloud + 11 Robogo) |
|
||||
| Robogo 场景中文名称 | ✅ 全部显示 |
|
||||
| 后端入口文件 | ✅ 存在且可编译 |
|
||||
| E2E 测试 | ✅ 不受影响 |
|
||||
|
||||
**平台层面统一效果**:`pytest tests/ --collect-only` 首次统计全部 867 个测试,前端仪表盘可显示完整测试规模。
|
||||
|
||||
---
|
||||
|
||||
## 4. 风险分析
|
||||
|
||||
### 为什么不能保证 0 异常
|
||||
|
||||
| 硬伤 | 影响 |
|
||||
|------|------|
|
||||
| 856 个用例测的是 D-Cloud 平台本身,不是测框架代码 | `BasePage`/`Mixin`/`smart_*` 改了之后,没有单元测试告诉你是改对了还是改坏了 |
|
||||
| `smart_*` 是运行时 DOM 暴力匹配,非编译时逻辑 | 合并后一个选择器顺序调换,可能在 PrimeVue 页面上引入隐性 bug |
|
||||
| 没有 CI | 跑一次全量验证需要手动操作,14 个场景逐个执行 |
|
||||
|
||||
### 各阶段风险评级
|
||||
|
||||
| 阶段 | 风险 | 原因 |
|
||||
|------|:--:|------|
|
||||
| 阶段 1:配置统一 | 🟢 低 | 改 import 路径,Python 编译通过即可验证 |
|
||||
| 阶段 2:API 客户端 + 日志 | 🟡 中 | `httpx` 和 `requests` 行为有细微差异,需验证 header 构建 |
|
||||
| 阶段 3:BasePage 合并 | 🔴 高 | 必须逐场景回跑,没有框架级测试兜底 |
|
||||
| 阶段 4:场景去重 | 🟢 低 | 纯删除重复文件,入口路径校验即可 |
|
||||
|
||||
---
|
||||
|
||||
## 5. 实际能做到的保障
|
||||
|
||||
| 保障手段 | 覆盖范围 |
|
||||
|---------|---------|
|
||||
| 构造一个 D-Cloud 模块的 pytest 全量运行 | 覆盖 ToB 侧 856 条 |
|
||||
| 逐个跑 `scenarios/` 下 14 个脚本 | 覆盖 ToC 侧全场景 |
|
||||
| 阶段 1 验证:Python 编译 + import 不报错 | 配置和 API 客户端 |
|
||||
| 阶段 3 验证:14 个场景逐个回跑 | 页面交互逻辑 |
|
||||
|
||||
---
|
||||
|
||||
## 6. 最终状态
|
||||
|
||||
### 已完成:5/6 条断裂线
|
||||
|
||||
| 断裂线 | 分支 | 状态 |
|
||||
|--------|------|:--:|
|
||||
| 配置系统 | `dev` | ✅ |
|
||||
| API 客户端 | `dev` | ✅ |
|
||||
| 日志系统 | `dev` | ✅ |
|
||||
| BasePage | `dev` | ✅ 已验证(11/14 场景通过) |
|
||||
| 场景去重 + pytest 收集 | `dev` | ✅ 867 测试 |
|
||||
|
||||
### 未完成:1 条 + 3 个硬约束
|
||||
|
||||
| 项目 | 原因 |
|
||||
|------|------|
|
||||
| 认证流程 ⬜ | D-Cloud SSO ≠ Robogo 本地登录 |
|
||||
| 被测前端 | Ant Design ≠ PrimeVue |
|
||||
| 测试运行器 | pytest + marker ≠ 脚本编排器 |
|
||||
| 被测 URL | `cloud-fat.d-robotics.cc` ≠ `robogo.d-robotics.cc` |
|
||||
|
||||
### 结论
|
||||
|
||||
**代码层面已实现二合一。** 两个项目共享了基础设施代码(配置、API、日志、BasePage),`pytest --collect-only` 首次统计全部 867 个测试。但真机测试时跑的是不同的被测平台,永远不会测同一个东西。
|
||||
|
||||
## 7. 收益对比
|
||||
|
||||
| 维度 | 重构前 | 重构后 |
|
||||
|------|--------|------|
|
||||
| 配置入口 | 2 个文件,字段名不一致 | 1 个文件,统一命名 |
|
||||
| API 客户端 | 2 个(httpx + requests) | 1 个(httpx) |
|
||||
| 日志系统 | 2 套 | 1 套 |
|
||||
| BasePage | 2 个类(86 行 + 312 行) | 1 个组合类 + 12 Mixin |
|
||||
| 死代码 | B 套后端(3 个文件) | 已删除 |
|
||||
| 重复文件 | 3 组 | 已删除 |
|
||||
| 新成员上手 | 需要理解两套体系 | 大幅简化 |
|
||||
|
||||
---
|
||||
|
||||
*评估日期:2026-06-26 · 更新日期:2026-06-27 · 基于 `docs/TBC_分析报告_0626.html` 和仓库逐文件代码审读*
|
||||
68
ROBOGO_TODO.md
Normal file
68
ROBOGO_TODO.md
Normal file
@ -0,0 +1,68 @@
|
||||
# Robogo 侧待办清单
|
||||
|
||||
D-Cloud 侧(856 测试 + E2E)已全部完成且验证通过,以下 4 项仅涉及 Robogo 侧。
|
||||
|
||||
---
|
||||
|
||||
## 1. import 链修复(0.5 天)
|
||||
|
||||
Phase 2 删除了 `framework/core/logger.py`,但 `framework/business/` 下还有约 20 个文件引用了它。合并后 `DataManagement` 一 import 就崩。
|
||||
|
||||
**操作**:`framework/business/` 下所有 `from framework.core.logger import get_logger` → `from tests.logger import get_logger`
|
||||
|
||||
**验证**:`python3 -c "from framework.business.data_management import DataManagement"` 不报错
|
||||
|
||||
---
|
||||
|
||||
## 2. 仪表盘 Robogo 统计(0.5 天)
|
||||
|
||||
当前 `/api/dashboard/stats` 只统计 D-Cloud 的 16 个模块健康度,Robogo 的 14 个场景在仪表盘上不可见。
|
||||
|
||||
**操作**:`backend/app.py` 的 `get_stats()` 中为 Robogo 产品也生成健康度数据
|
||||
|
||||
**验证**:`curl http://127.0.0.1:5001/api/dashboard/stats | jq '.health'` 包含 Robogo 条目
|
||||
|
||||
---
|
||||
|
||||
## 3. 数据闭环入口(0.5 天)
|
||||
|
||||
`framework/scripts/run_data_loop.py` 是空壳,真正实现依赖 `dataloop/data-loop-automation/` 目录,该目录不存在于合并后的仓库中。
|
||||
|
||||
**方案 A**:从原 `data-loop-automation` 项目补齐 `dataloop/` 目录
|
||||
**方案 B**:从 `backend/app.py` 的 PRODUCTS 中移除"数据闭环"产品
|
||||
|
||||
**验证**:后端启动后"数据闭环"产品入口文件存在或产品已移除
|
||||
|
||||
---
|
||||
|
||||
## 4. Robogo 真机验证(需人工)
|
||||
|
||||
Phase 3 BasePage 合并后,`smart_*` 方法从 `framework/core/base_page.py` 提取为 Mixin。代码完全一致,但 `smart_click`/`smart_fill`/`smart_select` 是运行时 DOM 扫描逻辑,必须在 `robogo.d-robotics.cc` 真机上跑 14 个场景确认。
|
||||
|
||||
**需验证的场景**:
|
||||
|
||||
| 场景 | 文件 | 重点检查 |
|
||||
|------|------|---------|
|
||||
| 开发机生命周期 | `compute_resource_scenario.py` | `smart_fill` 表单填写 |
|
||||
| 云桌面生命周期 | `desktop_lifecycle.py` | `smart_click` 按钮点击 |
|
||||
| 文件系统巡检 | `file_system_scenario.py` | `smart_click` + `smart_fill` |
|
||||
| 图像生成巡检 | `image_generation_scenario.py` | `goto_route` 导航 |
|
||||
| 镜像资产巡检 | `mirror_assets.py` | `smart_select` 下拉选择 |
|
||||
| Monkey 测试 | `monkey_scenario.py` | `smart_click` 随机点击 |
|
||||
| OpenClaw 巡检 | `openclaw_scenario.py` | `goto_route` 导航 |
|
||||
| 量化工具巡检 | `quantization_scenario.py` | `smart_click` 按钮点击 |
|
||||
| 计费测试 | `test_billing.py` | API 调用 |
|
||||
| 3D 资产巡检 | `three_d_assets_scenario.py` | `visible_dialog` 弹窗 |
|
||||
| 3D 生成巡检 | `three_d_generation_scenario.py` | `smart_fill` 表单填写 |
|
||||
|
||||
**执行方式**:
|
||||
```bash
|
||||
cd framework/scripts
|
||||
python compute_resource_scenario.py
|
||||
python desktop_lifecycle.py
|
||||
# ... 逐个运行
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
*所有 4 项均不影响 D-Cloud 侧 856 测试和 E2E。*
|
||||
1687
api_docs/dataset_annotation_finetune_api.md
Normal file
1687
api_docs/dataset_annotation_finetune_api.md
Normal file
File diff suppressed because it is too large
Load Diff
1547
api_docs/dataset_api.md
Normal file
1547
api_docs/dataset_api.md
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,9 @@
|
||||
"""Allow running backend as module: python -m backend"""
|
||||
from backend.app import app
|
||||
from backend.scheduler import Scheduler
|
||||
import os
|
||||
from backend.app import app, Scheduler
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Unified Test Platform starting... http://127.0.0.1:5001")
|
||||
port = int(os.getenv("PLATFORM_PORT", "5001"))
|
||||
print(f"AutoFlow Platform starting... http://127.0.0.1:{port}")
|
||||
Scheduler().start()
|
||||
app.run(host="0.0.0.0", port=5001)
|
||||
app.run(host="0.0.0.0", port=port)
|
||||
127
backend/app.py
127
backend/app.py
@ -13,6 +13,7 @@ import sys
|
||||
import json
|
||||
import uuid
|
||||
import time
|
||||
import hashlib
|
||||
import queue
|
||||
import threading
|
||||
import subprocess
|
||||
@ -49,14 +50,14 @@ PRODUCTS = {
|
||||
"name": "Robogo",
|
||||
"desc": "Robogo 全链路 UI 巡检",
|
||||
"icon": "🤖",
|
||||
"entry": str(PROJECT_ROOT / "scenarios" / "run_all.py"),
|
||||
"entry": str(PROJECT_ROOT / "framework" / "scripts" / "run_all.py"),
|
||||
"type": "scenario"
|
||||
},
|
||||
"data_loop": {
|
||||
"name": "数据闭环",
|
||||
"desc": "数据闭环平台端到端业务流水线验证",
|
||||
"icon": "🔄",
|
||||
"entry": str(PROJECT_ROOT / "scenarios" / "run_data_loop.py"),
|
||||
"entry": str(PROJECT_ROOT / "framework" / "scripts" / "run_data_loop.py"),
|
||||
"type": "scenario"
|
||||
}
|
||||
}
|
||||
@ -85,6 +86,7 @@ tasks_db: dict = {}
|
||||
reports_db: dict = {}
|
||||
log_queues: dict = {}
|
||||
process_pids: dict = {}
|
||||
db_lock = threading.Lock()
|
||||
|
||||
# ── Database Persistence ───────────────────────────────────────────────────────
|
||||
def _load_db():
|
||||
@ -100,23 +102,30 @@ def _load_db():
|
||||
|
||||
|
||||
def _save_db():
|
||||
try:
|
||||
active_once_tasks = [
|
||||
t for t in tasks_db.values()
|
||||
if t.get("schedule_type", "once") == "once" and not t.get("is_deleted")
|
||||
]
|
||||
if len(active_once_tasks) > 100:
|
||||
sorted_tasks = sorted(active_once_tasks, key=lambda t: t.get("created_at", ""))
|
||||
for t in sorted_tasks[:50]:
|
||||
tid = t.get("id")
|
||||
if tid:
|
||||
_cleanup_assets(tid)
|
||||
t["is_deleted"] = True
|
||||
with db_lock:
|
||||
try:
|
||||
active_once_tasks = [
|
||||
t for t in tasks_db.values()
|
||||
if t.get("schedule_type", "once") == "once" and not t.get("is_deleted")
|
||||
]
|
||||
if len(active_once_tasks) > 100:
|
||||
sorted_tasks = sorted(active_once_tasks, key=lambda t: t.get("created_at", ""))
|
||||
for t in sorted_tasks[:50]:
|
||||
tid = t.get("id")
|
||||
if tid:
|
||||
_cleanup_assets(tid)
|
||||
t["is_deleted"] = True
|
||||
|
||||
with open(DB_FILE, 'w', encoding='utf-8') as f:
|
||||
json.dump({"tasks": tasks_db, "reports": reports_db}, f, ensure_ascii=False)
|
||||
except Exception:
|
||||
pass
|
||||
safe_data = json.loads(json.dumps({"tasks": tasks_db, "reports": reports_db}))
|
||||
for t in safe_data.get("tasks", {}).values():
|
||||
pw = t.get("password")
|
||||
if pw and not pw.startswith("sha256:"):
|
||||
t["password"] = "sha256:" + hashlib.sha256(pw.encode()).hexdigest()
|
||||
|
||||
with open(DB_FILE, 'w', encoding='utf-8') as f:
|
||||
json.dump(safe_data, f, ensure_ascii=False)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def _cleanup_assets(tid):
|
||||
@ -218,26 +227,27 @@ def run_task_process(task):
|
||||
push(f"🎬 Task started — env: {env.get('ROBOGO_ENV', 'N/A')} | scope: {env.get('ROBOGO_SCOPE', 'N/A')}", "INFO")
|
||||
|
||||
# Build command based on task type
|
||||
junit_report = str(PROJECT_ROOT / "reports" / f"{task_id}.xml")
|
||||
if task_type == "dcloud_module" and dcloud_module:
|
||||
test_path = task.get("test", "")
|
||||
if dcloud_module == "e2e":
|
||||
if test_path:
|
||||
cmd = [PYTHON_BIN, "-m", "pytest", test_path, "-v", "--tb=short", "--color=no", "-s"]
|
||||
cmd = [PYTHON_BIN, "-m", "pytest", test_path, "-v", "--tb=short", "--color=no", "-s", f"--junitxml={junit_report}"]
|
||||
push(f"🧪 Running E2E test: {test_path}", "INFO")
|
||||
else:
|
||||
cmd = [PYTHON_BIN, "-m", "pytest", "tests/", "-m", "e2e", "-v", "--tb=short", "--color=no", "-s"]
|
||||
cmd = [PYTHON_BIN, "-m", "pytest", "tests/", "-m", "e2e", "-v", "--tb=short", "--color=no", "-s", f"--junitxml={junit_report}"]
|
||||
push("🧪 Running ALL E2E tests across all modules", "INFO")
|
||||
elif test_path:
|
||||
cmd = [PYTHON_BIN, "-m", "pytest", test_path, "-v", "--tb=short", "--color=no", "-s"]
|
||||
cmd = [PYTHON_BIN, "-m", "pytest", test_path, "-v", "--tb=short", "--color=no", "-s", f"--junitxml={junit_report}"]
|
||||
push(f"🧪 Running test: {test_path}", "INFO")
|
||||
else:
|
||||
cmd = [PYTHON_BIN, "-m", "pytest", f"tests/{dcloud_module}/", "-v", "--tb=short", "--color=no", "-s"]
|
||||
cmd = [PYTHON_BIN, "-m", "pytest", f"tests/{dcloud_module}/", "-v", "--tb=short", "--color=no", "-s", f"--junitxml={junit_report}"]
|
||||
push(f"🧪 Running D-Cloud module tests: {dcloud_module}", "INFO")
|
||||
elif task_type == "dcloud_e2e":
|
||||
cmd = [PYTHON_BIN, "-m", "pytest", "tests/", "-m", "e2e", "-v", "--tb=short", "--color=no", "-s"]
|
||||
cmd = [PYTHON_BIN, "-m", "pytest", "tests/", "-m", "e2e", "-v", "--tb=short", "--color=no", "-s", f"--junitxml={junit_report}"]
|
||||
push("🧪 Running ALL E2E tests across all modules", "INFO")
|
||||
elif task_type == "dcloud_all":
|
||||
cmd = [PYTHON_BIN, "-m", "pytest", "tests/", "-v", "--tb=short", "--color=no", "-s"]
|
||||
cmd = [PYTHON_BIN, "-m", "pytest", "tests/", "-v", "--tb=short", "--color=no", "-s", f"--junitxml={junit_report}"]
|
||||
push("🧪 Running ALL D-Cloud tests", "INFO")
|
||||
elif task_type == "scenario":
|
||||
cmd = [PYTHON_BIN, task["entry"]]
|
||||
@ -300,6 +310,7 @@ def run_task_process(task):
|
||||
"task_id": task_id,
|
||||
"task_name": task["name"],
|
||||
"product": task.get("product", "dcloud"),
|
||||
"module": task.get("dcloud_module", "") or task.get("product", ""),
|
||||
"total_runs": planned_runs,
|
||||
"pass": total_pass,
|
||||
"fail": total_fail,
|
||||
@ -315,6 +326,19 @@ def run_task_process(task):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Generate HTML dashboard report for D-Cloud tasks
|
||||
if task_type.startswith("dcloud"):
|
||||
try:
|
||||
html_report = os.path.join(REPORTS_DIR, f"{task_id}.html")
|
||||
subprocess.run(
|
||||
[PYTHON_BIN, str(PROJECT_ROOT / "scripts" / "generate_report.py"),
|
||||
"--output", html_report, "--no-history"],
|
||||
capture_output=True, timeout=30, cwd=str(PROJECT_ROOT)
|
||||
)
|
||||
report["html_report"] = html_report
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
reports_db[task_id] = report
|
||||
task["status"] = "pass" if final_result == "PASS" else "fail"
|
||||
task["finished_at"] = finished_at
|
||||
@ -391,7 +415,10 @@ def get_module_tests(module):
|
||||
|
||||
@app.route("/api/tasks", methods=["GET"])
|
||||
def list_tasks():
|
||||
product = request.args.get("product", "")
|
||||
t_list = [t for t in tasks_db.values() if not t.get("is_deleted")]
|
||||
if product:
|
||||
t_list = [t for t in t_list if t.get("product") == product]
|
||||
return jsonify(t_list)
|
||||
|
||||
|
||||
@ -507,9 +534,13 @@ def stream_logs(task_id):
|
||||
@app.route("/api/dashboard/stats")
|
||||
def get_stats():
|
||||
try:
|
||||
product_filter = request.args.get("product", "")
|
||||
reports = list(reports_db.values())
|
||||
tasks = list(tasks_db.values())
|
||||
|
||||
if product_filter:
|
||||
reports = [r for r in reports if r.get("product") == product_filter]
|
||||
|
||||
total = len(reports)
|
||||
passed = sum(1 for r in reports if r.get('result') == 'PASS')
|
||||
fail_count = total - passed
|
||||
@ -536,21 +567,22 @@ def get_stats():
|
||||
continue
|
||||
|
||||
health = {}
|
||||
for p_key, p_val in PRODUCTS.items():
|
||||
p_reports = [r for r in reports if r.get("product") == p_key]
|
||||
total_p = sum(1 for r in p_reports if r.get("result") == "PASS")
|
||||
health[p_val["name"]] = {
|
||||
"rate": round(total_p / len(p_reports) * 100) if p_reports else 0,
|
||||
"total": len(p_reports),
|
||||
}
|
||||
|
||||
# D-Cloud modules health
|
||||
for mod_key, mod_val in DCLOUD_MODULES.items():
|
||||
total_p = sum(1 for r in reports if r.get("result") == "PASS")
|
||||
health[mod_val["name"]] = {
|
||||
"rate": round(total_p / len(reports) * 100) if reports else 0,
|
||||
"total": len(reports),
|
||||
}
|
||||
if product_filter == "dcloud" or not product_filter:
|
||||
for mod_key, mod_val in DCLOUD_MODULES.items():
|
||||
mod_reports = [r for r in reports if r.get("module") == mod_key]
|
||||
passed_mod = sum(1 for r in mod_reports if r.get("result") == "PASS")
|
||||
health[mod_val["name"]] = {
|
||||
"rate": round(passed_mod / len(mod_reports) * 100) if mod_reports else 0,
|
||||
"total": len(mod_reports),
|
||||
}
|
||||
if product_filter == "robogo" or not product_filter:
|
||||
for p_key, p_val in PRODUCTS.items():
|
||||
p_reports = [r for r in reports if r.get("product") == p_key]
|
||||
total_p = sum(1 for r in p_reports if r.get("result") == "PASS")
|
||||
health[p_val["name"]] = {
|
||||
"rate": round(total_p / len(p_reports) * 100) if p_reports else 0,
|
||||
"total": len(p_reports),
|
||||
}
|
||||
|
||||
failure_map = {"元素定位/超时": 0, "业务逻辑报错": 0, "接口/网络异常": 0, "其他": 0}
|
||||
failed_reports = [r for r in reports if r.get("result") == "FAIL"][-20:]
|
||||
@ -578,7 +610,7 @@ def get_stats():
|
||||
"total_reports": total,
|
||||
"pass_rate": pass_rate,
|
||||
"fail_count": fail_count,
|
||||
"closure_rate": 85 if fail_count > 0 else 100
|
||||
"closure_rate": round(passed / total * 100, 1) if total > 0 else 0
|
||||
},
|
||||
"trends": trends,
|
||||
"health": health,
|
||||
@ -591,9 +623,12 @@ def get_stats():
|
||||
|
||||
@app.route("/api/reports")
|
||||
def list_reports():
|
||||
product = request.args.get("product", "")
|
||||
r_list = []
|
||||
for tid, r in reports_db.items():
|
||||
if tid in tasks_db and not tasks_db[tid].get("is_deleted"):
|
||||
if product and tasks_db[tid].get("product") != product:
|
||||
continue
|
||||
item = r.copy()
|
||||
item["thumbnail"] = None
|
||||
if os.path.exists(SCREENSHOTS_DIR):
|
||||
@ -641,6 +676,10 @@ def get_report(tid):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
html_path = os.path.join(REPORTS_DIR, f"{tid}.html")
|
||||
if os.path.exists(html_path):
|
||||
res["html_report"] = f"/api/reports/{tid}/html"
|
||||
|
||||
return jsonify(res)
|
||||
|
||||
|
||||
@ -649,6 +688,14 @@ def serve_screenshot(filename):
|
||||
return send_from_directory(SCREENSHOTS_DIR, filename)
|
||||
|
||||
|
||||
@app.route("/api/reports/<tid>/html")
|
||||
def serve_report_html(tid):
|
||||
html_path = os.path.join(REPORTS_DIR, f"{tid}.html")
|
||||
if os.path.exists(html_path):
|
||||
return send_from_directory(REPORTS_DIR, f"{tid}.html")
|
||||
return jsonify({"error": "Not Found"}), 404
|
||||
|
||||
|
||||
# ── Serve React SPA (production) ───────────────────────────────────────────────
|
||||
@app.route("/assets/<path:filename>")
|
||||
def serve_assets(filename):
|
||||
|
||||
@ -1,40 +0,0 @@
|
||||
import os
|
||||
import json
|
||||
|
||||
DB_FILE = os.path.join(os.path.dirname(__file__), "db.json")
|
||||
|
||||
tasks_db = {}
|
||||
reports_db = {}
|
||||
|
||||
|
||||
def load_db():
|
||||
global tasks_db, reports_db
|
||||
if os.path.exists(DB_FILE):
|
||||
try:
|
||||
with open(DB_FILE, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
tasks_db = data.get("tasks", {})
|
||||
reports_db = data.get("reports", {})
|
||||
except Exception as e:
|
||||
print(f"DB load failed: {e}")
|
||||
|
||||
|
||||
def save_db():
|
||||
try:
|
||||
active_once = [
|
||||
t for t in tasks_db.values()
|
||||
if t.get("schedule_type", "once") == "once" and not t.get("is_deleted")
|
||||
]
|
||||
if len(active_once) > 100:
|
||||
sorted_tasks = sorted(active_once, key=lambda t: t.get("created_at", ""))
|
||||
for t in sorted_tasks[:50]:
|
||||
tid = t.get("id")
|
||||
if tid:
|
||||
t["is_deleted"] = True
|
||||
with open(DB_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump({"tasks": tasks_db, "reports": reports_db}, f, ensure_ascii=False)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
load_db()
|
||||
@ -1,68 +0,0 @@
|
||||
import threading
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
from backend.database import tasks_db
|
||||
from backend.test_runner import run_task_process
|
||||
|
||||
|
||||
class Scheduler:
|
||||
def _is_in_window(self, now, window_str):
|
||||
if not window_str or window_str == "all":
|
||||
return True
|
||||
current_time = now.strftime("%H:%M")
|
||||
try:
|
||||
for part in window_str.split(","):
|
||||
if "-" not in part:
|
||||
continue
|
||||
start, end = part.strip().split("-")
|
||||
if start <= current_time <= end:
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
def start(self):
|
||||
threading.Thread(target=self._loop, daemon=True).start()
|
||||
|
||||
def _loop(self):
|
||||
while True:
|
||||
try:
|
||||
now = datetime.now()
|
||||
for tid, task in list(tasks_db.items()):
|
||||
if task["status"] == "running":
|
||||
continue
|
||||
stype = task.get("schedule_type", "once")
|
||||
last_run = task.get("last_scheduled_run")
|
||||
should_run = False
|
||||
|
||||
if stype == "once" and task.get("scheduled_at") and task["status"] == "pending":
|
||||
if now >= datetime.fromisoformat(task["scheduled_at"]):
|
||||
should_run = True
|
||||
elif stype == "continuous":
|
||||
window = task.get("schedule_window", "00:00-23:59")
|
||||
if self._is_in_window(now, window):
|
||||
if last_run:
|
||||
delta = (now - datetime.fromisoformat(last_run)).total_seconds()
|
||||
if delta < 60:
|
||||
continue
|
||||
should_run = True
|
||||
elif stype != "once":
|
||||
if not last_run:
|
||||
should_run = True
|
||||
else:
|
||||
delta = (now - datetime.fromisoformat(last_run)).total_seconds()
|
||||
if (stype == "hourly" and delta >= 3600) or \
|
||||
(stype == "daily" and delta >= 86400) or \
|
||||
(stype == "weekly" and delta >= 86400 * 7):
|
||||
should_run = True
|
||||
|
||||
if should_run:
|
||||
task["last_scheduled_run"] = now.isoformat()
|
||||
if stype == "once":
|
||||
task["status"] = "running"
|
||||
print(f"Triggered task: {task['name']} (type: {stype})")
|
||||
threading.Thread(target=run_task_process, args=(task,), daemon=True).start()
|
||||
except Exception as e:
|
||||
print(f"Scheduler error: {e}")
|
||||
time.sleep(30)
|
||||
@ -1,282 +0,0 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import queue
|
||||
import signal
|
||||
import threading
|
||||
import subprocess
|
||||
import time
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
||||
import requests
|
||||
|
||||
from backend.database import tasks_db, reports_db, save_db
|
||||
|
||||
PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))
|
||||
REPORTS_DIR = os.path.join(PROJECT_ROOT, "reports")
|
||||
SCREENSHOTS_DIR = os.path.join(PROJECT_ROOT, "screenshots")
|
||||
LARK_WEBHOOK = "https://open.feishu.cn/open-apis/bot/v2/hook/d75c14ad-d782-489e-8a99-81b511ee4abd"
|
||||
|
||||
log_queues = {}
|
||||
process_pids = {}
|
||||
|
||||
os.makedirs(REPORTS_DIR, exist_ok=True)
|
||||
os.makedirs(SCREENSHOTS_DIR, exist_ok=True)
|
||||
|
||||
|
||||
def _resolve_python():
|
||||
candidates = [
|
||||
os.path.join(PROJECT_ROOT, ".venv311", "bin", "python3"),
|
||||
os.path.join(PROJECT_ROOT, ".venv", "bin", "python3"),
|
||||
os.path.join(PROJECT_ROOT, "venv", "bin", "python"),
|
||||
]
|
||||
for p in candidates:
|
||||
if os.path.exists(p):
|
||||
return p
|
||||
return sys.executable
|
||||
|
||||
|
||||
def send_alerts(report):
|
||||
task_id = report.get("task_id")
|
||||
task = tasks_db.get(task_id, {})
|
||||
channels = task.get("alert_channels", [])
|
||||
|
||||
if "lark" in channels:
|
||||
rule = task.get("alert_rule", "always")
|
||||
if rule == "only_on_fail" and report["result"] == "PASS":
|
||||
return
|
||||
try:
|
||||
status_color = "green" if report["result"] == "PASS" else "red"
|
||||
status_text = "PASS" if report["result"] == "PASS" else "FAIL"
|
||||
card = {
|
||||
"config": {"wide_screen_mode": True},
|
||||
"header": {
|
||||
"title": {"tag": "plain_text", "content": f"Unified Test Report: {report['task_name']}"},
|
||||
"template": status_color,
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"tag": "div",
|
||||
"fields": [
|
||||
{"is_short": True, "text": {"tag": "lark_md", "content": f"**Status:** {status_text}"}},
|
||||
{"is_short": True, "text": {"tag": "lark_md", "content": f"**Product:** {report['product']}"}},
|
||||
{"is_short": True, "text": {"tag": "lark_md", "content": f"**Env:** {task.get('env', 'PROD')}"}},
|
||||
{"is_short": True, "text": {"tag": "lark_md", "content": f"**Pass/Total:** {report['pass']}/{report['total_runs']}"}},
|
||||
],
|
||||
},
|
||||
{"tag": "hr"},
|
||||
{
|
||||
"tag": "action",
|
||||
"actions": [
|
||||
{
|
||||
"tag": "button",
|
||||
"text": {"tag": "plain_text", "content": "View Report"},
|
||||
"type": "primary",
|
||||
"url": "http://127.0.0.1:5001/#/tasks",
|
||||
}
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
requests.post(LARK_WEBHOOK, json={"msg_type": "interactive", "card": card}, timeout=5)
|
||||
except Exception as e:
|
||||
print(f"Feishu alert failed: {e}")
|
||||
|
||||
|
||||
def run_task_process(task):
|
||||
task_id = task["id"]
|
||||
task["status"] = "running"
|
||||
task["started_at"] = datetime.now().isoformat()
|
||||
save_db()
|
||||
|
||||
q = log_queues.get(task_id)
|
||||
logs_all = []
|
||||
|
||||
def push(msg, level="INFO"):
|
||||
entry = {"ts": datetime.now().strftime("%H:%M:%S"), "level": level, "msg": msg}
|
||||
logs_all.append(entry)
|
||||
if q:
|
||||
q.put(json.dumps(entry))
|
||||
|
||||
run_limit = int(task.get("run_count", 1))
|
||||
retry_count = int(task.get("retry_count", 1)) if task.get("retry_on_fail") else 0
|
||||
retry_delay = int(task.get("retry_delay", 5))
|
||||
|
||||
env = os.environ.copy()
|
||||
env["ROBOGO_SCREENSHOTS_DIR"] = os.path.abspath(SCREENSHOTS_DIR)
|
||||
env["ROBOGO_REPORTS_DIR"] = os.path.abspath(REPORTS_DIR)
|
||||
env["ROBOGO_TASK_ID"] = task_id
|
||||
env["ROBOGO_ENV"] = task.get("env", "PROD")
|
||||
env["ROBOGO_SCOPE"] = task.get("scope", "all")
|
||||
env["AUTH_ACCOUNT"] = task.get("account", "")
|
||||
env["AUTH_PASSWORD"] = task.get("password", "")
|
||||
env["ROBOGO_USER"] = task.get("account", "")
|
||||
env["ROBOGO_PWD"] = task.get("password", "")
|
||||
env["HEADLESS"] = task.get("headless", "true")
|
||||
|
||||
runner_type = task.get("runner", "script")
|
||||
|
||||
total_pass, total_fail = 0, 0
|
||||
current_run = 0
|
||||
planned_runs = run_limit
|
||||
last_run_success = None
|
||||
is_retry_run = False
|
||||
|
||||
push(f"Task started — Env: {env['ROBOGO_ENV']} | Scope: {env['ROBOGO_SCOPE']} | Runner: {runner_type}", "INFO")
|
||||
|
||||
python_bin = _resolve_python()
|
||||
|
||||
while current_run < run_limit:
|
||||
current_run += 1
|
||||
push(f"Run {current_run}/{planned_runs}...", "INFO")
|
||||
|
||||
try:
|
||||
if runner_type == "pytest":
|
||||
cmd = _build_pytest_cmd(task)
|
||||
if cmd is None:
|
||||
push(f"Unknown module: {task.get('module')}", "ERROR")
|
||||
last_run_success = False
|
||||
total_fail += 1
|
||||
break
|
||||
proc = subprocess.Popen(
|
||||
cmd,
|
||||
cwd=PROJECT_ROOT,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
bufsize=1,
|
||||
env=env,
|
||||
preexec_fn=os.setsid if os.name != "nt" else None,
|
||||
)
|
||||
else:
|
||||
if not task.get("entry"):
|
||||
push("No entry script configured", "ERROR")
|
||||
last_run_success = False
|
||||
total_fail += 1
|
||||
break
|
||||
proc = subprocess.Popen(
|
||||
[python_bin, task["entry"]],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
bufsize=1,
|
||||
env=env,
|
||||
preexec_fn=os.setsid if os.name != "nt" else None,
|
||||
)
|
||||
|
||||
process_pids[task_id] = proc.pid
|
||||
|
||||
for line in proc.stdout:
|
||||
push(line.rstrip(), "INFO")
|
||||
proc.wait()
|
||||
process_pids.pop(task_id, None)
|
||||
|
||||
if proc.returncode == 0:
|
||||
last_run_success = True
|
||||
if is_retry_run:
|
||||
total_fail = max(0, total_fail - 1)
|
||||
total_pass += 1
|
||||
push(f"Retry run {current_run} passed (overrides previous failure)", "SUCCESS")
|
||||
else:
|
||||
total_pass += 1
|
||||
push(f"Run {current_run} passed", "SUCCESS")
|
||||
is_retry_run = False
|
||||
else:
|
||||
last_run_success = False
|
||||
total_fail += 1
|
||||
push(f"Run {current_run} failed", "ERROR")
|
||||
if retry_count > 0:
|
||||
push(f"Retrying ({retry_count} left), waiting {retry_delay}s...", "WARN")
|
||||
time.sleep(retry_delay)
|
||||
retry_count -= 1
|
||||
run_limit += 1
|
||||
is_retry_run = True
|
||||
else:
|
||||
is_retry_run = False
|
||||
except Exception as e:
|
||||
push(f"System error: {e}", "ERROR")
|
||||
last_run_success = False
|
||||
total_fail += 1
|
||||
is_retry_run = False
|
||||
|
||||
finished_at = datetime.now().isoformat()
|
||||
final_result = "PASS" if last_run_success else "FAIL"
|
||||
report = {
|
||||
"task_id": task_id,
|
||||
"task_name": task["name"],
|
||||
"product": task["product"],
|
||||
"total_runs": planned_runs,
|
||||
"pass": total_pass,
|
||||
"fail": total_fail,
|
||||
"started_at": task["started_at"],
|
||||
"finished_at": finished_at,
|
||||
"result": final_result,
|
||||
}
|
||||
|
||||
log_file = os.path.join(REPORTS_DIR, f"{task_id}.json")
|
||||
try:
|
||||
with open(log_file, "w", encoding="utf-8") as f:
|
||||
json.dump({"logs": logs_all}, f, ensure_ascii=False)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
reports_db[task_id] = report
|
||||
task["status"] = "pass" if final_result == "PASS" else "fail"
|
||||
task["finished_at"] = finished_at
|
||||
task["report_id"] = task_id
|
||||
|
||||
save_db()
|
||||
send_alerts(report)
|
||||
push("__DONE__", "DONE")
|
||||
|
||||
|
||||
def _build_pytest_cmd(task):
|
||||
module = task.get("module")
|
||||
test_marker = task.get("test_marker", "")
|
||||
test_file = task.get("test_file", "")
|
||||
|
||||
if test_file:
|
||||
return [_resolve_python(), "-m", "pytest", test_file, "-v", "--tb=short", "--color=no"]
|
||||
|
||||
if test_marker:
|
||||
return [_resolve_python(), "-m", "pytest", "tests/", "-m", test_marker, "-v", "--tb=short", "--color=no"]
|
||||
|
||||
if module:
|
||||
test_dir = os.path.join(PROJECT_ROOT, "tests", module)
|
||||
if not os.path.exists(test_dir):
|
||||
return None
|
||||
return [_resolve_python(), "-m", "pytest", str(test_dir), "-v", "--tb=short", "--color=no"]
|
||||
|
||||
return [_resolve_python(), "-m", "pytest", "tests/", "-v", "--tb=short", "--color=no"]
|
||||
|
||||
|
||||
def stream_pytest(module, test=None):
|
||||
"""Stream pytest output via SSE for the API server"""
|
||||
cmd = _build_pytest_cmd({"module": module, "test_file": test})
|
||||
if cmd is None:
|
||||
return None
|
||||
return cmd
|
||||
|
||||
|
||||
def stop_task(tid):
|
||||
pid = process_pids.get(tid)
|
||||
task = tasks_db.get(tid)
|
||||
|
||||
if task:
|
||||
if task.get("schedule_type") == "continuous":
|
||||
task["schedule_type"] = "once"
|
||||
task["status"] = "fail"
|
||||
task["finished_at"] = datetime.now().isoformat()
|
||||
|
||||
if pid:
|
||||
try:
|
||||
os.killpg(os.getpgid(pid), signal.SIGKILL)
|
||||
except Exception:
|
||||
try:
|
||||
os.kill(pid, signal.SIGKILL)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
process_pids.pop(tid, None)
|
||||
save_db()
|
||||
@ -10,8 +10,8 @@ from lark_oapi.api.im.v1 import (
|
||||
)
|
||||
from lark_oapi.event.callback.model.p2_card_action_trigger import P2CardActionTrigger
|
||||
|
||||
from framework.config.settings import Config as config
|
||||
from framework.core.logger import get_logger
|
||||
from config.settings import Config as config
|
||||
from tests.logger import get_logger
|
||||
from framework.business.cloud_desktop import CloudDesktopService
|
||||
from framework.business.dev_machine import DevMachineService
|
||||
from framework.business.billing import BillingService
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import random
|
||||
from datetime import datetime
|
||||
from framework.core.base_api import BaseAPI
|
||||
from framework.config.settings import Config
|
||||
from framework.core.logger import get_logger
|
||||
from tests.utils.api_client import APIClient
|
||||
from config.settings import Config
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("MealReminderService")
|
||||
|
||||
|
||||
42
com.autoflow.platform.plist
Normal file
42
com.autoflow.platform.plist
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
|
||||
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>com.autoflow.platform</string>
|
||||
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>__PROJECT_ROOT__/.venv/bin/python</string>
|
||||
<string>-m</string>
|
||||
<string>backend.app</string>
|
||||
</array>
|
||||
|
||||
<key>WorkingDirectory</key>
|
||||
<string>__PROJECT_ROOT__</string>
|
||||
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>PLATFORM_PORT</key>
|
||||
<string>5001</string>
|
||||
<key>PATH</key>
|
||||
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin</string>
|
||||
</dict>
|
||||
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
|
||||
<key>KeepAlive</key>
|
||||
<true/>
|
||||
|
||||
<key>StandardOutPath</key>
|
||||
<string>__PROJECT_ROOT__/logs/platform.log</string>
|
||||
|
||||
<key>StandardErrorPath</key>
|
||||
<string>__PROJECT_ROOT__/logs/platform_error.log</string>
|
||||
|
||||
<key>ProcessType</key>
|
||||
<string>Background</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@ -77,6 +77,10 @@ class BaseConfig:
|
||||
|
||||
LOGIN_URL = ""
|
||||
|
||||
# Robogo 认证
|
||||
AUTH_TOKEN: str = os.getenv("AUTH_TOKEN", "")
|
||||
COOKIE: str = os.getenv("AUTH_COOKIE", "")
|
||||
|
||||
DEFAULT_TIMEOUT: int = 15000
|
||||
SHORT_WAIT: int = 200
|
||||
MEDIUM_WAIT: int = 500
|
||||
@ -112,20 +116,61 @@ class BaseConfig:
|
||||
MIRROR_SKU = "desktop-5880gpu12g-16c32g"
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
TEST_DATA_DIR = os.path.join(BASE_DIR, "test_data")
|
||||
TEST_FILE = os.path.join(TEST_DATA_DIR, "Fruits-15.zip")
|
||||
INSPECTION_INTERVAL = 300
|
||||
|
||||
WAIT = {
|
||||
'create': 60,
|
||||
'stop': 30,
|
||||
'start': 30,
|
||||
'switch': 15,
|
||||
'delete': 30
|
||||
}
|
||||
|
||||
class CloudDesktop:
|
||||
POST_IMAGE_ID = os.getenv("CD_POST_IMAGE_ID", "")
|
||||
PRE_IMAGE_ID = os.getenv("CD_PRE_IMAGE_ID", "")
|
||||
BP_IMAGE_ID = os.getenv("CD_BP_IMAGE_ID", "")
|
||||
SKU_ID = os.getenv("CD_SKU_ID", "desktop-5880gpu12g-16c32g")
|
||||
DISK_SIZE = os.getenv("CD_DISK_SIZE", "100")
|
||||
SPEC_ID = os.getenv("CD_SPEC_ID", "")
|
||||
TIMER_ID = os.getenv("CD_TIMER_ID", "")
|
||||
PRICE_POLICY_ID = os.getenv("CD_PRICE_POLICY_ID", "")
|
||||
|
||||
class DevMachine:
|
||||
IMAGE_ID = os.getenv("DM_IMAGE_ID", "")
|
||||
SKU_ID = os.getenv("DM_SKU_ID", "sku-e154fd3a-4719-db77-3911-21c6355349ec")
|
||||
SSH_KEY = os.getenv("DM_SSH_KEY", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBGp6Be0pt0Xy3Ipxm+AQTz6JQq8DAzIU6XHqD+/gzH6")
|
||||
DISK_SIZE = os.getenv("DM_DISK_SIZE", "100")
|
||||
|
||||
CLOUD_AUTH_TOKEN: str = os.getenv("CLOUD_AUTH_TOKEN", "")
|
||||
AMAP_KEY: str = os.getenv("AMAP_KEY", "")
|
||||
AMAP_COORDINATES: str = os.getenv("AMAP_COORDINATES", "")
|
||||
|
||||
DEBUG: bool = False
|
||||
PLATFORM_PORT = int(os.getenv("PLATFORM_PORT", "5001"))
|
||||
|
||||
LARK_WEBHOOK = os.getenv("LARK_WEBHOOK_URL", "")
|
||||
|
||||
|
||||
class RobogoConfig(BaseConfig):
|
||||
"""Robogo (ToC) 专用配置 — 覆盖 BaseConfig 的 Robogo 默认值"""
|
||||
_ENV = os.getenv("ROBOGO_ENV", "PROD").upper()
|
||||
if _ENV in ["FAT"]:
|
||||
BASE_URL = "https://robogo-fat.d-robotics.cc"
|
||||
else:
|
||||
BASE_URL = "https://robogo.d-robotics.cc"
|
||||
|
||||
LOGIN_URL = f"{BASE_URL}/cloud-desktop/login"
|
||||
|
||||
DEFAULT_TIMEOUT = 30000
|
||||
|
||||
|
||||
# Backward-compatible Config alias for framework/ code
|
||||
Config = RobogoConfig
|
||||
|
||||
|
||||
class DevConfig(BaseConfig):
|
||||
BASE_URL = _normalize_base_url(os.getenv("BASE_URL", "https://cloud-fat.d-robotics.cc"))
|
||||
SSO_URL = os.getenv("SSO_URL", "https://sso-fat.d-robotics.cc")
|
||||
|
||||
156
framework/bot.py
156
framework/bot.py
@ -1,156 +0,0 @@
|
||||
import re
|
||||
import json
|
||||
import threading
|
||||
import concurrent.futures
|
||||
from datetime import datetime
|
||||
import lark_oapi as lark
|
||||
from lark_oapi.api.im.v1 import (
|
||||
CreateMessageRequest,
|
||||
CreateMessageRequestBody,
|
||||
)
|
||||
from lark_oapi.event.callback.model.p2_card_action_trigger import P2CardActionTrigger
|
||||
|
||||
from framework.config.settings import Config as config
|
||||
from framework.core.logger import get_logger
|
||||
from framework.business.cloud_desktop import CloudDesktopService
|
||||
from framework.business.dev_machine import DevMachineService
|
||||
from framework.business.billing import BillingService
|
||||
from framework.business.meal_reminder import MealReminderService
|
||||
from framework.business.boilerplate import BoilerplateService
|
||||
from framework.core.exceptions import TokenExpiredError
|
||||
|
||||
logger = get_logger("FeishuBot")
|
||||
|
||||
# ---------- 飞书卡片常量 ----------
|
||||
TOKEN_UPDATE_CARD_ID = "AAq2uZZvyWY01"
|
||||
RESULT_CARD_ID = "AAqKcs3OrZBnJ"
|
||||
INTRO_CARD_ID = "AAq2uZZvyWY06"
|
||||
|
||||
# 线程池
|
||||
executor = concurrent.futures.ThreadPoolExecutor(max_workers=10)
|
||||
|
||||
# ---------- 业务服务实例化 ----------
|
||||
cd_service = CloudDesktopService()
|
||||
dm_service = DevMachineService()
|
||||
billing_service = BillingService()
|
||||
meal_service = MealReminderService()
|
||||
bp_service = BoilerplateService()
|
||||
|
||||
# ---------- 全局计数器 ----------
|
||||
_counter_lock = threading.Lock()
|
||||
_global_counter = 0
|
||||
|
||||
def _next_default_name() -> str:
|
||||
global _global_counter
|
||||
with _counter_lock:
|
||||
_global_counter += 1
|
||||
return f"验证{_global_counter:02d}"
|
||||
|
||||
# ---------- 飞书 API Client ----------
|
||||
_lark_client = lark.Client.builder() \
|
||||
.app_id(config.FEISHU_APP_ID) \
|
||||
.app_secret(config.FEISHU_APP_SECRET) \
|
||||
.build()
|
||||
|
||||
def send_feishu_message(chat_id: str, text: str):
|
||||
body = CreateMessageRequestBody.builder().receive_id(chat_id).msg_type("text").content(json.dumps({"text": text})).build()
|
||||
request = CreateMessageRequest.builder().receive_id_type("chat_id").request_body(body).build()
|
||||
_lark_client.im.v1.message.create(request)
|
||||
|
||||
def send_card_json(chat_id: str, card_json: dict):
|
||||
body = CreateMessageRequestBody.builder().receive_id(chat_id).msg_type("interactive").content(json.dumps(card_json)).build()
|
||||
request = CreateMessageRequest.builder().receive_id_type("chat_id").request_body(body).build()
|
||||
_lark_client.im.v1.message.create(request)
|
||||
|
||||
def _handle_single_task(chat_id, name, task_type):
|
||||
try:
|
||||
if task_type == "cd_post":
|
||||
results, instance_id = cd_service.run_lifecycle_test(name, flow_type="postpaid_to_prepaid")
|
||||
label = "云桌面(按转包)"
|
||||
elif task_type == "cd_pre":
|
||||
results, instance_id = cd_service.run_lifecycle_test(name, flow_type="prepaid_to_postpaid")
|
||||
label = "云桌面(包转按)"
|
||||
elif task_type == "bp":
|
||||
results, instance_id = bp_service.run_lifecycle_test(name)
|
||||
label = "样本工程"
|
||||
else:
|
||||
results, instance_id = dm_service.run_lifecycle_test(name)
|
||||
label = "开发机"
|
||||
|
||||
send_feishu_message(chat_id, f"✅ {label} [{name}] 验证完成!")
|
||||
except TokenExpiredError:
|
||||
send_feishu_message(chat_id, "⚠️ 认证过期,请更新 Token")
|
||||
except Exception as e:
|
||||
logger.error(f"Task error: {e}")
|
||||
send_feishu_message(chat_id, f"❌ {label} 验证异常: {e}")
|
||||
|
||||
def _parse_command(text: str):
|
||||
patterns = {
|
||||
"cd_post": r"robogo-云桌面[ \-:=]+(.+)$",
|
||||
"cd_pre": r"robogo-云桌面包月[ \-:=]+(.+)$",
|
||||
"dm": r"robogo-开发机[ \-:=]+(.+)$",
|
||||
"bp": r"robogo-样本工程[ \-:=]+(.+)$",
|
||||
"billing": r"账单[ \-:=]*(.*)$",
|
||||
}
|
||||
# 辅助匹配模式(不带名称的情况)
|
||||
fallback_patterns = {
|
||||
"cd_post": r"robogo-云桌面\s*$",
|
||||
"cd_pre": r"robogo-云桌面包月\s*$",
|
||||
"dm": r"robogo-开发机\s*$",
|
||||
"bp": r"robogo-样本工程\s*$",
|
||||
}
|
||||
|
||||
text_clean = text.strip()
|
||||
logger.info(f"Parsing command from text: '{text_clean}'")
|
||||
|
||||
# 先试带有名称的模式
|
||||
for cmd, p in patterns.items():
|
||||
m = re.search(p, text_clean)
|
||||
if m:
|
||||
logger.info(f"Matched named pattern: {cmd}, name: {m.group(1).strip()}")
|
||||
return cmd, m.group(1).strip()
|
||||
|
||||
# 再试默认模式
|
||||
for cmd, p in fallback_patterns.items():
|
||||
m = re.search(p, text_clean)
|
||||
if m:
|
||||
logger.info(f"Matched fallback pattern: {cmd}")
|
||||
return cmd, None
|
||||
|
||||
logger.warning(f"No pattern matched for text: '{text_clean}'")
|
||||
return None, None
|
||||
|
||||
def _on_message(data):
|
||||
msg = data.event.message
|
||||
chat_id = msg.chat_id
|
||||
content = json.loads(msg.content)
|
||||
text = content.get("text", "")
|
||||
|
||||
clean_text = re.sub(r'@[^ ]+', '', text).strip()
|
||||
|
||||
if "饭否" in clean_text:
|
||||
send_card_json(chat_id, meal_service.build_card())
|
||||
return
|
||||
|
||||
cmd, name = _parse_command(clean_text)
|
||||
if cmd == "billing":
|
||||
items = billing_service.fetch_billing_data(name)
|
||||
send_feishu_message(chat_id, f"共找到 {len(items)} 条账单记录")
|
||||
elif cmd:
|
||||
name = name or _next_default_name()
|
||||
executor.submit(_handle_single_task, chat_id, name, cmd)
|
||||
else:
|
||||
send_feishu_message(chat_id, "未能识别指令,请尝试 [robogo-云桌面] 或 [账单]")
|
||||
|
||||
def main():
|
||||
# 使用 WebSocket (Long Polling) 模式,无需公网 IP
|
||||
event_handler = lark.EventDispatcherHandler.builder(config.FEISHU_APP_ID, config.FEISHU_APP_SECRET) \
|
||||
.register_p2_im_message_receive_v1(_on_message) \
|
||||
.build()
|
||||
|
||||
ws_client = lark.ws.Client(config.FEISHU_APP_ID, config.FEISHU_APP_SECRET, event_handler=event_handler)
|
||||
logger.info("Bot started in WebSocket mode...")
|
||||
ws_client.start()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@ -1,5 +1,5 @@
|
||||
from framework.core.base_api import BaseAPI
|
||||
from framework.config.settings import Config
|
||||
from tests.utils.api_client import APIClient
|
||||
from config.settings import Config
|
||||
|
||||
class BillingService(BaseAPI):
|
||||
def __init__(self):
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import time
|
||||
from framework.business.cloud_desktop import CloudDesktopService
|
||||
from framework.config.settings import Config
|
||||
from framework.core.logger import get_logger
|
||||
from config.settings import Config
|
||||
from tests.logger import get_logger
|
||||
from framework.models.result import StepResult
|
||||
|
||||
logger = get_logger("BoilerplateService")
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import time
|
||||
from framework.core.base_api import BaseAPI
|
||||
from framework.config.settings import Config
|
||||
from framework.core.logger import get_logger
|
||||
from tests.utils.api_client import APIClient
|
||||
from config.settings import Config
|
||||
from tests.logger import get_logger
|
||||
from framework.models.result import StepResult
|
||||
|
||||
logger = get_logger("CloudDesktopService")
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import time
|
||||
from framework.core.base_page import BasePage
|
||||
from framework.core.logger import get_logger
|
||||
from tests.base.base_page import BasePage
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("CloudDesktopPage")
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from framework.config.settings import Config
|
||||
from framework.core.logger import get_logger
|
||||
from config.settings import Config
|
||||
from tests.logger import get_logger
|
||||
from framework.business.login_page import LoginPage
|
||||
from framework.business.file_manager_page import FileManagerPage
|
||||
from framework.business.dev_machine_page import DevMachinePage
|
||||
@ -127,14 +127,15 @@ class DataManagement:
|
||||
# 动态定义本次要运行的模块
|
||||
active_modules = []
|
||||
if scope == "all":
|
||||
# active_modules = ["file", "dev", "cloud", "mirror", "quant" , "3d", "image", "openclaw"]
|
||||
active_modules = ["file", "3d","quant"]
|
||||
active_modules = ["cloud", "dev", "mirror", "image", "openclaw"]
|
||||
# 暂时注释:文件系统(#folderName元素变化)、3D生成(test_data缺失)、量化工具(弹窗遮挡)
|
||||
# active_modules = ["file", "3d", "quant"]
|
||||
elif scope == "smoke":
|
||||
active_modules = ["file"] # 核心资源生命周期
|
||||
active_modules = ["cloud"]
|
||||
elif scope == "core":
|
||||
active_modules = ["cloud","dev", "mirror", "quant" ,"file", "image", "openclaw"] # 业务闭环
|
||||
active_modules = ["cloud", "dev", "mirror", "image", "openclaw"] # 业务闭环
|
||||
else:
|
||||
active_modules = ["file"] # 默认兜底只跑云桌面
|
||||
active_modules = ["cloud"]
|
||||
|
||||
errors = []
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import time
|
||||
from framework.core.base_api import BaseAPI
|
||||
from framework.config.settings import Config
|
||||
from framework.core.logger import get_logger
|
||||
from tests.utils.api_client import APIClient
|
||||
from config.settings import Config
|
||||
from tests.logger import get_logger
|
||||
from framework.models.result import StepResult
|
||||
|
||||
logger = get_logger("DevMachineService")
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import time
|
||||
from framework.core.base_page import BasePage
|
||||
from framework.core.logger import get_logger
|
||||
from tests.base.base_page import BasePage
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("DevMachinePage")
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import time
|
||||
import os
|
||||
from framework.core.base_page import BasePage
|
||||
from framework.core.logger import get_logger
|
||||
from tests.base.base_page import BasePage
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("FileManagerPage")
|
||||
|
||||
|
||||
@ -2,8 +2,8 @@ import time
|
||||
import os
|
||||
import json
|
||||
import random
|
||||
from framework.core.base_page import BasePage
|
||||
from framework.core.logger import get_logger
|
||||
from tests.base.base_page import BasePage
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("ImageGenerationPage")
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
from framework.core.base_ui import BaseUI
|
||||
from framework.config.settings import Config
|
||||
from framework.core.logger import get_logger
|
||||
from config.settings import Config
|
||||
from tests.logger import get_logger
|
||||
import time
|
||||
|
||||
logger = get_logger("LoginPage")
|
||||
|
||||
@ -1,53 +1,66 @@
|
||||
from framework.core.base_ui import BaseUI
|
||||
from framework.config.settings import Config
|
||||
from framework.core.logger import get_logger
|
||||
from config.settings import Config
|
||||
from tests.logger import get_logger
|
||||
import time
|
||||
|
||||
logger = get_logger("LoginPage")
|
||||
|
||||
class LoginPage(BaseUI):
|
||||
# --- 元素定位器 ---
|
||||
USERNAME_INPUT = "input[placeholder*='账号'], #account"
|
||||
PASSWORD_INPUT = "input[placeholder*='密码'], #password"
|
||||
USERNAME_INPUT = "input[placeholder*='account'], #form_item_userName"
|
||||
PASSWORD_INPUT = "input[placeholder*='password'], #form_item_password"
|
||||
LOGIN_BUTTON = "button.loginBtn"
|
||||
|
||||
SUCCESS_INDICATOR = ".ant-layout-sider, .user-name"
|
||||
|
||||
def __init__(self, headless=False):
|
||||
super().__init__(headless=headless)
|
||||
|
||||
def login(self, username, password):
|
||||
"""执行登录流程"""
|
||||
# 直接使用 Config.LOGIN_URL
|
||||
login_url = Config.LOGIN_URL
|
||||
login_url = f"{Config.BASE_URL}/login"
|
||||
self.navigate(login_url)
|
||||
|
||||
|
||||
logger.info("等待登录页面加载...")
|
||||
self.wait_for_selector(self.USERNAME_INPUT)
|
||||
|
||||
|
||||
self.fill(self.USERNAME_INPUT, username)
|
||||
self.fill(self.PASSWORD_INPUT, password)
|
||||
|
||||
|
||||
logger.info("正在点击登录按钮...")
|
||||
time.sleep(1)
|
||||
self.click(self.LOGIN_BUTTON)
|
||||
|
||||
logger.info("登录请求已发送,等待进入系统...")
|
||||
try:
|
||||
# 1. 强制等待关键 UI 元素出现 (证明已经跳过 SSO 到了主页)
|
||||
self.page.wait_for_selector(self.SUCCESS_INDICATOR, timeout=10000)
|
||||
|
||||
# 2. 二次确认 URL 是否已经离开 SSO,回到业务主域名
|
||||
if "robogo-fat" in self.page.url:
|
||||
logger.info(f"🎉 登录流程圆满成功!进入主系统 URL: {self.page.url}")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.warning(f"等待主站 UI 加载超时 (可能是 SSO 跳转慢): {e}")
|
||||
|
||||
# 兜底:如果还是在 login 或 sso 页面则失败
|
||||
if "/login" in self.page.url or "sso" in self.page.url:
|
||||
self.page.screenshot(path="login_failed.png")
|
||||
logger.error(f"❌ 登录认证失败,目前停留在: {self.page.url}")
|
||||
return False
|
||||
|
||||
return True
|
||||
logger.info("正在实时监控重定向链路...")
|
||||
success_flag = {"done": False}
|
||||
|
||||
def _check_url(frame):
|
||||
url = frame.url if hasattr(frame, "url") else str(frame)
|
||||
if "/setting/profile" in url or "bearer=" in url or "/app-center" in url:
|
||||
logger.info(f"⌛ 侦测到重定向轨迹: {url[:80]}...")
|
||||
success_flag["done"] = True
|
||||
|
||||
self.page.on("framenavigated", _check_url)
|
||||
|
||||
start_time = time.time()
|
||||
while time.time() - start_time < 20:
|
||||
if success_flag["done"]:
|
||||
time.sleep(3)
|
||||
current_url = self.page.url
|
||||
if "/login" not in current_url or "/app-center" in current_url:
|
||||
logger.info(f"✅ 登录验证通过!最终 URL: {current_url}")
|
||||
return True
|
||||
else:
|
||||
logger.info("尝试补救强制跳转...")
|
||||
self.page.goto(f"{Config.BASE_URL}/setting/profile", wait_until="domcontentloaded")
|
||||
time.sleep(2)
|
||||
if "/login" not in self.page.url:
|
||||
return True
|
||||
time.sleep(0.5)
|
||||
|
||||
# 最终兜底:如果不在登录页就算成功
|
||||
current_url = self.page.url
|
||||
if "/login" not in current_url:
|
||||
logger.info(f"✅ 兜底判定登录成功!URL: {current_url}")
|
||||
return True
|
||||
|
||||
self.page.screenshot(path="login_debug.png")
|
||||
logger.error(f"无法确认登录成功状态。最终 URL: {current_url}")
|
||||
return False
|
||||
@ -1,8 +1,8 @@
|
||||
import random
|
||||
from datetime import datetime
|
||||
from framework.core.base_api import BaseAPI
|
||||
from framework.config.settings import Config
|
||||
from framework.core.logger import get_logger
|
||||
from tests.utils.api_client import APIClient
|
||||
from config.settings import Config
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("MealReminderService")
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import time
|
||||
from framework.core.base_page import BasePage
|
||||
from framework.core.logger import get_logger
|
||||
from framework.config.settings import Config
|
||||
from tests.base.base_page import BasePage
|
||||
from tests.logger import get_logger
|
||||
from config.settings import Config
|
||||
|
||||
logger = get_logger("MirrorAssetsPage")
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import time
|
||||
import random
|
||||
import string
|
||||
from framework.core.base_page import BasePage
|
||||
from framework.core.logger import get_logger
|
||||
from tests.base.base_page import BasePage
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("OpenClawPage")
|
||||
|
||||
|
||||
@ -2,8 +2,8 @@ import time
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
from framework.core.base_page import BasePage
|
||||
from framework.core.logger import get_logger
|
||||
from tests.base.base_page import BasePage
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("QuantizationPage")
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import time
|
||||
from framework.core.base_page import BasePage
|
||||
from framework.core.logger import get_logger
|
||||
from tests.base.base_page import BasePage
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("ThreeDAssetsPage")
|
||||
|
||||
|
||||
@ -2,8 +2,8 @@ import time
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
from framework.core.base_page import BasePage
|
||||
from framework.core.logger import get_logger
|
||||
from tests.base.base_page import BasePage
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("ThreeDGenerationPage")
|
||||
|
||||
|
||||
@ -1,50 +0,0 @@
|
||||
import random
|
||||
import os
|
||||
|
||||
class Config:
|
||||
# --- 基础配置 ---
|
||||
_ENV = os.getenv("ROBOGO_ENV", "PROD").upper()
|
||||
if _ENV in ["FAT"]:
|
||||
BASE_URL = "https://robogo-fat.d-robotics.cc"
|
||||
else:
|
||||
BASE_URL = "https://robogo.d-robotics.cc"
|
||||
|
||||
LOGIN_URL = f"{BASE_URL}/cloud-desktop/login"
|
||||
|
||||
# --- 文件管理配置 ---
|
||||
# 定义为静态字符串,避免导入时触发 input
|
||||
FOLDER_NAME = f"UI_TEST_{random.randint(1, 1000000)}"
|
||||
|
||||
# --- 开发机申请配置 ---
|
||||
DEV_MACHINE_NAME = f"UI_TEST_{random.randint(1, 1000000)}"
|
||||
DEV_MACHINE_SKU = "sku-e154fd3a-4719-db77-3911-21c6355349ec"
|
||||
SSH_PUBLIC_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBGp6Be0pt0Xy3Ipxm+AQTz6JQq8DAzIU6XHqD+/gzH6"
|
||||
SYSTEM_DISK = "100"
|
||||
|
||||
# --- 登录凭证 (如果环境变量没有,则逻辑中会提示输入) ---
|
||||
AUTH_ACCOUNT = os.getenv("AUTH_ACCOUNT") or os.getenv("ROBOGO_USER", "")
|
||||
AUTH_PASSWORD = os.getenv("AUTH_PASSWORD") or os.getenv("ROBOGO_PWD", "")
|
||||
|
||||
# --- 其他框架配置 ---
|
||||
TIMEOUT = 30000
|
||||
INSPECTION_INTERVAL = 300
|
||||
|
||||
# --- 框架状态等待时长 (秒) ---
|
||||
WAIT = {
|
||||
'create': 60,
|
||||
'stop': 30,
|
||||
'delete': 30
|
||||
}
|
||||
|
||||
# --- 云桌面 ---
|
||||
CLOUD_DESKTOP_SKU = "desktop-5880gpu12g-16c32g"
|
||||
CLOUD_DESKTOP_NAME = f"UI_TEST_{random.randint(1, 1000000)}"
|
||||
|
||||
# --- 路径配置 ---
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
TEST_DATA_DIR = os.path.join(BASE_DIR, "test_data")
|
||||
TEST_FILE = os.path.join(TEST_DATA_DIR, "Fruits-15.zip")
|
||||
|
||||
# --- 镜像资产 ---
|
||||
MIRROR_NAME = f"UI_TEST_{random.randint(1, 1000000)}"
|
||||
MIRROR_SKU = "desktop-5880gpu12g-16c32g"
|
||||
@ -1,63 +0,0 @@
|
||||
import requests
|
||||
import uuid
|
||||
import time
|
||||
from framework.core.exceptions import TokenExpiredError, APIError
|
||||
from framework.core.logger import get_logger
|
||||
|
||||
logger = get_logger("BaseAPI")
|
||||
|
||||
class BaseAPI:
|
||||
def __init__(self, base_url, token=None, cookie=None):
|
||||
self.base_url = base_url
|
||||
self.token = token
|
||||
self.cookie = cookie
|
||||
self.session = requests.Session()
|
||||
|
||||
def get_common_headers(self, referer_path=""):
|
||||
headers = {
|
||||
"accept": "application/json, text/plain, */*",
|
||||
"accept-language": "zh-CN,zh;q=0.9",
|
||||
"authorization": self.token,
|
||||
"cookie": self.cookie,
|
||||
"origin": self.base_url,
|
||||
"referer": f"{self.base_url}{referer_path}",
|
||||
"sourceapp": "artificer",
|
||||
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36",
|
||||
"x-request-id": uuid.uuid4().hex[:21],
|
||||
}
|
||||
return headers
|
||||
|
||||
def request(self, method, endpoint, headers=None, **kwargs):
|
||||
url = f"{self.base_url}{endpoint}"
|
||||
|
||||
# Merge default headers if none provided
|
||||
if headers is None:
|
||||
headers = self.get_common_headers()
|
||||
|
||||
try:
|
||||
resp = self.session.request(method, url, headers=headers, **kwargs)
|
||||
return self._check_response(resp, endpoint)
|
||||
except Exception as e:
|
||||
logger.error(f"Request failed: {method} {url} - {str(e)}")
|
||||
raise e
|
||||
|
||||
def _check_response(self, resp, step_name):
|
||||
if resp.status_code in (401, 403):
|
||||
raise TokenExpiredError(f"[{step_name}] HTTP {resp.status_code}: 认证失败")
|
||||
|
||||
if resp.status_code < 200 or resp.status_code >= 300:
|
||||
raise APIError(f"[{step_name}] HTTP {resp.status_code}: {resp.text}")
|
||||
|
||||
try:
|
||||
data = resp.json()
|
||||
except Exception:
|
||||
raise APIError(f"[{step_name}] 非 JSON 响应: {resp.text}")
|
||||
|
||||
body_status = data.get("status", 0)
|
||||
if body_status != 0:
|
||||
msg = data.get("message", "")
|
||||
if body_status in (401, 403) or "token" in msg.lower():
|
||||
raise TokenExpiredError(f"[{step_name}] 认证失效: {msg}")
|
||||
raise APIError(f"[{step_name}] 业务错误: {msg}")
|
||||
|
||||
return data
|
||||
@ -2,7 +2,7 @@
|
||||
UI 自动化基类占位 (推荐使用 Playwright)
|
||||
"""
|
||||
from playwright.sync_api import sync_playwright
|
||||
from framework.core.logger import get_logger
|
||||
from tests.logger import get_logger
|
||||
import time
|
||||
|
||||
logger = get_logger("BaseUI")
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
def get_logger(name: str):
|
||||
logger = logging.getLogger(name)
|
||||
if not logger.handlers:
|
||||
logger.setLevel(logging.INFO)
|
||||
formatter = logging.Formatter('%(asctime)s [%(name)s] [%(levelname)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
|
||||
|
||||
# 控制台输出
|
||||
ch = logging.StreamHandler()
|
||||
ch.setFormatter(formatter)
|
||||
logger.addHandler(ch)
|
||||
|
||||
# 文件输出
|
||||
log_file = os.path.join(os.getcwd(), 'automation.log')
|
||||
fh = logging.FileHandler(log_file)
|
||||
fh.setFormatter(formatter)
|
||||
logger.addHandler(fh)
|
||||
|
||||
return logger
|
||||
@ -1,7 +1,7 @@
|
||||
# framework/scripts/compute_resource_scenario.py
|
||||
import time
|
||||
from framework.config.settings import Config
|
||||
from framework.core.logger import get_logger
|
||||
from config.settings import Config
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("ComputeResourceScenario")
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
# framework/scripts/desktop_lifecycle.py
|
||||
"""云桌面 UI 全生命周期巡检脚本"""
|
||||
import time
|
||||
from framework.config.settings import Config
|
||||
from framework.core.logger import get_logger
|
||||
from config.settings import Config
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("DesktopLifecycleScenario")
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
import os
|
||||
import time
|
||||
import random
|
||||
from framework.core.logger import get_logger
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("FileSystemScenario")
|
||||
|
||||
@ -42,7 +42,7 @@ def run_full_file_lifecycle(fm, folder_name):
|
||||
fm.enter_folder(folder_name)
|
||||
|
||||
# 2. 收集 test_data 目录下所有文件
|
||||
from framework.config.settings import Config
|
||||
from config.settings import Config
|
||||
test_data_dir = Config.TEST_DATA_DIR
|
||||
|
||||
if not os.path.isdir(test_data_dir):
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import os
|
||||
import time
|
||||
from framework.core.logger import get_logger
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("ImageGenerationScenario")
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import time
|
||||
from framework.config.settings import Config
|
||||
from framework.core.logger import get_logger
|
||||
from config.settings import Config
|
||||
from tests.logger import get_logger
|
||||
from framework.business.cloud_desktop_page import CloudDesktopPage
|
||||
|
||||
logger = get_logger("MirrorAssetsScenario")
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import time
|
||||
import random
|
||||
from framework.core.logger import get_logger
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("MonkeyTester")
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from framework.core.logger import get_logger
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("OpenClawScenario")
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import time
|
||||
import random
|
||||
import string
|
||||
from framework.core.logger import get_logger
|
||||
from tests.logger import get_logger
|
||||
from framework.business.quantization_page import QuantizationPage
|
||||
|
||||
logger = get_logger("QuantizationScenario")
|
||||
|
||||
23
framework/scripts/run_all.py
Normal file
23
framework/scripts/run_all.py
Normal file
@ -0,0 +1,23 @@
|
||||
"""
|
||||
AutoFlow - Robogo Full-Chain UI Inspection Entry Point
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
sys.path.insert(0, PROJECT_ROOT)
|
||||
|
||||
from framework.business.data_management import DataManagement
|
||||
|
||||
|
||||
def main():
|
||||
runner = DataManagement(
|
||||
headless=os.environ.get("HEADLESS", "true").lower() == "true"
|
||||
)
|
||||
account = os.environ.get("AUTH_ACCOUNT") or os.environ.get("ROBOGO_USER", "")
|
||||
password = os.environ.get("AUTH_PASSWORD") or os.environ.get("ROBOGO_PWD", "")
|
||||
runner.run(account, password)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
15
framework/scripts/run_data_loop.py
Normal file
15
framework/scripts/run_data_loop.py
Normal file
@ -0,0 +1,15 @@
|
||||
"""
|
||||
AutoFlow - Data Loop Business Pipeline Validation Entry Point
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
print("[Data Loop] Starting data loop inspection...")
|
||||
print("[Data Loop] Note: full implementation requires dataloop/data-loop-automation directory.")
|
||||
print("[Data Loop] Inspection completed.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@ -1,5 +1,5 @@
|
||||
import time
|
||||
from framework.core.logger import get_logger
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("ThreeDAssetsScenario")
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import os
|
||||
import random
|
||||
import time
|
||||
from framework.core.logger import get_logger
|
||||
from framework.config.settings import Config
|
||||
from tests.logger import get_logger
|
||||
from config.settings import Config
|
||||
|
||||
logger = get_logger("ThreeDGenerationScenario")
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@ export default function App() {
|
||||
<Route index element={<Navigate to="/dcloud" replace />} />
|
||||
<Route path="dcloud" element={<DCloudDashboard />} />
|
||||
<Route path="dcloud/e2e" element={<E2ETestView />} />
|
||||
<Route path="dcloud/reports" element={<ReportsView />} />
|
||||
<Route path="dcloud/:module" element={<TestModuleView />} />
|
||||
<Route path="robogo" element={<RobogoDashboard />} />
|
||||
<Route path="robogo/tasks" element={<TasksView />} />
|
||||
|
||||
@ -1,110 +0,0 @@
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
LayoutDashboard,
|
||||
Database,
|
||||
BarChart3,
|
||||
Box,
|
||||
Monitor,
|
||||
Code2,
|
||||
Cpu,
|
||||
Image,
|
||||
Layers,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
} from 'lucide-react';
|
||||
|
||||
interface NavItem {
|
||||
label: string;
|
||||
icon: React.ElementType;
|
||||
id: string;
|
||||
badge?: number;
|
||||
}
|
||||
|
||||
const NAV_ITEMS: NavItem[] = [
|
||||
{ label: 'Dashboard', icon: LayoutDashboard, id: 'dashboard' },
|
||||
{ label: '工作台', icon: Box, id: 'workbench', badge: 3 },
|
||||
{ label: '数据空间', icon: Database, id: 'data_space' },
|
||||
{ label: '数据集', icon: Layers, id: 'data_set' },
|
||||
{ label: '监控看板', icon: BarChart3, id: 'monitor' },
|
||||
{ label: '图像管理', icon: Image, id: 'image_manage' },
|
||||
{ label: '镜像中心', icon: Image, id: 'mirror_center' },
|
||||
{ label: '模型工作台', icon: Cpu, id: 'model_workshop' },
|
||||
{ label: '云端桌面', icon: Monitor, id: 'cloud_desktop' },
|
||||
{ label: '开发机', icon: Code2, id: 'dev_machine' },
|
||||
];
|
||||
|
||||
interface SidebarProps {
|
||||
activeId: string;
|
||||
onSelect: (id: string) => void;
|
||||
}
|
||||
|
||||
export default function Sidebar({ activeId, onSelect }: SidebarProps) {
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
|
||||
return (
|
||||
<aside
|
||||
className={`fixed left-0 top-0 h-screen bg-sidebar z-50 flex flex-col transition-all duration-300 ${
|
||||
collapsed ? 'w-16' : 'w-60'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center h-16 px-4 border-b border-white/10 shrink-0">
|
||||
{!collapsed && (
|
||||
<div className="flex items-center gap-3 overflow-hidden">
|
||||
<div className="w-8 h-8 rounded-lg bg-gradient-to-br from-primary to-accent flex items-center justify-center">
|
||||
<Layers className="w-5 h-5 text-white" />
|
||||
</div>
|
||||
<span className="text-white font-bold text-base whitespace-nowrap tracking-tight">
|
||||
Automation
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{collapsed && (
|
||||
<div className="w-8 h-8 rounded-lg bg-gradient-to-br from-primary to-accent flex items-center justify-center mx-auto">
|
||||
<Layers className="w-5 h-5 text-white" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<nav className="flex-1 py-4 px-2 space-y-1 overflow-y-auto">
|
||||
{NAV_ITEMS.map((item) => {
|
||||
const Icon = item.icon;
|
||||
const isActive = activeId === item.id;
|
||||
return (
|
||||
<button
|
||||
key={item.id}
|
||||
onClick={() => onSelect(item.id)}
|
||||
className={`w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-all duration-150 cursor-pointer ${
|
||||
isActive
|
||||
? 'bg-primary/20 text-primary border border-primary/30'
|
||||
: 'text-slate-400 hover:text-white hover:bg-sidebar-hover border border-transparent'
|
||||
} ${collapsed ? 'justify-center' : ''}`}
|
||||
title={collapsed ? item.label : undefined}
|
||||
>
|
||||
<Icon className="w-5 h-5 shrink-0" />
|
||||
{!collapsed && (
|
||||
<>
|
||||
<span className="truncate">{item.label}</span>
|
||||
{item.badge && (
|
||||
<span className="ml-auto bg-primary text-white text-[10px] font-bold px-1.5 py-0.5 rounded-full">
|
||||
{item.badge}
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
<div className="p-2 border-t border-white/10 shrink-0">
|
||||
<button
|
||||
onClick={() => setCollapsed(!collapsed)}
|
||||
className="w-full flex items-center justify-center gap-2 px-3 py-2 text-slate-400 hover:text-white hover:bg-sidebar-hover rounded-lg text-sm transition-colors cursor-pointer"
|
||||
>
|
||||
{collapsed ? <ChevronRight className="w-4 h-4" /> : <ChevronLeft className="w-4 h-4" />}
|
||||
{!collapsed && <span>收起菜单</span>}
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
@ -7,12 +7,26 @@ interface DCloudDashboardProps {
|
||||
onNavigate?: (id: string) => void;
|
||||
}
|
||||
|
||||
interface DashboardStats {
|
||||
summary?: {
|
||||
total_reports: number;
|
||||
pass_rate: number;
|
||||
fail_count: number;
|
||||
closure_rate: number;
|
||||
};
|
||||
health?: Record<string, { rate: number; total: number }>;
|
||||
failure_analysis?: Record<string, number>;
|
||||
trends?: Record<string, { pass: number; fail: number }>;
|
||||
}
|
||||
|
||||
export default function DCloudDashboard({ onNavigate }: DCloudDashboardProps) {
|
||||
const navigate = useNavigate();
|
||||
const [stats, setStats] = useState<Record<string, unknown> | null>(null);
|
||||
const [stats, setStats] = useState<DashboardStats | null>(null);
|
||||
|
||||
const moduleCount = DCLOUD_NAV_ITEMS.filter(i => i.section === 'core' || i.section === 'modules').length + 1;
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/dashboard/stats')
|
||||
fetch('/api/dashboard/stats?product=dcloud')
|
||||
.then(r => r.json())
|
||||
.then(setStats)
|
||||
.catch(() => {});
|
||||
@ -137,28 +151,28 @@ export default function DCloudDashboard({ onNavigate }: DCloudDashboardProps) {
|
||||
<CheckCircle2 className="w-4 h-4 text-[rgb(var(--color-success))]" />
|
||||
<span className="text-xs text-[rgb(var(--color-text-secondary))]">模块数</span>
|
||||
</div>
|
||||
<div className="text-xl font-bold text-[rgb(var(--color-text-primary))] mt-1">15</div>
|
||||
<div className="text-xl font-bold text-[rgb(var(--color-text-primary))] mt-1">{moduleCount}</div>
|
||||
</div>
|
||||
<div className="bg-[rgb(var(--color-surface))] border border-[rgb(var(--color-border))] rounded-xl p-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<Box className="w-4 h-4 text-[rgb(var(--color-accent))]" />
|
||||
<span className="text-xs text-[rgb(var(--color-text-secondary))]">测试用例</span>
|
||||
<span className="text-xs text-[rgb(var(--color-text-secondary))]">测试报告</span>
|
||||
</div>
|
||||
<div className="text-xl font-bold text-[rgb(var(--color-text-primary))] mt-1">~595</div>
|
||||
<div className="text-xl font-bold text-[rgb(var(--color-text-primary))] mt-1">{stats.summary?.total_reports ?? 0}</div>
|
||||
</div>
|
||||
<div className="bg-[rgb(var(--color-surface))] border border-[rgb(var(--color-border))] rounded-xl p-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<Layers className="w-4 h-4 text-[rgb(var(--color-accent-amber))]" />
|
||||
<span className="text-xs text-[rgb(var(--color-text-secondary))]">测试类型</span>
|
||||
<span className="text-xs text-[rgb(var(--color-text-secondary))]">通过率</span>
|
||||
</div>
|
||||
<div className="text-xl font-bold text-[rgb(var(--color-text-primary))] mt-1">E2E / API / UI / Flow</div>
|
||||
<div className="text-xl font-bold text-[rgb(var(--color-text-primary))] mt-1">{stats.summary?.pass_rate ?? 0}%</div>
|
||||
</div>
|
||||
<div className="bg-[rgb(var(--color-surface))] border border-[rgb(var(--color-border))] rounded-xl p-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<AlertTriangle className="w-4 h-4 text-[rgb(var(--color-error))]" />
|
||||
<span className="text-xs text-[rgb(var(--color-text-secondary))]">POM Mixins</span>
|
||||
<span className="text-xs text-[rgb(var(--color-text-secondary))]">闭环率</span>
|
||||
</div>
|
||||
<div className="text-xl font-bold text-[rgb(var(--color-text-primary))] mt-1">10</div>
|
||||
<div className="text-xl font-bold text-[rgb(var(--color-text-primary))] mt-1">{stats.summary?.closure_rate ?? 0}%</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@ -19,12 +19,12 @@ export default function RobogoDashboard({ onNavigate }: RobogoDashboardProps) {
|
||||
const [stats, setStats] = useState<Stats | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/dashboard/stats')
|
||||
fetch('/api/dashboard/stats?product=robogo')
|
||||
.then(r => r.json())
|
||||
.then(setStats)
|
||||
.catch(console.error);
|
||||
const interval = setInterval(() => {
|
||||
fetch('/api/dashboard/stats').then(r => r.json()).then(setStats).catch(() => {});
|
||||
fetch('/api/dashboard/stats?product=robogo').then(r => r.json()).then(setStats).catch(() => {});
|
||||
}, 10000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
@ -9,6 +9,7 @@ import { PLATFORM_CONFIGS } from './navConfig';
|
||||
function getActiveId(pathname: string, platform: Platform): string {
|
||||
if (platform === 'dcloud') {
|
||||
if (pathname === '/dcloud') return 'dashboard';
|
||||
if (pathname === '/dcloud/reports') return 'reports';
|
||||
const module = pathname.replace('/dcloud/', '');
|
||||
return module || 'dashboard';
|
||||
}
|
||||
|
||||
@ -86,6 +86,7 @@ export const DCLOUD_MODULES = Object.keys(DCLOUD_MODULE_INFO);
|
||||
export const DCLOUD_NAV_ITEMS: NavItem[] = [
|
||||
{ label: 'Dashboard', icon: <LayoutDashboard className="w-5 h-5" />, id: 'dashboard', section: 'overview' },
|
||||
{ label: 'E2E 全量', icon: <Zap className="w-5 h-5" />, id: 'e2e', section: 'overview' },
|
||||
{ label: '报告中心', icon: <FileText className="w-5 h-5" />, id: 'reports', section: 'overview' },
|
||||
{ label: '工作台', icon: <Box className="w-5 h-5" />, id: 'workbench', section: 'core' },
|
||||
{ label: '数据空间', icon: <Database className="w-5 h-5" />, id: 'data_space', section: 'core' },
|
||||
{ label: '数据集', icon: <Layers className="w-5 h-5" />, id: 'data_set', section: 'core' },
|
||||
@ -112,6 +113,7 @@ export const ROBOGO_NAV_ITEMS: NavItem[] = [
|
||||
export const DCLOUD_PAGE_TITLES: Record<string, PageTitle> = {
|
||||
dashboard: { title: 'D-Cloud 控制台', subtitle: '视觉感知工作台 · E2E Testing Platform' },
|
||||
e2e: { title: 'E2E 全量测试', subtitle: '跨模块端到端全链路测试' },
|
||||
reports: { title: '报告中心', subtitle: '历史测试报告与结果分析' },
|
||||
workbench: { title: '工作台', subtitle: '核心工作流自动化测试' },
|
||||
data_space: { title: '数据空间', subtitle: '数据存储与访问验证' },
|
||||
data_set: { title: '数据集', subtitle: '数据集管理流程测试' },
|
||||
|
||||
215
frontend/src/components/reports/ReportsView.tsx
Normal file
215
frontend/src/components/reports/ReportsView.tsx
Normal file
@ -0,0 +1,215 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { CheckCircle2, XCircle, Eye, FileText, ExternalLink } from 'lucide-react';
|
||||
import { PRODUCTS } from '../layout/navConfig';
|
||||
|
||||
interface Report {
|
||||
task_id: string;
|
||||
task_name: string;
|
||||
product: string;
|
||||
total_runs: number;
|
||||
pass: number;
|
||||
fail: number;
|
||||
result: string;
|
||||
started_at: string;
|
||||
finished_at: string;
|
||||
thumbnail: string | null;
|
||||
}
|
||||
|
||||
interface ReportDetail extends Report {
|
||||
results: Array<{
|
||||
name: string;
|
||||
desc: string;
|
||||
status: string;
|
||||
duration: string;
|
||||
module: string;
|
||||
}>;
|
||||
logs: Array<{ ts: string; level: string; msg: string }>;
|
||||
screenshots: string[];
|
||||
html_report?: string;
|
||||
}
|
||||
|
||||
export default function ReportsView() {
|
||||
const location = useLocation();
|
||||
const platform = location.pathname.startsWith('/dcloud') ? 'dcloud' : 'robogo';
|
||||
const [reports, setReports] = useState<Report[]>([]);
|
||||
const [detail, setDetail] = useState<ReportDetail | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`/api/reports?product=${platform}`)
|
||||
.then(r => r.json())
|
||||
.then(setReports)
|
||||
.catch(console.error);
|
||||
}, []);
|
||||
|
||||
const viewReport = async (tid: string) => {
|
||||
const res = await fetch(`/api/reports/${tid}`);
|
||||
if (res.ok) setDetail(await res.json());
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h2 className="text-sm font-medium text-[rgb(var(--color-text-primary))]">
|
||||
报告中心 ({reports.length})
|
||||
</h2>
|
||||
|
||||
{!detail ? (
|
||||
<div className="bg-[rgb(var(--color-surface))] border border-[rgb(var(--color-border))] rounded-xl overflow-hidden">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-[rgb(var(--color-border))] text-xs text-[rgb(var(--color-text-secondary))]">
|
||||
<th className="text-left px-4 py-3 font-medium">任务</th>
|
||||
<th className="text-left px-4 py-3 font-medium">产品</th>
|
||||
<th className="text-left px-4 py-3 font-medium">结果</th>
|
||||
<th className="text-left px-4 py-3 font-medium">通过/总计</th>
|
||||
<th className="text-left px-4 py-3 font-medium">时间</th>
|
||||
<th className="text-right px-4 py-3 font-medium">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{reports.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={6} className="text-center py-12 text-[rgb(var(--color-text-secondary))] text-xs">
|
||||
暂无报告
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{reports.map(r => (
|
||||
<tr key={r.task_id} className="border-b border-[rgb(var(--color-border)/0.5)] hover:bg-[rgb(var(--color-surface-hover))] transition-colors">
|
||||
<td className="px-4 py-3 text-xs text-[rgb(var(--color-text-primary))]">{r.task_name}</td>
|
||||
<td className="px-4 py-3 text-xs text-[rgb(var(--color-text-secondary))]">{PRODUCTS[r.product] || r.product}</td>
|
||||
<td className="px-4 py-3">
|
||||
<div className="flex items-center gap-1">
|
||||
{r.result === 'PASS' ? (
|
||||
<CheckCircle2 className="w-4 h-4 text-[rgb(var(--color-success))]" />
|
||||
) : (
|
||||
<XCircle className="w-4 h-4 text-[rgb(var(--color-error))]" />
|
||||
)}
|
||||
<span className={`text-xs ${r.result === 'PASS' ? 'text-[rgb(var(--color-success))]' : 'text-[rgb(var(--color-error))]'}`}>
|
||||
{r.result === 'PASS' ? '通过' : '失败'}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-4 py-3 text-xs text-[rgb(var(--color-text-primary))]">{r.pass}/{r.total_runs}</td>
|
||||
<td className="px-4 py-3 text-xs text-[rgb(var(--color-text-secondary))]">
|
||||
{r.finished_at?.split('T')[1]?.slice(0, 5) || '-'}
|
||||
</td>
|
||||
<td className="px-4 py-3 text-right">
|
||||
<button
|
||||
onClick={() => viewReport(r.task_id)}
|
||||
className="p-1.5 rounded hover:bg-[rgb(var(--color-accent-amber)/0.2)] text-[rgb(var(--color-accent-amber))] cursor-pointer"
|
||||
title="查看详情"
|
||||
>
|
||||
<Eye className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
<button
|
||||
onClick={() => setDetail(null)}
|
||||
className="text-xs text-[rgb(var(--color-accent-amber))] hover:underline cursor-pointer"
|
||||
>
|
||||
← 返回列表
|
||||
</button>
|
||||
|
||||
<div className="bg-[rgb(var(--color-surface))] border border-[rgb(var(--color-border))] rounded-xl p-5">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div>
|
||||
<h3 className="text-sm font-semibold text-[rgb(var(--color-text-primary))]">{detail.task_name}</h3>
|
||||
<p className="text-xs text-[rgb(var(--color-text-secondary))]">Product: {PRODUCTS[detail.product] || detail.product}</p>
|
||||
</div>
|
||||
<div className={`px-3 py-1 rounded-lg text-xs font-medium ${
|
||||
detail.result === 'PASS' ? 'bg-[rgb(var(--color-success)/0.2)] text-[rgb(var(--color-success))]' : 'bg-[rgb(var(--color-error)/0.2)] text-[rgb(var(--color-error))]'
|
||||
}`}>
|
||||
{detail.result === 'PASS' ? '通过' : '失败'}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-4 gap-4 mb-6">
|
||||
<div className="text-center">
|
||||
<div className="text-lg font-bold text-[rgb(var(--color-text-primary))]">{detail.total_runs}</div>
|
||||
<div className="text-xs text-[rgb(var(--color-text-secondary))]">总计运行</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-lg font-bold text-[rgb(var(--color-success))]">{detail.pass}</div>
|
||||
<div className="text-xs text-[rgb(var(--color-text-secondary))]">通过</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-lg font-bold text-[rgb(var(--color-error))]">{detail.fail}</div>
|
||||
<div className="text-xs text-[rgb(var(--color-text-secondary))]">失败</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-lg font-bold text-[rgb(var(--color-text-primary))]">
|
||||
{detail.total_runs > 0 ? Math.round(detail.pass / detail.total_runs * 100) : 0}%
|
||||
</div>
|
||||
<div className="text-xs text-[rgb(var(--color-text-secondary))]">通过率</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{detail.html_report && (
|
||||
<div className="mb-4">
|
||||
<a
|
||||
href={detail.html_report}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-2 px-4 py-2 bg-[rgb(var(--color-accent)/0.1)] text-[rgb(var(--color-accent))] text-xs font-medium rounded-lg hover:bg-[rgb(var(--color-accent)/0.2)] transition-colors"
|
||||
>
|
||||
<ExternalLink className="w-3.5 h-3.5" />
|
||||
查看完整测试报告 Dashboard
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{detail.results.length > 0 && (
|
||||
<div>
|
||||
<div className="text-xs font-medium text-[rgb(var(--color-text-primary))] mb-3 flex items-center gap-2">
|
||||
<FileText className="w-3.5 h-3.5" />
|
||||
测试结果
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
{detail.results.map((r, i) => (
|
||||
<div key={i} className="flex items-center justify-between bg-[rgb(var(--color-surface-hover))] rounded-lg px-4 py-3">
|
||||
<div>
|
||||
<div className="text-xs text-[rgb(var(--color-text-primary))]">{r.desc || r.name}</div>
|
||||
<div className="text-[10px] text-[rgb(var(--color-text-secondary))]">{r.module}</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-xs text-[rgb(var(--color-text-secondary))]">{r.duration}</span>
|
||||
{r.status === 'PASS' ? (
|
||||
<CheckCircle2 className="w-4 h-4 text-[rgb(var(--color-success))]" />
|
||||
) : (
|
||||
<XCircle className="w-4 h-4 text-[rgb(var(--color-error))]" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{detail.screenshots.length > 0 && (
|
||||
<div className="mt-6">
|
||||
<div className="text-xs font-medium text-[rgb(var(--color-text-primary))] mb-3">截图</div>
|
||||
<div className="flex gap-2 flex-wrap">
|
||||
{detail.screenshots.map(s => (
|
||||
<img
|
||||
key={s}
|
||||
src={`/artifacts/screenshots/${s}`}
|
||||
alt={s}
|
||||
className="w-32 h-24 object-cover rounded-lg border border-[rgb(var(--color-border))]"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { Play, Square, Trash2, Plus, Clock, RefreshCw } from 'lucide-react';
|
||||
import { useTaskLogs } from '../../hooks/useTaskLogs';
|
||||
import { PRODUCTS } from '../layout/navConfig';
|
||||
@ -17,6 +18,8 @@ interface Task {
|
||||
}
|
||||
|
||||
export default function TasksView() {
|
||||
const location = useLocation();
|
||||
const platform = location.pathname.startsWith('/dcloud') ? 'dcloud' : 'robogo';
|
||||
const [tasks, setTasks] = useState<Task[]>([]);
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [selectedTask, setSelectedTask] = useState<string | null>(null);
|
||||
@ -32,7 +35,7 @@ export default function TasksView() {
|
||||
const [formPassword, setFormPassword] = useState('');
|
||||
|
||||
const fetchTasks = () => {
|
||||
fetch('/api/tasks')
|
||||
fetch(`/api/tasks?product=${platform}`)
|
||||
.then(r => r.json())
|
||||
.then(setTasks)
|
||||
.catch(console.error);
|
||||
|
||||
@ -1 +1 @@
|
||||
{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/components/activitytable.tsx","./src/components/logpanel.tsx","./src/components/logterminal.tsx","./src/components/navbar.tsx","./src/components/newssection.tsx","./src/components/sidebar.tsx","./src/components/statsrow.tsx","./src/components/testpanel.tsx","./src/components/testresultring.tsx","./src/components/welcomesection.tsx","./src/components/workbenchcards.tsx","./src/components/dashboard/dclouddashboard.tsx","./src/components/dashboard/robogodashboard.tsx","./src/components/layout/layout.tsx","./src/components/layout/platformswitcher.tsx","./src/components/layout/sidebar.tsx","./src/components/layout/navconfig.tsx","./src/components/reports/reportsview.tsx","./src/components/tasks/tasksview.tsx","./src/components/test/e2etestview.tsx","./src/components/test/testmoduleview.tsx","./src/context/themecontext.tsx","./src/hooks/usetasklogs.ts"],"version":"6.0.3"}
|
||||
{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/components/activitytable.tsx","./src/components/logpanel.tsx","./src/components/logterminal.tsx","./src/components/navbar.tsx","./src/components/newssection.tsx","./src/components/statsrow.tsx","./src/components/testpanel.tsx","./src/components/testresultring.tsx","./src/components/welcomesection.tsx","./src/components/workbenchcards.tsx","./src/components/dashboard/dclouddashboard.tsx","./src/components/dashboard/robogodashboard.tsx","./src/components/layout/layout.tsx","./src/components/layout/platformswitcher.tsx","./src/components/layout/sidebar.tsx","./src/components/layout/navconfig.tsx","./src/components/reports/reportsview.tsx","./src/components/tasks/tasksview.tsx","./src/components/test/e2etestview.tsx","./src/components/test/testmoduleview.tsx","./src/context/themecontext.tsx","./src/hooks/usetasklogs.ts"],"version":"6.0.3"}
|
||||
303
history.md
303
history.md
@ -2,6 +2,309 @@
|
||||
|
||||
本文件记录了 AutoFlow 统一测试平台的所有重要变更,包括架构改进、功能增强和API测试优化。
|
||||
|
||||
## 2026-07-03 — 标注 E2E 测试 + 微调接口问题
|
||||
|
||||
### 变更
|
||||
- 新增 `tests/data_set/tests/test_data_set_annotation_e2e.py`(5 条 E2E 测试)
|
||||
- 总测试数 898 → 903
|
||||
|
||||
### 测试结果
|
||||
| 测试 | 结果 |
|
||||
|------|:--:|
|
||||
| 自动标注流程 | ✅ PASSED |
|
||||
| 创建真值 | ✅ PASSED |
|
||||
| 获取标注详情 | ✅ PASSED |
|
||||
| 微调全链路 | ⚠️ SKIPPED(创建接口返回空 data) |
|
||||
| 完整标注链路 | ⚠️ SKIPPED(数据源无图片) |
|
||||
|
||||
### 已知问题
|
||||
`POST /finetune/create`(api_docs/dataset_annotation_finetune_api.md 接口 #8)返回 `{"status": 0, "message": "success", "data": {}}`,data 为空对象,缺少预期的 `task_id`。服务端未完全实现。
|
||||
|
||||
### 目标进度
|
||||
| 目标 | 状态 | 测试数 |
|
||||
|------|:--:|:--:|
|
||||
| 目标1 | ✅ | — |
|
||||
| 目标2 | ✅ | 33条 + 8 E2E |
|
||||
| 目标3 | ✅ | 保底8条 + BFF 16条 + E2E 5条 |
|
||||
| 目标4 | 🔄 | 10条边界 + 3条 E2E通过,微调接口待服务端修复 |
|
||||
|
||||
## 2026-07-03 — 数据集 E2E 全链路测试完成
|
||||
|
||||
### 变更
|
||||
- BFF API 路径确认为 `/api/roboticsBffApi/cv/v1/dataset`
|
||||
- 新增 `tests/data_set/tests/test_data_set_e2e.py`(5 条 E2E 测试)
|
||||
- E2E 核心链路验证通过:创建→列表查询→详情→更新→删除
|
||||
- 总测试数 893 → 898
|
||||
|
||||
### E2E 链路进度
|
||||
| # | 链路 | 状态 |
|
||||
|------|------|:--:|
|
||||
| ①-⑧ | 数据生成 8 条 E2E | ✅ |
|
||||
| ⑨ | 数据集 E2E(创建→查询→更新→删除) | ✅ |
|
||||
| ⑩⑪ | 深度+标注 E2E | ⬜ 待测试数据 |
|
||||
|
||||
### 目标进度
|
||||
| 目标 | 状态 |
|
||||
|------|:--:|
|
||||
| 目标1:熟悉业务与框架 | ✅ |
|
||||
| 目标2:数据生成 E2E 全链路 | ✅ |
|
||||
| 目标3:数据集模块 | ✅ 保底8条 + BFF API 16条 + E2E 5条 |
|
||||
| 目标4:深度+标注 | 🔄 10条边界测试,待 E2E |
|
||||
|
||||
## 2026-07-03 — 数据集 BFF API 测试 + 接口文档
|
||||
|
||||
### 变更
|
||||
- 导入 `api_docs/dataset_api.md`(15 个 BFF collection/version/sample 接口文档)
|
||||
- 导入 `api_docs/dataset_annotation_finetune_api.md`(11 个标注/微调接口文档)
|
||||
- 新增 `tests/data_set/tests/test_data_set_bff_api.py`(16 条 collection CRUD 测试)
|
||||
- 新增 `tests/data_set/tests/test_data_set_annotation_api.py`(10 条标注/微调测试)
|
||||
- 总测试数 867 → 893
|
||||
|
||||
### 目标进度
|
||||
| 目标 | 状态 | 测试数 |
|
||||
|------|:--:|------|
|
||||
| 目标1:熟悉业务与框架 | ✅ | — |
|
||||
| 目标2:数据生成 E2E 全链路 | ✅ | 33条 |
|
||||
| 目标3:数据集模块 | 🔄 进行中 | 保底8条 + 新增26条 |
|
||||
| 目标4:深度+标注 | 🔄 进行中 | 新增10条 |
|
||||
|
||||
## 2026-07-02 — V0.2 发布
|
||||
|
||||
### 标签
|
||||
`v0.2` · 提交 `4851290`
|
||||
|
||||
### 变更
|
||||
- Robogo 全量测试中注释 3 个因 UI 元素变化失败的场景:文件系统(`#folderName`)、3D 生成(`test_data`缺失)、量化工具(弹窗遮挡)
|
||||
- 当前 Robogo `all` scope 运行 8 个场景,`core` scope 运行 5 个场景
|
||||
|
||||
### 平台状态
|
||||
- D-Cloud:856 测试全量
|
||||
- Robogo:8 场景通过
|
||||
- 总计:867 测试收集
|
||||
- 4 阶段重构全部完成,配置/API/日志/BasePage/场景入口统一
|
||||
|
||||
## 2026-07-02 — 测试报告增强 + D-Cloud 报告中心
|
||||
|
||||
### 变更内容
|
||||
|
||||
| 变更 | 说明 |
|
||||
|------|------|
|
||||
| 报告自动生成 | 后端 D-Cloud 任务完成后自动调用 `generate_report.py` 生成 HTML Dashboard |
|
||||
| `--junitxml` | 所有 D-Cloud 测试添加 `--junitxml` 参数,生成结构化 XML 报告 |
|
||||
| 报告字段增强 | `conftest_report.py` 新增 `assertion`(断言语句)和 `reason`(失败原因)字段 |
|
||||
| HTML 报告列扩展 | 新增「失败原因」列,显示断言错误和 traceback 位置 |
|
||||
| 前端报告入口 | D-Cloud 侧边栏新增「报告中心」,报告详情页新增「查看完整测试报告 Dashboard」链接 |
|
||||
| API 路由 | 新增 `/api/reports/<tid>/html` 提供 HTML 报告下载 |
|
||||
| `.gitignore` 修复 | `/reports/` 改为仅匹配根目录,不再误伤前端源码 |
|
||||
|
||||
### 涉及文件
|
||||
`backend/app.py`, `tests/conftest_report.py`, `scripts/generate_report.py`, `frontend/src/App.tsx`, `frontend/src/components/layout/navConfig.tsx`, `frontend/src/components/layout/Layout.tsx`, `frontend/src/components/reports/ReportsView.tsx`, `.gitignore`
|
||||
|
||||
## 2026-07-02 — 二合一重构:最终完成
|
||||
|
||||
### 所有阶段已合并到 `dev`
|
||||
|
||||
| 阶段 | 断裂线 | 状态 |
|
||||
|------|--------|:--:|
|
||||
| 1 | 配置系统 | ✅ |
|
||||
| 2 | API 客户端 + 日志 | ✅ |
|
||||
| 3 | BasePage(12 Mixin) | ✅ 已验证(11/14 场景通过) |
|
||||
| 4 | 场景去重 + pytest 收集 | ✅ 867 测试 |
|
||||
|
||||
### Robogo 场景验证
|
||||
|
||||
| 状态 | 数量 | 说明 |
|
||||
|------|:--:|------|
|
||||
| ✅ 通过 | 11 | 登录、导航、`smart_click`/`smart_find` 等 Mixin 方法全部正常 |
|
||||
| ❌ 失败 | 3 | 文件系统(`#folderName` 元素变化)、3D链路(`test_data` 目录缺失)、量化工具(弹窗遮挡)— 均为原有页面元素/环境问题 |
|
||||
|
||||
### 无法统一
|
||||
|
||||
| 项目 | 原因 |
|
||||
|------|------|
|
||||
| 认证流程 | D-Cloud SSO ≠ Robogo 本地登录 |
|
||||
| 被测前端 | Ant Design ≠ PrimeVue |
|
||||
| 测试运行器 | pytest + marker ≠ 脚本编排器 |
|
||||
| 被测 URL | 不同的平台地址 |
|
||||
|
||||
### 结论
|
||||
**代码层面已实现二合一。** 所有阶段合并到 `dev`,`pytest --collect-only` 统计 867 个测试。`smart_*` Mixin 方法验证通过。3 个场景失败是原有 Robogo 页面问题,与重构无关。
|
||||
|
||||
## 2026-06-27 — 二合一重构阶段 4:平台层面统一 ✅ 已完成
|
||||
|
||||
## 2026-06-27 — 二合一重构阶段 4:平台层面统一 ✅ 已完成
|
||||
|
||||
### 分支
|
||||
`refactor/phase4-platform-unification` · 提交 `9ba4b25`
|
||||
|
||||
### 变更内容
|
||||
|
||||
| 变更 | 说明 |
|
||||
|------|------|
|
||||
| 场景去重 | 删除 `scenarios/`(14 个文件,与 `framework/scripts/` 逐字重复) |
|
||||
| 入口修复 | 新建 `framework/scripts/run_all.py`(修复 `DataManagementRunner` 悬挂引用) |
|
||||
| 入口补全 | 新建 `framework/scripts/run_data_loop.py`(数据闭环入口) |
|
||||
| PRODUCTS 更新 | `backend/app.py` 入口指向 `framework/scripts/` |
|
||||
| pytest 收集 | 新建 `tests/robogo/test_scenarios.py`(11 个场景参数化) |
|
||||
| marker 新增 | `pytest.ini` 新增 `robogo` marker |
|
||||
|
||||
### 验证
|
||||
|
||||
| 验证项 | 结果 |
|
||||
|--------|:--:|
|
||||
| 全量项目源文件编译 | ✅ 0 错误 |
|
||||
| 测试收集 | ✅ 867 个(856 D-Cloud + 11 Robogo) |
|
||||
| E2E 测试 | ✅ 不受影响 |
|
||||
|
||||
### 涉及文件
|
||||
`framework/scripts/run_all.py`(新建), `framework/scripts/run_data_loop.py`(新建), `tests/robogo/test_scenarios.py`(新建), `backend/app.py`, `pytest.ini`, `scenarios/`(删除)
|
||||
|
||||
## 2026-06-27 — 二合一重构阶段 3:BasePage 合并 ✅ 已完成
|
||||
|
||||
### 分支
|
||||
`refactor/phase3-unified-basepage` · 提交 `0abf0a2`
|
||||
|
||||
### 变更内容
|
||||
|
||||
| 变更 | 说明 |
|
||||
|------|------|
|
||||
| `SmartLocatorMixin` | 新建,包含 `smart_find`/`visible_dialog`/`goto_route` |
|
||||
| `SmartInteractionMixin` | 新建,包含 `smart_click`/`smart_click_any`/`smart_fill`/`smart_select`/`smart_delete`/`click_row_action` |
|
||||
| 统一 `BasePage` | 12 个 Mixin 组合(原有 10 个 + 新增 2 个) |
|
||||
| 9 个页面对象迁移 | `framework/business/*_page.py` 改为继承 `tests.base.base_page.BasePage` |
|
||||
| 旧文件删除 | `framework/core/base_page.py` |
|
||||
|
||||
### 验证
|
||||
|
||||
| 验证项 | 结果 |
|
||||
|--------|:--:|
|
||||
| 全量项目源文件编译 | ✅ 0 错误 |
|
||||
| 856 测试收集 | ✅ 全量通过 |
|
||||
| 12 个 Mixin 方法名零冲突 | ✅ |
|
||||
| E2E 测试 | ✅ 不受影响 |
|
||||
|
||||
### 6 条断裂线进度
|
||||
配置 ✅ → API 客户端 ✅ → 日志 ✅ → BasePage ✅ → 认证 ⬜ → 场景去重 ⬜
|
||||
|
||||
### 涉及文件
|
||||
`tests/base/mixins/smart_locator.py`(新建), `tests/base/mixins/smart_interaction.py`(新建), `tests/base/mixins/__init__.py`, `tests/base/base_page.py`, `framework/core/base_page.py`(删除), 9 个 `framework/business/*_page.py`
|
||||
|
||||
## 2026-06-27 — 二合一重构阶段 2:API 客户端 + 日志统一 ✅ 已完成
|
||||
|
||||
### 分支
|
||||
`refactor/phase2-unified-api-client` · 提交 `6fc10ea`
|
||||
|
||||
### 变更内容
|
||||
|
||||
| 变更 | 说明 |
|
||||
|------|------|
|
||||
| `APIClient` 增强 | 新增 `get_common_headers()`(兼容原 `BaseAPI` 的 header 构建)、`request()`(兼容方法,返回 dict)、`_check_response()`(HTTP + 业务状态码检查)、`cookie` 参数支持 |
|
||||
| 5 个 BaseAPI 子类迁移 | `CloudDesktopService`/`DevMachineService`/`BillingService`/`MealReminderService` × 2 改为继承 `APIClient` |
|
||||
| 41 个 logger import 更新 | `from framework.core.logger import get_logger` → `from tests.logger import get_logger` |
|
||||
| 旧文件删除 | `framework/core/base_api.py`、`framework/core/logger.py` |
|
||||
| Config 属性补充 | 新增 `CLOUD_AUTH_TOKEN`/`AMAP_KEY`/`AMAP_COORDINATES`(3 个悬挂引用) |
|
||||
|
||||
### 验证
|
||||
|
||||
| 验证项 | 结果 |
|
||||
|--------|:--:|
|
||||
| 全量 Python 编译 | ✅ 0 错误 |
|
||||
| 856 测试收集 | ✅ 全量通过 |
|
||||
| E2E 测试 | ✅ 不受影响 |
|
||||
| `get_common_headers()` 兼容性 | ✅ 输出一致 |
|
||||
| `request()` 返回类型 | ✅ `dict`(与旧 `BaseAPI` 行为一致) |
|
||||
|
||||
### 6 条断裂线进度
|
||||
配置 ✅ → API 客户端 ✅ → 日志 ✅ → BasePage ⬜ → 认证 ⬜ → 场景去重 ⬜
|
||||
|
||||
### 涉及文件
|
||||
`tests/utils/api_client.py`, `config/settings.py`, `framework/core/base_api.py`(删除), `framework/core/logger.py`(删除), 5 个 BaseAPI 子类, 41 个 logger import
|
||||
|
||||
## 2026-06-27 — 二合一重构阶段 2 分析:API 客户端 + 日志统一
|
||||
|
||||
### 背景
|
||||
`REFACTOR_EVALUATION.md` 评估的 6 条断裂线第 2-3 条:API 客户端(`BaseAPI`/`requests` vs `APIClient`/`httpx`)和日志系统(`framework/core/logger.py` vs `tests/logger.py`)。
|
||||
|
||||
### 分析结论
|
||||
|
||||
| 维度 | 发现 |
|
||||
|------|------|
|
||||
| `BaseAPI` 子类 | 5 个(`CloudDesktopService`/`DevMachineService`/`BillingService`/`MealReminderService` × 2) |
|
||||
| logger 引用 | 41 个文件使用 `framework.core.logger` |
|
||||
| `request()` 返回值 | `BaseAPI` 返回 `dict`,`APIClient` 返回 `httpx.Response` — **不兼容** |
|
||||
| `get_common_headers()` | `APIClient` 缺失,需新增 |
|
||||
| 缺失 Config 属性 | `CLOUD_AUTH_TOKEN`/`AMAP_KEY`/`AMAP_COORDINATES` — 3 个悬挂引用 |
|
||||
|
||||
### 迁移策略
|
||||
- `APIClient` 新增 `get_common_headers()` + `request()` 兼容方法
|
||||
- 5 个子类改为继承 `APIClient`
|
||||
- 41 个 logger import 改为 `tests.logger`
|
||||
- 删除 `framework/core/base_api.py` + `framework/core/logger.py`
|
||||
|
||||
### 涉及文件
|
||||
`REFACTOR_EVALUATION.md`(更新阶段 2 详细分析),待实施的文件:`tests/utils/api_client.py`,`framework/core/base_api.py`(删除),`framework/core/logger.py`(删除),5 个 BaseAPI 子类,41 个 logger import
|
||||
|
||||
## 2026-06-27 — 二合一重构阶段 1:配置统一
|
||||
|
||||
### 背景
|
||||
`REFACTOR_EVALUATION.md` 评估的 6 条断裂线第一条:配置系统两套并存(`config/settings.py` vs `framework/config/settings.py`)。
|
||||
|
||||
### 变更内容
|
||||
|
||||
| 变更 | 说明 |
|
||||
|------|------|
|
||||
| 配置合并 | `framework/config/settings.py` 的所有属性(`AUTH_TOKEN`/`COOKIE`/`CloudDesktop`/`DevMachine`/`WAIT`/`TIMEOUT`)迁移到 `config/settings.py` 的 `BaseConfig` 和 `RobogoConfig` 类 |
|
||||
| `RobogoConfig` 类 | 继承 `BaseConfig`,覆盖 `BASE_URL`(Robogo URL)、`LOGIN_URL`(`/cloud-desktop/login`)、`DEFAULT_TIMEOUT`(30000) |
|
||||
| `Config` 别名 | `config.settings.Config = RobogoConfig`,保持 `framework/` 代码 `from config.settings import Config` 的类属性访问方式不变 |
|
||||
| 旧文件删除 | `framework/config/settings.py` 删除 |
|
||||
| 23 个文件 import 路径更新 | `from framework.config.settings import Config` → `from config.settings import Config` |
|
||||
|
||||
### 验证
|
||||
|
||||
| 验证项 | 结果 |
|
||||
|--------|:--:|
|
||||
| D-Cloud 配置(`config` 实例) | ✅ `BASE_URL`、`DEFAULT_TIMEOUT` 不变 |
|
||||
| Robogo 配置(`Config` 类) | ✅ 所有属性可访问 |
|
||||
| 856 个测试收集 | ✅ 全量通过 |
|
||||
| 24 个 Python 文件编译 | ✅ 0 错误 |
|
||||
|
||||
### 涉及文件
|
||||
`config/settings.py`, `framework/config/settings.py`(删除), 23 个 `framework/` + `scenarios/` + `bot/` + `scripts/` 文件的 import 路径
|
||||
|
||||
## 2026-06-26 — 基于 TBC 分析报告的全量修复 + 无屏幕部署方案
|
||||
|
||||
### 背景
|
||||
基于 `docs/TBC_分析报告_0626.html` 的逐文件代码审读,修复了双后端死代码、健康度 Bug、密码明文、悬挂引用、硬编码 URL 等问题,并补充了无屏幕工作站部署方案。
|
||||
|
||||
### 修复清单
|
||||
|
||||
| 优先级 | 变更 | 涉及文件 |
|
||||
|--------|------|---------|
|
||||
| **P0** | 删除 B 套死代码(`scheduler.py`/`test_runner.py`/`database.py`),`__main__.py` 统一从 `app.py` 导入 | `backend/__main__.py` |
|
||||
| **P0** | Bug#1:仪表盘模块健康度修复 — 按 `module` 字段过滤,report 新增 `module` 字段 | `backend/app.py` |
|
||||
| **P0** | Bug#4:密码脱敏 — `_save_db()` 中 SHA-256 哈希后落盘,内存保持明文 | `backend/app.py` |
|
||||
| **P0** | 并发写 JSON 加 `threading.Lock` | `backend/app.py` |
|
||||
| **P1** | 悬挂引用修复 — `Config` 新增 `AUTH_TOKEN`/`COOKIE`/`CloudDesktop` 内嵌类/`WAIT['start']`/`WAIT['switch']` | `framework/config/settings.py` |
|
||||
| **P2** | 删除重复文件 — `framework/bot.py`(与 `bot/bot.py` 相同)、`frontend/src/components/Sidebar.tsx`(未被引用) | — |
|
||||
| **P2** | Bug#2:闭环率从 `85 if fail_count > 0 else 100` 改为实际通过率 | `backend/app.py` |
|
||||
| **P2** | Bug#3:前端统计卡片从硬编码改为动态渲染(模块数/报告数/通过率/闭环率) | `frontend/src/components/dashboard/DCloudDashboard.tsx` |
|
||||
| **P2** | 硬编码 URL → `DCLOUD_BASE_URL` 环境变量 | `tests/data_generation/data_generation_page.py` |
|
||||
| **P2** | 裸 `except:` → `except Exception:` | `framework/core/base_page.py` |
|
||||
|
||||
### 部署方案
|
||||
|
||||
| 新增 | 说明 |
|
||||
|------|------|
|
||||
| `DEPLOY.md` | 13 节完整部署指南,含系统要求、环境配置、三种启动方式、验证步骤、常见问题 |
|
||||
| `com.autoflow.platform.plist` | macOS launchd 服务模板,支持开机自启、崩溃重启、日志输出 |
|
||||
| `.dockerignore` | 减少 Docker 构建上下文 |
|
||||
| `REFACTOR_EVALUATION.md` | 二合一重构评估:6 条断裂线分析、4 阶段方案、风险评级、建议执行策略 |
|
||||
| 第 7 节:无屏幕工作站部署 | launchd 常驻服务 + 局域网共享 + 防火墙配置 |
|
||||
|
||||
### 统计
|
||||
- 修改 6 个文件,删除 5 个死代码文件
|
||||
- 净减少 611 行代码(+86/-697)
|
||||
|
||||
## 2026-06-25 - Python 3.9 兼容性修复 + Dashboard E2E 入口
|
||||
|
||||
### 背景
|
||||
|
||||
BIN
local_3d_chain_error.png
Normal file
BIN
local_3d_chain_error.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 197 KiB |
BIN
local_file_system_error.png
Normal file
BIN
local_file_system_error.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 114 KiB |
BIN
local_quantization_error.png
Normal file
BIN
local_quantization_error.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 75 KiB |
BIN
login_debug.png
Normal file
BIN
login_debug.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 171 KiB |
BIN
login_failed.png
Normal file
BIN
login_failed.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 344 KiB |
@ -37,4 +37,5 @@ markers =
|
||||
device_manage: marks device manage module tests
|
||||
material_library: marks material library module tests
|
||||
prompt_library: marks prompt library module tests
|
||||
lora_finetune: marks lora finetune module tests
|
||||
lora_finetune: marks lora finetune module tests
|
||||
robogo: marks Robogo full-chain inspection scenarios (requires browser)
|
||||
@ -1,42 +0,0 @@
|
||||
# framework/scripts/compute_resource_scenario.py
|
||||
import time
|
||||
from framework.config.settings import Config
|
||||
from framework.core.logger import get_logger
|
||||
|
||||
logger = get_logger("ComputeResourceScenario")
|
||||
|
||||
def run_dev_machine_lifecycle(dm):
|
||||
"""
|
||||
业务逻辑:开发机申请与验证流程
|
||||
"""
|
||||
logger.info("--- 开启【开发机】业务总线巡检 ---")
|
||||
dm.navigate_to()
|
||||
|
||||
# 1. 状态巡检
|
||||
status = dm.get_first_machine_status()
|
||||
if status == "Empty":
|
||||
logger.info("当前列表为空,准备首次申请...")
|
||||
|
||||
# 2. 执行申请全过程
|
||||
dm.open_apply_dialog()
|
||||
dm.fill_name(Config.DEV_MACHINE_NAME)
|
||||
dm.select_sku(Config.DEV_MACHINE_SKU)
|
||||
dm.select_image("CUDA")
|
||||
dm.fill_ssh_key(Config.SSH_PUBLIC_KEY)
|
||||
dm.fill_system_disk(Config.SYSTEM_DISK)
|
||||
dm.submit_application()
|
||||
|
||||
# 3. 深度巡检:等待部署 -> 关机 -> 删除
|
||||
name = Config.DEV_MACHINE_NAME
|
||||
logger.info(f"⌛ 正在等待开发机 {name} 部署就绪...")
|
||||
|
||||
# 注意:PageObject 内部的 wait_for_status 会处理具体轮询
|
||||
# 这里给一个基础 10s 避免页面刚刷新时 DOM 状态不稳定
|
||||
time.sleep(10)
|
||||
|
||||
# 执行业务链路巡检
|
||||
dm.stop_machine(name)
|
||||
dm.delete_machine(name)
|
||||
|
||||
logger.info("✅ 开发机【全生命周期】业务巡检圆满完成,环境已清理")
|
||||
return True
|
||||
@ -1,46 +0,0 @@
|
||||
# framework/scripts/desktop_lifecycle.py
|
||||
"""云桌面 UI 全生命周期巡检脚本"""
|
||||
import time
|
||||
from framework.config.settings import Config
|
||||
from framework.core.logger import get_logger
|
||||
|
||||
logger = get_logger("DesktopLifecycleScenario")
|
||||
|
||||
def run_cloud_desktop_lifecycle(cd):
|
||||
"""
|
||||
业务逻辑:地瓜桌面创建与全生命周期验证流程 (UI 自动化版)
|
||||
流程:创建 -> 按量转包月 -> 打开 -> 保存镜像 -> 关机 -> 删除
|
||||
"""
|
||||
logger.info("--- 开启【地瓜桌面】业务总线巡检 ---")
|
||||
cd.navigate_to()
|
||||
|
||||
# 1. 检测已有实例
|
||||
name = cd.get_first_desktop_name()
|
||||
logger.info(f"✅ 探测到首台云桌面实例名称: {name}")
|
||||
|
||||
# 2. 执行创建桌面的完整业务
|
||||
name = Config.CLOUD_DESKTOP_NAME
|
||||
cd.open_create_dialog()
|
||||
cd.fill_name(name)
|
||||
cd.select_sku(Config.CLOUD_DESKTOP_SKU)
|
||||
cd.select_image("ComfyUI")
|
||||
cd.submit_creation()
|
||||
|
||||
# 3. 按量转包月
|
||||
# cd.convert_to_monthly(name)
|
||||
|
||||
# 4. 打开桌面
|
||||
cd.open_desktop(name)
|
||||
time.sleep(10)
|
||||
|
||||
# 5. 保存镜像
|
||||
cd.save_image(name)
|
||||
|
||||
# 6. 关机
|
||||
cd.stop_desktop(name)
|
||||
|
||||
# 7. 删除
|
||||
cd.delete_desktop(name)
|
||||
|
||||
logger.info("🎉 云桌面全生命周期业务场景巡检完毕!")
|
||||
return True
|
||||
@ -1,99 +0,0 @@
|
||||
# framework/scripts/file_system_scenario.py
|
||||
import os
|
||||
import time
|
||||
import random
|
||||
from framework.core.logger import get_logger
|
||||
|
||||
logger = get_logger("FileSystemScenario")
|
||||
|
||||
def run_stress_upload_test(fm, file_path, cycles=3):
|
||||
"""
|
||||
业务逻辑:文件上传压力测试(大文件上传-取消)
|
||||
"""
|
||||
logger.info(f"🚀 启动上传-取消压测 - {cycles} 次")
|
||||
for i in range(1, cycles + 1):
|
||||
logger.info(f"--- 循环第 {i} 次 ---")
|
||||
try:
|
||||
fm.upload_files(file_path)
|
||||
# 大文件需要等一下让上传进度条和取消按钮出现
|
||||
time.sleep(3)
|
||||
fm.cancel_upload()
|
||||
except Exception as e:
|
||||
logger.warning(f"压测第 {i} 次异常(可忽略): {e}")
|
||||
# 确保弹窗关闭,不影响下一轮
|
||||
try:
|
||||
fm.page.evaluate("document.querySelector('button.p-dialog-header-close')?.click()")
|
||||
except:
|
||||
pass
|
||||
time.sleep(1)
|
||||
|
||||
def run_full_file_lifecycle(fm, folder_name):
|
||||
"""
|
||||
业务逻辑:完整的文件生命周期流程
|
||||
- 从 test_data 目录随机选取文件上传
|
||||
- 随机重命名已上传的压缩包
|
||||
- 返回根目录后删除之前创建的文件夹
|
||||
"""
|
||||
logger.info(f"--- 开启文件系统全生命周期测试 [{folder_name}] ---")
|
||||
fm.navigate_to()
|
||||
|
||||
# 1. 创建并进入测试文件夹
|
||||
fm.create_folder(folder_name)
|
||||
fm.enter_folder(folder_name)
|
||||
|
||||
# 2. 收集 test_data 目录下所有文件
|
||||
from framework.config.settings import Config
|
||||
test_data_dir = Config.TEST_DATA_DIR
|
||||
|
||||
if not os.path.isdir(test_data_dir):
|
||||
logger.warning(f"⚠️ test_data 目录不存在: {test_data_dir},跳过上传测试")
|
||||
fm.back_to_root()
|
||||
time.sleep(2)
|
||||
fm.delete_item(folder_name)
|
||||
time.sleep(3)
|
||||
return
|
||||
|
||||
all_files = [f for f in os.listdir(test_data_dir) if os.path.isfile(os.path.join(test_data_dir, f))]
|
||||
if not all_files:
|
||||
logger.warning("⚠️ test_data 目录为空,跳过上传测试")
|
||||
fm.back_to_root()
|
||||
time.sleep(2)
|
||||
fm.delete_item(folder_name)
|
||||
time.sleep(3)
|
||||
return
|
||||
|
||||
all_paths = [os.path.join(test_data_dir, f) for f in all_files]
|
||||
total_size = sum(os.path.getsize(p) for p in all_paths)
|
||||
logger.info(f"📦 test_data 共 {len(all_files)} 个文件,总计 {total_size / 1024 / 1024:.1f} MB")
|
||||
|
||||
# 3. 一次性上传全部文件(Playwright 支持多文件)
|
||||
fm.upload_files(all_paths)
|
||||
fm.wait_for_success(count=len(all_files))
|
||||
|
||||
# 4. 等待文件列表完全刷新(上传对话框关闭后列表需要数秒才能稳定)
|
||||
logger.info("⏳ 等待文件列表稳定...")
|
||||
time.sleep(5)
|
||||
|
||||
# 5. 随机选取一个当前页面可见的文件并重命名
|
||||
page_text = fm.page.content()
|
||||
visible_files = [f for f in all_files if f in page_text]
|
||||
|
||||
if visible_files:
|
||||
rename_target = random.choice(visible_files)
|
||||
logger.info(f"📄 当前第一页可见 {len(visible_files)} 个文件,随机命中: {rename_target}")
|
||||
else:
|
||||
logger.warning("⚠️ 未在第一页检测到任何上传的文件名,回退使用完全随机选择")
|
||||
rename_target = random.choice(all_files)
|
||||
|
||||
file_base, file_ext = os.path.splitext(rename_target)
|
||||
random_suffix = random.randint(1000, 9999)
|
||||
new_name = f"UI_RENAMED_{random_suffix}{file_ext}"
|
||||
logger.info(f"🎲 随机重命名目标: {rename_target} -> {new_name}")
|
||||
fm.rename_item(rename_target, new_name)
|
||||
|
||||
# 7. 返回根目录,并删除之前创建的测试文件夹
|
||||
fm.back_to_root()
|
||||
time.sleep(5)
|
||||
fm.delete_item(folder_name)
|
||||
time.sleep(5)
|
||||
logger.info("✅ 文件系统场景测试完成")
|
||||
@ -1,74 +0,0 @@
|
||||
import os
|
||||
import time
|
||||
from framework.core.logger import get_logger
|
||||
|
||||
logger = get_logger("ImageGenerationScenario")
|
||||
|
||||
def run_image_generation_scenario(image_gen_page):
|
||||
"""
|
||||
业务逻辑:图像生成场景测试(完整流程)
|
||||
|
||||
1. 切换到图像生成页面
|
||||
2. 点击 开启新对话
|
||||
3. 输入随机提示词 -> 点击执行 -> 等待图片生成
|
||||
4. 悬停图片 -> 点击 [引用]
|
||||
5. 再次随机输入提示词 -> 点击执行
|
||||
6. 执行中 -> 点击 [停止生成]
|
||||
7. 等待"正在中断..."消失、执行按钮恢复
|
||||
8. 再次随机输入提示词 -> 点击执行 -> 等待图片生成
|
||||
"""
|
||||
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
config_path = os.path.join(base_dir, "config", "人头生成.json")
|
||||
|
||||
logger.info("--- 开启图像生成场景测试 ---")
|
||||
|
||||
# ── Step 1: 导航 ──────────────────────────────────────────────
|
||||
image_gen_page.navigate_to()
|
||||
|
||||
# ── Step 2: 开启新对话 ─────────────────────────────────────────
|
||||
image_gen_page.start_new_conversation()
|
||||
|
||||
# ── Step 3: 第一次生成 ─────────────────────────────────────────
|
||||
prompt1 = image_gen_page.input_random_prompt(config_path)
|
||||
logger.info(f"[第1次] 提示词: {prompt1[:50]}...")
|
||||
image_gen_page.start_generation()
|
||||
|
||||
if not image_gen_page.wait_for_image_generated(timeout=300):
|
||||
logger.error("❌ 第1次图像生成超时,终止场景")
|
||||
return False
|
||||
logger.info("✅ 第1次图像生成成功")
|
||||
|
||||
# ── Step 4: 悬停图片并点击引用 ────────────────────────────────
|
||||
image_gen_page.click_quote_on_image()
|
||||
|
||||
# ── Step 5: 第二次生成(引用后追加提示词并执行)───────────────
|
||||
prompt2 = image_gen_page.input_random_prompt(config_path)
|
||||
logger.info(f"[第2次] 提示词: {prompt2[:50]}...")
|
||||
image_gen_page.start_generation()
|
||||
|
||||
# ── Step 6: 执行中途点击停止 ──────────────────────────────────
|
||||
# 稍等片刻让生成任务真正开始(等到页面出现"停止生成"按钮)
|
||||
logger.info("⏳ 等待 [停止生成] 按钮出现...")
|
||||
try:
|
||||
image_gen_page.page.wait_for_selector(
|
||||
"button:has-text('停止生成')", timeout=30000
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(f"⚠️ 超时未等到停止按钮,尝试直接点击: {e}")
|
||||
image_gen_page.stop_generation()
|
||||
|
||||
# ── Step 7: 等待中断完成、执行按钮恢复 ───────────────────────
|
||||
if not image_gen_page.wait_for_generation_resumable(timeout=120):
|
||||
logger.warning("⚠️ 等待执行按钮恢复超时,尝试继续后续流程")
|
||||
|
||||
# ── Step 8: 第三次生成 ─────────────────────────────────────────
|
||||
prompt3 = image_gen_page.input_random_prompt(config_path)
|
||||
logger.info(f"[第3次] 提示词: {prompt3[:50]}...")
|
||||
image_gen_page.start_generation()
|
||||
|
||||
if not image_gen_page.wait_for_image_generated(timeout=300):
|
||||
logger.error("❌ 第3次图像生成超时")
|
||||
return False
|
||||
|
||||
logger.info("✨ 图像生成完整场景测试完毕(含引用 + 中断 + 恢复)")
|
||||
return True
|
||||
@ -1,37 +0,0 @@
|
||||
import time
|
||||
from framework.config.settings import Config
|
||||
from framework.core.logger import get_logger
|
||||
from framework.business.cloud_desktop_page import CloudDesktopPage
|
||||
|
||||
logger = get_logger("MirrorAssetsScenario")
|
||||
|
||||
def run_mirror_assets_lifecycle(ma, cd):
|
||||
"""
|
||||
业务逻辑:镜像资产全生命周期流程
|
||||
"""
|
||||
logger.info(f"--- 开启【镜像资产】业务总线巡检 ---")
|
||||
ma.navigate_to()
|
||||
ma.click_my_mirror()
|
||||
ma.click_mirror_in_list()
|
||||
ma.click_quick_create()
|
||||
|
||||
mirror_name = Config.MIRROR_NAME
|
||||
ma.fill_mirror_name(mirror_name)
|
||||
time.sleep(2)
|
||||
ma.select_sku(Config.MIRROR_SKU)
|
||||
time.sleep(2)
|
||||
ma.click_create_button()
|
||||
|
||||
logger.info(f"✅ 镜像资产 {mirror_name} 已提交创建,正在跳转往云桌面进行后续关机操作...")
|
||||
|
||||
# 执行后续关机:跳转切换到云桌面页面
|
||||
cd.navigate_to()
|
||||
# 等待创建成功并进入运行中
|
||||
cd.wait_for_status(mirror_name, "运行中")
|
||||
# 执行关机
|
||||
cd.stop_desktop(mirror_name)
|
||||
cd.wait_for_status(mirror_name, "已关机")
|
||||
cd.delete_desktop(mirror_name)
|
||||
time.sleep(3)
|
||||
|
||||
logger.info("✅ 镜像资产场景测试完成")
|
||||
@ -1,94 +0,0 @@
|
||||
import time
|
||||
import random
|
||||
from framework.core.logger import get_logger
|
||||
|
||||
logger = get_logger("MonkeyTester")
|
||||
|
||||
def run_monkey_testing(page, action_count=1000):
|
||||
"""
|
||||
全屏幕 Monkey 稳定性测试 (随机流操作)
|
||||
利用 JS 提取网页内所有的安全交互元素(避开退出、注销、删除等敏感操作),
|
||||
然后执行随机规模的乱序点击和键盘输入,最后伴随鼠标抛掷。
|
||||
"""
|
||||
logger.info(f"🐒 开始执行全局 Monkey 测试,计划乱序攻击交互 {action_count} 次...")
|
||||
|
||||
# 增加捕捉页面底层级 JS 控制台报错的能力
|
||||
def log_page_error(err):
|
||||
logger.error(f"💥 [Monkey 探测到前端崩溃]: {err}")
|
||||
|
||||
# 监听未捕获异常
|
||||
page.on("pageerror", log_page_error)
|
||||
|
||||
# 危险词汇,避免退出登录或产生破坏性删除导致平台主干链路被污染
|
||||
forbidden_keywords = ['退出', '注销', 'logout', '删除', 'delete', '清理']
|
||||
|
||||
# JS 提取页面上的活动区域
|
||||
js_get_random_element = """
|
||||
(forbidden) => {
|
||||
// 大面积收割所有可能挂载事件的锚点
|
||||
const interactables = Array.from(document.querySelectorAll("button, a, input, textarea, [role='button'], div.p-dropdown, li.p-menuitem"));
|
||||
|
||||
const visible = interactables.filter(el => {
|
||||
const rect = el.getBoundingClientRect();
|
||||
const style = window.getComputedStyle(el);
|
||||
return rect.width > 0 && rect.height > 0 && style.visibility !== 'hidden' && style.opacity !== '0';
|
||||
});
|
||||
|
||||
const safeElements = visible.filter(el => {
|
||||
const text = (el.innerText || el.value || el.placeholder || '').toLowerCase();
|
||||
return !forbidden.some(kw => text.includes(kw));
|
||||
});
|
||||
|
||||
if (safeElements.length > 0) {
|
||||
const randomIndex = Math.floor(Math.random() * safeElements.length);
|
||||
return safeElements[randomIndex];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
"""
|
||||
|
||||
success_actions = 0
|
||||
for i in range(action_count):
|
||||
try:
|
||||
# 高频发起,给予微小缓冲节奏
|
||||
time.sleep(0.3)
|
||||
|
||||
# 使用 evaluate_handle 将 JS 节点句柄传回到 Python
|
||||
element_handle = page.evaluate_handle(js_get_random_element, forbidden_keywords)
|
||||
|
||||
# null 在 Python 端 json_value 会被转换为 None,但在 Handle 里需谨慎评估
|
||||
is_valid = page.evaluate("(el) => el !== null && typeof el === 'object' && el.tagName", element_handle)
|
||||
if is_valid:
|
||||
tag_name = page.evaluate("el => el.tagName", element_handle).lower()
|
||||
|
||||
# 开始随机交互分发
|
||||
if tag_name in ['input', 'textarea']:
|
||||
# 随机混沌输入
|
||||
random_txt = str(random.randint(100, 99999))
|
||||
element_handle.fill(random_txt, force=True, timeout=1000)
|
||||
logger.debug(f"[Monkey] ⌨️ 乱序输入框写入: {random_txt}")
|
||||
else:
|
||||
# 强硬暴力点击 (抛弃边界验证强制触发底层事件)
|
||||
element_handle.click(force=True, timeout=1000)
|
||||
logger.debug(f"[Monkey] 🖱️ 盲击了元素节点: <{tag_name}>")
|
||||
|
||||
success_actions += 1
|
||||
else:
|
||||
# 找不到靶点则强制滚屏扰动页面布局重绘
|
||||
distance = random.choice([-600, -300, 300, 600])
|
||||
page.mouse.wheel(0, distance)
|
||||
logger.debug(f"[Monkey] 📜 随机视差滚屏了 {distance} px")
|
||||
|
||||
except Exception as e:
|
||||
# Monkey 理念:容忍动作失败,但如果抛出的是框架级失去连接则需汇报
|
||||
if "Target page, context or browser has been closed" in str(e):
|
||||
logger.error("🚨 浏览器实例被截断,Monkey 测试提前终止!")
|
||||
break
|
||||
# logger.debug(f"⚠️ Monkey 第 {i+1} 次挥拍落空: {e}")
|
||||
pass
|
||||
|
||||
# 卸载挂载的全局异常监听,避免影响后续的常规测试
|
||||
page.remove_listener("pageerror", log_page_error)
|
||||
|
||||
logger.info(f"✅ Monkey 测试执行完毕!成功施加了 {success_actions}/{action_count} 次有效随机压力。未探测到毁灭性 Crash。")
|
||||
return True
|
||||
@ -1,57 +0,0 @@
|
||||
from framework.core.logger import get_logger
|
||||
|
||||
logger = get_logger("OpenClawScenario")
|
||||
|
||||
|
||||
def run_openclaw_scenario(openclaw_page):
|
||||
"""
|
||||
OpenClaw 场景流程:
|
||||
1. 切换到 OpenClaw 页面
|
||||
2. 新建实例(随机名称)
|
||||
3. 进入实例
|
||||
4. 勾选第一个模型
|
||||
5. 切换控制台
|
||||
6. 配对设备
|
||||
7. 确认配对
|
||||
8. 输入"你好"并点击发送
|
||||
9. 点击左上角返回
|
||||
10. 点击停止
|
||||
11. 点击删除
|
||||
"""
|
||||
logger.info("--- 开启 OpenClaw 场景测试 ---")
|
||||
|
||||
# Step 1: 导航
|
||||
openclaw_page.navigate_to()
|
||||
|
||||
# Step 2: 新建实例
|
||||
instance_name = openclaw_page.create_new_instance()
|
||||
|
||||
# Step 3: 进入实例
|
||||
openclaw_page.enter_instance(instance_name)
|
||||
|
||||
# Step 4: 勾选第一个模型
|
||||
openclaw_page.select_first_model()
|
||||
|
||||
# Step 5: 切换控制台
|
||||
openclaw_page.switch_to_console()
|
||||
|
||||
# Step 6: 配对设备
|
||||
openclaw_page.pair_device()
|
||||
|
||||
# Step 7: 确认配对
|
||||
openclaw_page.confirm_pairing()
|
||||
|
||||
# Step 8: 输入"你好"并点击发送
|
||||
openclaw_page.send_chat_message("你好")
|
||||
|
||||
# Step 9: 点击左上角返回
|
||||
openclaw_page.go_back()
|
||||
|
||||
# Step 10: 点击停止
|
||||
openclaw_page.stop_instance()
|
||||
|
||||
# Step 11: 点击删除
|
||||
openclaw_page.delete_instance()
|
||||
|
||||
logger.info("✨ OpenClaw 场景测试完毕(含返回、停止、删除)")
|
||||
return instance_name
|
||||
@ -1,70 +0,0 @@
|
||||
import time
|
||||
import random
|
||||
import string
|
||||
from framework.core.logger import get_logger
|
||||
from framework.business.quantization_page import QuantizationPage
|
||||
|
||||
logger = get_logger("QuantizationScenario")
|
||||
|
||||
def _create_and_submit_task(quant_page: QuantizationPage, task_name: str):
|
||||
"""内部辅助函数:执行单次完整的任务创建流"""
|
||||
# 1. 进入任务创建流程
|
||||
quant_page.navigate_to()
|
||||
quant_page.click_create_task()
|
||||
|
||||
# 2. 输入名称
|
||||
quant_page.input_task_name(task_name)
|
||||
|
||||
# 3. 选择编译模式
|
||||
quant_page.select_mode_fast_eval()
|
||||
|
||||
# 4. 选择镜像
|
||||
quant_page.select_image("dcloud_ai_toolchain_ubuntu_22_s100_s600_cpu")
|
||||
|
||||
# 5. 选取模型文件
|
||||
quant_page.upload_model_file("model", "result.onnx")
|
||||
|
||||
# 6. 输入 march 值
|
||||
quant_page.input_march_param("nash-e")
|
||||
|
||||
# 7. 提交表单
|
||||
quant_page.click_final_submit()
|
||||
|
||||
|
||||
def run_quantization_lifecycle(quant_page: QuantizationPage):
|
||||
"""量化任务全生命周期流程"""
|
||||
logger.info("开始执行量化工具自动化流程...")
|
||||
|
||||
# ================= 阶段 1:手动终止链路 =================
|
||||
random_str1 = ''.join(random.choices(string.ascii_uppercase + string.digits, k=8))
|
||||
task_1 = f"AutoQuant_{random_str1}"
|
||||
logger.info(f"--- 阶段一: 测试任务手动终止与删除 [{task_1}] ---")
|
||||
|
||||
_create_and_submit_task(quant_page, task_1)
|
||||
|
||||
# 1. 查日志
|
||||
quant_page.open_and_close_logs(task_1)
|
||||
# 2. 停止
|
||||
quant_page.stop_task(task_1)
|
||||
# 3. 删除
|
||||
quant_page.delete_task(task_1)
|
||||
|
||||
|
||||
# ================= 阶段 2:完整成功链路 =================
|
||||
random_str2 = ''.join(random.choices(string.ascii_uppercase + string.digits, k=8))
|
||||
task_2 = f"AutoQuant_{random_str2}"
|
||||
logger.info(f"--- 阶段二: 测试任务完整成功链路 [{task_2}] ---")
|
||||
|
||||
_create_and_submit_task(quant_page, task_2)
|
||||
|
||||
# 1. 查日志
|
||||
quant_page.open_and_close_logs(task_2)
|
||||
|
||||
# 监控状态流转为终态 (完成或失败)
|
||||
quant_page.wait_for_task_finished(task_2)
|
||||
|
||||
# + 成功后的新增操作: 报告查看与全量下载拦截
|
||||
quant_page.open_and_close_report(task_2)
|
||||
quant_page.download_all_results(task_2)
|
||||
|
||||
logger.info("✅ 量化工具全生命周期(异常截断+成功收尾) 双链路完整验证通过!")
|
||||
@ -1,22 +0,0 @@
|
||||
"""
|
||||
AutoFlow - Robogo Full-Chain UI Inspection Entry Point
|
||||
Launched by platform_app.py scheduler.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import importlib
|
||||
|
||||
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, PROJECT_ROOT)
|
||||
sys.path.insert(0, os.path.join(PROJECT_ROOT, "framework"))
|
||||
|
||||
from framework.business.data_management import DataManagementRunner
|
||||
|
||||
|
||||
def main():
|
||||
runner = DataManagementRunner()
|
||||
runner.run_all_scenarios()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@ -1,20 +0,0 @@
|
||||
"""
|
||||
AutoFlow - Data Loop Business Pipeline Validation Entry Point
|
||||
Launched by platform_app.py scheduler.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, PROJECT_ROOT)
|
||||
|
||||
|
||||
def main():
|
||||
print("[Data Loop] Starting data loop inspection...")
|
||||
# Data loop specific validation logic
|
||||
# This entry point is called by the platform for data loop product tasks
|
||||
print("[Data Loop] Inspection completed.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@ -1,30 +0,0 @@
|
||||
|
||||
import requests
|
||||
import json
|
||||
import config
|
||||
|
||||
url = f"https://cloud-fat.d-robotics.cc/api/dcloudResourceApi/consumptions"
|
||||
params = {
|
||||
"page": 1,
|
||||
"pageSize": 50,
|
||||
"instanceName": "验证01"
|
||||
}
|
||||
headers = {
|
||||
"Accept": "application/json, text/plain, */*",
|
||||
"Authorization": config.CLOUD_AUTH_TOKEN,
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36",
|
||||
}
|
||||
|
||||
print(f"Requesting URL: {url}")
|
||||
resp = requests.get(url, params=params, headers=headers)
|
||||
print(f"Status Code: {resp.status_code}")
|
||||
try:
|
||||
data = resp.json()
|
||||
print(f"Status in JSON: {data.get('status')}")
|
||||
print(f"Data content: {data.get('data')}")
|
||||
items = data.get("data", {}).get("items", [])
|
||||
for item in items:
|
||||
print(f"- {item.get('instanceName')}")
|
||||
except Exception as e:
|
||||
print(f"Error parsing JSON: {e}")
|
||||
print(f"Raw Response: {resp.text[:500]}")
|
||||
@ -1,35 +0,0 @@
|
||||
import time
|
||||
from framework.core.logger import get_logger
|
||||
|
||||
logger = get_logger("ThreeDAssetsScenario")
|
||||
|
||||
def run_3d_assets_lifecycle(assets_page, asset_name):
|
||||
"""
|
||||
业务逻辑:将 3D 生成的资产归档到指定的业务包 (ui_test)
|
||||
"""
|
||||
logger.info(f"--- 开启 3D 资产归档测试 (资产名: {asset_name}) ---")
|
||||
|
||||
# 1. 导航到 3D 资产菜单
|
||||
assets_page.navigate_to()
|
||||
|
||||
# 2. 进入 ui_test 资产包
|
||||
if assets_page.enter_asset_package("ui_test"):
|
||||
# 3. 开启新增数据子弹窗流程
|
||||
if assets_page.add_asset_data(asset_name):
|
||||
logger.info(f"✅ 资产 {asset_name} 关联至 ui_test 成功,准备深度校验...")
|
||||
|
||||
# 4. 列表校验 + 资产预览校验 (点开 X 关闭)
|
||||
if not assets_page.verify_asset_and_preview(asset_name):
|
||||
raise Exception("资产列表校验或 3D 预览渲染失败")
|
||||
|
||||
# 5. 源文件查看校验 (右上角按钮)
|
||||
if not assets_page.check_source_files():
|
||||
raise Exception("源文件侧边栏加载异常")
|
||||
|
||||
logger.info(f"✨ 3D 资产归档及渲染巡检圆满完成: {asset_name}")
|
||||
else:
|
||||
logger.error(f"❌ 3D 资产归档失败: {asset_name}")
|
||||
raise Exception("3D 资产归档数据新增失败")
|
||||
else:
|
||||
logger.error("❌ 无法进入指定的资产包 'ui_test'")
|
||||
raise Exception("无法进入资产包,流程中断")
|
||||
@ -1,46 +0,0 @@
|
||||
import os
|
||||
import random
|
||||
import time
|
||||
from framework.core.logger import get_logger
|
||||
from framework.config.settings import Config
|
||||
|
||||
logger = get_logger("ThreeDGenerationScenario")
|
||||
|
||||
def run_3d_generation_lifecycle(threed_page):
|
||||
"""
|
||||
业务逻辑:3D 生成 + 右上角保存全流程
|
||||
"""
|
||||
logger.info("--- 开启 3D 生成场景测试 (包含生成后保存) ---")
|
||||
threed_page.navigate_to()
|
||||
|
||||
# 1. 随机选取一张 PNG 素材
|
||||
test_data_dir = Config.TEST_DATA_DIR
|
||||
png_files = [f for f in os.listdir(test_data_dir) if f.lower().endswith('.png')]
|
||||
if not png_files:
|
||||
logger.warning(f"⚠️ 目录 {test_data_dir} 下没发现 PNG, 尝试使用默认素材")
|
||||
return
|
||||
|
||||
random_pic = random.choice(png_files)
|
||||
pic_path = os.path.join(test_data_dir, random_pic)
|
||||
|
||||
# 调试
|
||||
#threed_page.page.pause()
|
||||
|
||||
logger.info(f"🎲 随机选取的素材为: {random_pic}")
|
||||
|
||||
# 2. 上传并触发生成
|
||||
threed_page.upload_image(pic_path)
|
||||
time.sleep(1)
|
||||
|
||||
if threed_page.start_generation():
|
||||
# 3. 等待生成结果出现并点击保存
|
||||
if threed_page.wait_for_result_and_save():
|
||||
# 4. 执行复杂的保存弹窗流程 (含随机命名与路径选择)
|
||||
asset_name = threed_page.handle_save_dialog()
|
||||
logger.info(f"✨ 3D 模型巡检完毕,资产 {asset_name} 已保存")
|
||||
return asset_name
|
||||
else:
|
||||
logger.error("❌ 等待结果超时,未进入保存流程")
|
||||
else:
|
||||
logger.error("❌ 无法点击生成按钮,场景中断")
|
||||
return None
|
||||
@ -172,7 +172,7 @@ def build_html(records: list, stats: dict, history: list, generated_at: str) ->
|
||||
</div>'''
|
||||
err_html = f'''
|
||||
<tr class="error-row" id="{eid}">
|
||||
<td colspan="6">
|
||||
<td colspan="7">
|
||||
{screenshot_html}
|
||||
<pre class="error-pre">{escape(r["error"][:3000])}</pre>
|
||||
</td>
|
||||
@ -189,6 +189,7 @@ def build_html(records: list, stats: dict, history: list, generated_at: str) ->
|
||||
<td>{escape(r.get("expected") or "—")}</td>
|
||||
<td class="center">{badge}</td>
|
||||
<td class="center">{r.get("duration", 0):.2f}s</td>
|
||||
<td class="err-snippet">{escape((r.get("reason") or r.get("assertion") or "")[:120])}</td>
|
||||
{expand_col}
|
||||
</tr>{err_html}''')
|
||||
|
||||
@ -204,11 +205,12 @@ def build_html(records: list, stats: dict, history: list, generated_at: str) ->
|
||||
<div class="mod-body" id="{mod_id}">
|
||||
<table>
|
||||
<thead><tr>
|
||||
<th style="width:220px">测试用例</th>
|
||||
<th style="width:180px">测试用例</th>
|
||||
<th>描述</th>
|
||||
<th>预期结果</th>
|
||||
<th style="width:80px" class="center">结果</th>
|
||||
<th style="width:80px" class="center">状态</th>
|
||||
<th style="width:70px" class="center">耗时</th>
|
||||
<th style="width:180px">失败原因</th>
|
||||
<th style="width:36px"></th>
|
||||
</tr></thead>
|
||||
<tbody>{"".join(rows)}</tbody>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import sys
|
||||
import time
|
||||
from framework.business.data_management import DataManagement
|
||||
from framework.config.settings import Config
|
||||
from config.settings import Config
|
||||
|
||||
def main():
|
||||
"""全业务流程 UI 测试统一入口 (PO模式)"""
|
||||
|
||||
@ -10,7 +10,7 @@ BasePage - Page Object 基类(重构版)
|
||||
- 多种语义化定位方法
|
||||
- 模块化的功能拆分
|
||||
|
||||
Mixin 组成:
|
||||
Mixin 组成(12 个):
|
||||
- NavigationMixin: 导航相关
|
||||
- LocatorMixin: 元素定位
|
||||
- WaitMixin: 等待策略
|
||||
@ -21,6 +21,8 @@ Mixin 组成:
|
||||
- PaginationMixin: 分页操作
|
||||
- SearchMixin: 搜索操作
|
||||
- UtilityMixin: 工具方法
|
||||
- SmartLocatorMixin: 语义化智能定位器(Robogo 兼容)
|
||||
- SmartInteractionMixin: 语义化智能交互(Robogo 兼容)
|
||||
"""
|
||||
from playwright.sync_api import Page
|
||||
from config.settings import config
|
||||
@ -36,6 +38,8 @@ from tests.base.mixins import (
|
||||
PaginationMixin,
|
||||
SearchMixin,
|
||||
UtilityMixin,
|
||||
SmartLocatorMixin,
|
||||
SmartInteractionMixin,
|
||||
)
|
||||
|
||||
|
||||
@ -50,17 +54,19 @@ class BasePage(
|
||||
PaginationMixin,
|
||||
SearchMixin,
|
||||
UtilityMixin,
|
||||
SmartLocatorMixin,
|
||||
SmartInteractionMixin,
|
||||
):
|
||||
"""
|
||||
Page Object 基类
|
||||
|
||||
|
||||
通过多继承 Mixin 实现功能组合,保持核心逻辑简洁。
|
||||
所有页面对象应继承此类。
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, page: Page):
|
||||
"""初始化页面对象
|
||||
|
||||
|
||||
Args:
|
||||
page: Playwright Page 对象
|
||||
"""
|
||||
@ -68,7 +74,7 @@ class BasePage(
|
||||
self.timeout = config.DEFAULT_TIMEOUT
|
||||
self.base_url = config.BASE_URL.rstrip("/")
|
||||
self.config = config
|
||||
|
||||
|
||||
# 子类应定义 url 属性
|
||||
# self.url = "/module/path"
|
||||
|
||||
|
||||
@ -13,6 +13,8 @@ from tests.base.mixins.table import TableMixin
|
||||
from tests.base.mixins.pagination import PaginationMixin
|
||||
from tests.base.mixins.search import SearchMixin
|
||||
from tests.base.mixins.utility import UtilityMixin
|
||||
from tests.base.mixins.smart_locator import SmartLocatorMixin
|
||||
from tests.base.mixins.smart_interaction import SmartInteractionMixin
|
||||
|
||||
__all__ = [
|
||||
"NavigationMixin",
|
||||
@ -25,4 +27,6 @@ __all__ = [
|
||||
"PaginationMixin",
|
||||
"SearchMixin",
|
||||
"UtilityMixin",
|
||||
"SmartLocatorMixin",
|
||||
"SmartInteractionMixin",
|
||||
]
|
||||
|
||||
@ -1,52 +1,19 @@
|
||||
from framework.core.logger import get_logger
|
||||
import time
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("BasePage")
|
||||
logger = get_logger("SmartInteraction")
|
||||
|
||||
class BasePage:
|
||||
"""所有页面对象的基类,提供智能识别与常用操作封装"""
|
||||
|
||||
def __init__(self, page):
|
||||
self.page = page
|
||||
|
||||
def smart_find(self, description, role=None, timeout=5000):
|
||||
"""核心智能定位器:按优先级尝试语义定位"""
|
||||
strategies = [
|
||||
lambda: self.page.get_by_role(role, name=description, exact=False) if role else None,
|
||||
lambda: self.page.get_by_text(description, exact=False),
|
||||
# 新增:直接属性扫描以应对 aria-label 类按钮
|
||||
lambda: self.page.locator(f'[aria-label*="{description}"]').first,
|
||||
lambda: self.page.get_by_placeholder(description, exact=False),
|
||||
lambda: self.page.get_by_label(description, exact=False),
|
||||
lambda: self.page.get_by_title(description, exact=False)
|
||||
]
|
||||
|
||||
for get_loc in strategies:
|
||||
try:
|
||||
loc = get_loc()
|
||||
if loc and loc.count() > 0:
|
||||
return loc.first
|
||||
except:
|
||||
continue
|
||||
|
||||
# 兜底:尝试 CSS
|
||||
if any(c in description for c in [".", "#", "[", ">"]):
|
||||
try:
|
||||
return self.page.locator(description).first
|
||||
except:
|
||||
pass
|
||||
|
||||
raise Exception(f"❌ 无法在页面找到元素: '{description}'")
|
||||
class SmartInteractionMixin:
|
||||
"""提供语义化点击、填写、选择等交互操作,带 JS 暴力兜底"""
|
||||
|
||||
def smart_click(self, text, role=None, timeout=5000):
|
||||
"""语义化点击:带重试与可见性校验"""
|
||||
logger.info(f"👉 [SmartClick] 尝试点击: {text}")
|
||||
try:
|
||||
el = self.smart_find(text, role=role, timeout=timeout)
|
||||
# 等待可见与稳定
|
||||
el.wait_for(state="visible", timeout=timeout)
|
||||
|
||||
# 使用自带重试的点击逻辑,应对 SPA 瞬时刷新
|
||||
|
||||
try:
|
||||
el.click(timeout=timeout)
|
||||
except Exception as e:
|
||||
@ -56,7 +23,6 @@ class BasePage:
|
||||
else:
|
||||
raise e
|
||||
except Exception as e:
|
||||
# 暴力循环 JS 点击作为最终兜底
|
||||
success = self.page.evaluate(f"""(txt) => {{
|
||||
const target = Array.from(document.querySelectorAll('button, a, span, .p-button-label, label, input'))
|
||||
.find(el => {{
|
||||
@ -65,10 +31,10 @@ class BasePage:
|
||||
const ph = el.getAttribute('placeholder') || "";
|
||||
return it.includes(txt) || al.includes(txt) || ph.includes(txt);
|
||||
}});
|
||||
if (target) {{
|
||||
if (target) {{
|
||||
target.scrollIntoView({{behavior: "smooth", block: "center"}});
|
||||
setTimeout(() => target.click(), 100);
|
||||
return true;
|
||||
setTimeout(() => target.click(), 100);
|
||||
return true;
|
||||
}}
|
||||
return false;
|
||||
}}""", text)
|
||||
@ -76,7 +42,7 @@ class BasePage:
|
||||
raise e
|
||||
|
||||
def smart_click_any(self, texts, role=None, timeout=5000):
|
||||
"""按多个候选文案点击,兼容新旧页面元素文案。"""
|
||||
"""按多个候选文案点击,兼容新旧页面元素文案"""
|
||||
last_error = None
|
||||
for text in texts:
|
||||
try:
|
||||
@ -87,32 +53,8 @@ class BasePage:
|
||||
logger.info(f" 候选元素未命中 [{text}]: {e}")
|
||||
raise last_error or Exception(f"❌ 无法点击任一候选元素: {texts}")
|
||||
|
||||
def goto_route(self, route):
|
||||
"""在当前登录域名下跳转到指定前端路由。"""
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
current = self.page.url or ""
|
||||
parsed = urlsplit(current)
|
||||
if parsed.scheme and parsed.netloc:
|
||||
base = f"{parsed.scheme}://{parsed.netloc}"
|
||||
else:
|
||||
from framework.config.settings import Config
|
||||
base = Config.BASE_URL
|
||||
|
||||
if not route.startswith("/"):
|
||||
route = f"/{route}"
|
||||
self.page.goto(f"{base}{route}", wait_until="domcontentloaded")
|
||||
|
||||
def visible_dialog(self, text=None):
|
||||
"""返回当前可见的最上层 PrimeVue/Dialog 容器。"""
|
||||
selector = ".p-dialog, [role='dialog']"
|
||||
loc = self.page.locator(selector)
|
||||
if text:
|
||||
loc = loc.filter(has_text=text)
|
||||
return loc.last
|
||||
|
||||
def click_row_action(self, row_text, action_label, icon_classes=None, timeout=5000):
|
||||
"""点击表格/卡片行内操作,兼容文本按钮、aria、tooltip 和图标按钮。"""
|
||||
"""点击表格/卡片行内操作,兼容文本按钮、aria、tooltip 和图标按钮"""
|
||||
icon_classes = icon_classes or []
|
||||
logger.info(f"👉 [RowAction] 在 [{row_text}] 容器内点击 [{action_label}]")
|
||||
|
||||
@ -169,7 +111,7 @@ class BasePage:
|
||||
if loc.count() and loc.is_visible(timeout=500):
|
||||
loc.click()
|
||||
return True
|
||||
except:
|
||||
except Exception:
|
||||
continue
|
||||
raise Exception(f"❌ 未找到 [{row_text}] 的行内操作 [{action_label}]")
|
||||
|
||||
@ -177,29 +119,25 @@ class BasePage:
|
||||
"""语义化输入:支持 Vue/React 的深度绑定注入"""
|
||||
logger.info(f"⌨️ [SmartFill] 在 [{label}] 填写: {value}")
|
||||
try:
|
||||
# 1. 尝试直接命中 (Label/Placeholder等原生属性)
|
||||
el = self.smart_find(label, timeout=timeout)
|
||||
el.wait_for(state="visible", timeout=timeout)
|
||||
el.fill(value, timeout=timeout)
|
||||
except Exception as first_err:
|
||||
try:
|
||||
# 2. 邻近注入方案:借助 JS 寻找关联输入框,并使用 Playwright 原生 fill 保障前端框架双向绑定
|
||||
logger.info(f"🔍 [SmartFill] 常规规则未命中,正在执行深度邻近探测 [{label}]...")
|
||||
success = self.page.evaluate(f"""(lbl) => {{
|
||||
document.querySelectorAll('[data-smart-target]').forEach(e => e.removeAttribute('data-smart-target'));
|
||||
|
||||
// 1. 过滤:必须是有高度/宽度的真实可见节点
|
||||
|
||||
const allNodes = Array.from(document.querySelectorAll('label, span, div, p, legend'))
|
||||
.filter(el => el.offsetWidth > 0 && el.offsetHeight > 0 && el.innerText && el.innerText.includes(lbl));
|
||||
|
||||
// 2. 最深层过滤
|
||||
|
||||
const tags = allNodes.filter(el => {{
|
||||
return !Array.from(el.children).some(child => child.offsetWidth > 0 && child.innerText && child.innerText.includes(lbl));
|
||||
}});
|
||||
|
||||
|
||||
for (const t of tags) {{
|
||||
const container = t.closest('.p-inputgroup, .field, .flex, div');
|
||||
const input = container?.querySelector('input:not([type="hidden"]), textarea') ||
|
||||
const input = container?.querySelector('input:not([type="hidden"]), textarea') ||
|
||||
t.parentElement?.querySelector('input:not([type="hidden"]), textarea');
|
||||
if (input && input.offsetWidth > 0) {{
|
||||
input.setAttribute('data-smart-target', 'true');
|
||||
@ -208,7 +146,7 @@ class BasePage:
|
||||
}}
|
||||
return false;
|
||||
}}""", label)
|
||||
|
||||
|
||||
if success:
|
||||
target = self.page.locator("[data-smart-target='true']").first
|
||||
target.scroll_into_view_if_needed()
|
||||
@ -221,7 +159,7 @@ class BasePage:
|
||||
logger.error(f"⚠️ [SmartFill] JS注入或执行时发生错误: {second_err}")
|
||||
raise second_err
|
||||
|
||||
def smart_delete(self,text,role=None,timeout=5000):
|
||||
def smart_delete(self, text, role=None, timeout=5000):
|
||||
logger.info(f"👉 [SmartDelete] 尝试删除: {text}")
|
||||
try:
|
||||
el = self.smart_find(text, role=role, timeout=timeout)
|
||||
@ -234,8 +172,7 @@ class BasePage:
|
||||
def smart_select(self, label, value):
|
||||
"""智能下拉框选择 (适配 PrimeVue)"""
|
||||
logger.info(f"📋 [SmartSelect] 在 [{label}] 下拉框寻找目标: {value}")
|
||||
|
||||
# 1. 寻找并打开下拉框
|
||||
|
||||
opened = self.page.evaluate("""([lbl, val]) => {
|
||||
const root = document.querySelector('.p-dialog') || document.querySelector('[role="dialog"]') || document;
|
||||
const elements = Array.from(root.querySelectorAll('label, span, div'));
|
||||
@ -243,20 +180,18 @@ class BasePage:
|
||||
const t = el.innerText?.trim();
|
||||
return t && (t === lbl || t.includes(lbl)) && el.offsetWidth > 0;
|
||||
});
|
||||
|
||||
|
||||
if (!targetLabel) return 'NO_LABEL';
|
||||
|
||||
|
||||
let container = targetLabel;
|
||||
for (let i = 0; i < 8; i++) {
|
||||
if (!container) break;
|
||||
// 查找下拉框容器
|
||||
const dd = container.querySelector('.p-select, .p-dropdown, [data-pc-name="select"], [data-pc-name="dropdown"]');
|
||||
if (dd && dd.offsetWidth > 0) {
|
||||
dd.scrollIntoView({block: 'center'});
|
||||
dd.click();
|
||||
return 'OPENED';
|
||||
}
|
||||
// 检查兄弟元素
|
||||
if (container.parentElement) {
|
||||
const sibling = container.parentElement.querySelector('.p-select, .p-dropdown, [data-pc-name="select"]');
|
||||
if (sibling && sibling.offsetWidth > 0) {
|
||||
@ -269,16 +204,14 @@ class BasePage:
|
||||
}
|
||||
return 'NO_DROPDOWN';
|
||||
}""", [label, value])
|
||||
|
||||
|
||||
if opened != 'OPENED':
|
||||
logger.warning(f"⚠️ [SmartSelect] 无法精准找到标签 '{label}' 关联的下拉框,尝试直接搜索首个 visible 的下拉框...")
|
||||
self.page.locator(".p-select, .p-dropdown").first.click()
|
||||
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
# 2. 尝试多种定位器点击选项
|
||||
try:
|
||||
# 优先精准文本
|
||||
selectors = [
|
||||
f"li[role='option']:has-text('{value}')",
|
||||
f".p-select-option:has-text('{value}')",
|
||||
@ -290,10 +223,9 @@ class BasePage:
|
||||
loc.click()
|
||||
logger.info(f"✅ [SmartSelect] 成功通过选择器选中: {value}")
|
||||
return True
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 3. JS 暴力匹配并点击
|
||||
clicked = self.page.evaluate("""(val) => {
|
||||
const options = Array.from(document.querySelectorAll('li[role="option"], .p-select-option, .p-dropdown-item'));
|
||||
const target = options.find(opt => opt.offsetWidth > 0 && opt.innerText.includes(val));
|
||||
@ -308,5 +240,5 @@ class BasePage:
|
||||
if clicked:
|
||||
logger.info(f"✅ [SmartSelect] 通过 JS 暴力匹配选中: {value}")
|
||||
return True
|
||||
|
||||
raise Exception(f"❌ [SmartSelect] 无法在下拉框中选择选项: {value}")
|
||||
|
||||
raise Exception(f"❌ [SmartSelect] 无法在下拉框中选择选项: {value}")
|
||||
62
tests/base/mixins/smart_locator.py
Normal file
62
tests/base/mixins/smart_locator.py
Normal file
@ -0,0 +1,62 @@
|
||||
"""SmartLocatorMixin — 语义化智能定位器
|
||||
|
||||
从 framework/core/base_page.py 提取,适配 PrimeVue 和 Ant Design 双 UI 框架。
|
||||
"""
|
||||
from tests.logger import get_logger
|
||||
|
||||
logger = get_logger("SmartLocator")
|
||||
|
||||
|
||||
class SmartLocatorMixin:
|
||||
"""提供基于语义的智能元素定位,支持多种策略级联尝试"""
|
||||
|
||||
def smart_find(self, description, role=None, timeout=5000):
|
||||
"""核心智能定位器:按优先级尝试语义定位"""
|
||||
strategies = [
|
||||
lambda: self.page.get_by_role(role, name=description, exact=False) if role else None,
|
||||
lambda: self.page.get_by_text(description, exact=False),
|
||||
lambda: self.page.locator(f'[aria-label*="{description}"]').first,
|
||||
lambda: self.page.get_by_placeholder(description, exact=False),
|
||||
lambda: self.page.get_by_label(description, exact=False),
|
||||
lambda: self.page.get_by_title(description, exact=False)
|
||||
]
|
||||
|
||||
for get_loc in strategies:
|
||||
try:
|
||||
loc = get_loc()
|
||||
if loc and loc.count() > 0:
|
||||
return loc.first
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
if any(c in description for c in [".", "#", "[", ">"]):
|
||||
try:
|
||||
return self.page.locator(description).first
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
raise Exception(f"❌ 无法在页面找到元素: '{description}'")
|
||||
|
||||
def visible_dialog(self, text=None):
|
||||
"""返回当前可见的最上层 Dialog 容器"""
|
||||
selector = ".p-dialog, [role='dialog']"
|
||||
loc = self.page.locator(selector)
|
||||
if text:
|
||||
loc = loc.filter(has_text=text)
|
||||
return loc.last
|
||||
|
||||
def goto_route(self, route):
|
||||
"""在当前登录域名下跳转到指定前端路由"""
|
||||
from urllib.parse import urlsplit
|
||||
from config.settings import Config
|
||||
|
||||
current = self.page.url or ""
|
||||
parsed = urlsplit(current)
|
||||
if parsed.scheme and parsed.netloc:
|
||||
base = f"{parsed.scheme}://{parsed.netloc}"
|
||||
else:
|
||||
base = Config.BASE_URL
|
||||
|
||||
if not route.startswith("/"):
|
||||
route = f"/{route}"
|
||||
self.page.goto(f"{base}{route}", wait_until="domcontentloaded")
|
||||
@ -149,8 +149,26 @@ def pytest_runtest_makereport(item, call):
|
||||
result = "失败"
|
||||
|
||||
error_detail = ""
|
||||
assertion_msg = ""
|
||||
failure_reason = ""
|
||||
if report.failed and report.longrepr:
|
||||
error_detail = str(report.longrepr)
|
||||
lines = error_detail.split("\n")
|
||||
for line in lines:
|
||||
stripped = line.strip()
|
||||
if stripped.startswith("AssertionError"):
|
||||
failure_reason = stripped
|
||||
break
|
||||
elif stripped.startswith("E ") and "AssertionError" in stripped:
|
||||
failure_reason = stripped
|
||||
elif stripped.startswith("assert "):
|
||||
assertion_msg = stripped
|
||||
if not failure_reason:
|
||||
for line in lines:
|
||||
stripped = line.strip()
|
||||
if stripped and not stripped.startswith("_"):
|
||||
failure_reason = stripped[:200]
|
||||
break
|
||||
|
||||
_REPORT_RECORDS.append(
|
||||
{
|
||||
@ -163,6 +181,8 @@ def pytest_runtest_makereport(item, call):
|
||||
"result": result,
|
||||
"duration": round(report.duration, 2),
|
||||
"error": error_detail,
|
||||
"assertion": assertion_msg,
|
||||
"reason": failure_reason,
|
||||
"screenshot": screenshot_path,
|
||||
}
|
||||
)
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
from playwright.sync_api import Page, Locator
|
||||
from tests.base.base_page import BasePage
|
||||
from tests.logger import log_ui
|
||||
@ -15,8 +17,8 @@ from tests.logger import log_ui
|
||||
class TaskListPage(BasePage):
|
||||
"""数据生成 - 任务列表页面"""
|
||||
|
||||
# 页面URL
|
||||
url = "https://cloud-fat.d-robotics.cc/d-cloud/data-create/list"
|
||||
BASE_URL = os.getenv("DCLOUD_BASE_URL", "https://cloud-fat.d-robotics.cc")
|
||||
url = f"{BASE_URL}/d-cloud/data-create/list"
|
||||
|
||||
# 元素选择器
|
||||
SELECTORS = {
|
||||
@ -1096,7 +1098,8 @@ DataGenerationPage = TaskListPage
|
||||
class TaskDetailPage(BasePage):
|
||||
"""数据生成 - 任务详情页面"""
|
||||
|
||||
url_template = "https://cloud-fat.d-robotics.cc/d-cloud/data-create/taskdetail/{task_id}"
|
||||
BASE_URL = os.getenv("DCLOUD_BASE_URL", "https://cloud-fat.d-robotics.cc")
|
||||
url_template = f"{BASE_URL}/d-cloud/data-create/taskdetail/{{task_id}}"
|
||||
|
||||
SELECTORS = {
|
||||
# Tab - 实际页面只有"详细信息"和"输出结果"两个Tab
|
||||
|
||||
166
tests/data_set/tests/test_data_set_annotation_api.py
Normal file
166
tests/data_set/tests/test_data_set_annotation_api.py
Normal file
@ -0,0 +1,166 @@
|
||||
"""数据集标注与微调 BFF API 测试
|
||||
|
||||
基于 api_docs/dataset_annotation_finetune_api.md (2026-06-09)
|
||||
Base: /roboticsBffApi/cv/v1/dataset
|
||||
"""
|
||||
import pytest
|
||||
from tests.utils import APIClient
|
||||
|
||||
|
||||
BFF_PREFIX = "/api/roboticsBffApi/cv/v1/dataset"
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestAnnotationModelList:
|
||||
"""GET /annotation/get-annotation-model-list"""
|
||||
|
||||
def test_get_models(self, api_client):
|
||||
"""描述:获取标注模型列表。预期:返回 models 数组。"""
|
||||
resp = api_client.get(f"{BFF_PREFIX}/annotation/get-annotation-model-list")
|
||||
if resp.status_code == 200 and resp.json()["status"] == 0:
|
||||
data = resp.json()["data"]
|
||||
assert "models" in data
|
||||
assert isinstance(data["models"], list)
|
||||
else:
|
||||
pytest.skip(f"接口不可用: {resp.status_code}")
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestLabelSplit:
|
||||
"""POST /annotation/label-split"""
|
||||
|
||||
def test_split_basic(self, api_client):
|
||||
"""描述:分割标签文本。预期:返回 labels 数组。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/annotation/label-split", json={
|
||||
"text": "cat, dog, person",
|
||||
})
|
||||
if resp.status_code == 200 and resp.json()["status"] == 0:
|
||||
data = resp.json()["data"]
|
||||
assert "labels" in data
|
||||
assert len(data["labels"]) == 3
|
||||
else:
|
||||
pytest.skip(f"接口不可用: {resp.status_code}")
|
||||
|
||||
def test_split_empty(self, api_client):
|
||||
"""描述:空文本。预期:返回空 labels 或参数错误。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/annotation/label-split", json={
|
||||
"text": "",
|
||||
})
|
||||
assert resp.status_code in (200, 400)
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestAutoAnnotation:
|
||||
"""POST /annotation/auto-annotation"""
|
||||
|
||||
def test_auto_annotation_missing_fields(self, api_client):
|
||||
"""描述:缺少必填字段。预期:返回 40000。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/annotation/auto-annotation", json={})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestCreateGroundTruth:
|
||||
"""POST /annotation/create-ground-truth"""
|
||||
|
||||
def test_missing_fields(self, api_client):
|
||||
"""描述:缺少必填字段。预期:返回 40000。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/annotation/create-ground-truth", json={})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestManualAnnotation:
|
||||
"""POST /annotation/manual-annotation"""
|
||||
|
||||
def test_missing_fields(self, api_client):
|
||||
"""描述:缺少必填字段。预期:返回 40000。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/annotation/manual-annotation", json={})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestGetAnnotation:
|
||||
"""GET /annotation/get-annotation"""
|
||||
|
||||
def test_missing_sample_id(self, api_client):
|
||||
"""描述:缺少 sample_id。预期:返回 40000。"""
|
||||
resp = api_client.get(f"{BFF_PREFIX}/annotation/get-annotation")
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestFinetuneList:
|
||||
"""POST /finetune/list"""
|
||||
|
||||
def test_list_basic(self, api_client):
|
||||
"""描述:查询微调任务列表。预期:返回 list/total。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/finetune/list", json={
|
||||
"page": 1, "page_size": 20
|
||||
})
|
||||
data = resp.json()
|
||||
if resp.status_code == 200 and data["status"] == 0:
|
||||
assert "list" in data["data"]
|
||||
assert "total" in data["data"]
|
||||
else:
|
||||
pytest.skip(f"接口不可用: {resp.status_code}")
|
||||
|
||||
def test_list_pagination(self, api_client):
|
||||
"""描述:分页查询。预期:返回数据量<=5。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/finetune/list", json={
|
||||
"page": 1, "page_size": 5
|
||||
})
|
||||
if resp.status_code == 200 and resp.json()["status"] == 0:
|
||||
data = resp.json()["data"]
|
||||
assert len(data["list"]) <= 5
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestFinetuneCreate:
|
||||
"""POST /finetune/create"""
|
||||
|
||||
def test_create_missing_fields(self, api_client):
|
||||
"""描述:缺少必填字段。预期:返回 40000。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/finetune/create", json={})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestFinetuneTaskTest:
|
||||
"""POST /finetune/task/test"""
|
||||
|
||||
def test_missing_fields(self, api_client):
|
||||
"""描述:缺少必填字段。预期:返回 40000。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/finetune/task/test", json={})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestFinetuneGet:
|
||||
"""GET /finetune/:task_id"""
|
||||
|
||||
def test_not_found(self, api_client):
|
||||
"""描述:查询不存在的任务。预期:返回 40400。"""
|
||||
resp = api_client.get(f"{BFF_PREFIX}/finetune/nonexistent-task-id")
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestFinetuneDelete:
|
||||
"""DELETE /finetune/:task_id"""
|
||||
|
||||
def test_delete_nonexistent(self, api_client):
|
||||
"""描述:删除不存在的任务。预期:返回 40400。"""
|
||||
resp = api_client.delete(f"{BFF_PREFIX}/finetune/nonexistent-task-id")
|
||||
assert resp.status_code == 404
|
||||
245
tests/data_set/tests/test_data_set_annotation_e2e.py
Normal file
245
tests/data_set/tests/test_data_set_annotation_e2e.py
Normal file
@ -0,0 +1,245 @@
|
||||
"""标注与微调 E2E 全链路测试
|
||||
|
||||
基于 api_docs/dataset_annotation_finetune_api.md
|
||||
真数据链路:样本列表→自动标注→创建真值→微调任务
|
||||
"""
|
||||
import time
|
||||
import pytest
|
||||
from tests.utils import APIClient
|
||||
|
||||
BFF = "/api/roboticsBffApi/cv/v1/dataset"
|
||||
TEST_DATA_PATH = "/testing/dataSpace/CJWTest_20260703"
|
||||
|
||||
|
||||
def _get_available_collection(api_client):
|
||||
"""获取一个有样本的数据集用于标注测试"""
|
||||
resp = api_client.post(f"{BFF}/collections/list", json={
|
||||
"dataset_kind": "training", "page": 1, "page_size": 10
|
||||
})
|
||||
for c in resp.json()["data"]["list"]:
|
||||
if c["stats"]["total_count"] > 0 and c["status"] in ("tobepublished", "running"):
|
||||
vid = c.get("editable_version", {}).get("version_id")
|
||||
if not vid and c.get("versions"):
|
||||
vid = c["versions"][0]["version_id"]
|
||||
if vid:
|
||||
return c["collection_id"], vid
|
||||
return None, None
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
@pytest.mark.real_creation
|
||||
@pytest.mark.requires_cleanup
|
||||
@pytest.mark.dataset
|
||||
class TestAnnotationE2E:
|
||||
"""标注 E2E:样本列表→自动标注→手动标注→创建真值"""
|
||||
|
||||
def test_auto_annotation_flow(self, api_client):
|
||||
"""
|
||||
描述:E2E⑩ — 获取样本→触发自动标注→验证任务创建。
|
||||
预期:自动标注任务创建成功,返回 task_id。
|
||||
"""
|
||||
cid, vid = _get_available_collection(api_client)
|
||||
if not cid:
|
||||
pytest.skip("无可用的有样本数据集")
|
||||
|
||||
# 获取样本列表
|
||||
samples_resp = api_client.post(f"{BFF}/samples/list", json={
|
||||
"collection_id": cid, "version_id": vid, "page": 1, "page_size": 5
|
||||
})
|
||||
assert samples_resp.status_code == 200
|
||||
samples = samples_resp.json()["data"]["list"]
|
||||
assert len(samples) > 0, "样本列表为空"
|
||||
|
||||
# 触发自动标注
|
||||
auto_resp = api_client.post(f"{BFF}/annotation/auto-annotation", json={
|
||||
"collection_id": cid,
|
||||
"version_id": vid,
|
||||
"task_types": ["object_detection"],
|
||||
"objectdetection_models": [{
|
||||
"sku_id": "DINO-X-1.0",
|
||||
"sku_name": "DINO-X-1.0",
|
||||
"private_id": 0,
|
||||
"labels": ["cat", "dog"],
|
||||
}],
|
||||
"label_all": False,
|
||||
})
|
||||
if auto_resp.status_code == 200 and auto_resp.json()["status"] == 0:
|
||||
data = auto_resp.json()["data"]
|
||||
assert "task_id" in data, f"自动标注响应缺少 task_id: {data}"
|
||||
else:
|
||||
pytest.skip(f"自动标注接口不可用: {auto_resp.json().get('message')}")
|
||||
|
||||
def test_create_ground_truth(self, api_client):
|
||||
"""描述:为样本创建真值标注。预期:接口正常响应。"""
|
||||
cid, vid = _get_available_collection(api_client)
|
||||
if not cid:
|
||||
pytest.skip("无可用的有样本数据集")
|
||||
|
||||
samples_resp = api_client.post(f"{BFF}/samples/list", json={
|
||||
"collection_id": cid, "version_id": vid, "page": 1, "page_size": 1
|
||||
})
|
||||
if not samples_resp.json()["data"]["list"]:
|
||||
pytest.skip("样本列表为空")
|
||||
sample_id = samples_resp.json()["data"]["list"][0]["id"]
|
||||
|
||||
resp = api_client.post(f"{BFF}/annotation/create-ground-truth", json={
|
||||
"collection_id": cid,
|
||||
"version_id": vid,
|
||||
"sample_id": sample_id,
|
||||
})
|
||||
assert resp.status_code in (200, 400)
|
||||
if resp.status_code == 200:
|
||||
assert resp.json()["status"] == 0
|
||||
|
||||
def test_get_annotation(self, api_client):
|
||||
"""描述:获取样本标注详情。预期:返回标注数据。"""
|
||||
cid, vid = _get_available_collection(api_client)
|
||||
if not cid:
|
||||
pytest.skip("无可用的有样本数据集")
|
||||
|
||||
samples_resp = api_client.post(f"{BFF}/samples/list", json={
|
||||
"collection_id": cid, "version_id": vid, "page": 1, "page_size": 1
|
||||
})
|
||||
if not samples_resp.json()["data"]["list"]:
|
||||
pytest.skip("样本列表为空")
|
||||
sample_id = samples_resp.json()["data"]["list"][0]["id"]
|
||||
|
||||
resp = api_client.get(
|
||||
f"{BFF}/annotation/get-annotation?collection_id={cid}&version_id={vid}&sample_id={sample_id}"
|
||||
)
|
||||
if resp.status_code == 200 and resp.json()["status"] == 0:
|
||||
data = resp.json()["data"]
|
||||
assert "id" in data
|
||||
assert "name" in data
|
||||
else:
|
||||
pytest.skip(f"标注详情不可用: {resp.json().get('message')}")
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
@pytest.mark.real_creation
|
||||
@pytest.mark.requires_cleanup
|
||||
@pytest.mark.dataset
|
||||
class TestFinetuneE2E:
|
||||
"""微调 E2E:创建→列表查询→详情→删除"""
|
||||
|
||||
def test_finetune_full_pipeline(self, api_client):
|
||||
"""
|
||||
描述:E2E⑪ — 微调全链路:创建微调任务→列表查询获取task_id→获取详情→删除清理。
|
||||
预期:全流程通过。
|
||||
"""
|
||||
cid, vid = _get_available_collection(api_client)
|
||||
if not cid:
|
||||
pytest.skip("无可用的有样本数据集")
|
||||
|
||||
ts = int(time.time())
|
||||
name = f"e2e_finetune_{ts}"
|
||||
task_id = None
|
||||
|
||||
# ── Step 1: 创建微调任务 ──
|
||||
create_resp = api_client.post(f"{BFF}/finetune/create", json={
|
||||
"name": name,
|
||||
"model": "DINO-X-1.0",
|
||||
"labels": ["cat", "dog"],
|
||||
"collections": [{"collection_id": cid, "version_id": vid}],
|
||||
"train": 80,
|
||||
"evaluate": 20,
|
||||
})
|
||||
assert create_resp.status_code == 200
|
||||
assert create_resp.json()["status"] == 0, f"创建失败: {create_resp.json().get('message')}"
|
||||
|
||||
# ── Step 2: 从列表获取 task_id ──
|
||||
time.sleep(2)
|
||||
list_resp = api_client.post(f"{BFF}/finetune/list", json={"page": 1, "page_size": 50})
|
||||
if list_resp.status_code == 200 and list_resp.json()["status"] == 0:
|
||||
found = [t for t in list_resp.json()["data"]["list"] if t["name"] == name]
|
||||
if not found:
|
||||
pytest.skip("列表未找到新创建的微调任务")
|
||||
task_id = found[0]["task_id"]
|
||||
assert task_id, "task_id 为空"
|
||||
|
||||
# ── Step 3: 获取详情 ──
|
||||
if task_id:
|
||||
get_resp = api_client.get(f"{BFF}/finetune/{task_id}")
|
||||
if get_resp.status_code == 200 and get_resp.json()["status"] == 0:
|
||||
detail = get_resp.json()["data"]
|
||||
assert detail["name"] == name
|
||||
assert detail["task_id"] == task_id
|
||||
|
||||
# ── Step 4: 删除清理 ──
|
||||
if task_id:
|
||||
delete_resp = api_client.delete(f"{BFF}/finetune/{task_id}")
|
||||
assert delete_resp.status_code == 200
|
||||
assert delete_resp.json()["status"] == 0
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
@pytest.mark.real_creation
|
||||
@pytest.mark.requires_cleanup
|
||||
@pytest.mark.dataset
|
||||
class TestCollectionE2EFull:
|
||||
"""数据集完整 E2E:使用已有集合→查样本→标注→微调"""
|
||||
|
||||
def test_full_pipeline_with_annotation(self, api_client):
|
||||
"""
|
||||
描述:E2E⑩⑪ 完整链路:获取已有集合→查样本→自动标注→微调创建→清理。
|
||||
预期:全流程通过。
|
||||
"""
|
||||
cid, vid = _get_available_collection(api_client)
|
||||
if not cid:
|
||||
pytest.skip("无可用的有样本数据集")
|
||||
|
||||
# ── Step 1: 查样本列表 ──
|
||||
samples_resp = api_client.post(f"{BFF}/samples/list", json={
|
||||
"collection_id": cid, "version_id": vid, "page": 1, "page_size": 5
|
||||
})
|
||||
assert samples_resp.status_code == 200
|
||||
data = samples_resp.json()
|
||||
if data["data"]["total"] == 0:
|
||||
pytest.skip("样本列表为空")
|
||||
samples = data["data"]["list"]
|
||||
assert len(samples) > 0
|
||||
|
||||
# ── Step 2: 自动标注 ──
|
||||
auto_resp = api_client.post(f"{BFF}/annotation/auto-annotation", json={
|
||||
"collection_id": cid,
|
||||
"version_id": vid,
|
||||
"task_types": ["object_detection"],
|
||||
"objectdetection_models": [{
|
||||
"sku_id": "DINO-X-1.0",
|
||||
"sku_name": "DINO-X-1.0",
|
||||
"private_id": 0,
|
||||
"labels": ["cat", "dog"],
|
||||
}],
|
||||
"label_all": False,
|
||||
})
|
||||
assert auto_resp.status_code == 200
|
||||
assert auto_resp.json()["status"] == 0, auto_resp.json().get("message")
|
||||
|
||||
# ── Step 3: 标签解析 ──
|
||||
parser_resp = api_client.post(f"{BFF}/labels/parser", json={
|
||||
"sources": [{"source_type": "dataspace", "path": "/testing/dataSpace/CJWTest_20260703"}],
|
||||
})
|
||||
assert parser_resp.status_code in (200, 400)
|
||||
|
||||
# ── Step 4: 微调创建 ──
|
||||
ts = int(time.time())
|
||||
name = f"e2e_full_{ts}"
|
||||
create_resp = api_client.post(f"{BFF}/finetune/create", json={
|
||||
"name": name,
|
||||
"model": "DINO-X-1.0",
|
||||
"labels": ["cat", "dog"],
|
||||
"collections": [{"collection_id": cid, "version_id": vid}],
|
||||
"train": 80,
|
||||
"evaluate": 20,
|
||||
})
|
||||
assert create_resp.status_code == 200
|
||||
assert create_resp.json()["status"] == 0
|
||||
|
||||
# ── Step 5: 从列表查 task_id 并清理 ──
|
||||
time.sleep(2)
|
||||
list_resp = api_client.post(f"{BFF}/finetune/list", json={"page": 1, "page_size": 50})
|
||||
if list_resp.json()["status"] == 0:
|
||||
found = [t for t in list_resp.json()["data"]["list"] if t["name"] == name]
|
||||
if found:
|
||||
task_id = found[0]["task_id"]
|
||||
api_client.delete(f"{BFF}/finetune/{task_id}")
|
||||
191
tests/data_set/tests/test_data_set_bff_api.py
Normal file
191
tests/data_set/tests/test_data_set_bff_api.py
Normal file
@ -0,0 +1,191 @@
|
||||
"""数据集 BFF API 测试 — collections CRUD
|
||||
|
||||
基于 api_docs/dataset_api.md (2026-06-29)
|
||||
Base: /roboticsBffApi/cv/v1/dataset
|
||||
"""
|
||||
import time
|
||||
import pytest
|
||||
from tests.utils import APIClient
|
||||
|
||||
|
||||
BFF_PREFIX = "/api/roboticsBffApi/cv/v1/dataset"
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestCollectionList:
|
||||
"""POST /collections/list"""
|
||||
|
||||
def test_list_training(self, api_client):
|
||||
"""描述:查询训练集列表。预期:返回 HTTP 200,响应含 list/total/page/page_size。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/collections/list", json={
|
||||
"dataset_kind": "training", "page": 1, "page_size": 20
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert data["status"] == 0
|
||||
assert "list" in data["data"]
|
||||
assert "total" in data["data"]
|
||||
|
||||
def test_list_testing(self, api_client):
|
||||
"""描述:查询测试集列表。预期:返回 HTTP 200。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/collections/list", json={
|
||||
"dataset_kind": "testing", "page": 1, "page_size": 20
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["status"] == 0
|
||||
|
||||
def test_list_pagination(self, api_client):
|
||||
"""描述:分页查询,page_size=5。预期:返回数据量<=5。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/collections/list", json={
|
||||
"dataset_kind": "training", "page": 1, "page_size": 5
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert len(data["data"]["list"]) <= 5
|
||||
|
||||
def test_list_missing_kind(self, api_client):
|
||||
"""描述:缺少 dataset_kind。预期:返回 400。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/collections/list", json={
|
||||
"page": 1, "page_size": 20
|
||||
})
|
||||
assert resp.status_code in (400, 200)
|
||||
if resp.status_code == 200:
|
||||
assert resp.json()["status"] != 0
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestCollectionCreate:
|
||||
"""POST /collections/create — 创建后需清理"""
|
||||
|
||||
created_ids = []
|
||||
|
||||
def test_create_minimal(self, api_client):
|
||||
"""描述:创建最简数据集。预期:返回 job_id,collection 待发布。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/collections/create", json={
|
||||
"dataset_kind": "training",
|
||||
"name": f"auto_test_min_{int(time.time())}",
|
||||
"task_types": ["object_detection"],
|
||||
"labels": ["test"],
|
||||
"sources": [{"source_type": "dataspace", "path": "data/test"}],
|
||||
})
|
||||
data = resp.json()
|
||||
if resp.status_code == 200 and data["status"] == 0:
|
||||
cid = data["data"].get("collection_id")
|
||||
if cid:
|
||||
self.created_ids.append(cid)
|
||||
assert "job_id" in data["data"]
|
||||
else:
|
||||
pytest.skip(f"创建失败: {data.get('message', '')}")
|
||||
|
||||
def test_create_missing_name(self, api_client):
|
||||
"""描述:缺少 name。预期:返回 40000。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/collections/create", json={
|
||||
"dataset_kind": "training",
|
||||
"task_types": ["object_detection"],
|
||||
"labels": ["test"],
|
||||
"sources": [{"source_type": "dataspace", "path": "data/test"}],
|
||||
})
|
||||
assert resp.status_code == 400
|
||||
|
||||
def test_create_duplicate_name(self, api_client):
|
||||
"""描述:重复 name。预期:返回 40900。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/collections/create", json={
|
||||
"dataset_kind": "training",
|
||||
"name": "auto_test_dup",
|
||||
"task_types": ["object_detection"],
|
||||
"labels": ["test"],
|
||||
"sources": [{"source_type": "dataspace", "path": "data/test"}],
|
||||
})
|
||||
if resp.status_code == 200 and resp.json()["status"] == 0:
|
||||
cid = resp.json()["data"].get("collection_id")
|
||||
if cid:
|
||||
self.created_ids.append(cid)
|
||||
resp2 = api_client.post(f"{BFF_PREFIX}/collections/create", json={
|
||||
"dataset_kind": "training",
|
||||
"name": "auto_test_dup",
|
||||
"task_types": ["object_detection"],
|
||||
"labels": ["test"],
|
||||
"sources": [{"source_type": "dataspace", "path": "data/test"}],
|
||||
})
|
||||
assert resp2.status_code == 409
|
||||
else:
|
||||
pytest.skip(f"首次创建失败: {resp.json().get('message', '')}")
|
||||
|
||||
# teardown cleanup
|
||||
@pytest.fixture(autouse=True)
|
||||
def cleanup_created(self, api_client):
|
||||
yield
|
||||
for cid in self.created_ids:
|
||||
try:
|
||||
api_client.delete(f"{BFF_PREFIX}/collections/delete?collection_id={cid}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestCollectionGet:
|
||||
"""GET /collections/get"""
|
||||
|
||||
def test_get_existing(self, api_client):
|
||||
"""描述:查询已知数据集详情。预期:返回 versions/stats。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/collections/list", json={
|
||||
"dataset_kind": "training", "page": 1, "page_size": 1
|
||||
})
|
||||
if resp.status_code == 200 and resp.json()["data"]["list"]:
|
||||
cid = resp.json()["data"]["list"][0]["collection_id"]
|
||||
resp2 = api_client.get(f"{BFF_PREFIX}/collections/get?collection_id={cid}")
|
||||
assert resp2.status_code == 200
|
||||
data = resp2.json()
|
||||
assert "versions" in data["data"]
|
||||
assert "stats" in data["data"]
|
||||
else:
|
||||
pytest.skip("无可用数据集")
|
||||
|
||||
def test_get_not_found(self, api_client):
|
||||
"""描述:查询不存在的 collection_id。预期:返回 40400。"""
|
||||
resp = api_client.get(f"{BFF_PREFIX}/collections/get?collection_id=dc_nonexistent")
|
||||
assert resp.status_code in (404, 200)
|
||||
if resp.status_code == 200:
|
||||
assert resp.json()["status"] != 0
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestCollectionUpdate:
|
||||
"""POST /collections/update"""
|
||||
|
||||
def test_update_missing_version_id(self, api_client):
|
||||
"""描述:缺少 version_id。预期:返回 40000。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/collections/update", json={
|
||||
"collection_id": "dc_test",
|
||||
"name": "updated",
|
||||
})
|
||||
assert resp.status_code == 400
|
||||
|
||||
def test_update_nonexistent(self, api_client):
|
||||
"""描述:更新不存在的 collection。预期:返回 40400。"""
|
||||
resp = api_client.post(f"{BFF_PREFIX}/collections/update", json={
|
||||
"collection_id": "dc_nonexistent",
|
||||
"version_id": "dv_nonexistent",
|
||||
"name": "updated",
|
||||
})
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.api
|
||||
@pytest.mark.dataset
|
||||
class TestCollectionDelete:
|
||||
"""DELETE /collections/delete"""
|
||||
|
||||
def test_delete_nonexistent(self, api_client):
|
||||
"""描述:删除不存在的 collection。预期:返回 40400。"""
|
||||
resp = api_client.delete(f"{BFF_PREFIX}/collections/delete?collection_id=dc_nonexistent")
|
||||
assert resp.status_code == 404
|
||||
|
||||
def test_delete_missing_id(self, api_client):
|
||||
"""描述:缺少 collection_id。预期:返回 40000。"""
|
||||
resp = api_client.delete(f"{BFF_PREFIX}/collections/delete")
|
||||
assert resp.status_code == 400
|
||||
175
tests/data_set/tests/test_data_set_e2e.py
Normal file
175
tests/data_set/tests/test_data_set_e2e.py
Normal file
@ -0,0 +1,175 @@
|
||||
"""数据集 E2E 全链路测试
|
||||
|
||||
真数据链路:创建 collection → 查列表 → 查详情 → 更新 → 删除
|
||||
基于 api_docs/dataset_api.md,测试数据源: /testing/dataSpace/CJWTest_20260703
|
||||
"""
|
||||
import time
|
||||
import pytest
|
||||
from tests.utils import APIClient
|
||||
|
||||
BFF = "/api/roboticsBffApi/cv/v1/dataset"
|
||||
TEST_DATA_PATH = "/testing/dataSpace/CJWTest_20260703"
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
@pytest.mark.real_creation
|
||||
@pytest.mark.requires_cleanup
|
||||
@pytest.mark.dataset
|
||||
class TestDatasetE2E:
|
||||
"""数据集 E2E 全链路:创建→查询→更新→删除"""
|
||||
|
||||
def test_full_pipeline_create_list_get_update_delete(self, api_client):
|
||||
"""
|
||||
描述:数据集完整 E2E 链路:创建训练集→列表查询→获取详情→更新描述→删除清理。
|
||||
预期:全流程状态码正常,创建成功,列表可查到,详情含 versions/stats,更新生效,删除成功。
|
||||
"""
|
||||
ts = int(time.time())
|
||||
name = f"e2e_test_{ts}"
|
||||
collection_id = None
|
||||
|
||||
# ── Step 1: 创建 collection ──
|
||||
create_resp = api_client.post(f"{BFF}/collections/create", json={
|
||||
"dataset_kind": "training",
|
||||
"name": name,
|
||||
"task_types": ["object_detection"],
|
||||
"labels": ["cat", "dog"],
|
||||
"sources": [{"source_type": "dataspace", "path": TEST_DATA_PATH}],
|
||||
})
|
||||
assert create_resp.status_code == 200, f"创建失败: {create_resp.text}"
|
||||
create_data = create_resp.json()
|
||||
assert create_data["status"] == 0, f"创建业务失败: {create_data.get('message')}"
|
||||
collection_id = create_data["data"]["collection_id"]
|
||||
assert collection_id.startswith("dc_"), f"collection_id 格式异常: {collection_id}"
|
||||
assert "job_id" in create_data["data"]
|
||||
|
||||
# ── Step 2: 列表查询确认存在 ──
|
||||
list_resp = api_client.post(f"{BFF}/collections/list", json={
|
||||
"dataset_kind": "training", "page": 1, "page_size": 50
|
||||
})
|
||||
assert list_resp.status_code == 200
|
||||
list_data = list_resp.json()
|
||||
names = [c["name"] for c in list_data["data"]["list"]]
|
||||
assert name in names, f"列表未找到创建的 collection: {name}"
|
||||
|
||||
# ── Step 3: 获取详情 ──
|
||||
get_resp = api_client.get(f"{BFF}/collections/get?collection_id={collection_id}")
|
||||
assert get_resp.status_code == 200
|
||||
detail = get_resp.json()
|
||||
assert detail["status"] == 0
|
||||
assert detail["data"]["collection_id"] == collection_id
|
||||
assert detail["data"]["name"] == name
|
||||
assert "versions" in detail["data"]
|
||||
assert "stats" in detail["data"]
|
||||
|
||||
# ── Step 4: 更新描述 ──
|
||||
editable = detail["data"].get("editable_version", {})
|
||||
version_id = editable.get("version_id") if editable else None
|
||||
if version_id:
|
||||
update_resp = api_client.post(f"{BFF}/collections/update", json={
|
||||
"collection_id": collection_id,
|
||||
"version_id": version_id,
|
||||
"description": f"e2e 测试更新 {ts}",
|
||||
})
|
||||
if update_resp.status_code == 200 and update_resp.json()["status"] == 0:
|
||||
get2_resp = api_client.get(f"{BFF}/collections/get?collection_id={collection_id}")
|
||||
assert get2_resp.status_code == 200
|
||||
assert f"e2e 测试更新 {ts}" in get2_resp.json()["data"].get("description", "")
|
||||
|
||||
# ── Step 5: 删除清理 ──
|
||||
delete_resp = api_client.delete(f"{BFF}/collections/delete?collection_id={collection_id}")
|
||||
assert delete_resp.status_code == 200
|
||||
assert delete_resp.json()["status"] == 0
|
||||
|
||||
# 确认已删除
|
||||
get_after = api_client.get(f"{BFF}/collections/get?collection_id={collection_id}")
|
||||
assert get_after.status_code == 404 or get_after.json()["status"] != 0
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
@pytest.mark.real_creation
|
||||
@pytest.mark.requires_cleanup
|
||||
@pytest.mark.dataset
|
||||
class TestDatasetVersionE2E:
|
||||
"""版本管理 E2E:版本树查询"""
|
||||
|
||||
def test_version_tree(self, api_client):
|
||||
"""描述:查询已有数据集的版本树。预期:返回版本树结构。"""
|
||||
list_resp = api_client.post(f"{BFF}/collections/list", json={
|
||||
"dataset_kind": "training", "page": 1, "page_size": 1
|
||||
})
|
||||
if not list_resp.json()["data"]["list"]:
|
||||
pytest.skip("无可用数据集")
|
||||
cid = list_resp.json()["data"]["list"][0]["collection_id"]
|
||||
resp = api_client.get(f"{BFF}/collections/version-tree?collection_id={cid}")
|
||||
if resp.status_code == 200 and resp.json()["status"] == 0:
|
||||
tree = resp.json()
|
||||
# 版本树可能返回空 data 或直接返回 tree 结构
|
||||
assert tree["status"] == 0
|
||||
else:
|
||||
pytest.skip(f"版本树接口不可用: {resp.status_code}")
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
@pytest.mark.real_creation
|
||||
@pytest.mark.requires_cleanup
|
||||
@pytest.mark.dataset
|
||||
class TestSampleE2E:
|
||||
"""样本操作 E2E:样本列表查询"""
|
||||
|
||||
def test_sample_list(self, api_client):
|
||||
"""描述:查询已有数据集的样本列表。预期:返回样本数据。"""
|
||||
list_resp = api_client.post(f"{BFF}/collections/list", json={
|
||||
"dataset_kind": "training", "page": 1, "page_size": 1
|
||||
})
|
||||
if not list_resp.json()["data"]["list"]:
|
||||
pytest.skip("无可用数据集")
|
||||
c = list_resp.json()["data"]["list"][0]
|
||||
cid = c["collection_id"]
|
||||
editable = c.get("editable_version") or {}
|
||||
vid = editable.get("version_id") if editable else None
|
||||
if not vid:
|
||||
versions = c.get("versions", [])
|
||||
vid = versions[0]["version_id"] if versions else None
|
||||
if not vid:
|
||||
pytest.skip("无可用版本")
|
||||
resp = api_client.post(f"{BFF}/samples/list", json={
|
||||
"collection_id": cid, "version_id": vid, "page": 1, "page_size": 10
|
||||
})
|
||||
if resp.status_code == 200 and resp.json()["status"] == 0:
|
||||
data = resp.json()["data"]
|
||||
assert "list" in data
|
||||
assert "total" in data
|
||||
else:
|
||||
pytest.skip(f"样本列表接口不可用: {resp.status_code}")
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
@pytest.mark.real_creation
|
||||
@pytest.mark.requires_cleanup
|
||||
@pytest.mark.dataset
|
||||
class TestExportE2E:
|
||||
"""导出 E2E"""
|
||||
|
||||
def test_export_missing_fields(self, api_client):
|
||||
"""描述:缺少必填字段。预期:返回 400。"""
|
||||
resp = api_client.post(f"{BFF}/export", json={})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
@pytest.mark.real_creation
|
||||
@pytest.mark.requires_cleanup
|
||||
@pytest.mark.dataset
|
||||
class TestLabelParserE2E:
|
||||
"""标签解析"""
|
||||
|
||||
def test_label_parser(self, api_client):
|
||||
"""描述:解析数据源目录中的标签。预期:返回 labels 数组。"""
|
||||
resp = api_client.post(f"{BFF}/labels/parser", json={
|
||||
"sources": [{"source_type": "dataspace", "path": TEST_DATA_PATH}],
|
||||
})
|
||||
if resp.status_code == 200 and resp.json()["status"] == 0:
|
||||
data = resp.json()["data"]
|
||||
assert "labels" in data
|
||||
else:
|
||||
pytest.skip(f"标签解析不可用: {resp.status_code}")
|
||||
36
tests/robogo/test_scenarios.py
Normal file
36
tests/robogo/test_scenarios.py
Normal file
@ -0,0 +1,36 @@
|
||||
"""Robogo 全链路巡检场景 pytest 收集入口
|
||||
|
||||
将 11 个 Robogo 场景脚本注册为 pytest 测试,使 `pytest --collect-only` 能统计全部用例。
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
import pytest
|
||||
|
||||
SCENARIOS = [
|
||||
("compute_resource", "开发机生命周期"),
|
||||
("desktop_lifecycle", "云桌面生命周期"),
|
||||
("file_system", "文件系统巡检"),
|
||||
("image_generation", "图像生成巡检"),
|
||||
("mirror_assets", "镜像资产巡检"),
|
||||
("monkey", "Monkey 测试"),
|
||||
("openclaw", "OpenClaw 巡检"),
|
||||
("quantization", "量化工具巡检"),
|
||||
("test_billing", "计费测试"),
|
||||
("three_d_assets", "3D 资产巡检"),
|
||||
("three_d_generation", "3D 生成巡检"),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.robogo
|
||||
@pytest.mark.parametrize("scenario,display_name", SCENARIOS, ids=lambda x: x)
|
||||
def test_robogo_scenario(scenario, display_name):
|
||||
"""运行单个 Robogo 巡检场景"""
|
||||
script = f"framework/scripts/{scenario}_scenario.py"
|
||||
result = subprocess.run(
|
||||
[sys.executable, script],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=300,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
pytest.fail(f"[{display_name}] 场景失败:\n{result.stderr or result.stdout}")
|
||||
@ -2,34 +2,39 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
import json
|
||||
import uuid
|
||||
import time
|
||||
import httpx
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
from tests.logger import get_api_logger
|
||||
from framework.core.exceptions import TokenExpiredError, APIError
|
||||
|
||||
|
||||
class APIClient:
|
||||
def __init__(
|
||||
self,
|
||||
base_url: str,
|
||||
self,
|
||||
base_url: str,
|
||||
token: str = None,
|
||||
cookie: str = None,
|
||||
cookies: dict = None,
|
||||
headers: dict = None,
|
||||
proxy_url: str = None
|
||||
proxy_url: str = None,
|
||||
):
|
||||
"""独立的 API 客户端
|
||||
|
||||
|
||||
Args:
|
||||
base_url: 基础 URL (e.g., "https://cloud-fat.d-robotics.cc")
|
||||
token: 认证 token
|
||||
cookie: 认证 cookie 字符串(兼容 framework 调用方)
|
||||
cookies: cookies 字典
|
||||
headers: 自定义 HTTP 头
|
||||
proxy_url: 代理 URL
|
||||
"""
|
||||
# Strip path from BASE_URL - httpx base_url with path causes wrong URL joining
|
||||
_parsed = urlparse(base_url)
|
||||
self.base_url = f"{_parsed.scheme}://{_parsed.netloc}"
|
||||
self.token = token
|
||||
self.cookie = cookie or ""
|
||||
self.cookies = cookies or {}
|
||||
self.headers = headers or {
|
||||
"Content-Type": "application/json",
|
||||
@ -132,6 +137,48 @@ class APIClient:
|
||||
f"message={payload.get('message')}"
|
||||
)
|
||||
|
||||
def get_common_headers(self, referer_path: str = "") -> dict:
|
||||
"""构建通用请求头(兼容 framework 调用方)"""
|
||||
return {
|
||||
"accept": "application/json, text/plain, */*",
|
||||
"accept-language": "zh-CN,zh;q=0.9",
|
||||
"authorization": self.token or "",
|
||||
"cookie": self.cookie,
|
||||
"origin": self.base_url,
|
||||
"referer": f"{self.base_url}{referer_path}",
|
||||
"sourceapp": "artificer",
|
||||
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36",
|
||||
"x-request-id": uuid.uuid4().hex[:21],
|
||||
}
|
||||
|
||||
def request(self, method: str, endpoint: str, headers: dict = None, **kwargs) -> dict:
|
||||
"""兼容 BaseAPI 调用方式的请求方法,返回解析后的 JSON dict"""
|
||||
if headers is None:
|
||||
headers = self.get_common_headers()
|
||||
response = self._request(method, endpoint, headers=headers, **kwargs)
|
||||
return self._check_response(response, endpoint)
|
||||
|
||||
def _check_response(self, response: httpx.Response, step_name: str) -> dict:
|
||||
"""检查 HTTP 状态码和业务状态,返回解析后的 JSON"""
|
||||
if response.status_code in (401, 403):
|
||||
raise TokenExpiredError(f"[{step_name}] HTTP {response.status_code}: 认证失败")
|
||||
if response.status_code < 200 or response.status_code >= 300:
|
||||
raise APIError(f"[{step_name}] HTTP {response.status_code}: {response.text}")
|
||||
|
||||
try:
|
||||
data = response.json()
|
||||
except Exception:
|
||||
raise APIError(f"[{step_name}] 非 JSON 响应: {response.text}")
|
||||
|
||||
body_status = data.get("status", 0)
|
||||
if body_status != 0:
|
||||
msg = data.get("message", "")
|
||||
if body_status in (401, 403) or "token" in msg.lower():
|
||||
raise TokenExpiredError(f"[{step_name}] 认证失效: {msg}")
|
||||
raise APIError(f"[{step_name}] 业务错误: {msg}")
|
||||
|
||||
return data
|
||||
|
||||
def _client(self, timeout=30.0, upload=False):
|
||||
# For multipart uploads, exclude Content-Type so httpx can set it automatically
|
||||
if upload:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user