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

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.
@@ -1,6 +1,6 @@
1
1
  ---
2
- description: 管理CODING Issue工具的默认配置(baseUrl/projectId/account)
3
- argument-hint: <get|set|clear> [--baseUrl=xxx] [--projectId=yyy] [--account=zzz]
2
+ description: 管理CODING Issue工具的默认配置(baseUrl/account)
3
+ argument-hint: <get|set|clear> [--baseUrl=xxx] [--account=yyy]
4
4
  ---
5
5
 
6
6
  请帮我管理 szcd MCP 的 CODING 默认配置。
@@ -18,11 +18,10 @@ argument-hint: <get|set|clear> [--baseUrl=xxx] [--projectId=yyy] [--account=zzz]
18
18
 
19
19
  - **设置配置**:逐项向用户询问以下参数,选项中提供当前值作为默认,用户也可自由输入新值:
20
20
  - CODING_BASE_URL — CODING 基础地址,如 `http://e-kjr1wok.coding.smartcitysz.work`
21
- - CODING_DEFAULT_PROJECT_ID — 默认项目 ID,如 `907`
22
21
  - CODING_ACCOUNT — 默认账号(邮箱)
23
22
  收集完参数后执行:
24
23
  ```bash
25
- npx szcd-mcp-coding-config set --baseUrl="<baseUrl>" --projectId="<projectId>" --account="<account>"
24
+ npx szcd-mcp-coding-config set --baseUrl="<baseUrl>" --account="<account>"
26
25
  ```
27
26
 
28
27
  - **清除配置**:确认后执行 `npx szcd-mcp-coding-config clear`
@@ -33,10 +32,9 @@ argument-hint: <get|set|clear> [--baseUrl=xxx] [--projectId=yyy] [--account=zzz]
33
32
 
34
33
  **配置字段说明**:
35
34
  - `CODING_BASE_URL` — CODING 基础地址
36
- - `CODING_DEFAULT_PROJECT_ID` — 默认项目 ID
37
35
  - `CODING_ACCOUNT` — 默认账号(邮箱)
38
36
 
39
- 配置保存在 `~/.szcd-mcp-config.json` 中,设置后 `coding_fetch_issue` 工具可省略 `baseUrl` 和 `projectId` 参数。
37
+ 配置保存在 `~/.szcd-mcp-config.json` 中,设置后 `coding_fetch_issue` 工具可省略 `baseUrl` 参数。
40
38
 
41
39
  当前配置:
42
40
  !`cat ~/.szcd-mcp-config.json 2>/dev/null | grep -E "CODING|MCP_SERVER" || echo "配置文件不存在或无 CODING 配置"`
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "szcd-component-helper",
3
- "version": "0.19.1",
3
+ "version": "0.20.0",
4
4
  "description": "szcd 组件库 MCP 助手 — 查询组件信息、匹配需求、生成代码",
5
5
  "mcpServers": {
6
6
  "szcd-component-helper": {
@@ -68,6 +68,10 @@ AI 直接构造测试计划 JSON:
68
68
  | waitFor | 等待条件 | `selector` 或 `url`, `timeout` | `{ matched, waited }` |
69
69
  | evaluate | 执行 JS | `expression` | `{ result }` |
70
70
  | checkElement | 元素断言 | `selector`, `expect: {visible, minCount, maxCount, hasText}` | `{ passed, checks, elementCount }` |
71
+ | findPage | 查找已打开的标签页 | `urlIncludes` 或 `urlRegex` 或 `titleIncludes` | `{ found, url, title, totalPages }` |
72
+ | findFrame | 查找微前端 iframe | `urlIncludes` 或 `urlRegex` 或 `titleIncludes` 或 `contentIncludes` 或 `frameIndex` | `{ found, frameUrl, matchedBy, totalFrames }` |
73
+ | loginWait | 等待 SSO 登录完成 | `loginSelector`, `timeout`, `interval` | `{ loggedIn, elapsed, currentUrl }` |
74
+ | aiAssert | 语义断言(截图+审查) | `assertion`, `filename` | `{ screenshotPath, assertion, needsVisualReview }` |
71
75
 
72
76
  ### 场景选择策略
73
77
 
@@ -85,6 +89,11 @@ AI 直接构造测试计划 JSON:
85
89
  **场景 D:仅页面检查**
86
90
  `navigate → waitFor → screenshot → evaluate(JS错误检查)`
87
91
 
92
+ **场景 E:微前端 + SSO 登录(最常见生产场景)**
93
+ `findPage(按路径发现标签页) → findFrame(按内容发现iframe) → 在 iframe 内执行功能步骤`
94
+
95
+ > 微前端场景端口可变,优先用 `findPage` + `findFrame` 发现页面,而非硬编码 URL 导航。
96
+
88
97
  ### 构造步骤的指导原则
89
98
 
90
99
  1. **selector 必须从用户代码中读取,不要猜测**
@@ -96,19 +105,80 @@ AI 直接构造测试计划 JSON:
96
105
  - dataSource 有数据 → `expect: { minCount: 1 }`(检查行数)
97
106
  4. **compare 的 regions 从设计稿分析结果或组件布局推断**
98
107
 
108
+ ## 微前端测试指南(实战经验)
109
+
110
+ 项目多使用 wujie/qiankun 微前端,测试时需注意:
111
+
112
+ ### 端口可变问题(重点)
113
+ 微前端主应用和子应用的端口会变化,**不要在计划中硬编码 URL**。两种方案:
114
+
115
+ **方案 A:`findPage` 发现已打开的标签页(推荐,connect 模式)**
116
+ 用户已在浏览器中打开了目标页面,按路径或标题发现:
117
+ ```json
118
+ { "type": "findPage", "urlIncludes": "knowledge-main" }
119
+ { "type": "findPage", "titleIncludes": "知识库" }
120
+ ```
121
+
122
+ **方案 B:URL 模板变量 + `--base-url` 运行时传入**
123
+ 计划中使用占位符,运行时替换:
124
+ ```json
125
+ { "type": "navigate", "url": "{{baseUrl}}/knowledge-main/", "allowRedirects": true }
126
+ ```
127
+ 执行时传入:`--base-url http://localhost:9090`
128
+
129
+ ### SSO 登录重定向链
130
+ 主应用访问时会重定向到登录服务,登录后再跳回。
131
+
132
+ ```json
133
+ { "type": "navigate", "url": "{{baseUrl}}/app/", "allowRedirects": true, "redirectWait": 5000 }
134
+ { "type": "loginWait", "timeout": 120000, "loginSelector": "input[type='password']" }
135
+ ```
136
+
137
+ - `allowRedirects: true` 使用 `domcontentloaded` 避免重定向链导致 page 对象销毁
138
+ - `loginWait` 轮询检测登录页是否消失(用户手动登录)
139
+
140
+ ### iframe 内操作
141
+ wujie 微前端子应用渲染在 blob URL iframe 中,**坐标点击无法到达 iframe 内容**。
142
+
143
+ ```json
144
+ { "type": "findFrame", "contentIncludes": "知识采编" }
145
+ { "type": "click", "selector": "a.edit-btn" }
146
+ { "type": "checkElement", "selector": "~.editKnowledge", "expect": { "minCount": 1 } }
147
+ ```
148
+
149
+ - `findFrame` 支持 `urlIncludes`、`titleIncludes`、`contentIncludes` 多种发现方式
150
+ - 优先用 `contentIncludes`(按页面文字内容查找),不依赖 URL/端口
151
+ - `findFrame` 后,后续所有步骤自动在 iframe 内执行
152
+ - iframe 内的 click 使用 `evaluate()` 触发 DOM click,不依赖坐标
153
+
154
+ ### CSS Modules 哈希类名
155
+ 项目使用 CSS Modules,类名会被哈希化(如 `editKnowledge___ynQgI`)。
156
+
157
+ 选择器语法:
158
+ - `~.editKnowledge` → 自动转为 `[class*="editKnowledge"]`(模糊匹配)
159
+ - `~#myId` → 自动转为 `[id*="myId"]`
160
+ - 普通选择器(如 `.my-class`)保持精确匹配
161
+
162
+ ### puppeteer-core v22 注意事项
163
+ - `page.$x()` 已移除,用 `evaluate` + `querySelectorAll` 替代
164
+ - SVG 元素的 `className` 是 `SVGAnimatedString` 对象而非字符串,需先检查 `typeof`
165
+ - 所有 `evaluate` 调用内部使用 `safeEval` 包装,自动处理 context destroyed 错误
166
+
99
167
  ## 执行命令
100
168
 
101
169
  ```bash
102
170
  node {client_install_path}/local-browser-executor.js \
103
171
  --plan '<测试计划JSON>' \
104
- --output /tmp/browser-test-result.json
172
+ --output /tmp/browser-test-result.json \
173
+ --base-url http://localhost:8088
105
174
  ```
106
175
 
107
176
  也支持从文件读取计划:
108
177
  ```bash
109
178
  node {client_install_path}/local-browser-executor.js \
110
179
  --plan-file /tmp/test-plan.json \
111
- --output /tmp/browser-test-result.json
180
+ --output /tmp/browser-test-result.json \
181
+ --base-url http://localhost:8088
112
182
  ```
113
183
 
114
184
  ### 可选参数
@@ -116,11 +186,37 @@ node {client_install_path}/local-browser-executor.js \
116
186
  - `--cdp-url http://localhost:9223`:指定非默认的 CDP 端口
117
187
  - `--page-url http://xxx/page`:connect 模式下指定目标页面
118
188
 
119
- ## 依赖检查
189
+ ## AI 语义断言(aiAssert)
190
+
191
+ `aiAssert` 截图后需要视觉审查,三级降级路由:
192
+
193
+ ### Level 1:你能读取图片
194
+ 直接读取截图文件,用你的视觉能力判断是否满足断言。
195
+
196
+ ### Level 2:你无法读图,但 MCP 服务器可用
197
+ 1. 调用 `get_upload_endpoint` 获取上传地址
198
+ 2. 用 curl 上传截图
199
+ 3. 调用 `assert_page_screenshot` 工具,传入 `upload_id` + 断言描述
200
+ 4. 工具返回 `{ passed, confidence, reasoning, details }`
201
+
202
+ ### Level 3:都没有
203
+ 降级为 `checkElement` 步骤,用 DOM 选择器做替代验证。
204
+
205
+ **构造 aiAssert 步骤示例**:
206
+ ```json
207
+ { "type": "aiAssert", "assertion": "页面显示三栏布局,右侧有滚动条", "filename": "assert-layout.png" }
208
+ { "type": "aiAssert", "assertion": "表格至少有 5 行数据,包含姓名、手机号列" }
209
+ { "type": "aiAssert", "assertion": "表单包含必填标记和提交按钮" }
210
+ ```
211
+
212
+ ## 依赖管理
120
213
 
121
- 如果执行报错依赖缺失,引导用户安装:
214
+ 浏览器测试依赖(puppeteer-core, pixelmatch, pngjs, sharp)采用**共享缓存**方案:
215
+ - 首次使用时自动安装到 `~/.szcd-mcp/deps/`
216
+ - 后续所有项目共享复用,无需重复安装
217
+ - 如果自动安装失败,引导用户手动执行:
122
218
  ```bash
123
- npm install puppeteer-core pixelmatch pngjs sharp
219
+ cd ~/.szcd-mcp/deps && npm install puppeteer-core pixelmatch pngjs sharp --registry=https://npmmirror.com
124
220
  ```
125
221
 
126
222
  ## 结果解读