@szc-ft/mcp-szcd-client 0.19.0 → 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.
- package/agents/build.js +118 -0
- package/agents/opencode-extension/agents/szcd-component-expert.md +224 -0
- package/agents/platforms.json +15 -0
- package/agents/qwen-extension/agents/szcd-component-expert.md +8 -0
- package/agents/src/szcd-component-expert.md +8 -0
- package/agents/src/tools.json +5 -0
- package/agents/szcd-component-expert.md +8 -0
- package/agents/szcd-component-expert.qoder.md +9 -0
- package/agents/szcd-component-expert.trae.md +8 -0
- package/commands/szcd-mcp-coding-config.md +4 -6
- package/lib/browser-engine.js +318 -23
- package/lib/shared-deps.js +97 -0
- package/lib/visual-compare.js +7 -4
- package/local-browser-executor.js +17 -5
- package/package.json +1 -7
- package/qwen-extension/agents/szcd-component-expert.md +8 -0
- package/qwen-extension/commands/szcd-mcp-coding-config.md +4 -6
- package/qwen-extension/qwen-extension.json +1 -1
- package/qwen-extension/skills/local-browser-test/SKILL.md +101 -5
- package/scripts/lib/opencode.js +510 -22
- package/scripts/postinstall.js +14 -3
- package/scripts/update-mcp-url.js +3 -0
- package/standard-skill/local-browser-test/SKILL.md +101 -5
package/scripts/postinstall.js
CHANGED
|
@@ -82,7 +82,7 @@ function createConfigTemplate() {
|
|
|
82
82
|
|
|
83
83
|
// ==================== 成功信息 ====================
|
|
84
84
|
|
|
85
|
-
function showSuccessMessage(traeResult, claudeResult, qwenResult, qoderResult) {
|
|
85
|
+
function showSuccessMessage(traeResult, claudeResult, qwenResult, qoderResult, openCodeResult) {
|
|
86
86
|
const configPath = common.getConfigFilePath();
|
|
87
87
|
const projectRoot = common.PROJECT_ROOT;
|
|
88
88
|
|
|
@@ -97,6 +97,7 @@ function showSuccessMessage(traeResult, claudeResult, qwenResult, qoderResult) {
|
|
|
97
97
|
console.log(` Claude Code: ${path.join(claudeResult.skillsDirectory, common.getMcpServerName(), "SKILL.md")}`);
|
|
98
98
|
console.log(` Qwen Code: ${path.join(qwenResult.skillsDirectory, common.getMcpServerName(), "SKILL.md")}`);
|
|
99
99
|
console.log(` Qoder CLI: ${path.join(qoderResult.skillsDirectory, common.getMcpServerName(), "SKILL.md")}`);
|
|
100
|
+
console.log(` OpenCode: ${path.join(openCodeResult.skillsDirectory, common.getMcpServerName(), "SKILL.md")}`);
|
|
100
101
|
if (traeResult.traeProjectInstalled) {
|
|
101
102
|
console.log(` Trae Project: ${path.join(projectRoot, ".trae", "skills", common.getMcpServerName(), "SKILL.md")}`);
|
|
102
103
|
}
|
|
@@ -109,6 +110,12 @@ function showSuccessMessage(traeResult, claudeResult, qwenResult, qoderResult) {
|
|
|
109
110
|
if (qoderResult.qoderProjectInstalled) {
|
|
110
111
|
console.log(` Qoder Project: ${path.join(projectRoot, ".qoder", "skills", common.getMcpServerName(), "SKILL.md")}`);
|
|
111
112
|
}
|
|
113
|
+
// 项目级配置暂不启用
|
|
114
|
+
/*
|
|
115
|
+
if (openCodeResult.openCodeProjectInstalled) {
|
|
116
|
+
console.log(` OpenCode Project: ${path.join(projectRoot, ".opencode", "skills", common.getMcpServerName(), "SKILL.md")}`);
|
|
117
|
+
}
|
|
118
|
+
*/
|
|
112
119
|
|
|
113
120
|
console.log("\n⚙️ Configuration Files:");
|
|
114
121
|
console.log(` 1. Config file: ${configPath}`);
|
|
@@ -116,6 +123,7 @@ function showSuccessMessage(traeResult, claudeResult, qwenResult, qoderResult) {
|
|
|
116
123
|
console.log(` 3. Claude Code: via 'claude mcp add'`);
|
|
117
124
|
console.log(` 4. Qwen Code: via 'qwen extensions install'`);
|
|
118
125
|
console.log(` 5. Qoder CLI: via 'qoder mcp add'`);
|
|
126
|
+
console.log(` 6. OpenCode: via 'opencode mcp add'`);
|
|
119
127
|
|
|
120
128
|
console.log("\n📝 Edit the config file to set your MCP server URL:");
|
|
121
129
|
console.log(` "MCP_SERVER_URL": "http://YOUR_SERVER_IP:3456"`);
|
|
@@ -131,6 +139,8 @@ function showSuccessMessage(traeResult, claudeResult, qwenResult, qoderResult) {
|
|
|
131
139
|
console.log(` qwen mcp add --transport http --scope user ${common.getMcpServerName()} ${common.getMcpServerUrl()}/mcp`);
|
|
132
140
|
console.log("\n For Qoder CLI (via CLI):");
|
|
133
141
|
console.log(` qoder mcp add ${common.getMcpServerName()} -s user -- ${common.getMcpServerUrl()}/mcp`);
|
|
142
|
+
console.log("\n For OpenCode (via CLI):");
|
|
143
|
+
console.log(` opencode mcp add ${common.getMcpServerName()} --scope user --url ${common.getMcpServerUrl()}/mcp`);
|
|
134
144
|
|
|
135
145
|
console.log("\n💡 Configuration Priority:");
|
|
136
146
|
console.log(" 1. Environment variables (highest priority)");
|
|
@@ -169,7 +179,8 @@ function main() {
|
|
|
169
179
|
|
|
170
180
|
// ---- 配置文件 ----
|
|
171
181
|
createConfigTemplate();
|
|
172
|
-
|
|
182
|
+
console.log("\n🔧 Setting up OpenCode compatibility...\n");
|
|
183
|
+
const openCodeResult = setupOpenCode(deps);
|
|
173
184
|
|
|
174
185
|
// ---- Trae CLI ----
|
|
175
186
|
console.log("\n🔧 Setting up Trae CLI compatibility...\n");
|
|
@@ -187,7 +198,7 @@ function main() {
|
|
|
187
198
|
console.log("\n🔧 Setting up Qoder CLI compatibility...\n");
|
|
188
199
|
const qoderResult = setupQoder(deps);
|
|
189
200
|
|
|
190
|
-
showSuccessMessage(traeResult, claudeResult, qwenResult, qoderResult);
|
|
201
|
+
showSuccessMessage(traeResult, claudeResult, qwenResult, qoderResult, openCodeResult);
|
|
191
202
|
} catch (error) {
|
|
192
203
|
console.error("\n❌ Error during installation:", error.message);
|
|
193
204
|
console.error("Please report this issue at: https://github.com/szc-ft/szcd/issues");
|
|
@@ -32,6 +32,7 @@ import { syncMcpUrl as syncTraeIde } from "./lib/trae-ide.js";
|
|
|
32
32
|
import { syncMcpUrl as syncClaudeCode } from "./lib/claude-code.js";
|
|
33
33
|
import { syncMcpUrl as syncQwenCode } from "./lib/qwen-code.js";
|
|
34
34
|
import { syncMcpUrl as syncQoder } from "./lib/qoder.js";
|
|
35
|
+
import { syncMcpUrl as syncOpenCode } from "./lib/opencode.js";
|
|
35
36
|
|
|
36
37
|
const DEFAULT_MCP_SERVER_NAME = "szcd-component-helper";
|
|
37
38
|
const DEFAULT_MCP_SERVER_URL = "http://localhost:3456";
|
|
@@ -183,6 +184,7 @@ function main() {
|
|
|
183
184
|
syncClaudeCode(targetUrl, serverName);
|
|
184
185
|
syncQwenCode(targetUrl, serverName);
|
|
185
186
|
syncQoder(targetUrl, serverName);
|
|
187
|
+
syncOpenCode(targetUrl, serverName);
|
|
186
188
|
|
|
187
189
|
console.log(`\n✅ Done! MCP_SERVER_URL = ${targetUrl}`);
|
|
188
190
|
console.log(`\n📋 Updated configuration files:`);
|
|
@@ -192,6 +194,7 @@ function main() {
|
|
|
192
194
|
console.log(` ${path.join(getHomeDir(), ".claude.json")}`);
|
|
193
195
|
console.log(` ${path.join(getHomeDir(), ".qwen", "settings.json")}`);
|
|
194
196
|
console.log(` ${path.join(getHomeDir(), ".qoder", "settings.json")}`);
|
|
197
|
+
console.log(` ${path.join(getHomeDir(), ".config", "opencode", "opencode.jsonc")}`);
|
|
195
198
|
console.log(`\n💡 Restart your IDE/CLI for changes to take effect.\n`);
|
|
196
199
|
}
|
|
197
200
|
|
|
@@ -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
|
## 结果解读
|