@szc-ft/mcp-szcd-client 0.18.0 → 0.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,153 @@
1
+ ---
2
+ name: local-browser-test
3
+ description: 本地浏览器测试工具,在用户本地 Chrome 中执行自动化测试。支持设计稿还原度对比(像素级评分)、功能验证(点击/输入/导航)、DOM 结构检查、JS 错误检测。通过 puppeteer-core 连接用户真实浏览器,天然继承登录态和微前端环境。
4
+ compatibility:
5
+ tools:
6
+ - run_command
7
+ - read_file
8
+ ---
9
+
10
+ # 本地浏览器测试工具(local-browser-test)
11
+
12
+ ## 触发条件
13
+
14
+ 当用户说出以下关键词时启动浏览器测试:
15
+ - "测试一下"、"帮我验证"、"浏览器测试"
16
+ - "对比设计稿"、"还原度"、"看看效果"
17
+ - "功能测试"、"能不能正常用"
18
+ - "检查页面"、"页面渲染"
19
+
20
+ ## 浏览器模式
21
+
22
+ 支持两种模式,执行器自动检测优先使用 connect:
23
+
24
+ ### connect 模式(推荐)
25
+ 连接用户已启动的调试 Chrome,天然继承登录态/微前端环境。
26
+
27
+ 用户一次性配置:
28
+ ```bash
29
+ # macOS
30
+ open -a "Google Chrome" --args --remote-debugging-port=9222
31
+ # Linux
32
+ google-chrome --remote-debugging-port=9222
33
+ # Windows
34
+ "C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
35
+ ```
36
+
37
+ ### launch 模式(回退)
38
+ 启动新的 headless Chrome,需要用户提供可直接访问的 URL。
39
+
40
+ 执行器会自动检测 localhost:9222 是否可用,有则 connect,无则 launch。
41
+
42
+ ## 测试计划 Schema
43
+
44
+ AI 直接构造测试计划 JSON:
45
+
46
+ ```json
47
+ {
48
+ "planId": "<uuid>",
49
+ "description": "<测试描述>",
50
+ "steps": [ ... ],
51
+ "options": {
52
+ "viewport": { "width": 1440, "height": 900 },
53
+ "timeout": 120000,
54
+ "outputDir": "/tmp/browser-test-<planId>"
55
+ }
56
+ }
57
+ ```
58
+
59
+ ### 支持的步骤类型
60
+
61
+ | type | 功能 | 参数 | 返回 |
62
+ |------|------|------|------|
63
+ | navigate | 导航到 URL | `url`, `waitUntil` | `{ url, title, loadTime }` |
64
+ | screenshot | 页面截图 | `fullPage`, `clip`, `filename` | `{ filepath, width, height }` |
65
+ | compare | 设计稿对比 | `designImagePath`, `threshold`, `regions[]` | `{ fidelity, diffPixels, diffImagePath, regions[] }` |
66
+ | click | 点击元素 | `selector`, `waitForNavigation` | `{ clicked, tagName }` |
67
+ | type | 输入文本 | `selector`, `text`, `clear` | `{ typed, value }` |
68
+ | waitFor | 等待条件 | `selector` 或 `url`, `timeout` | `{ matched, waited }` |
69
+ | evaluate | 执行 JS | `expression` | `{ result }` |
70
+ | checkElement | 元素断言 | `selector`, `expect: {visible, minCount, maxCount, hasText}` | `{ passed, checks, elementCount }` |
71
+
72
+ ### 场景选择策略
73
+
74
+ 根据上下文自动选择步骤组合:
75
+
76
+ **场景 A:有设计稿 + 功能验证(最完整)**
77
+ `navigate → waitFor → screenshot → compare → 功能步骤`
78
+
79
+ **场景 B:无设计稿 + 功能验证**
80
+ `navigate → waitFor → screenshot → evaluate(JS错误检查) → 功能步骤`
81
+
82
+ **场景 C:仅视觉对比**
83
+ `navigate → waitFor → screenshot → compare`
84
+
85
+ **场景 D:仅页面检查**
86
+ `navigate → waitFor → screenshot → evaluate(JS错误检查)`
87
+
88
+ ### 构造步骤的指导原则
89
+
90
+ 1. **selector 必须从用户代码中读取,不要猜测**
91
+ - 读代码中的 `id`、`className`、`data-testid`
92
+ - szcd 组件的 class 可通过 `get_component_full_profile` 获取
93
+ 2. **API 路径从代码中的接口调用读取**
94
+ 3. **checkElement 的 expect 从代码逻辑推断**
95
+ - columns 定义了 N 列 → `expect: { minCount: N }`(检查 th 数量)
96
+ - dataSource 有数据 → `expect: { minCount: 1 }`(检查行数)
97
+ 4. **compare 的 regions 从设计稿分析结果或组件布局推断**
98
+
99
+ ## 执行命令
100
+
101
+ ```bash
102
+ node {client_install_path}/local-browser-executor.js \
103
+ --plan '<测试计划JSON>' \
104
+ --output /tmp/browser-test-result.json
105
+ ```
106
+
107
+ 也支持从文件读取计划:
108
+ ```bash
109
+ node {client_install_path}/local-browser-executor.js \
110
+ --plan-file /tmp/test-plan.json \
111
+ --output /tmp/browser-test-result.json
112
+ ```
113
+
114
+ ### 可选参数
115
+
116
+ - `--cdp-url http://localhost:9223`:指定非默认的 CDP 端口
117
+ - `--page-url http://xxx/page`:connect 模式下指定目标页面
118
+
119
+ ## 依赖检查
120
+
121
+ 如果执行报错依赖缺失,引导用户安装:
122
+ ```bash
123
+ npm install puppeteer-core pixelmatch pngjs sharp
124
+ ```
125
+
126
+ ## 结果解读
127
+
128
+ ### 还原度评分
129
+ - fidelity >= 95%:还原度优秀
130
+ - fidelity 90-95%:还原度良好,有优化空间
131
+ - fidelity < 90%:还原度不足,需要调整
132
+
133
+ ### 功能测试
134
+ - passed = total:全部通过
135
+ - 有失败步骤:根据 `step` + `error` 字段定位代码问题
136
+
137
+ ### 结果文件结构
138
+ ```json
139
+ {
140
+ "planId": "xxx",
141
+ "mode": "connect",
142
+ "steps": [
143
+ { "index": 1, "step": "navigate", "status": "PASS", "duration": 1200, ... },
144
+ { "index": 2, "step": "screenshot", "status": "PASS", "duration": 500, ... },
145
+ { "index": 3, "step": "compare", "status": "PASS", "fidelity": 94.7, ... }
146
+ ],
147
+ "summary": {
148
+ "total": 5, "passed": 4, "failed": 1,
149
+ "fidelity": 94.7
150
+ },
151
+ "outputDir": "/tmp/browser-test-xxx"
152
+ }
153
+ ```
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: local-api-tool
3
- description: 本地网络 API 工具,专门处理 10.x.x.x 网段的 Swagger/YApi 文档拉取和联调测试。当服务端 api_tool 因 LOCAL_NETWORK_UNREACHABLE 无法访问时,此技能在用户本地环境执行 curl,再将结果交给服务端解析。适用于内网开发环境、VPN 场景。
3
+ description: 本地网络 API 工具,专门处理 10.x.x.x 网段的 Swagger/YApi 文档拉取和联调测试。当服务端 api_tool 因 LOCAL_NETWORK_UNREACHABLE 无法访问时,此技能在用户本地环境执行 curl,再将结果交给服务端解析。适用于内网开发环境、VPN 场景。**仅限 10.x.x.x 网段**,172.16-31.x.x 和 192.168.x.x 服务端可直连,不要使用本技能。
4
4
  compatibility:
5
5
  tools:
6
6
  - run_command
@@ -20,6 +20,19 @@ compatibility:
20
20
  - API 联调测试目标为 `10.x.x.x` 网段
21
21
  - 用户在 VPN 或内网开发环境中,本地可访问但远程服务器不可达
22
22
 
23
+ ## ⚠️ 网段区分(重要)
24
+
25
+ **仅 `10.x.x.x` 网段需要走本地解析,其他私有网段服务端均可直连,切勿误用本技能:**
26
+
27
+ | 网段 | 是否需要本地解析 | 原因 | 处理方式 |
28
+ |------|:---:|------|------|
29
+ | `10.x.x.x` | **是** | 用户本地可达,服务端不可达 | 使用本技能在本地 curl |
30
+ | `172.16-31.x.x` | **否** | 服务端可直接访问 | 直接调用 api_tool,无需本技能 |
31
+ | `192.168.x.x` | **否** | 服务端通过弹性 IP 映射访问 | 直接调用 api_tool,无需本技能 |
32
+ | 公网 IP | **否** | 服务端可直接访问 | 直接调用 api_tool,无需本技能 |
33
+
34
+ **禁止对 172.16-31.x.x 和 192.168.x.x 使用本技能!** 这些地址虽然也是 RFC 1918 私有地址,但服务端网络环境可以直达,不需要在用户本地执行 curl。
35
+
23
36
  ## 工作流
24
37
 
25
38
  ### 流程 A:拉取 Swagger API 文档(fetch)
@@ -0,0 +1,153 @@
1
+ ---
2
+ name: local-browser-test
3
+ description: 本地浏览器测试工具,在用户本地 Chrome 中执行自动化测试。支持设计稿还原度对比(像素级评分)、功能验证(点击/输入/导航)、DOM 结构检查、JS 错误检测。通过 puppeteer-core 连接用户真实浏览器,天然继承登录态和微前端环境。
4
+ compatibility:
5
+ tools:
6
+ - run_command
7
+ - read_file
8
+ ---
9
+
10
+ # 本地浏览器测试工具(local-browser-test)
11
+
12
+ ## 触发条件
13
+
14
+ 当用户说出以下关键词时启动浏览器测试:
15
+ - "测试一下"、"帮我验证"、"浏览器测试"
16
+ - "对比设计稿"、"还原度"、"看看效果"
17
+ - "功能测试"、"能不能正常用"
18
+ - "检查页面"、"页面渲染"
19
+
20
+ ## 浏览器模式
21
+
22
+ 支持两种模式,执行器自动检测优先使用 connect:
23
+
24
+ ### connect 模式(推荐)
25
+ 连接用户已启动的调试 Chrome,天然继承登录态/微前端环境。
26
+
27
+ 用户一次性配置:
28
+ ```bash
29
+ # macOS
30
+ open -a "Google Chrome" --args --remote-debugging-port=9222
31
+ # Linux
32
+ google-chrome --remote-debugging-port=9222
33
+ # Windows
34
+ "C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
35
+ ```
36
+
37
+ ### launch 模式(回退)
38
+ 启动新的 headless Chrome,需要用户提供可直接访问的 URL。
39
+
40
+ 执行器会自动检测 localhost:9222 是否可用,有则 connect,无则 launch。
41
+
42
+ ## 测试计划 Schema
43
+
44
+ AI 直接构造测试计划 JSON:
45
+
46
+ ```json
47
+ {
48
+ "planId": "<uuid>",
49
+ "description": "<测试描述>",
50
+ "steps": [ ... ],
51
+ "options": {
52
+ "viewport": { "width": 1440, "height": 900 },
53
+ "timeout": 120000,
54
+ "outputDir": "/tmp/browser-test-<planId>"
55
+ }
56
+ }
57
+ ```
58
+
59
+ ### 支持的步骤类型
60
+
61
+ | type | 功能 | 参数 | 返回 |
62
+ |------|------|------|------|
63
+ | navigate | 导航到 URL | `url`, `waitUntil` | `{ url, title, loadTime }` |
64
+ | screenshot | 页面截图 | `fullPage`, `clip`, `filename` | `{ filepath, width, height }` |
65
+ | compare | 设计稿对比 | `designImagePath`, `threshold`, `regions[]` | `{ fidelity, diffPixels, diffImagePath, regions[] }` |
66
+ | click | 点击元素 | `selector`, `waitForNavigation` | `{ clicked, tagName }` |
67
+ | type | 输入文本 | `selector`, `text`, `clear` | `{ typed, value }` |
68
+ | waitFor | 等待条件 | `selector` 或 `url`, `timeout` | `{ matched, waited }` |
69
+ | evaluate | 执行 JS | `expression` | `{ result }` |
70
+ | checkElement | 元素断言 | `selector`, `expect: {visible, minCount, maxCount, hasText}` | `{ passed, checks, elementCount }` |
71
+
72
+ ### 场景选择策略
73
+
74
+ 根据上下文自动选择步骤组合:
75
+
76
+ **场景 A:有设计稿 + 功能验证(最完整)**
77
+ `navigate → waitFor → screenshot → compare → 功能步骤`
78
+
79
+ **场景 B:无设计稿 + 功能验证**
80
+ `navigate → waitFor → screenshot → evaluate(JS错误检查) → 功能步骤`
81
+
82
+ **场景 C:仅视觉对比**
83
+ `navigate → waitFor → screenshot → compare`
84
+
85
+ **场景 D:仅页面检查**
86
+ `navigate → waitFor → screenshot → evaluate(JS错误检查)`
87
+
88
+ ### 构造步骤的指导原则
89
+
90
+ 1. **selector 必须从用户代码中读取,不要猜测**
91
+ - 读代码中的 `id`、`className`、`data-testid`
92
+ - szcd 组件的 class 可通过 `get_component_full_profile` 获取
93
+ 2. **API 路径从代码中的接口调用读取**
94
+ 3. **checkElement 的 expect 从代码逻辑推断**
95
+ - columns 定义了 N 列 → `expect: { minCount: N }`(检查 th 数量)
96
+ - dataSource 有数据 → `expect: { minCount: 1 }`(检查行数)
97
+ 4. **compare 的 regions 从设计稿分析结果或组件布局推断**
98
+
99
+ ## 执行命令
100
+
101
+ ```bash
102
+ node {client_install_path}/local-browser-executor.js \
103
+ --plan '<测试计划JSON>' \
104
+ --output /tmp/browser-test-result.json
105
+ ```
106
+
107
+ 也支持从文件读取计划:
108
+ ```bash
109
+ node {client_install_path}/local-browser-executor.js \
110
+ --plan-file /tmp/test-plan.json \
111
+ --output /tmp/browser-test-result.json
112
+ ```
113
+
114
+ ### 可选参数
115
+
116
+ - `--cdp-url http://localhost:9223`:指定非默认的 CDP 端口
117
+ - `--page-url http://xxx/page`:connect 模式下指定目标页面
118
+
119
+ ## 依赖检查
120
+
121
+ 如果执行报错依赖缺失,引导用户安装:
122
+ ```bash
123
+ npm install puppeteer-core pixelmatch pngjs sharp
124
+ ```
125
+
126
+ ## 结果解读
127
+
128
+ ### 还原度评分
129
+ - fidelity >= 95%:还原度优秀
130
+ - fidelity 90-95%:还原度良好,有优化空间
131
+ - fidelity < 90%:还原度不足,需要调整
132
+
133
+ ### 功能测试
134
+ - passed = total:全部通过
135
+ - 有失败步骤:根据 `step` + `error` 字段定位代码问题
136
+
137
+ ### 结果文件结构
138
+ ```json
139
+ {
140
+ "planId": "xxx",
141
+ "mode": "connect",
142
+ "steps": [
143
+ { "index": 1, "step": "navigate", "status": "PASS", "duration": 1200, ... },
144
+ { "index": 2, "step": "screenshot", "status": "PASS", "duration": 500, ... },
145
+ { "index": 3, "step": "compare", "status": "PASS", "fidelity": 94.7, ... }
146
+ ],
147
+ "summary": {
148
+ "total": 5, "passed": 4, "failed": 1,
149
+ "fidelity": 94.7
150
+ },
151
+ "outputDir": "/tmp/browser-test-xxx"
152
+ }
153
+ ```