@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
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Config management tool: init/init-app-config/get/set/list operations on config.yaml.
|
|
4
|
+
*
|
|
5
|
+
* Ported from python tools/config/config_tool.py.
|
|
6
|
+
*
|
|
7
|
+
* Commands:
|
|
8
|
+
* init - Create a default config.yaml template at the specified path.
|
|
9
|
+
* init-app-config - Create an example app_config.json for MCP bundle name mapping.
|
|
10
|
+
* get - Read a config value by dot-notation key.
|
|
11
|
+
* set - Write a config value by dot-notation key.
|
|
12
|
+
* list - List all config key-value pairs.
|
|
13
|
+
*/
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
+
}) : function(o, v) {
|
|
28
|
+
o["default"] = v;
|
|
29
|
+
});
|
|
30
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
+
var ownKeys = function(o) {
|
|
32
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
+
var ar = [];
|
|
34
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
+
return ar;
|
|
36
|
+
};
|
|
37
|
+
return ownKeys(o);
|
|
38
|
+
};
|
|
39
|
+
return function (mod) {
|
|
40
|
+
if (mod && mod.__esModule) return mod;
|
|
41
|
+
var result = {};
|
|
42
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.main = main;
|
|
49
|
+
const fs = __importStar(require("fs"));
|
|
50
|
+
const path = __importStar(require("path"));
|
|
51
|
+
const yaml = __importStar(require("js-yaml"));
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// Default config template source
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
function getDefaultConfigPath() {
|
|
56
|
+
return path.join(__dirname, '..', '..', 'common', 'config', 'config.yaml');
|
|
57
|
+
}
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// YAML helpers
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
function loadYaml(filePath) {
|
|
62
|
+
if (!fs.existsSync(filePath)) {
|
|
63
|
+
console.error(`Error: config file not found: ${filePath}`);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
const data = yaml.load(fs.readFileSync(filePath, 'utf-8'));
|
|
67
|
+
return (data && typeof data === 'object') ? data : {};
|
|
68
|
+
}
|
|
69
|
+
function saveYaml(filePath, data) {
|
|
70
|
+
const content = yaml.dump(data, { lineWidth: -1, noRefs: true });
|
|
71
|
+
fs.writeFileSync(filePath, content, 'utf-8');
|
|
72
|
+
}
|
|
73
|
+
function resolveKey(data, key) {
|
|
74
|
+
const parts = key.split('.');
|
|
75
|
+
let current = data;
|
|
76
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
77
|
+
if (typeof current !== 'object' || current === null || !(parts[i] in current)) {
|
|
78
|
+
return { parent: null, leaf: '' };
|
|
79
|
+
}
|
|
80
|
+
current = current[parts[i]];
|
|
81
|
+
}
|
|
82
|
+
if (typeof current !== 'object' || current === null) {
|
|
83
|
+
return { parent: null, leaf: '' };
|
|
84
|
+
}
|
|
85
|
+
return { parent: current, leaf: parts[parts.length - 1] };
|
|
86
|
+
}
|
|
87
|
+
function getValue(data, key) {
|
|
88
|
+
const { parent, leaf } = resolveKey(data, key);
|
|
89
|
+
if (parent === null || !(leaf in parent)) {
|
|
90
|
+
return { found: false, value: null };
|
|
91
|
+
}
|
|
92
|
+
return { found: true, value: parent[leaf] };
|
|
93
|
+
}
|
|
94
|
+
function setValue(data, key, value) {
|
|
95
|
+
const parts = key.split('.');
|
|
96
|
+
let current = data;
|
|
97
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
98
|
+
if (!(parts[i] in current) || typeof current[parts[i]] !== 'object' || current[parts[i]] === null) {
|
|
99
|
+
current[parts[i]] = {};
|
|
100
|
+
}
|
|
101
|
+
current = current[parts[i]];
|
|
102
|
+
}
|
|
103
|
+
current[parts[parts.length - 1]] = value;
|
|
104
|
+
}
|
|
105
|
+
function parseValue(raw) {
|
|
106
|
+
const lower = raw.toLowerCase();
|
|
107
|
+
if (lower === 'true' || lower === 'yes')
|
|
108
|
+
return true;
|
|
109
|
+
if (lower === 'false' || lower === 'no')
|
|
110
|
+
return false;
|
|
111
|
+
if (lower === 'null' || lower === 'none' || lower === '~')
|
|
112
|
+
return null;
|
|
113
|
+
if (/^-?\d+$/.test(raw))
|
|
114
|
+
return parseInt(raw, 10);
|
|
115
|
+
if (/^-?\d*\.\d+$/.test(raw))
|
|
116
|
+
return parseFloat(raw);
|
|
117
|
+
if (raw.startsWith('[') || raw.startsWith('{')) {
|
|
118
|
+
try {
|
|
119
|
+
return JSON.parse(raw);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// fall through
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return raw;
|
|
126
|
+
}
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
// Flatten for list command
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
function flatten(data, prefix = '') {
|
|
131
|
+
const result = [];
|
|
132
|
+
for (const [k, v] of Object.entries(data)) {
|
|
133
|
+
const fullKey = prefix ? `${prefix}.${k}` : k;
|
|
134
|
+
if (v && typeof v === 'object' && !Array.isArray(v)) {
|
|
135
|
+
result.push(...flatten(v, fullKey));
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
result.push([fullKey, v]);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
// Commands
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
const APP_CONFIG_TEMPLATE = {
|
|
147
|
+
bundle_names: {
|
|
148
|
+
'设置': 'com.huawei.hmos.settings',
|
|
149
|
+
},
|
|
150
|
+
main_abilities: {
|
|
151
|
+
'com.huawei.hmos.settings': 'com.huawei.hmos.setting.MainAbility',
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
function cmdInit(opts) {
|
|
155
|
+
const src = getDefaultConfigPath();
|
|
156
|
+
if (!fs.existsSync(src)) {
|
|
157
|
+
console.error(`Error: default config template not found at: ${src}`);
|
|
158
|
+
return 1;
|
|
159
|
+
}
|
|
160
|
+
if (fs.existsSync(opts.output) && !opts.force) {
|
|
161
|
+
console.error(`Error: file already exists: ${opts.output}`);
|
|
162
|
+
console.error('Use --force to overwrite.');
|
|
163
|
+
return 1;
|
|
164
|
+
}
|
|
165
|
+
const content = fs.readFileSync(src, 'utf-8');
|
|
166
|
+
const outputDir = path.dirname(path.resolve(opts.output));
|
|
167
|
+
if (outputDir)
|
|
168
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
169
|
+
fs.writeFileSync(opts.output, content, 'utf-8');
|
|
170
|
+
console.log(`\n${'='.repeat(60)}`);
|
|
171
|
+
console.log(` 配置文件已创建: ${path.resolve(opts.output)}`);
|
|
172
|
+
console.log(`${'='.repeat(60)}`);
|
|
173
|
+
console.log(`\n下一步:编辑该文件,填入你的 API Key 和模型配置:\n`);
|
|
174
|
+
console.log(` model.unified.api_key → 填入你的 DashScope API Key`);
|
|
175
|
+
console.log(` model.unified.name → 填入模型名(如 qwen3.7-plus)`);
|
|
176
|
+
console.log(` device.device_sn → 填入设备序列号(hdc list targets 查看)`);
|
|
177
|
+
console.log(`\n或用命令行修改:`);
|
|
178
|
+
console.log(` node dist/tools/config/config_tool.js set model.unified.api_key "sk-xxx"`);
|
|
179
|
+
console.log(` node dist/tools/config/config_tool.js set model.unified.name "qwen3.7-plus"`);
|
|
180
|
+
console.log(` node dist/tools/config/config_tool.js set device.device_sn "YOUR_DEVICE_SN"`);
|
|
181
|
+
console.log(`\n配置完成后即可运行测试:`);
|
|
182
|
+
console.log(` node dist/autotest-cli.js run --task "你的测试任务描述"`);
|
|
183
|
+
console.log(`\n${'='.repeat(60)}\n`);
|
|
184
|
+
return 0;
|
|
185
|
+
}
|
|
186
|
+
function cmdInitAppConfig(opts) {
|
|
187
|
+
if (fs.existsSync(opts.output) && !opts.force) {
|
|
188
|
+
console.error(`Error: file already exists: ${opts.output}`);
|
|
189
|
+
console.error('Use --force to overwrite.');
|
|
190
|
+
return 1;
|
|
191
|
+
}
|
|
192
|
+
const outputDir = path.dirname(path.resolve(opts.output));
|
|
193
|
+
if (outputDir)
|
|
194
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
195
|
+
fs.writeFileSync(opts.output, JSON.stringify(APP_CONFIG_TEMPLATE, null, 2) + '\n', 'utf-8');
|
|
196
|
+
console.log(`Created app_config template: ${path.resolve(opts.output)}`);
|
|
197
|
+
console.log(` bundle_names: ${Object.keys(APP_CONFIG_TEMPLATE.bundle_names).length} entries`);
|
|
198
|
+
console.log(` main_abilities: ${Object.keys(APP_CONFIG_TEMPLATE.main_abilities).length} entries`);
|
|
199
|
+
console.log(`\nEdit the file to add your app mappings, then use:`);
|
|
200
|
+
console.log(` autotest run --task "..." --app-config ${opts.output}`);
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
function cmdGet(opts) {
|
|
204
|
+
const data = loadYaml(opts.config);
|
|
205
|
+
const { found, value } = getValue(data, opts.key);
|
|
206
|
+
if (!found) {
|
|
207
|
+
console.error(`Key not found: ${opts.key}`);
|
|
208
|
+
return 1;
|
|
209
|
+
}
|
|
210
|
+
if (value && typeof value === 'object') {
|
|
211
|
+
console.log(yaml.dump(value, { lineWidth: -1, noRefs: true }).trimEnd());
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
console.log(value === null ? 'null' : String(value));
|
|
215
|
+
}
|
|
216
|
+
return 0;
|
|
217
|
+
}
|
|
218
|
+
function cmdSet(opts) {
|
|
219
|
+
const data = loadYaml(opts.config);
|
|
220
|
+
const parsed = parseValue(opts.value);
|
|
221
|
+
setValue(data, opts.key, parsed);
|
|
222
|
+
saveYaml(opts.config, data);
|
|
223
|
+
console.log(`Set ${opts.key} = ${JSON.stringify(parsed)}`);
|
|
224
|
+
return 0;
|
|
225
|
+
}
|
|
226
|
+
function cmdList(opts) {
|
|
227
|
+
const data = loadYaml(opts.config);
|
|
228
|
+
const items = flatten(data);
|
|
229
|
+
if (items.length === 0) {
|
|
230
|
+
console.log('(empty config)');
|
|
231
|
+
return 0;
|
|
232
|
+
}
|
|
233
|
+
const maxKeyLen = Math.max(...items.map(([k]) => k.length));
|
|
234
|
+
const separator = '─'.repeat(maxKeyLen + 20);
|
|
235
|
+
let currentPrefix = null;
|
|
236
|
+
for (const [key, value] of items) {
|
|
237
|
+
const prefix = key.split('.')[0];
|
|
238
|
+
if (prefix !== currentPrefix) {
|
|
239
|
+
console.log(separator);
|
|
240
|
+
console.log(` [${prefix}]`);
|
|
241
|
+
console.log(separator);
|
|
242
|
+
currentPrefix = prefix;
|
|
243
|
+
}
|
|
244
|
+
const valStr = value === null ? 'null' : String(value);
|
|
245
|
+
console.log(` ${key.padEnd(maxKeyLen)} ${valStr}`);
|
|
246
|
+
}
|
|
247
|
+
console.log(`\n${separator}`);
|
|
248
|
+
console.log(`Total: ${items.length} keys`);
|
|
249
|
+
return 0;
|
|
250
|
+
}
|
|
251
|
+
function parseArgs(args) {
|
|
252
|
+
const result = {
|
|
253
|
+
command: '',
|
|
254
|
+
output: '',
|
|
255
|
+
force: false,
|
|
256
|
+
key: '',
|
|
257
|
+
value: '',
|
|
258
|
+
config: 'config.yaml',
|
|
259
|
+
};
|
|
260
|
+
if (args.length === 0)
|
|
261
|
+
return result;
|
|
262
|
+
result.command = args[0];
|
|
263
|
+
for (let i = 1; i < args.length; i++) {
|
|
264
|
+
switch (args[i]) {
|
|
265
|
+
case '-o':
|
|
266
|
+
case '--output':
|
|
267
|
+
result.output = args[++i] ?? '';
|
|
268
|
+
break;
|
|
269
|
+
case '--force':
|
|
270
|
+
result.force = true;
|
|
271
|
+
break;
|
|
272
|
+
case '--config':
|
|
273
|
+
case '-c':
|
|
274
|
+
result.config = args[++i] ?? 'config.yaml';
|
|
275
|
+
break;
|
|
276
|
+
default:
|
|
277
|
+
if (!result.key) {
|
|
278
|
+
result.key = args[i];
|
|
279
|
+
}
|
|
280
|
+
else if (!result.value) {
|
|
281
|
+
result.value = args[i];
|
|
282
|
+
}
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return result;
|
|
287
|
+
}
|
|
288
|
+
function printUsage() {
|
|
289
|
+
console.log(`
|
|
290
|
+
Usage: autotest-config <command> [options]
|
|
291
|
+
|
|
292
|
+
Commands:
|
|
293
|
+
init Create a default config.yaml template
|
|
294
|
+
init-app-config Create an example app_config.json for MCP bundle name mapping
|
|
295
|
+
get Get a config value by dot-notation key
|
|
296
|
+
set Set a config value by dot-notation key
|
|
297
|
+
list List all config key-value pairs
|
|
298
|
+
|
|
299
|
+
Options:
|
|
300
|
+
-o, --output <path> Output file path (for init/init-app-config)
|
|
301
|
+
--force Overwrite existing file
|
|
302
|
+
-c, --config <path> Config file path (for get/set/list, default: config.yaml)
|
|
303
|
+
`);
|
|
304
|
+
}
|
|
305
|
+
function main() {
|
|
306
|
+
const args = process.argv.slice(2);
|
|
307
|
+
const parsed = parseArgs(args);
|
|
308
|
+
if (!parsed.command) {
|
|
309
|
+
printUsage();
|
|
310
|
+
return 1;
|
|
311
|
+
}
|
|
312
|
+
switch (parsed.command) {
|
|
313
|
+
case 'init':
|
|
314
|
+
return cmdInit({ output: parsed.output || 'config.yaml', force: parsed.force });
|
|
315
|
+
case 'init-app-config':
|
|
316
|
+
return cmdInitAppConfig({ output: parsed.output || 'app_config.json', force: parsed.force });
|
|
317
|
+
case 'get':
|
|
318
|
+
if (!parsed.key) {
|
|
319
|
+
console.error('Usage: autotest-config get <key>');
|
|
320
|
+
return 1;
|
|
321
|
+
}
|
|
322
|
+
return cmdGet({ config: parsed.config, key: parsed.key });
|
|
323
|
+
case 'set':
|
|
324
|
+
if (!parsed.key || !parsed.value) {
|
|
325
|
+
console.error('Usage: autotest-config set <key> <value>');
|
|
326
|
+
return 1;
|
|
327
|
+
}
|
|
328
|
+
return cmdSet({ config: parsed.config, key: parsed.key, value: parsed.value });
|
|
329
|
+
case 'list':
|
|
330
|
+
return cmdList({ config: parsed.config });
|
|
331
|
+
default:
|
|
332
|
+
console.error(`Unknown command: ${parsed.command}`);
|
|
333
|
+
printUsage();
|
|
334
|
+
return 1;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (require.main === module) {
|
|
338
|
+
process.exit(main());
|
|
339
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-prompt batch comparison runner.
|
|
3
|
+
*
|
|
4
|
+
* Ported from python tools/prompt_compare/compare_runner.py.
|
|
5
|
+
*
|
|
6
|
+
* Sequentially runs the same test cases with different prompts (via the
|
|
7
|
+
* batch_runner as a subprocess), then generates a comparison summary report
|
|
8
|
+
* (JSON + CSV + Markdown).
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* node dist/tools/prompt_compare.js --prompts single_v2.0 single_v1.0 --testcases cases.json
|
|
12
|
+
*/
|
|
13
|
+
export declare function main(): Promise<number>;
|