@autotest/agent 0.0.3 → 0.0.4
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/README.md +130 -75
- package/dist/api/agent_api.d.ts +2 -6
- package/dist/api/agent_api.js +6 -11
- package/dist/autotest-cli.js +9 -2
- package/dist/common/config/config.yaml +134 -0
- package/dist/common/model/custom_model.js +24 -5
- package/dist/common/path_utils.d.ts +7 -3
- package/dist/common/path_utils.js +12 -5
- package/dist/common/result_parser.js +1 -1
- package/dist/core/agent/layered_agent/decision.js +61 -23
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.d.ts +1 -1
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +5 -5
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +1 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +1 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +1 -1
- package/dist/core/agent/layered_agent/execute_agent/prompts.d.ts +1 -1
- package/dist/core/agent/layered_agent/execute_agent/prompts.js +5 -5
- package/dist/core/mcp/mcp_tools.d.ts +19 -2
- package/dist/core/mcp/mcp_tools.js +40 -12
- package/dist/core/memory/_utils.d.ts +18 -0
- package/dist/core/memory/_utils.js +140 -0
- package/dist/core/memory/replan_manager.d.ts +9 -0
- package/dist/core/memory/replan_manager.js +12 -0
- package/dist/core/memory/tool_player_popup.d.ts +66 -0
- package/dist/core/memory/tool_player_popup.js +276 -0
- package/dist/core/memory/tool_player_replan.d.ts +49 -0
- package/dist/core/memory/tool_player_replan.js +226 -0
- package/dist/core/memory/tool_player_xpath.d.ts +52 -0
- package/dist/core/memory/tool_player_xpath.js +139 -0
- package/dist/core/prompt/prompt_loader.js +3 -1
- package/dist/core/prompt/templates/debug/hypium/hypium_v2.0_optimize_scroll_search.md +310 -0
- package/dist/core/prompt/templates/debug/hypium/hypium_v2.0_relative_1000.md +284 -0
- package/dist/core/prompt/templates/debug/planner/planner_v3.0.md +140 -0
- package/dist/core/prompt/templates/debug/single/single_v2.0_optimize_scroll_search.md +272 -0
- package/dist/core/prompt/templates/debug/single/single_v2.0_relative_1000.md +277 -0
- package/dist/core/prompt/templates/single/single_v2.0_0_1000.md +315 -0
- package/dist/core/skill/skill_manager.js +4 -1
- package/dist/core/skill/skills/cancel-all-follows/SKILL.md +23 -0
- package/dist/core/skill/skills/create-local-image/SKILL.md +12 -0
- package/dist/core/skill/skills/create-local-video/SKILL.md +12 -0
- package/dist/core/skill/skills/dismiss-popups/SKILL.md +39 -0
- package/dist/core/skill/skills/douyin_test_skills.md +16 -0
- package/dist/data_types/case.d.ts +32 -0
- package/dist/data_types/case.js +57 -0
- package/dist/data_types/index.d.ts +2 -0
- package/dist/data_types/index.js +6 -1
- package/dist/data_types/screen.d.ts +12 -0
- package/dist/data_types/screen.js +23 -0
- package/dist/mcp-server/types.js +72 -50
- package/dist/reporter/generator.d.ts +0 -14
- package/dist/reporter/generator.js +18 -504
- package/dist/reporter/html_template/index.d.ts +56 -0
- package/dist/reporter/html_template/index.js +524 -0
- package/dist/reporter/json_report.d.ts +1 -0
- package/dist/reporter/json_report.js +6 -0
- package/dist/reporter/types.d.ts +1 -0
- package/dist/reporter/types.js +1 -0
- package/dist/tools/batch_runner.d.ts +3 -1
- package/dist/tools/batch_runner.js +13 -6
- package/dist/tools/case_runner/report.d.ts +9 -0
- package/dist/tools/case_runner/report.js +264 -0
- package/dist/tools/case_runner/runner.d.ts +57 -0
- package/dist/tools/case_runner/runner.js +410 -0
- package/dist/tools/config/config_tool.d.ts +13 -0
- package/dist/tools/config/config_tool.js +339 -0
- package/dist/tools/prompt_compare/compare_runner.d.ts +13 -0
- package/dist/tools/prompt_compare/compare_runner.js +360 -0
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -11,7 +11,8 @@ AutoTest Agent 是一个智能化的移动设备自动化测试框架,支持 *
|
|
|
11
11
|
- **多架构模式**:`single`(统一 Agent)、`layered`(Planner + Executor)两种模式可切换
|
|
12
12
|
- **多模态视觉理解**:通过多模态模型观察屏幕截图、定位 UI 元素、判断操作结果
|
|
13
13
|
- **自然语言交互**:中文描述测试步骤,自动转换为设备操作
|
|
14
|
-
- **多平台支持**:HarmonyOS(纯 TS 直驱 HDC
|
|
14
|
+
- **多平台支持**:HarmonyOS(纯 TS 直驱 HDC,35 个设备操作全覆盖)、Android、iOS
|
|
15
|
+
- **MCP Server**:42 个工具(35 设备操作 + 7 管理)通过 JSON-RPC 2.0 对外暴露
|
|
15
16
|
- **Bug 自动发现与根因分析**:执行中主动发现异常,`analyze` 命令基于报告生成根因分析与改进建议
|
|
16
17
|
- **多格式报告**:自动生成 HTML / Markdown / JSON 测试报告与汇总
|
|
17
18
|
- **批量执行**:JSONL/JSON 批量用例执行,支持断点续跑、进度报告、分类汇总
|
|
@@ -22,7 +23,7 @@ AutoTest Agent 是一个智能化的移动设备自动化测试框架,支持 *
|
|
|
22
23
|
## 目录结构
|
|
23
24
|
|
|
24
25
|
```
|
|
25
|
-
AutoTest/
|
|
26
|
+
AutoTest-nodejs/
|
|
26
27
|
├── src/
|
|
27
28
|
│ ├── autotest-cli.ts # CLI 入口(run/list-devices/analyze/config)
|
|
28
29
|
│ ├── index.ts # 包导出
|
|
@@ -69,7 +70,7 @@ AutoTest/
|
|
|
69
70
|
│ │ │ └── hdc/ # HDC 协议(device/input/screenshot/apps)
|
|
70
71
|
│ │ ├── mcp/ # MCP 适配器
|
|
71
72
|
│ │ │ ├── base_adapter.ts
|
|
72
|
-
│ │ │ ├── harmony_hdc_adapter.ts # HarmonyOS 适配器(纯 TS 直驱 hdc
|
|
73
|
+
│ │ │ ├── harmony_hdc_adapter.ts # HarmonyOS 适配器(纯 TS 直驱 hdc,35 设备操作)
|
|
73
74
|
│ │ │ ├── android_adapter.ts # Android 适配器
|
|
74
75
|
│ │ │ ├── ios_adapter.ts # iOS 适配器
|
|
75
76
|
│ │ │ ├── adapter_factory.ts # 适配器工厂
|
|
@@ -82,16 +83,24 @@ AutoTest/
|
|
|
82
83
|
│ │ ├── knowledge/ # 知识库(knowledge_manager.ts / vectordb.ts)
|
|
83
84
|
│ │ ├── memory/ # 记忆系统(memory_manager / compressed_session / context_compressor / reflector / tool_player / tool_recorder / session_factory)
|
|
84
85
|
│ │ └── preprocessor/ # 任务预处理
|
|
85
|
-
│ ├── data_types/ #
|
|
86
|
-
│ ├── reporter/ # 报告生成(generator.ts / batch_summary.ts / types.ts)
|
|
87
|
-
│ ├──
|
|
88
|
-
│ ├──
|
|
89
|
-
│ ├──
|
|
86
|
+
│ ├── data_types/ # 数据模型(action / agent / case / device / report / screen / task)
|
|
87
|
+
│ ├── reporter/ # 报告生成(generator.ts / batch_summary.ts / json_report.ts / html_template/ / types.ts)
|
|
88
|
+
│ ├── loop/ # 自愈闭环编排(执行→归因→改写→重执行,cli / orchestrator / result_writer / types)
|
|
89
|
+
│ ├── mcp-server/ # MCP server(42 工具:35 设备操作 + 7 管理)
|
|
90
|
+
│ │ ├── server.ts # JSON-RPC 2.0 HTTP 服务 + adapter 委托
|
|
91
|
+
│ │ └── types.ts # 工具枚举 + Zod schema + 描述
|
|
90
92
|
│ └── tools/ # 工具
|
|
91
93
|
│ ├── batch_runner.ts # 批量执行(发布为 autotest-batch 二进制)
|
|
94
|
+
│ ├── case_runner/ # 结构化用例执行(setup/process/teardown,发布为 autotest-case)
|
|
95
|
+
│ ├── config/ # 配置管理 CLI(init/get/set/list,发布为 autotest-config)
|
|
96
|
+
│ ├── prompt_compare/ # 多 Prompt 批量对比(发布为 autotest-prompt-compare)
|
|
92
97
|
│ └── runner.mjs # caseTest/batchCaseTest 一键封装(自动 install/build)
|
|
93
|
-
├──
|
|
98
|
+
├── types/
|
|
99
|
+
│ └── ai-stub.d.ts # ai/@ai-sdk/openai 类型桩(仅 .d.ts 生成时使用,避免 OOM)
|
|
100
|
+
├── tests/ # 单元测试(vitest,205 个)
|
|
94
101
|
├── app_config.json # App bundle/ability 映射
|
|
102
|
+
├── tsconfig.json # 主 tsconfig(JS 编译,--noCheck)
|
|
103
|
+
├── tsconfig.emit.json # .d.ts 生成配置(用桩文件替换 ai 泛型)
|
|
95
104
|
└── package.json
|
|
96
105
|
```
|
|
97
106
|
|
|
@@ -104,7 +113,7 @@ AutoTest/
|
|
|
104
113
|
| **单层 Agent** | `single`(默认) | 统一 Agent 处理规划与执行,基于 AI SDK,效率高 |
|
|
105
114
|
| **双层 Agent** | `layered` | Planner 决策 + Executor 执行,适合复杂任务拆解 |
|
|
106
115
|
|
|
107
|
-
> 历史的 `hypium` 模式已移除(`
|
|
116
|
+
> 历史的 `hypium` 模式已移除(`hypium_generator/` 包删除)。
|
|
108
117
|
|
|
109
118
|
### 单层 Agent 工作流程
|
|
110
119
|
|
|
@@ -141,7 +150,7 @@ AutoTest/
|
|
|
141
150
|
|
|
142
151
|
> HarmonyOS 设备测试通过纯 TypeScript 的 HDC 适配器直接驱动 `hdc` 命令。
|
|
143
152
|
|
|
144
|
-
HarmonyOS 适配器(`src/core/mcp/harmony_hdc_adapter.ts`)通过 `hdc shell` 执行 `uitest uiInput`(点击/滑动/输入)、`snapshot_display`(截图)、`uitest dumpLayout`(布局)、`aa`(应用启停)、`bm`(清数据)、`power-shell
|
|
153
|
+
HarmonyOS 适配器(`src/core/mcp/harmony_hdc_adapter.ts`)通过 `hdc shell` 执行 `uitest uiInput`(点击/滑动/输入)、`snapshot_display`(截图)、`uitest dumpLayout`(布局)、`aa`(应用启停)、`bm`(清数据)、`power-shell`(点亮/解锁)、`uinput`(多指手势)等原语,支持全部 35 个设备操作,进程内直接完成设备操作,无子进程、无 HTTP 服务。
|
|
145
154
|
|
|
146
155
|
Android/iOS 平台使用 `@mobilenext/mobile-mcp`(通过 npx 自动安装)。
|
|
147
156
|
|
|
@@ -151,6 +160,44 @@ Android/iOS 平台使用 `@mobilenext/mobile-mcp`(通过 npx 自动安装)
|
|
|
151
160
|
- **HDC 工具**:已安装并配置 `hdc` 命令行工具(加入 PATH)
|
|
152
161
|
- **网络连接**:开发机与设备网络连通
|
|
153
162
|
|
|
163
|
+
## 快速开始
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
cd AutoTest-nodejs
|
|
167
|
+
npm install # 安装依赖
|
|
168
|
+
npm run build # 构建项目
|
|
169
|
+
npm run setup # 生成 config.yaml 配置文件(项目根目录)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`npm run setup` 会在项目根目录创建 `config.yaml`(基于模板,含占位符),并提示需要修改的字段。编辑该文件填入你的配置:
|
|
173
|
+
|
|
174
|
+
```yaml
|
|
175
|
+
model:
|
|
176
|
+
unified:
|
|
177
|
+
name: "qwen3.7-plus" # 模型名
|
|
178
|
+
api_key: "sk-xxx" # 你的 DashScope API Key
|
|
179
|
+
base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
|
180
|
+
|
|
181
|
+
device:
|
|
182
|
+
device_sn: "LNG0223721000045" # hdc list targets 查看
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
> `config.yaml` 已加入 `.gitignore`,不会被提交,可安全填入真实密钥。
|
|
186
|
+
|
|
187
|
+
也可用 `autotest-config` 命令行工具修改:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
node dist/tools/config/config_tool.js set model.unified.api_key "sk-xxx"
|
|
191
|
+
node dist/tools/config/config_tool.js set model.unified.name "qwen3.7-plus"
|
|
192
|
+
node dist/tools/config/config_tool.js set device.device_sn "YOUR_DEVICE_SN"
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
配置完成后即可运行测试:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
node dist/autotest-cli.js run --task "打开设置应用,查看 WiFi 列表"
|
|
199
|
+
```
|
|
200
|
+
|
|
154
201
|
## 配置说明
|
|
155
202
|
|
|
156
203
|
配置文件位于 `src/common/config/config.yaml`(构建后随包发布到 `dist/common/config/config.yaml`)。ConfigManager 按以下顺序分层加载并合并(后者覆盖前者):
|
|
@@ -205,20 +252,31 @@ model:
|
|
|
205
252
|
|
|
206
253
|
```yaml
|
|
207
254
|
agent:
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
255
|
+
unified: # 统一 Agent 配置(single/layered 共用)
|
|
256
|
+
mode: "single" # single / layered
|
|
257
|
+
max_steps: 50 # 最大执行步数
|
|
258
|
+
lang: "zh" # 语言
|
|
259
|
+
enable_preprocess: false # 任务预处理
|
|
260
|
+
stream_log: false # 流式输出模型回复
|
|
261
|
+
debug_mode: null # null / "memory" / "file"(预留,尚未实现)
|
|
262
|
+
parse_mode: "native" # 解析模式:custom(文本标签)/ native(SDK 函数调用)
|
|
263
|
+
tool_provider: "device" # 工具提供者:device / mcp
|
|
264
|
+
action_interval: 1.5 # 操作间隔(秒)
|
|
265
|
+
max_history_image: 3 # 历史截图保留数量
|
|
266
|
+
screenshot_max_pixels: 1500 # 截图最大像素
|
|
267
|
+
include_previous_screenshot: true # 是否包含上一步截图
|
|
268
|
+
previous_screenshot_compress_ratio: 0.7 # 上一步截图压缩比
|
|
269
|
+
max_history_actions: 10 # 历史操作保留数量
|
|
270
|
+
role: null # Agent 角色(控制提示词和工具过滤,如 planner)
|
|
271
|
+
session_type: "compressed" # 会话类型:sqlite / compressed(自动压缩历史)
|
|
272
|
+
prompt_name: "single_v2.0" # 提示词名称(全文件名,优先于 prompt_version)
|
|
273
|
+
prompt_version: "" # 提示词版本覆盖
|
|
274
|
+
max_loops: 0 # 自愈闭环:>0 启用(N 轮迭代),0 禁用
|
|
275
|
+
enable_cache: true # 启用 LLM 缓存
|
|
276
|
+
screenshot_on_tool_end: true # 工具执行后截图
|
|
277
|
+
verbose: false # 详细日志
|
|
278
|
+
json_output: false # JSON 输出
|
|
279
|
+
apirec: false # API 录制
|
|
222
280
|
```
|
|
223
281
|
|
|
224
282
|
### 设备配置
|
|
@@ -228,10 +286,12 @@ device:
|
|
|
228
286
|
device_sn: null # 设备序列号(留空自动检测)
|
|
229
287
|
ip: "127.0.0.1" # 设备 IP
|
|
230
288
|
port: 8710 # HDC 端口
|
|
231
|
-
device_serial: ""
|
|
232
289
|
hdc_path: "hdc" # HDC 工具路径
|
|
233
|
-
|
|
234
|
-
|
|
290
|
+
reset_device: true # true=回主页+清后台, false=跳过, 列表=指定包名 force-stop
|
|
291
|
+
screen_always_on: true # 测试期间保持屏幕常亮
|
|
292
|
+
device_impl: "HDCDevice" # 设备实现:"HDCDevice"(默认)或 "HDCDeviceInner"
|
|
293
|
+
app_config: "" # app_config.json 路径(MCP bundle 映射,留空不使用)
|
|
294
|
+
operation_mode: "phone" # 操作模式:"phone"(默认)或 "pc"
|
|
235
295
|
```
|
|
236
296
|
|
|
237
297
|
### 日志 / 输出 / 网络配置
|
|
@@ -279,7 +339,7 @@ analyze:
|
|
|
279
339
|
|
|
280
340
|
## 使用方法
|
|
281
341
|
|
|
282
|
-
> 以下命令均在 `AutoTest/`
|
|
342
|
+
> 以下命令均在 `AutoTest-nodejs/` 目录下运行。
|
|
283
343
|
|
|
284
344
|
测试用例有三种运行方式,按场景选择:
|
|
285
345
|
|
|
@@ -294,7 +354,7 @@ analyze:
|
|
|
294
354
|
`caseTest` 通过 `runner.mjs` 自动检测源码变更并增量构建,无需手动 `npm run build`,然后以 `run` 子命令调用 `dist/autotest-cli.js`:
|
|
295
355
|
|
|
296
356
|
```bash
|
|
297
|
-
cd AutoTest
|
|
357
|
+
cd AutoTest-nodejs
|
|
298
358
|
|
|
299
359
|
# 基本用法:-- 后传递 CLI 参数
|
|
300
360
|
npm run caseTest -- --task "打开设置应用,查看 WiFi 列表"
|
|
@@ -368,7 +428,7 @@ npm run caseTest -- analyze --task-id 20260714_145936_001 --case-idx 0
|
|
|
368
428
|
通过 `batchCaseTest` 批量执行 JSONL/JSON 用例,具备断点续跑、进度报告、分类汇总能力。同样通过 `runner.mjs` 自动增量构建。
|
|
369
429
|
|
|
370
430
|
```bash
|
|
371
|
-
cd AutoTest
|
|
431
|
+
cd AutoTest-nodejs
|
|
372
432
|
|
|
373
433
|
# 位置参数:第 1 个 = 用例文件,第 2 个 = category(可选,默认 default)
|
|
374
434
|
npm run batchCaseTest cases.jsonl
|
|
@@ -397,8 +457,8 @@ npx autotest-batch cases.jsonl smoke
|
|
|
397
457
|
### 方式三:直接调用 CLI(需先构建)
|
|
398
458
|
|
|
399
459
|
```bash
|
|
400
|
-
cd AutoTest
|
|
401
|
-
npm run build # tsc
|
|
460
|
+
cd AutoTest-nodejs
|
|
461
|
+
npm run build # 两步构建:tsc --noCheck 生成 JS + tsc -p tsconfig.emit.json 生成 .d.ts
|
|
402
462
|
node dist/autotest-cli.js run --task "打开设置应用,查看 WiFi 列表"
|
|
403
463
|
```
|
|
404
464
|
|
|
@@ -414,23 +474,30 @@ Commands:
|
|
|
414
474
|
config Show or update configuration
|
|
415
475
|
|
|
416
476
|
Run options:
|
|
417
|
-
--task <desc>
|
|
418
|
-
--case-file <path>
|
|
419
|
-
--case-index <n>
|
|
420
|
-
--device <sn>
|
|
421
|
-
--platform <p>
|
|
422
|
-
--mode <m>
|
|
423
|
-
--ip <addr>
|
|
424
|
-
--port <num>
|
|
425
|
-
--task-name <name>
|
|
426
|
-
--case-num <num>
|
|
427
|
-
--report-dir <dir>
|
|
428
|
-
--prompt-version <v>
|
|
429
|
-
--
|
|
477
|
+
--task <desc> Task description
|
|
478
|
+
--case-file <path> Path to a JSON case file (use with --case-index)
|
|
479
|
+
--case-index <n> 1-based case index in the file
|
|
480
|
+
--device <sn> Device serial number
|
|
481
|
+
--platform <p> Platform: harmony | android | ios
|
|
482
|
+
--mode <m> Agent mode: single | layered
|
|
483
|
+
--ip <addr> Device IP address
|
|
484
|
+
--port <num> Device port number
|
|
485
|
+
--task-name <name> Test case name
|
|
486
|
+
--case-num <num> Case number
|
|
487
|
+
--report-dir <dir> Report output directory
|
|
488
|
+
--prompt-version <v> Prompt version
|
|
489
|
+
--prompt-name <name> Load prompt by name (priority over --prompt-version)
|
|
490
|
+
--app-config <path> App→bundle mapping config file path
|
|
491
|
+
--config <path> Path to config.yaml (default: bundled config.yaml)
|
|
492
|
+
--loop Enable self-healing loop (execute→analyze→rewrite→re-execute), default 3 iterations
|
|
493
|
+
--max-loops <n> Max loop iterations (>=2 enables FULL_LOOP; 0 disables)
|
|
494
|
+
--analyze-after Auto-analyze after task execution (requires --task)
|
|
495
|
+
--analyze <dir> Analyze-only: attribute an existing report dir (alias: --analyze-dir)
|
|
496
|
+
--rewrite <dir> Rewrite-only: rewrite from an existing analysis (alias: --rewrite-dir)
|
|
430
497
|
|
|
431
498
|
Analyze options:
|
|
432
|
-
--task-id <id>
|
|
433
|
-
--case-idx <n>
|
|
499
|
+
--task-id <id> Task ID to analyze
|
|
500
|
+
--case-idx <n> Case index within the task
|
|
434
501
|
```
|
|
435
502
|
|
|
436
503
|
## 测试报告
|
|
@@ -460,27 +527,7 @@ reports/
|
|
|
460
527
|
|
|
461
528
|
## Debug 调试模式
|
|
462
529
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
### 启用方式
|
|
466
|
-
|
|
467
|
-
在 `config.yaml` 中配置:
|
|
468
|
-
|
|
469
|
-
```yaml
|
|
470
|
-
agent:
|
|
471
|
-
debug_mode: "file"
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
- `null` — 不启用
|
|
475
|
-
- `"memory"` — 内存模式(窗口关闭后 session 丢失)
|
|
476
|
-
- `"file"` — 文件模式(session 保存在报告目录,可上传恢复)
|
|
477
|
-
|
|
478
|
-
### 使用流程
|
|
479
|
-
|
|
480
|
-
1. 任务执行完成后,浏览器打开 Dashboard 调试页
|
|
481
|
-
2. 显示任务执行历史(思考过程 + 输出内容)
|
|
482
|
-
3. 可继续对话追问、验证决策逻辑
|
|
483
|
-
4. 输入 `exit` 或点击「退出」结束
|
|
530
|
+
> **注意**:此功能目前尚未实现。配置字段 `agent.unified.debug_mode` 已在 schema 中预留(接受 `null` / `"memory"` / `"file"`),但浏览器交互式复盘 Dashboard 尚未开发。配置该字段不会产生错误,也不会启用任何调试行为。
|
|
484
531
|
|
|
485
532
|
## 作为三方库集成
|
|
486
533
|
|
|
@@ -590,10 +637,11 @@ const agent = new AutoTestAgent({
|
|
|
590
637
|
|
|
591
638
|
## 脚本
|
|
592
639
|
|
|
593
|
-
在 `AutoTest/` 目录下:
|
|
640
|
+
在 `AutoTest-nodejs/` 目录下:
|
|
594
641
|
|
|
595
642
|
```bash
|
|
596
|
-
|
|
643
|
+
cd AutoTest-nodejs
|
|
644
|
+
npm run build # 两步构建:tsc --noCheck 生成 JS + tsc -p tsconfig.emit.json 生成 .d.ts
|
|
597
645
|
npm run caseTest # 单用例运行(自动增量构建,推荐)
|
|
598
646
|
npm run batchCaseTest # 批量用例运行(自动增量构建)
|
|
599
647
|
npm test # 运行单元测试(vitest run)
|
|
@@ -601,9 +649,14 @@ npm run test:watch # 监听模式单元测试
|
|
|
601
649
|
npm run typecheck # 类型检查(tsc --noEmit)
|
|
602
650
|
```
|
|
603
651
|
|
|
652
|
+
> **构建说明**:由于 `ai` SDK 的深层泛型类型会导致 tsc OOM,构建拆分为两步:
|
|
653
|
+
> 1. `tsc --noCheck` — 跳过类型检查,快速生成 `.js` 文件
|
|
654
|
+
> 2. `tsc -p tsconfig.emit.json` — 使用 `types/ai-stub.d.ts` 桩文件替换 `ai`/`@ai-sdk/openai` 的复杂泛型类型,生成 `.d.ts` 类型声明
|
|
655
|
+
> 3. `copyfiles` — 拷贝 yaml/md 资源文件
|
|
656
|
+
|
|
604
657
|
## 单元测试
|
|
605
658
|
|
|
606
|
-
单元测试位于 `tests/`,使用 vitest,共
|
|
659
|
+
单元测试位于 `tests/`,使用 vitest,共 205 个测试(13 个文件):
|
|
607
660
|
|
|
608
661
|
| 测试文件 | 覆盖模块 | 测试数 |
|
|
609
662
|
|---------|---------|-------|
|
|
@@ -617,12 +670,12 @@ npm run typecheck # 类型检查(tsc --noEmit)
|
|
|
617
670
|
| `single-agent.test.ts` | Agent 执行/截图注入/abort | 9 |
|
|
618
671
|
| `key-steps-builder.test.ts` | 关键步骤构建 | 9 |
|
|
619
672
|
| `data-loader.test.ts` | 数据加载 | 9 |
|
|
620
|
-
| `hdc-adapter.test.ts` | HarmonyHdcAdapter
|
|
673
|
+
| `hdc-adapter.test.ts` | HarmonyHdcAdapter 35 设备操作全覆盖 | 42 |
|
|
621
674
|
| `autotest-agent.test.ts` | 门面类(mock adapter_factory,密闭) | 8 |
|
|
622
675
|
| `logger.test.ts` | 文件日志/格式 | 5 |
|
|
623
676
|
|
|
624
677
|
```bash
|
|
625
|
-
cd AutoTest
|
|
678
|
+
cd AutoTest-nodejs
|
|
626
679
|
npm test # 运行全部测试
|
|
627
680
|
npx vitest run tests/config-manager.test.ts # 运行单个文件
|
|
628
681
|
```
|
|
@@ -636,7 +689,9 @@ npx vitest run tests/config-manager.test.ts # 运行单个文件
|
|
|
636
689
|
### 添加新的 MCP 工具
|
|
637
690
|
|
|
638
691
|
1. 在 `src/core/mcp/mcp_tools.ts`(双层)或 `local_tools.ts`(本地)中添加
|
|
639
|
-
2.
|
|
692
|
+
2. 在 `src/core/mcp/harmony_hdc_adapter.ts` 的 `callTool` switch 中添加设备操作 case
|
|
693
|
+
3. 在 `src/mcp-server/types.ts` 中添加工具枚举 + Zod schema
|
|
694
|
+
4. 在 `src/mcp-server/server.ts` 中注册到 `SCHEMA_MAP` 和 `DEVICE_TOOL_NAMES`
|
|
640
695
|
|
|
641
696
|
### 自定义适配器
|
|
642
697
|
|
package/dist/api/agent_api.d.ts
CHANGED
|
@@ -11,14 +11,10 @@ export declare class AgentAPIImpl {
|
|
|
11
11
|
stopTask(): void;
|
|
12
12
|
runTask(task: string, options: TaskOptions): Promise<TaskResult>;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
* 假定 adapter 已连接(由 runTaskLoop 在循环前统一连接),在给定 reportDir 跑一轮。
|
|
16
|
-
*/
|
|
14
|
+
* 鍗曟 agent 鎵ц锛坙oop 缂栨帓鍣ㄧ殑 execute 鍘熻锛夈€? * 鍋囧畾 adapter 宸茶繛鎺ワ紙鐢?runTaskLoop 鍦ㄥ惊鐜墠缁熶竴杩炴帴锛夛紝鍦ㄧ粰瀹?reportDir 璺戜竴杞€? */
|
|
17
15
|
private executeOnce;
|
|
18
16
|
/**
|
|
19
|
-
* Loop
|
|
20
|
-
* 连接 adapter 一次,注入 execute/analyze/rewrite 三个原语,跑闭环状态机。
|
|
21
|
-
*/
|
|
17
|
+
* Loop 闂幆鎵ц鍏ュ彛锛堢Щ妞嶈嚜 python loop/orchestrator.run锛夈€? * 杩炴帴 adapter 涓€娆★紝娉ㄥ叆 execute/analyze/rewrite 涓変釜鍘熻锛岃窇闂幆鐘舵€佹満銆? */
|
|
22
18
|
private runTaskLoop;
|
|
23
19
|
resumeTask(taskId: string, startIndex?: number): Promise<TaskResult>;
|
|
24
20
|
listDevices(): Promise<DeviceInfo[]>;
|
package/dist/api/agent_api.js
CHANGED
|
@@ -63,7 +63,7 @@ class AgentAPIImpl {
|
|
|
63
63
|
if (adapter) {
|
|
64
64
|
this.adapter = adapter;
|
|
65
65
|
// Register adapter in the hybrid-style agent registry (aligned with python
|
|
66
|
-
// agent_registry.set_tool_manager
|
|
66
|
+
// agent_registry.set_tool_manager 鈥?enables mcp_tools to get device directly)
|
|
67
67
|
agent_registry_1.agentRegistry.setToolManager(adapter);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -96,7 +96,7 @@ class AgentAPIImpl {
|
|
|
96
96
|
if (options.appConfig) {
|
|
97
97
|
this.configManager.updateConfig({ device: { appConfig: options.appConfig } });
|
|
98
98
|
}
|
|
99
|
-
// Loop
|
|
99
|
+
// Loop 闘环(max_loops>=2) 仅归因 / 仅改写 → 委托 runTaskLoop
|
|
100
100
|
if ((options.maxLoops && options.maxLoops >= 2) ||
|
|
101
101
|
options.analyzeReportDir ||
|
|
102
102
|
options.rewriteReportDir) {
|
|
@@ -188,9 +188,7 @@ class AgentAPIImpl {
|
|
|
188
188
|
return taskResult;
|
|
189
189
|
}
|
|
190
190
|
/**
|
|
191
|
-
*
|
|
192
|
-
* 假定 adapter 已连接(由 runTaskLoop 在循环前统一连接),在给定 reportDir 跑一轮。
|
|
193
|
-
*/
|
|
191
|
+
* 鍗曟 agent 鎵ц锛坙oop 缂栨帓鍣ㄧ殑 execute 鍘熻锛夈€? * 鍋囧畾 adapter 宸茶繛鎺ワ紙鐢?runTaskLoop 鍦ㄥ惊鐜墠缁熶竴杩炴帴锛夛紝鍦ㄧ粰瀹?reportDir 璺戜竴杞€? */
|
|
194
192
|
async executeOnce(task, reportDir, runId, agentMode) {
|
|
195
193
|
const effectiveConfig = this.configManager.getEffectiveConfig();
|
|
196
194
|
fs.mkdirSync(reportDir, { recursive: true });
|
|
@@ -207,9 +205,7 @@ class AgentAPIImpl {
|
|
|
207
205
|
return { reportDir, status: agentResult.status };
|
|
208
206
|
}
|
|
209
207
|
/**
|
|
210
|
-
* Loop
|
|
211
|
-
* 连接 adapter 一次,注入 execute/analyze/rewrite 三个原语,跑闭环状态机。
|
|
212
|
-
*/
|
|
208
|
+
* Loop 闂幆鎵ц鍏ュ彛锛堢Щ妞嶈嚜 python loop/orchestrator.run锛夈€? * 杩炴帴 adapter 涓€娆★紝娉ㄥ叆 execute/analyze/rewrite 涓変釜鍘熻锛岃窇闂幆鐘舵€佹満銆? */
|
|
213
209
|
async runTaskLoop(task, options) {
|
|
214
210
|
const taskId = this.generateTaskId();
|
|
215
211
|
const taskResult = {
|
|
@@ -249,8 +245,7 @@ class AgentAPIImpl {
|
|
|
249
245
|
throw new common_errors_1.AgentError('DEVICE_NOT_CONNECTED', 'No device adapter configured');
|
|
250
246
|
}
|
|
251
247
|
const agentMode = options.agentMode ?? effectiveConfig.agent.unified.mode;
|
|
252
|
-
//
|
|
253
|
-
const rewriteModelConfig = effectiveConfig.model.unified;
|
|
248
|
+
// 鏀瑰啓妯″瀷锛氭棤鐙珛 loop 妯″瀷缁勶紝鍥為€€ unified锛堢Щ妞?python resolve_model_config("loop") 鐨?loop鈫抲nified 鍏滃簳锛? const rewriteModelConfig = effectiveConfig.model.unified;
|
|
254
249
|
const cfgAnalyzeAfter = Boolean(effectiveConfig.analyze?.analyzeAfterTask);
|
|
255
250
|
const resolved = (0, cli_1.resolveMode)({
|
|
256
251
|
task,
|
|
@@ -389,7 +384,7 @@ class AgentAPIImpl {
|
|
|
389
384
|
});
|
|
390
385
|
}
|
|
391
386
|
const devices = listResult.trim().split('\n').map((d) => d.trim()).filter(Boolean);
|
|
392
|
-
// Filter out remote targets (IP:PORT)
|
|
387
|
+
// Filter out remote targets (IP:PORT) 鈥?prefer USB device SNs (e.g. MJE...)
|
|
393
388
|
const localDevices = devices.filter((d) => !/^\d+\.\d+\.\d+\.\d+:\d+$/.test(d));
|
|
394
389
|
const preferred = localDevices.length > 0 ? localDevices : devices;
|
|
395
390
|
return preferred.map((deviceSn) => {
|
package/dist/autotest-cli.js
CHANGED
|
@@ -75,10 +75,17 @@ function printBanner(config) {
|
|
|
75
75
|
async function main() {
|
|
76
76
|
const args = process.argv.slice(2);
|
|
77
77
|
const command = args[0];
|
|
78
|
+
if (command === '--version' || command === '-v' || command === 'version') {
|
|
79
|
+
const pkg = require('../package.json');
|
|
80
|
+
console.log(`@autotest/agent v${pkg.version}`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
78
83
|
const configManager = new manager_1.ConfigManager();
|
|
79
84
|
configManager.loadDefaultConfig();
|
|
80
|
-
const
|
|
81
|
-
|
|
85
|
+
const explicitConfig = extractOption(args, '--config');
|
|
86
|
+
if (explicitConfig) {
|
|
87
|
+
configManager.loadFileConfig(explicitConfig);
|
|
88
|
+
}
|
|
82
89
|
const config = configManager.getEffectiveConfig();
|
|
83
90
|
// Startup banner + config validation (aligned with python __main__.py:178-238)
|
|
84
91
|
printBanner(config);
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
model:
|
|
2
|
+
unified:
|
|
3
|
+
name: "qwen3.7-plus"
|
|
4
|
+
base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
|
5
|
+
api_key: "YOUR_API_KEY_HERE"
|
|
6
|
+
provider: "openai"
|
|
7
|
+
temperature: 0.1
|
|
8
|
+
top_p: 0.9
|
|
9
|
+
frequency_penalty: 0.0
|
|
10
|
+
max_tokens: 2048
|
|
11
|
+
timeout: 600
|
|
12
|
+
max_retries: 3
|
|
13
|
+
prompt_type: "v2.0"
|
|
14
|
+
enable_thinking: null
|
|
15
|
+
|
|
16
|
+
execute:
|
|
17
|
+
name: "gui-plus-2026-02-26"
|
|
18
|
+
base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
|
19
|
+
api_key: "YOUR_API_KEY_HERE"
|
|
20
|
+
provider: "mai-ui"
|
|
21
|
+
|
|
22
|
+
decision:
|
|
23
|
+
name: "qwen3.5-plus"
|
|
24
|
+
base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
|
25
|
+
api_key: "YOUR_API_KEY_HERE"
|
|
26
|
+
provider: "openai"
|
|
27
|
+
temperature: 0.0
|
|
28
|
+
top_p: 0.1
|
|
29
|
+
frequency_penalty: 1.0
|
|
30
|
+
|
|
31
|
+
verify:
|
|
32
|
+
name: ""
|
|
33
|
+
base_url: ""
|
|
34
|
+
api_key: ""
|
|
35
|
+
provider: "openai"
|
|
36
|
+
temperature: 0.0
|
|
37
|
+
top_p: 0.1
|
|
38
|
+
frequency_penalty: 1.0
|
|
39
|
+
|
|
40
|
+
analyze:
|
|
41
|
+
temperature: 0.0
|
|
42
|
+
max_tokens: 10240
|
|
43
|
+
timeout: 600
|
|
44
|
+
max_retries: 3
|
|
45
|
+
enable_thinking: false
|
|
46
|
+
enable_multimodal: true
|
|
47
|
+
max_key_steps: 5
|
|
48
|
+
only_fail: true
|
|
49
|
+
analyze_after_task: false
|
|
50
|
+
|
|
51
|
+
agent:
|
|
52
|
+
unified:
|
|
53
|
+
mode: "single"
|
|
54
|
+
max_steps: 50
|
|
55
|
+
lang: "zh"
|
|
56
|
+
enable_preprocess: false
|
|
57
|
+
stream_log: false
|
|
58
|
+
debug_mode: null
|
|
59
|
+
parse_mode: "native"
|
|
60
|
+
tool_provider: "device"
|
|
61
|
+
action_interval: 1.5
|
|
62
|
+
max_history_image: 3
|
|
63
|
+
screenshot_max_pixels: 1500
|
|
64
|
+
include_previous_screenshot: true
|
|
65
|
+
previous_screenshot_compress_ratio: 0.7
|
|
66
|
+
max_history_actions: 10
|
|
67
|
+
role: null
|
|
68
|
+
session_type: "compressed"
|
|
69
|
+
prompt_name: "single_v2.0"
|
|
70
|
+
prompt_version: ""
|
|
71
|
+
max_loops: 0
|
|
72
|
+
enable_cache: true
|
|
73
|
+
screenshot_on_tool_end: true
|
|
74
|
+
verbose: false
|
|
75
|
+
json_output: false
|
|
76
|
+
apirec: false
|
|
77
|
+
|
|
78
|
+
log:
|
|
79
|
+
level: "DEBUG"
|
|
80
|
+
device_log_level: "info"
|
|
81
|
+
verbose: true
|
|
82
|
+
max_log_size: 10
|
|
83
|
+
max_log_file_num: 5
|
|
84
|
+
enable_console_log: true
|
|
85
|
+
enable_file_log: true
|
|
86
|
+
|
|
87
|
+
output:
|
|
88
|
+
json_output: false
|
|
89
|
+
report_dir: null
|
|
90
|
+
root_dir: "reports"
|
|
91
|
+
report_name: "autotest_report"
|
|
92
|
+
embed_images: false
|
|
93
|
+
embed_max_pixels: 800
|
|
94
|
+
|
|
95
|
+
device:
|
|
96
|
+
device_sn: null
|
|
97
|
+
ip: "127.0.0.1"
|
|
98
|
+
port: 8710
|
|
99
|
+
hdc_path: "hdc"
|
|
100
|
+
reset_device: true
|
|
101
|
+
screen_always_on: true
|
|
102
|
+
device_impl: "HDCDevice"
|
|
103
|
+
app_config: ""
|
|
104
|
+
operation_mode: "phone"
|
|
105
|
+
|
|
106
|
+
network:
|
|
107
|
+
timeout: 600
|
|
108
|
+
max_retries: 3
|
|
109
|
+
no_proxy: ""
|
|
110
|
+
|
|
111
|
+
analyze:
|
|
112
|
+
model_name: ""
|
|
113
|
+
base_url: ""
|
|
114
|
+
api_key: ""
|
|
115
|
+
temperature: 0.0
|
|
116
|
+
max_tokens: 4096
|
|
117
|
+
timeout: 90
|
|
118
|
+
max_retries: 3
|
|
119
|
+
enable_multimodal: true
|
|
120
|
+
max_key_steps: 5
|
|
121
|
+
only_fail: true
|
|
122
|
+
max_turns: 8
|
|
123
|
+
output_format: "all"
|
|
124
|
+
|
|
125
|
+
context_compression:
|
|
126
|
+
enabled: true
|
|
127
|
+
max_tokens: 7000
|
|
128
|
+
max_recent_messages: 6
|
|
129
|
+
|
|
130
|
+
reflection:
|
|
131
|
+
enabled: true
|
|
132
|
+
initial_step: 25
|
|
133
|
+
interval: 15
|
|
134
|
+
recent_messages: 10
|
|
@@ -245,8 +245,17 @@ class LLMCaller {
|
|
|
245
245
|
if (opts.systemPrompt)
|
|
246
246
|
logger_1.logger.debug(`LLM call() system prompt: ${opts.systemPrompt}`);
|
|
247
247
|
for (const m of messages) {
|
|
248
|
-
const content = typeof m.content === 'string'
|
|
249
|
-
|
|
248
|
+
const content = typeof m.content === 'string'
|
|
249
|
+
? m.content
|
|
250
|
+
: Array.isArray(m.content)
|
|
251
|
+
? m.content.filter((p) => p.type === 'text').map((p) => p.text ?? '').join('\n') || '[multimodal]'
|
|
252
|
+
: '[multimodal]';
|
|
253
|
+
if (m.role === 'user') {
|
|
254
|
+
logger_1.logger.info(`LLM call() message [user]: ${content}`);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
logger_1.logger.debug(`LLM call() message [${m.role}]: ${content}`);
|
|
258
|
+
}
|
|
250
259
|
}
|
|
251
260
|
if (opts.tools)
|
|
252
261
|
logger_1.logger.debug(`LLM call() tools: ${Object.keys(opts.tools).join(', ')}`);
|
|
@@ -264,7 +273,7 @@ class LLMCaller {
|
|
|
264
273
|
generateOpts.tools = opts.tools;
|
|
265
274
|
}
|
|
266
275
|
const result = await (0, ai_1.generateText)(generateOpts);
|
|
267
|
-
logger_1.logger.
|
|
276
|
+
logger_1.logger.info(`LLM call() output → finishReason=${result.finishReason} text=${result.text}`);
|
|
268
277
|
if (result.toolCalls && result.toolCalls.length > 0) {
|
|
269
278
|
logger_1.logger.debug(`LLM call() toolCalls: ${result.toolCalls.map(tc => tc.toolName).join(', ')}`);
|
|
270
279
|
}
|
|
@@ -366,7 +375,17 @@ class LLMCaller {
|
|
|
366
375
|
const tokenType = (0, token_usage_1.resolveTokenType)(opts.modelConfig.baseUrl);
|
|
367
376
|
logger_1.logger.debug(`LLM callWithMessages() input → model=${opts.modelConfig.name} messages=${opts.messages.length}`);
|
|
368
377
|
for (const m of opts.messages) {
|
|
369
|
-
|
|
378
|
+
const content = typeof m.content === 'string'
|
|
379
|
+
? m.content
|
|
380
|
+
: Array.isArray(m.content)
|
|
381
|
+
? m.content.filter((p) => p.type === 'text').map((p) => p.text ?? '').join('\n') || '[multimodal]'
|
|
382
|
+
: summarizeMessageContent(m.content);
|
|
383
|
+
if (m.role === 'user') {
|
|
384
|
+
logger_1.logger.info(`LLM callWithMessages() message [user]: ${content}`);
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
logger_1.logger.debug(`LLM callWithMessages() message [${m.role}]: ${summarizeMessageContent(m.content)}`);
|
|
388
|
+
}
|
|
370
389
|
}
|
|
371
390
|
if (opts.tools)
|
|
372
391
|
logger_1.logger.debug(`LLM callWithMessages() tools: ${Object.keys(opts.tools).join(', ')}`);
|
|
@@ -387,7 +406,7 @@ class LLMCaller {
|
|
|
387
406
|
generateOpts.tools = opts.tools;
|
|
388
407
|
}
|
|
389
408
|
const result = await (0, ai_1.generateText)(generateOpts);
|
|
390
|
-
logger_1.logger.
|
|
409
|
+
logger_1.logger.info(`LLM callWithMessages() output → finishReason=${result.finishReason} text=${result.text}`);
|
|
391
410
|
if (result.reasoningText)
|
|
392
411
|
logger_1.logger.debug(`LLM callWithMessages() reasoningText: ${result.reasoningText}`);
|
|
393
412
|
if (result.toolCalls && result.toolCalls.length > 0) {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 定位打包后 dist
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* 定位打包后 dist 根目录。
|
|
3
|
+
*
|
|
4
|
+
* 查找策略(从 __dirname 向上遍历):
|
|
5
|
+
* 1. 优先检查目录同时包含 common/ 和 core/ 子目录(最可靠,不依赖具体文件)
|
|
6
|
+
* 2. 回退检查 common/config/config.yaml 存在(兼容旧逻辑)
|
|
7
|
+
*
|
|
8
|
+
* 兼容普通构建(模块在 dist/core/... 子目录)与单文件 bundle(模块在 dist/index.js)。
|
|
5
9
|
*/
|
|
6
10
|
export declare function findDistRoot(): string;
|
|
7
11
|
export declare function findProjectRoot(): string;
|