Skip to content

Commit 1b6a011

Browse files
committed
v10.1: 蓝本自动生成+Preview服务器+MCP工具+插件更新+932测试
0 parents  commit 1b6a011

259 files changed

Lines changed: 56925 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cursorrules

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# TestPilot AI - 项目编码规范
2+
3+
## 蓝本文件(testpilot.json)管理规则
4+
5+
当你需要为某个被测应用生成或修改测试蓝本时,**必须遵守以下规则**:
6+
7+
1. **只允许存在一个蓝本文件**:每个被测应用目录下只保留一个 `testpilot.json`。
8+
2. **更新而非新建**:若该目录已存在 `testpilot.json`,直接覆盖更新,**不得**创建 `testpilot_v2.json`、`testpilot_new.json`、`testpilot_backup.json` 等任何变体文件。
9+
3. **文件放置位置**:蓝本文件必须放在被测应用的**根目录**,固定命名为 `testpilot.json`。
10+
- ✅ 正确:`shop-demo/testpilot.json`
11+
- ❌ 错误:`shop-demo/testpilot_v2.json`、`shop-demo/blueprints/test.json`
12+
13+
这样 TestPilot AI 插件才能自动扫描并选中正确的蓝本。

.env.example

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# TestPilot AI 环境变量配置
2+
# 复制此文件为 .env 并填入实际值
3+
4+
# ── 服务配置 ──
5+
TP_SERVER_HOST=127.0.0.1
6+
TP_SERVER_PORT=8900
7+
TP_SERVER_RELOAD=true
8+
TP_SERVER_LOG_LEVEL=DEBUG
9+
10+
# ── 沙箱配置 ──
11+
TP_SANDBOX_IMAGE=ghcr.io/agent-infra/sandbox:latest
12+
TP_SANDBOX_APP_PORT=3000
13+
14+
# ── 浏览器配置 ──
15+
TP_BROWSER_HEADLESS=true
16+
TP_BROWSER_VIEWPORT_WIDTH=1280
17+
TP_BROWSER_VIEWPORT_HEIGHT=720
18+
19+
# ── AI API 配置(必填) ──
20+
# 方舟平台 API 密钥(通过 OpenAI SDK 兼容接口调用)
21+
TP_AI_API_KEY=你的方舟平台API密钥
22+
TP_AI_API_BASE_URL=https://ark.cn-beijing.volces.com/api/v3
23+
# Doubao-Seed-1.8 统一模型(文本生成 + 视觉理解 + Agent)
24+
TP_AI_MODEL=doubao-seed-1-8-251228
25+
# 思考深度:minimal / low / medium / high
26+
TP_AI_REASONING_EFFORT=medium
27+
28+
# ── 调试模式 ──
29+
DEBUG=false

.github/copilot-instructions.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# TestPilot AI - 项目编码规范
2+
3+
## 蓝本文件(testpilot.json)管理规则
4+
5+
当你需要为某个被测应用生成或修改测试蓝本时,**必须遵守以下规则**
6+
7+
1. **只允许存在一个蓝本文件**:每个被测应用目录下只保留一个 `testpilot.json`
8+
2. **更新而非新建**:若该目录已存在 `testpilot.json`,直接覆盖更新,**不得**创建 `testpilot_v2.json``testpilot_new.json``testpilot_backup.json` 等任何变体文件。
9+
3. **文件放置位置**:蓝本文件必须放在被测应用的**根目录**,固定命名为 `testpilot.json`
10+
- ✅ 正确:`shop-demo/testpilot.json`
11+
- ❌ 错误:`shop-demo/testpilot_v2.json``shop-demo/blueprints/test.json`
12+
13+
这样 TestPilot AI 插件才能自动扫描并选中正确的蓝本。
14+
15+
## 编程完成后必须生成/更新蓝本
16+
17+
**每次完成编程任务后,你必须同时生成或更新被测应用的 `testpilot.json`**
18+
19+
这是因为你是最了解自己代码的人——你知道每个元素的 ID、class、功能逻辑,你生成的蓝本最精准、覆盖最全面。
20+
21+
### 蓝本生成时机
22+
23+
-**新建应用**:代码写完后,立即生成完整 `testpilot.json`
24+
-**修改功能**:新增/修改/删除任何 UI 元素或业务逻辑后,同步更新蓝本对应场景和选择器
25+
-**修复 Bug 后**:确认代码修复正确,更新蓝本中对应的 expected 断言
26+
-**不允许跳过**:不得以"稍后再写"为由跳过蓝本生成
27+
28+
### 蓝本质量要求
29+
30+
生成蓝本时,遵守以下规则:
31+
32+
1. **功能全覆盖**:每个可操作的功能(按钮/表单/导航/弹窗)必须有对应场景
33+
2. **使用精确选择器**:直接使用代码中的 `id``#login-btn`)或稳定 `class`,不要用 `div:nth-child(3)` 这类脆弱选择器
34+
3. **逐字段断言**`fill` 之后要有 `assert_text``screenshot` 验证,不能只操作不验证
35+
4. **边界场景**:包含空表单提交、错误输入、权限不足等异常场景
36+
5. **页面跳转显式化**:每次 `navigate` 必须有对应的 `assert_text``screenshot` 验证页面已正确加载
37+
38+
### 快速生成模板
39+
40+
```json
41+
{
42+
"app_name": "你的应用名",
43+
"base_url": "http://localhost:你的端口",
44+
"version": "1.0",
45+
"pages": [
46+
{
47+
"url": "/",
48+
"title": "页面标题",
49+
"elements": {
50+
"元素描述": "#实际CSS选择器"
51+
},
52+
"scenarios": [
53+
{
54+
"name": "功能场景名",
55+
"steps": [
56+
{"action": "navigate", "value": "http://localhost:端口"},
57+
{"action": "fill", "target": "#input-id", "value": "测试值"},
58+
{"action": "click", "target": "#submit-btn"},
59+
{"action": "assert_text", "target": "#result", "expected": "预期文本"}
60+
]
61+
}
62+
]
63+
}
64+
]
65+
}
66+
```
67+
68+
支持的 action:`navigate` / `click` / `fill` / `select` / `wait` / `screenshot` / `assert_text` / `assert_visible` / `hover` / `scroll`
69+

.github/workflows/test.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: TestPilot AI Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Python 3.11
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.11"
21+
22+
- name: Install Poetry
23+
run: |
24+
pip install "poetry>=2.0,<3.0"
25+
poetry --version
26+
27+
- name: Install dependencies
28+
run: |
29+
poetry config virtualenvs.in-project true
30+
poetry install --with dev -v
31+
32+
- name: Run tests
33+
run: poetry run pytest -x -q --tb=long 2>&1 | tail -80
34+
env:
35+
OPENAI_API_KEY: "sk-test-placeholder"
36+
TESTPILOT_ENV: "ci"

.gitignore

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
*.egg-info/
7+
dist/
8+
build/
9+
*.egg
10+
11+
# 虚拟环境
12+
.venv/
13+
venv/
14+
env/
15+
16+
# IDE
17+
.vscode/
18+
.idea/
19+
*.swp
20+
*.swo
21+
*~
22+
23+
# 环境变量(含密钥,绝不提交)
24+
.env
25+
26+
# 日志
27+
logs/
28+
29+
# 数据文件(截图、录屏等)
30+
data/
31+
screenshots/
32+
33+
# 系统文件
34+
.DS_Store
35+
Thumbs.db
36+
desktop.ini
37+
38+
# Poetry
39+
poetry.toml
40+
41+
# Playwright
42+
playwright-report/
43+
test-results/
44+
45+
# VSCode Extension
46+
extension/node_modules/
47+
extension/out/
48+
extension/*.vsix
49+
50+
# Desktop App (React + Vite)
51+
desktop/node_modules/
52+
desktop/dist/
53+
54+
# Tauri (Rust桌面应用)
55+
desktop/src-tauri/target/

Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# TestPilot AI CI Runner 镜像(v4.0)
2+
#
3+
# 用途:CI/CD 环境中运行 TestPilot AI 测试
4+
#
5+
# 构建:docker build -t testpilot/runner .
6+
# 使用:docker run --rm -v ./testpilot.json:/app/blueprint.json testpilot/runner run -b /app/blueprint.json
7+
#
8+
9+
FROM python:3.11-slim
10+
11+
# 安装系统依赖(Playwright 需要)
12+
RUN apt-get update && apt-get install -y --no-install-recommends \
13+
curl \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
# 安装 Poetry
17+
RUN pip install --no-cache-dir poetry
18+
19+
WORKDIR /app
20+
21+
# 复制依赖文件
22+
COPY pyproject.toml poetry.lock* ./
23+
24+
# 安装 Python 依赖
25+
RUN poetry config virtualenvs.create false \
26+
&& poetry install --no-interaction --no-root
27+
28+
# 安装 Playwright 浏览器
29+
RUN playwright install chromium \
30+
&& playwright install-deps chromium
31+
32+
# 复制项目文件
33+
COPY . .
34+
35+
# 暴露引擎端口
36+
EXPOSE 8900
37+
38+
# 默认命令:启动引擎
39+
ENTRYPOINT ["python", "cli.py"]
40+
CMD ["serve", "--host", "0.0.0.0"]

0 commit comments

Comments
 (0)