@autotest/agent 0.0.3 → 0.0.5
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 +63 -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/general_agent.js +1 -1
- 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 +21 -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
|
@@ -57,6 +57,14 @@ const agent_api_1 = require("../api/agent_api");
|
|
|
57
57
|
const manager_1 = require("../common/config/manager");
|
|
58
58
|
const adapter_factory_1 = require("../core/mcp/adapter_factory");
|
|
59
59
|
const logger_1 = require("../common/logger");
|
|
60
|
+
// EPIPE resilience: when stdout/stderr is a pipe whose read end closed (e.g. the
|
|
61
|
+
// spawning parent process died), writes would throw EPIPE and crash this (detached)
|
|
62
|
+
// batch_runner. Swallow EPIPE so it keeps running — writing per-case agent logs +
|
|
63
|
+
// summary.json — and stays pollable via --status. Other errors still propagate.
|
|
64
|
+
process.stdout.on('error', (err) => { if (err && (err.code === 'EPIPE' || err.code === 'ERR_STREAM_DESTROYED'))
|
|
65
|
+
return; throw err; });
|
|
66
|
+
process.stderr.on('error', (err) => { if (err && (err.code === 'EPIPE' || err.code === 'ERR_STREAM_DESTROYED'))
|
|
67
|
+
return; throw err; });
|
|
60
68
|
const UTF_8 = 'utf-8';
|
|
61
69
|
const CASE_TIMEOUT_MS = 10 * 60 * 1000;
|
|
62
70
|
const PROGRESS_REPORT_INTERVAL = 10;
|
|
@@ -74,10 +82,12 @@ class AutoTestBackend {
|
|
|
74
82
|
agent;
|
|
75
83
|
config;
|
|
76
84
|
mode;
|
|
77
|
-
|
|
85
|
+
promptName;
|
|
86
|
+
constructor(agent, config = '', mode = '', promptName = '') {
|
|
78
87
|
this.agent = agent;
|
|
79
88
|
this.config = config;
|
|
80
89
|
this.mode = mode;
|
|
90
|
+
this.promptName = promptName;
|
|
81
91
|
}
|
|
82
92
|
/** Execute a single test case. */
|
|
83
93
|
async executeCase(testSteps, reportDir, caseMode = '') {
|
|
@@ -88,6 +98,7 @@ class AutoTestBackend {
|
|
|
88
98
|
platform: 'harmony',
|
|
89
99
|
reportDir,
|
|
90
100
|
task: testSteps,
|
|
101
|
+
...(this.promptName ? { promptName: this.promptName } : {}),
|
|
91
102
|
};
|
|
92
103
|
fs.mkdirSync(path.join(reportDir, 'log'), { recursive: true });
|
|
93
104
|
try {
|
|
@@ -431,8 +442,8 @@ function printProgressReport(passCount, failCount, unknownCount, executedCount,
|
|
|
431
442
|
}
|
|
432
443
|
/** Execute a batch of test cases. */
|
|
433
444
|
async function executeBatch(options) {
|
|
434
|
-
const { agent, taskDir, testcases, category, testsetRoot = '', config = '', mode = '', maxCases } = options;
|
|
435
|
-
const backend = new AutoTestBackend(agent, config, mode);
|
|
445
|
+
const { agent, taskDir, testcases, category, testsetRoot = '', config = '', mode = '', promptName = '', maxCases } = options;
|
|
446
|
+
const backend = new AutoTestBackend(agent, config, mode, promptName);
|
|
436
447
|
const normalizedTaskDir = taskDir.replace(/\\/g, '/');
|
|
437
448
|
const csvFile = path.join(normalizedTaskDir, 'task_results.csv').replace(/\\/g, '/');
|
|
438
449
|
const jsonlFile = path.join(normalizedTaskDir, 'task_results.jsonl').replace(/\\/g, '/');
|
|
@@ -461,9 +472,7 @@ async function executeBatch(options) {
|
|
|
461
472
|
const caseName = String(testCase.case_name ?? '');
|
|
462
473
|
const testSteps = String(testCase.test_steps ?? '');
|
|
463
474
|
const caseMode = String(testCase.execute_mode ?? '');
|
|
464
|
-
const dirname =
|
|
465
|
-
? sanitizeFilename(`${uuid}_${caseName}`)
|
|
466
|
-
: sanitizeFilename(`${String(execIndex).padStart(indexWidth, '0')}_${caseName}`);
|
|
475
|
+
const dirname = sanitizeFilename(caseName) || sanitizeFilename(`${String(execIndex).padStart(indexWidth, '0')}`);
|
|
467
476
|
const reportDir = path.join(normalizedTaskDir, dirname).replace(/\\/g, '/');
|
|
468
477
|
if (fs.existsSync(reportDir)) {
|
|
469
478
|
fs.rmSync(reportDir, { recursive: true, force: true });
|
|
@@ -640,6 +649,7 @@ async function main() {
|
|
|
640
649
|
testsetRoot: opts.testsetRoot,
|
|
641
650
|
config: opts.config || configPath,
|
|
642
651
|
mode: resolvedMode,
|
|
652
|
+
promptName: opts.promptName,
|
|
643
653
|
maxCases: opts.maxCases,
|
|
644
654
|
});
|
|
645
655
|
if (opts.testcases.includes('.temp_') && fs.existsSync(opts.testcases)) {
|
|
@@ -662,6 +672,7 @@ function parseArgs(args) {
|
|
|
662
672
|
testsetRoot: '',
|
|
663
673
|
config: '',
|
|
664
674
|
mode: '',
|
|
675
|
+
promptName: '',
|
|
665
676
|
maxCases: 0,
|
|
666
677
|
};
|
|
667
678
|
let categorySet = false;
|
|
@@ -699,6 +710,10 @@ function parseArgs(args) {
|
|
|
699
710
|
opts.mode = value ?? '';
|
|
700
711
|
i++;
|
|
701
712
|
break;
|
|
713
|
+
case '--prompt-name':
|
|
714
|
+
opts.promptName = value ?? '';
|
|
715
|
+
i++;
|
|
716
|
+
break;
|
|
702
717
|
case '--max-cases':
|
|
703
718
|
opts.maxCases = Number(value) ?? 0;
|
|
704
719
|
i++;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Case execution summary HTML report generator.
|
|
3
|
+
*
|
|
4
|
+
* Ported from python tools/case_runner/report.py.
|
|
5
|
+
* Generates a sidebar + panel layout with iframe-embedded phase reports.
|
|
6
|
+
*/
|
|
7
|
+
import type { CaseInfo } from '../../data_types/case';
|
|
8
|
+
import type { CaseResult } from './runner';
|
|
9
|
+
export declare function generateCaseReport(caseInfo: CaseInfo, caseResult: CaseResult, reportDir: string): string;
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Case execution summary HTML report generator.
|
|
4
|
+
*
|
|
5
|
+
* Ported from python tools/case_runner/report.py.
|
|
6
|
+
* Generates a sidebar + panel layout with iframe-embedded phase reports.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.generateCaseReport = generateCaseReport;
|
|
43
|
+
const fs = __importStar(require("fs"));
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
function escapeHtml(s) {
|
|
46
|
+
return (s ?? '')
|
|
47
|
+
.replace(/&/g, '&')
|
|
48
|
+
.replace(/</g, '<')
|
|
49
|
+
.replace(/>/g, '>')
|
|
50
|
+
.replace(/"/g, '"');
|
|
51
|
+
}
|
|
52
|
+
const CSS = `
|
|
53
|
+
*{margin:0;padding:0;box-sizing:border-box}
|
|
54
|
+
body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif;background:#f8fafc;color:#1e293b;line-height:1.6;overflow:hidden;height:100vh}
|
|
55
|
+
.sidebar{width:52px;min-width:52px;height:100vh;position:fixed;left:0;top:0;background:#fff;border-right:1px solid #e2e8f0;display:flex;flex-direction:column;align-items:center;padding:0;gap:0;z-index:100;transition:width .2s}
|
|
56
|
+
.sidebar.expanded{width:200px;align-items:stretch}
|
|
57
|
+
.sidebar-top{display:flex;align-items:center;justify-content:center;padding:10px 8px;border-bottom:1px solid #e2e8f0;flex-shrink:0;gap:8px;min-height:44px;width:100%}
|
|
58
|
+
.sidebar-toggle{width:28px;height:28px;border-radius:6px;display:flex;align-items:center;justify-content:center;cursor:pointer;color:#94a3b8;background:transparent;border:none;outline:none;transition:all .15s;font-size:14px;flex-shrink:0}
|
|
59
|
+
.sidebar-toggle:hover{background:#f1f5f9;color:#3b82f6}
|
|
60
|
+
.status-dot{width:12px;height:12px;border-radius:50%;flex-shrink:0}
|
|
61
|
+
.status-dot.pass{background:#22c55e}.status-dot.fail{background:#ef4444}.status-dot.error{background:#f59e0b}.status-dot.unknown{background:#94a3b8}
|
|
62
|
+
.status-text{display:none;font-size:13px;font-weight:700;letter-spacing:.5px}
|
|
63
|
+
.sidebar.expanded .status-text{display:inline}
|
|
64
|
+
.status-text.pass{color:#166534}.status-text.fail{color:#991b1b}.status-text.error{color:#92400e}.status-text.unknown{color:#475569}
|
|
65
|
+
.sidebar-info{display:none;padding:12px 14px;border-bottom:1px solid #e2e8f0;flex-shrink:0}
|
|
66
|
+
.sidebar.expanded .sidebar-info{display:block}
|
|
67
|
+
.sidebar-info-name{font-size:14px;font-weight:700;color:#0f172a;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;margin-bottom:4px}
|
|
68
|
+
.sidebar-info-id{font-size:11px;color:#94a3b8;margin-bottom:8px}
|
|
69
|
+
.sidebar-info-row{display:flex;justify-content:space-between;align-items:center;font-size:12px;color:#64748b;padding:2px 0}
|
|
70
|
+
.sidebar-info-row .val{font-weight:600;color:#1e293b}
|
|
71
|
+
.sidebar-nav{flex:1;display:flex;flex-direction:column;align-items:center;padding:10px 8px;gap:4px;overflow-y:auto;width:100%}
|
|
72
|
+
.sidebar.expanded .sidebar-nav{align-items:stretch}
|
|
73
|
+
.nav-icon{width:36px;height:36px;border-radius:8px;display:flex;align-items:center;justify-content:center;cursor:pointer;color:#64748b;background:#f1f5f9;transition:all .15s;flex-shrink:0;font-size:14px;font-weight:700;position:relative;border:none;outline:none}
|
|
74
|
+
.nav-icon:hover{background:#e2e8f0;color:#3b82f6}
|
|
75
|
+
.nav-icon.active{background:#3b82f6;color:#fff}
|
|
76
|
+
.nav-icon svg{width:18px;height:18px;fill:currentColor}
|
|
77
|
+
.nav-icon::after{content:attr(data-tip);position:absolute;left:calc(100% + 8px);top:50%;transform:translateY(-50%);background:#1e293b;color:#fff;padding:4px 10px;border-radius:6px;font-size:12px;font-weight:500;white-space:nowrap;pointer-events:none;opacity:0;transition:opacity .15s;z-index:200}
|
|
78
|
+
.sidebar:not(.expanded) .nav-icon:hover::after{opacity:1}
|
|
79
|
+
.nav-label{display:none;font-size:12px;color:#475569;margin-left:8px;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
80
|
+
.sidebar.expanded .nav-label{display:block}
|
|
81
|
+
.sidebar.expanded .nav-icon{width:auto;padding:0 12px;gap:6px;align-self:stretch}
|
|
82
|
+
.nav-dot-sm{width:6px;height:6px;border-radius:50%;flex-shrink:0}
|
|
83
|
+
.nav-dot-sm.pass{background:#22c55e}.nav-dot-sm.fail{background:#ef4444}.nav-dot-sm.skip{background:#94a3b8}.nav-dot-sm.error{background:#f59e0b}
|
|
84
|
+
.nav-icon.active .nav-dot-sm{background:rgba(255,255,255,.7)}
|
|
85
|
+
.main{margin-left:52px;height:100vh;overflow:hidden;position:relative;transition:margin-left .2s}
|
|
86
|
+
.sidebar.expanded ~ .main{margin-left:200px}
|
|
87
|
+
.panel{position:absolute;top:0;left:0;right:0;bottom:0;display:none;overflow-y:auto;padding:0}
|
|
88
|
+
.panel.active{display:flex;flex-direction:column}
|
|
89
|
+
.overview-panel{padding:24px 30px;overflow-y:auto}
|
|
90
|
+
.info-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:16px;margin-bottom:20px}
|
|
91
|
+
.info-card{background:#fff;border-radius:12px;padding:16px 20px;box-shadow:0 1px 3px rgba(0,0,0,.08)}
|
|
92
|
+
.info-card h3{font-size:13px;color:#64748b;font-weight:600;margin-bottom:12px;text-transform:uppercase;letter-spacing:.5px;padding-left:12px;border-left:3px solid #3b82f6}
|
|
93
|
+
.info-row{display:flex;justify-content:space-between;align-items:center;padding:6px 0;font-size:13px;border-bottom:1px solid #f1f5f9}
|
|
94
|
+
.info-row:last-child{border-bottom:none}
|
|
95
|
+
.info-label{color:#64748b}.info-value{font-weight:600;color:#1e293b}
|
|
96
|
+
.overview-header{display:flex;justify-content:space-between;align-items:center;padding:20px 24px;background:#fff;border-radius:12px;box-shadow:0 1px 3px rgba(0,0,0,.08);margin-bottom:20px}
|
|
97
|
+
.overview-header h1{font-size:22px;font-weight:700;color:#0f172a}
|
|
98
|
+
.overview-header .subtitle{font-size:13px;color:#64748b;margin-top:4px}
|
|
99
|
+
.status-badge{display:inline-block;padding:6px 16px;border-radius:20px;font-size:14px;font-weight:700;letter-spacing:1px}
|
|
100
|
+
.status-badge.pass{background:#dcfce7;color:#166534}.status-badge.fail{background:#fee2e2;color:#991b1b}.status-badge.error{background:#fef3c7;color:#92400e}.status-badge.unknown{background:#f1f5f9;color:#475569}
|
|
101
|
+
.phase-panel{padding:0;overflow:hidden}
|
|
102
|
+
.phase-panel iframe{width:100%;height:100%;border:none;display:block}
|
|
103
|
+
.phase-panel .phase-empty{display:flex;align-items:center;justify-content:center;width:100%;height:100%;color:#94a3b8;font-size:15px}
|
|
104
|
+
.app-list{display:flex;gap:6px;flex-wrap:wrap}
|
|
105
|
+
.app-tag{background:#eff6ff;color:#1e40af;padding:3px 10px;border-radius:6px;font-size:12px;font-weight:500}
|
|
106
|
+
`;
|
|
107
|
+
const JS = `
|
|
108
|
+
var currentPanel = 'overview';
|
|
109
|
+
function switchPanel(panelId) {
|
|
110
|
+
var cur = document.getElementById('panel-' + currentPanel);
|
|
111
|
+
if (cur) cur.classList.remove('active');
|
|
112
|
+
var next = document.getElementById('panel-' + panelId);
|
|
113
|
+
if (next) next.classList.add('active');
|
|
114
|
+
document.querySelectorAll('.nav-icon').forEach(function(btn) {
|
|
115
|
+
btn.classList.remove('active');
|
|
116
|
+
if (btn.getAttribute('data-panel') === panelId) btn.classList.add('active');
|
|
117
|
+
});
|
|
118
|
+
currentPanel = panelId;
|
|
119
|
+
}
|
|
120
|
+
function toggleSidebar() { document.getElementById('sidebar').classList.toggle('expanded'); }
|
|
121
|
+
document.addEventListener('keydown', function(e) {
|
|
122
|
+
var panels = ['overview'];
|
|
123
|
+
document.querySelectorAll('.panel.phase-panel').forEach(function(p) { panels.push(p.id.replace('panel-', '')); });
|
|
124
|
+
var num = parseInt(e.key);
|
|
125
|
+
if (num >= 1 && num <= panels.length) switchPanel(panels[num - 1]);
|
|
126
|
+
});
|
|
127
|
+
`;
|
|
128
|
+
const SVG_OVERVIEW = '<svg viewBox="0 0 24 24"><path d="M3 13h8V3H3v10zm0 8h8v-6H3v6zm10 0h8V11h-8v10zm0-18v6h8V3h-8z"/></svg>';
|
|
129
|
+
const SVG_SETUP = '<svg viewBox="0 0 24 24"><path d="M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 00.12-.61l-1.92-3.32a.49.49 0 00-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.48.48 0 00-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96a.49.49 0 00-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.07.62-.07.94s.02.64.07.94l-2.03 1.58a.49.49 0 00-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6A3.6 3.6 0 1115.6 12 3.6 3.6 0 0112 15.6z"/></svg>';
|
|
130
|
+
const SVG_TEST = '<svg viewBox="0 0 24 24"><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z"/></svg>';
|
|
131
|
+
const SVG_TEARDOWN = '<svg viewBox="0 0 24 24"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>';
|
|
132
|
+
const PHASE_ICONS = { setup: SVG_SETUP, process: SVG_TEST, teardown: SVG_TEARDOWN };
|
|
133
|
+
const PHASE_LABELS = { setup: 'Setup', process: 'Process', teardown: 'Teardown' };
|
|
134
|
+
function statusClass(status) {
|
|
135
|
+
if (status === 'PASS')
|
|
136
|
+
return 'pass';
|
|
137
|
+
if (status === 'FAIL' || status === 'ERROR')
|
|
138
|
+
return 'fail';
|
|
139
|
+
if (status === 'SKIPPED')
|
|
140
|
+
return 'skip';
|
|
141
|
+
return 'error';
|
|
142
|
+
}
|
|
143
|
+
function buildSidebar(caseInfo, result) {
|
|
144
|
+
const status = result.overallStatus || 'UNKNOWN';
|
|
145
|
+
const sc = statusClass(status);
|
|
146
|
+
const navItems = [];
|
|
147
|
+
navItems.push(`<button class="nav-icon active" data-panel="overview" data-tip="Overview" onclick="switchPanel('overview')">${SVG_OVERVIEW}<span class="nav-label">Overview</span></button>`);
|
|
148
|
+
for (const phase of result.phaseResults) {
|
|
149
|
+
const label = PHASE_LABELS[phase.name] ?? phase.name;
|
|
150
|
+
const icon = PHASE_ICONS[phase.name] ?? SVG_TEST;
|
|
151
|
+
const nc = statusClass(phase.status);
|
|
152
|
+
navItems.push(`<button class="nav-icon" data-panel="phase-${phase.name}" data-tip="${escapeHtml(label)}" onclick="switchPanel('phase-${phase.name}')">${icon}<span class="nav-dot-sm ${nc}"></span><span class="nav-label">${escapeHtml(label)}</span></button>`);
|
|
153
|
+
}
|
|
154
|
+
const passed = result.phaseResults.filter((p) => p.status === 'PASS').length;
|
|
155
|
+
const total = result.phaseResults.length;
|
|
156
|
+
return `
|
|
157
|
+
<div class="sidebar-top">
|
|
158
|
+
<button class="sidebar-toggle" id="sidebarToggle" onclick="toggleSidebar()" title="Toggle sidebar"><svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><rect y="3" width="24" height="2.5" rx="1.2"/><rect y="10.75" width="24" height="2.5" rx="1.2"/><rect y="18.5" width="24" height="2.5" rx="1.2"/></svg></button>
|
|
159
|
+
<span class="status-dot ${sc}"></span>
|
|
160
|
+
<span class="status-text ${sc}">${escapeHtml(status)}</span>
|
|
161
|
+
</div>
|
|
162
|
+
<div class="sidebar-info">
|
|
163
|
+
<div class="sidebar-info-name">${escapeHtml(caseInfo.caseName)}</div>
|
|
164
|
+
<div class="sidebar-info-id">${escapeHtml(caseInfo.caseId)}</div>
|
|
165
|
+
<div class="sidebar-info-row"><span>Duration</span><span class="val">${result.totalDuration.toFixed(1)}s</span></div>
|
|
166
|
+
<div class="sidebar-info-row"><span>Tokens</span><span class="val">${result.totalTokens.toLocaleString()}</span></div>
|
|
167
|
+
<div class="sidebar-info-row"><span>Phases</span><span class="val">${passed}/${total} passed</span></div>
|
|
168
|
+
</div>
|
|
169
|
+
<div class="sidebar-nav">${navItems.join('')}</div>
|
|
170
|
+
`;
|
|
171
|
+
}
|
|
172
|
+
function buildOverviewPanel(caseInfo, result) {
|
|
173
|
+
const status = result.overallStatus || 'UNKNOWN';
|
|
174
|
+
const sc = statusClass(status);
|
|
175
|
+
const appTags = caseInfo.appInfos.map((a) => `<span class="app-tag">${escapeHtml(a.displayName)} (${escapeHtml(a.bundleName)})</span>`).join('');
|
|
176
|
+
let phaseRows = '';
|
|
177
|
+
for (const p of result.phaseResults) {
|
|
178
|
+
const label = PHASE_LABELS[p.name] ?? p.name;
|
|
179
|
+
const nc = statusClass(p.status);
|
|
180
|
+
const color = nc === 'pass' ? '#22c55e' : nc === 'fail' ? '#ef4444' : '#94a3b8';
|
|
181
|
+
phaseRows += `<div class="info-row"><span class="info-label">${escapeHtml(label)}</span><span class="info-value" style="color:${color}">${escapeHtml(p.status)} (${p.durationSeconds.toFixed(1)}s)</span></div>`;
|
|
182
|
+
}
|
|
183
|
+
return `
|
|
184
|
+
<div id="panel-overview" class="panel overview-panel active">
|
|
185
|
+
<div class="overview-header">
|
|
186
|
+
<div>
|
|
187
|
+
<h1>${escapeHtml(caseInfo.caseName)}</h1>
|
|
188
|
+
<div class="subtitle">Case ID: ${escapeHtml(caseInfo.caseId)} | ${escapeHtml(result.startTime)} ~ ${escapeHtml(result.endTime)}</div>
|
|
189
|
+
</div>
|
|
190
|
+
<span class="status-badge ${sc}">${escapeHtml(status)}</span>
|
|
191
|
+
</div>
|
|
192
|
+
<div class="info-grid">
|
|
193
|
+
<div class="info-card">
|
|
194
|
+
<h3>Case Info</h3>
|
|
195
|
+
<div class="info-row"><span class="info-label">Case ID</span><span class="info-value">${escapeHtml(caseInfo.caseId)}</span></div>
|
|
196
|
+
<div class="info-row"><span class="info-label">Case Name</span><span class="info-value">${escapeHtml(caseInfo.caseName)}</span></div>
|
|
197
|
+
<div class="info-row"><span class="info-label">Applications</span><span class="info-value"><div class="app-list">${appTags}</div></span></div>
|
|
198
|
+
<div class="info-row"><span class="info-label">Extend Tools</span><span class="info-value">${caseInfo.extendTools.length ? escapeHtml(caseInfo.extendTools.join(', ')) : 'None'}</span></div>
|
|
199
|
+
</div>
|
|
200
|
+
<div class="info-card">
|
|
201
|
+
<h3>Execution Summary</h3>
|
|
202
|
+
<div class="info-row"><span class="info-label">Duration</span><span class="info-value">${result.totalDuration.toFixed(1)}s</span></div>
|
|
203
|
+
<div class="info-row"><span class="info-label">Total Tokens</span><span class="info-value">${result.totalTokens.toLocaleString()}</span></div>
|
|
204
|
+
${phaseRows}
|
|
205
|
+
</div>
|
|
206
|
+
<div class="info-card">
|
|
207
|
+
<h3>Device Info</h3>
|
|
208
|
+
<div class="info-row"><span class="info-label">Device Type</span><span class="info-value">${escapeHtml(result.deviceType)}</span></div>
|
|
209
|
+
<div class="info-row"><span class="info-label">Device SN</span><span class="info-value">${escapeHtml(result.deviceSn || 'N/A')}</span></div>
|
|
210
|
+
<div class="info-row"><span class="info-label">Start Time</span><span class="info-value">${escapeHtml(result.startTime)}</span></div>
|
|
211
|
+
<div class="info-row"><span class="info-label">End Time</span><span class="info-value">${escapeHtml(result.endTime)}</span></div>
|
|
212
|
+
</div>
|
|
213
|
+
</div>
|
|
214
|
+
</div>`;
|
|
215
|
+
}
|
|
216
|
+
function buildPhasePanels(result, reportDir) {
|
|
217
|
+
const panels = [];
|
|
218
|
+
for (const phase of result.phaseResults) {
|
|
219
|
+
let content;
|
|
220
|
+
if (phase.reportHtmlPath) {
|
|
221
|
+
try {
|
|
222
|
+
const relPath = path.relative(reportDir, phase.reportHtmlPath).split(path.sep).join('/');
|
|
223
|
+
content = `<iframe src="${escapeHtml(relPath)}"></iframe>`;
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
content = `<iframe src="${escapeHtml(phase.reportHtmlPath)}"></iframe>`;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else if (phase.status === 'SKIPPED') {
|
|
230
|
+
content = '<div class="phase-empty">This phase was skipped.</div>';
|
|
231
|
+
}
|
|
232
|
+
else if (phase.error) {
|
|
233
|
+
content = `<div class="phase-empty">Error: ${escapeHtml(phase.error)}</div>`;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
content = '<div class="phase-empty">No report available for this phase.</div>';
|
|
237
|
+
}
|
|
238
|
+
panels.push(`<div id="panel-phase-${phase.name}" class="panel phase-panel">${content}</div>`);
|
|
239
|
+
}
|
|
240
|
+
return panels.join('\n');
|
|
241
|
+
}
|
|
242
|
+
function buildHtml(caseInfo, result, reportDir) {
|
|
243
|
+
return `<!DOCTYPE html>
|
|
244
|
+
<html lang="zh-CN">
|
|
245
|
+
<head>
|
|
246
|
+
<meta charset="UTF-8">
|
|
247
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
248
|
+
<title>Case Report: ${escapeHtml(caseInfo.caseName)}</title>
|
|
249
|
+
<style>${CSS}</style>
|
|
250
|
+
</head>
|
|
251
|
+
<body>
|
|
252
|
+
<div class="sidebar expanded" id="sidebar">${buildSidebar(caseInfo, result)}</div>
|
|
253
|
+
<div class="main" id="main">${buildOverviewPanel(caseInfo, result)}${buildPhasePanels(result, reportDir)}</div>
|
|
254
|
+
<script>${JS}</script>
|
|
255
|
+
</body>
|
|
256
|
+
</html>`;
|
|
257
|
+
}
|
|
258
|
+
function generateCaseReport(caseInfo, caseResult, reportDir) {
|
|
259
|
+
const html = buildHtml(caseInfo, caseResult, reportDir);
|
|
260
|
+
const outputPath = path.join(reportDir, `${caseInfo.caseId}_summary.html`);
|
|
261
|
+
fs.writeFileSync(outputPath, html, 'utf-8');
|
|
262
|
+
const absPath = path.resolve(outputPath).split(path.sep).join('/');
|
|
263
|
+
return `file://${absPath}`;
|
|
264
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured case runner with setup/process/teardown phase execution.
|
|
3
|
+
*
|
|
4
|
+
* Ported from python tools/case_runner/runner.py.
|
|
5
|
+
* Uses AgentAPIImpl (Node.js) instead of Python's HybridAgent/DeviceToolManager.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* node dist/tools/case_runner.js --case case.json [--config config.yaml] [--report-dir reports/]
|
|
9
|
+
*/
|
|
10
|
+
export interface PhaseResult {
|
|
11
|
+
name: string;
|
|
12
|
+
status: string;
|
|
13
|
+
durationSeconds: number;
|
|
14
|
+
totalTokens: number;
|
|
15
|
+
outputMessage: string;
|
|
16
|
+
reportDir: string;
|
|
17
|
+
reportHtmlPath: string;
|
|
18
|
+
error: string;
|
|
19
|
+
startTime: string;
|
|
20
|
+
endTime: string;
|
|
21
|
+
}
|
|
22
|
+
export interface CaseResult {
|
|
23
|
+
caseId: string;
|
|
24
|
+
caseName: string;
|
|
25
|
+
overallStatus: string;
|
|
26
|
+
totalDuration: number;
|
|
27
|
+
totalTokens: number;
|
|
28
|
+
totalSteps: number;
|
|
29
|
+
deviceSn: string;
|
|
30
|
+
deviceType: string;
|
|
31
|
+
phaseResults: PhaseResult[];
|
|
32
|
+
caseReportPath: string;
|
|
33
|
+
startTime: string;
|
|
34
|
+
endTime: string;
|
|
35
|
+
}
|
|
36
|
+
export declare class CaseRunner {
|
|
37
|
+
private caseInfo;
|
|
38
|
+
private configManager;
|
|
39
|
+
private reportDirOverride;
|
|
40
|
+
private deviceSnOverride;
|
|
41
|
+
private ipOverride;
|
|
42
|
+
private portOverride;
|
|
43
|
+
private verbose;
|
|
44
|
+
constructor(opts: {
|
|
45
|
+
casePath: string;
|
|
46
|
+
configPath?: string | null;
|
|
47
|
+
reportDir?: string | null;
|
|
48
|
+
deviceSn?: string | null;
|
|
49
|
+
ip?: string | null;
|
|
50
|
+
port?: number | null;
|
|
51
|
+
verbose?: boolean;
|
|
52
|
+
});
|
|
53
|
+
private resolveDeviceParams;
|
|
54
|
+
private runPhase;
|
|
55
|
+
run(): Promise<CaseResult>;
|
|
56
|
+
}
|
|
57
|
+
export declare function main(): Promise<number>;
|