@autotest/agent 0.0.18 → 0.0.21
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 +26 -14
- package/dist/api/types.d.ts +8 -0
- package/dist/autotest-cli.js +1 -1
- package/dist/common/config/config.yaml +4 -2
- package/dist/common/config/types.d.ts +87 -0
- package/dist/common/datetime.d.ts +19 -0
- package/dist/common/dfx/cache_fetch.d.ts +12 -0
- package/dist/common/dfx/client_factory.d.ts +10 -9
- package/dist/common/dfx/context.d.ts +0 -1
- package/dist/common/dfx/index.d.ts +5 -3
- package/dist/common/dfx/recorder.d.ts +13 -1
- package/dist/common/dfx/recorder_sqlite.d.ts +17 -0
- package/dist/common/dfx/recording_fetch.d.ts +2 -2
- package/dist/common/dfx/source.d.ts +1 -0
- package/dist/common/model/custom_model.d.ts +5 -0
- package/dist/core/agent/design_doc/design_doc.d.ts +106 -0
- package/dist/core/agent/report_analyzer_agent/agent.d.ts +6 -1
- package/dist/core/agent/report_analyzer_agent/analysis_progress.d.ts +54 -0
- package/dist/core/agent/report_analyzer_agent/design_tool.d.ts +8 -0
- package/dist/core/agent/report_analyzer_agent/guardrails.d.ts +24 -0
- package/dist/core/agent/report_analyzer_agent/hooks.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/index.d.ts +2 -1
- package/dist/core/agent/report_analyzer_agent/mapping.d.ts +1 -1
- package/dist/core/agent/report_analyzer_agent/prompt.d.ts +1 -1
- package/dist/core/agent/report_analyzer_agent/prompts/examples/example_out_of_scope_app_defect.md +13 -0
- package/dist/core/agent/report_analyzer_agent/prompts/examples/example_overturn_executor.md +13 -0
- package/dist/core/agent/report_analyzer_agent/prompts/examples/example_pass_precondition_selfconstruct.md +13 -0
- package/dist/core/agent/report_analyzer_agent/prompts/final_attribution.md +204 -0
- package/dist/core/agent/report_analyzer_agent/prompts/mid_analysis.md +177 -0
- package/dist/core/agent/report_analyzer_agent/report_html_template/_header.d.ts +5 -0
- package/dist/core/agent/report_analyzer_agent/report_html_template/_scripts.d.ts +1 -0
- package/dist/core/agent/report_analyzer_agent/report_html_template/_styles.d.ts +1 -0
- package/dist/core/agent/report_analyzer_agent/report_html_template/_summary.d.ts +2 -0
- package/dist/core/agent/report_analyzer_agent/report_html_template/_trace.d.ts +14 -0
- package/dist/core/agent/report_analyzer_agent/report_html_template/_utils.d.ts +20 -0
- package/dist/core/agent/report_analyzer_agent/report_html_template/_verdict.d.ts +2 -0
- package/dist/core/agent/report_analyzer_agent/report_html_template/index.d.ts +8 -0
- package/dist/core/agent/report_analyzer_agent/report_html_template/render.d.ts +6 -0
- package/dist/core/agent/report_analyzer_agent/report_markdown.d.ts +9 -0
- package/dist/core/agent/report_analyzer_agent/report_writer.d.ts +16 -1
- package/dist/core/agent/report_analyzer_agent/stage_contracts.d.ts +6 -5
- package/dist/core/agent/report_analyzer_agent/tools.d.ts +6 -0
- package/dist/core/agent/report_analyzer_agent/trace_extract.d.ts +49 -0
- package/dist/core/agent/report_analyzer_agent/types.d.ts +5 -1
- package/dist/core/agent/rewrite_agent/agent.d.ts +2 -0
- package/dist/core/agent/rewrite_agent/prompts/rewriter_v1.0.md +224 -168
- package/dist/core/agent/rewrite_agent/result_writer.d.ts +22 -0
- package/dist/core/agent/rewrite_agent/types.d.ts +4 -0
- package/dist/core/agent/single_agent/agent.d.ts +17 -7
- package/dist/core/agent/single_agent/context_builder.d.ts +61 -0
- package/dist/core/agent/single_agent/hook_manager.d.ts +15 -2
- package/dist/core/agent/single_agent/llm_helper.d.ts +84 -0
- package/dist/core/agent/single_agent/processors.d.ts +22 -0
- package/dist/core/agent/single_agent/report_hook.d.ts +22 -0
- package/dist/core/agent/single_agent/subagent_manager.d.ts +3 -4
- package/dist/core/agent/types.d.ts +5 -0
- package/dist/core/device/hdc/index.d.ts +1 -1
- package/dist/core/device/hdc/input.d.ts +7 -0
- package/dist/core/device/hdc/screenshot.d.ts +2 -0
- package/dist/core/mcp/base_adapter.d.ts +5 -0
- package/dist/core/mcp/harmony_hdc_adapter.d.ts +4 -0
- package/dist/core/mcp/mcp_tools.d.ts +1 -0
- package/dist/core/mcp/types.d.ts +2 -0
- package/dist/core/prompt/templates/single/single_v1.0.md +18 -18
- package/dist/core/prompt/templates/single/single_v2.0.md +31 -77
- package/dist/core/prompt/templates/single/single_v2.0_0_1000.md +6 -5
- package/dist/core/prompt/templates/single/single_v2.0_eco.md +14 -3
- package/dist/core/prompt/templates/single/single_v2.0_graph.md +244 -0
- package/dist/core/prompt/templates/single/single_v3.0.md +5 -5
- package/dist/generated/version.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/loop/orchestrator.d.ts +6 -0
- package/dist/loop/types.d.ts +4 -0
- package/dist/prompts/rewriter_v1.0.md +224 -168
- package/dist/reporter/generator.d.ts +12 -1
- package/dist/reporter/types.d.ts +45 -3
- package/dist/tools/batch_runner.d.ts +34 -1
- package/dist/tools/batch_runner.js +1 -1
- package/dist/tools/case_runner/runner.js +1 -1
- package/dist/tools/config/config_tool.js +1 -1
- package/dist/tools/prompt_compare/compare_runner.js +1 -1
- package/dist/tools/token_comparison/comparator.d.ts +74 -0
- package/package.json +10 -4
- package/scripts/bundle-obfuscate.js +111 -0
- package/scripts/gen-native-b64.js +51 -0
- package/scripts/gen_analysis_report.js +724 -0
- package/dist/core/agent/layered_agent/ability_helper.d.ts +0 -35
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 生成「测试用例执行分析报告」HTML。
|
|
4
|
+
*
|
|
5
|
+
* 数据源:
|
|
6
|
+
* 1. task_results.jsonl —— 本次批量执行结果(batch_runner 产出)
|
|
7
|
+
* 2. --truth <case_file.json> —— 原始用例文件(含 expected_result 真值)
|
|
8
|
+
* 3. --reports <reports.json> —— <category>_reports.json(含每条用例 token)
|
|
9
|
+
*
|
|
10
|
+
* 用法:
|
|
11
|
+
* node gen_analysis_report.js <task_results.jsonl> \
|
|
12
|
+
* --truth <case_file.json> --reports <reports.json> \
|
|
13
|
+
* [--output <path.html>] [--title "标题"]
|
|
14
|
+
*/
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
|
|
20
|
+
function parseArgs(argv) {
|
|
21
|
+
const opts = { input: '', truth: '', reports: '', output: '', title: '' };
|
|
22
|
+
const positional = [];
|
|
23
|
+
for (let i = 2; i < argv.length; i++) {
|
|
24
|
+
const a = argv[i];
|
|
25
|
+
if (a === '--truth') opts.truth = argv[++i] || '';
|
|
26
|
+
else if (a === '--reports') opts.reports = argv[++i] || '';
|
|
27
|
+
else if (a === '--output' || a === '-o') opts.output = argv[++i] || '';
|
|
28
|
+
else if (a === '--title') opts.title = argv[++i] || '';
|
|
29
|
+
else if (a && !a.startsWith('--')) positional.push(a);
|
|
30
|
+
}
|
|
31
|
+
opts.input = positional[0] || '';
|
|
32
|
+
return opts;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function loadJsonl(filePath) {
|
|
36
|
+
const raw = fs.readFileSync(filePath, 'utf-8').replace(/^\uFEFF/, '');
|
|
37
|
+
return raw.trim().split('\n').filter(Boolean).map((l) => JSON.parse(l));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function loadJson(filePath) {
|
|
41
|
+
if (!filePath || !fs.existsSync(filePath)) return null;
|
|
42
|
+
const raw = fs.readFileSync(filePath, 'utf-8').replace(/^\uFEFF/, '');
|
|
43
|
+
return JSON.parse(raw);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function parseVerdict(expected) {
|
|
47
|
+
if (!expected) return { verdict: '', detail: '' };
|
|
48
|
+
const s = String(expected).trim();
|
|
49
|
+
// English (PASS/FAIL…) or Chinese (任务结果: 通过 / 不通过 - …).
|
|
50
|
+
if (s.startsWith('FAIL')) return { verdict: 'FAIL', detail: s };
|
|
51
|
+
if (s.startsWith('PASS')) return { verdict: 'PASS', detail: s };
|
|
52
|
+
if (/不通过|未通过/.test(s)) return { verdict: 'FAIL', detail: s };
|
|
53
|
+
if (/通过/.test(s)) return { verdict: 'PASS', detail: s };
|
|
54
|
+
return { verdict: '', detail: s };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function esc(s) {
|
|
58
|
+
return String(s == null ? '' : s)
|
|
59
|
+
.replace(/&/g, '&')
|
|
60
|
+
.replace(/</g, '<')
|
|
61
|
+
.replace(/>/g, '>')
|
|
62
|
+
.replace(/"/g, '"');
|
|
63
|
+
}
|
|
64
|
+
function trunc(s, n) {
|
|
65
|
+
s = s == null ? '' : String(s);
|
|
66
|
+
return s.length > n ? s.slice(0, n) + '…' : s;
|
|
67
|
+
}
|
|
68
|
+
function fmtTime(s) {
|
|
69
|
+
s = Number(s) || 0;
|
|
70
|
+
if (s < 60) return s.toFixed(1) + 's';
|
|
71
|
+
const m = Math.floor(s / 60);
|
|
72
|
+
const r = Math.round(s % 60);
|
|
73
|
+
if (m < 60) return m + 'm' + r + 's';
|
|
74
|
+
const h = Math.floor(m / 60);
|
|
75
|
+
return h + 'h' + (m % 60) + 'm';
|
|
76
|
+
}
|
|
77
|
+
function fmtTok(t) {
|
|
78
|
+
t = Number(t) || 0;
|
|
79
|
+
if (t >= 1000) return (t / 1000).toFixed(1) + 'K';
|
|
80
|
+
return String(t);
|
|
81
|
+
}
|
|
82
|
+
function pct(n, d) {
|
|
83
|
+
return d ? ((n / d) * 100).toFixed(1) : '0.0';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 从每条用例的 report.json 中提取真实判定(task_end 事件)。
|
|
88
|
+
* batch_runner 用 agent 运行时 status 判定,遇到 JSON 格式 judge 结果
|
|
89
|
+
* ({"passed":false,...})会被误记为 PASS,故以 report.json 为准。
|
|
90
|
+
* 两种格式:
|
|
91
|
+
* - JSON: {"passed":bool,"reason":str} -> 直接用 passed
|
|
92
|
+
* - 文本: data.status(pass/fail) + 结论文本(通过/不通过)
|
|
93
|
+
*/
|
|
94
|
+
function extractVerdictFromReport(reportDir) {
|
|
95
|
+
if (!reportDir) return null;
|
|
96
|
+
let raw;
|
|
97
|
+
try {
|
|
98
|
+
raw = fs.readFileSync(path.join(reportDir, 'report.json'), 'utf-8');
|
|
99
|
+
} catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
let obj;
|
|
103
|
+
try {
|
|
104
|
+
obj = JSON.parse(raw);
|
|
105
|
+
} catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
const events = Array.isArray(obj.events) ? obj.events : [];
|
|
109
|
+
let taskEnd = null;
|
|
110
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
111
|
+
if (events[i] && events[i].event_type === 'task_end') {
|
|
112
|
+
taskEnd = events[i];
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!taskEnd) return null;
|
|
117
|
+
const data = (taskEnd.data && typeof taskEnd.data === 'object') ? taskEnd.data : {};
|
|
118
|
+
const result = data.result == null ? '' : String(data.result);
|
|
119
|
+
const status = String(data.status || '').toLowerCase();
|
|
120
|
+
// JSON 格式
|
|
121
|
+
try {
|
|
122
|
+
const parsed = JSON.parse(result);
|
|
123
|
+
if (parsed && typeof parsed === 'object' && typeof parsed.passed === 'boolean') {
|
|
124
|
+
return {
|
|
125
|
+
verdict: parsed.passed ? 'PASS' : 'FAIL',
|
|
126
|
+
reason: parsed.reason ? String(parsed.reason) : (parsed.passed ? '' : result),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
} catch {
|
|
130
|
+
/* 非JSON,按文本处理 */
|
|
131
|
+
}
|
|
132
|
+
// 文本格式
|
|
133
|
+
if (status === 'fail' || status === 'failed') return { verdict: 'FAIL', reason: result };
|
|
134
|
+
if (/不通过|未通过/.test(result)) return { verdict: 'FAIL', reason: result };
|
|
135
|
+
if (status === 'pass' || status === 'passed' || status === 'completed') return { verdict: 'PASS', reason: '' };
|
|
136
|
+
if (/通过/.test(result) && !/不通过|未通过/.test(result)) return { verdict: 'PASS', reason: '' };
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function buildRows(results, truthArr, reportsArr) {
|
|
141
|
+
const truthMap = {};
|
|
142
|
+
(truthArr || []).forEach((c) => {
|
|
143
|
+
if (c && c.uuid) truthMap[c.uuid] = c;
|
|
144
|
+
});
|
|
145
|
+
const repMap = {};
|
|
146
|
+
(reportsArr || []).forEach((r) => {
|
|
147
|
+
if (r && r.uuid) repMap[r.uuid] = r;
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return results.map((r, i) => {
|
|
151
|
+
const num = r.exec_index || i + 1;
|
|
152
|
+
const jsonlStatus = r.status === 'PASS' ? 'PASS' : 'FAIL';
|
|
153
|
+
const rv = extractVerdictFromReport(r.report_dir);
|
|
154
|
+
const autoStatus = rv ? rv.verdict : jsonlStatus;
|
|
155
|
+
const corrected = !!(rv && rv.verdict !== jsonlStatus);
|
|
156
|
+
const al = findAgentLog(r.report_dir, 250);
|
|
157
|
+
const t = truthMap[r.uuid] || {};
|
|
158
|
+
const exp = parseVerdict(t.expected_result || t.result);
|
|
159
|
+
const rep = repMap[r.uuid] || {};
|
|
160
|
+
|
|
161
|
+
let consistency = '';
|
|
162
|
+
let match = '无真值';
|
|
163
|
+
if (exp.verdict) {
|
|
164
|
+
if (exp.verdict === 'PASS' && autoStatus === 'PASS') { consistency = 'TP'; match = '一致'; }
|
|
165
|
+
else if (exp.verdict === 'FAIL' && autoStatus === 'FAIL') { consistency = 'TN'; match = '一致'; }
|
|
166
|
+
else if (exp.verdict === 'PASS' && autoStatus === 'FAIL') { consistency = 'FP'; match = '不一致'; }
|
|
167
|
+
else { consistency = 'FN'; match = '不一致'; }
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
num,
|
|
172
|
+
uuid: r.uuid || '',
|
|
173
|
+
app: t.app_name || '',
|
|
174
|
+
bundle: t.bundle_name || '',
|
|
175
|
+
autoStatus,
|
|
176
|
+
expVerdict: exp.verdict,
|
|
177
|
+
expDetail: exp.detail,
|
|
178
|
+
consistency,
|
|
179
|
+
match,
|
|
180
|
+
dur: Number(r.duration_seconds || rep.duration_seconds || 0),
|
|
181
|
+
tokens: Number(rep.total_tokens || 0),
|
|
182
|
+
reason: (rv && rv.reason) ? rv.reason : (r.reason || t.fail_reason || ''),
|
|
183
|
+
steps: r.test_steps || t.test_steps || '',
|
|
184
|
+
report: r.report_dir ? findHtmlLink(r.report_dir) : (rep.report_dir || ''),
|
|
185
|
+
startTime: r.start_time || rep.start_time || '',
|
|
186
|
+
endTime: r.end_time || rep.end_time || '',
|
|
187
|
+
corrected,
|
|
188
|
+
jsonlStatus,
|
|
189
|
+
logLink: al.logLink,
|
|
190
|
+
folderLink: al.folderLink,
|
|
191
|
+
folderAbs: al.folderAbs,
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function findHtmlLink(reportDir) {
|
|
197
|
+
// 在报告目录里找实际的 .html 文件(不依赖命名规律:隔离 run 里目录改名 00X 但内部 html 仍可能是 001_)
|
|
198
|
+
try {
|
|
199
|
+
const abs = path.isAbsolute(reportDir) ? reportDir : path.resolve(reportDir);
|
|
200
|
+
const html = fs.readdirSync(abs).find((n) => n.toLowerCase().endsWith('.html'));
|
|
201
|
+
if (html) return path.basename(reportDir) + '/' + html;
|
|
202
|
+
} catch (e) { /* 报告目录不存在或不可读 */ }
|
|
203
|
+
return path.basename(reportDir);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 读取用例报告目录里的 agent_<taskId>.log(AutoTest 执行日志),返回尾部片段 +
|
|
208
|
+
* 完整日志/文件夹的相对链接 + 文件夹绝对路径(供"复制路径"按钮)。
|
|
209
|
+
* tail 仅取尾部 maxTail 行,避免超大日志把 analysis_report.html 撑爆;完整日志走链接。
|
|
210
|
+
*/
|
|
211
|
+
function findAgentLog(reportDir, maxTail) {
|
|
212
|
+
const empty = { logTail: '', logLink: '', folderLink: '', folderAbs: '' };
|
|
213
|
+
if (!reportDir) return empty;
|
|
214
|
+
try {
|
|
215
|
+
const abs = path.isAbsolute(reportDir) ? reportDir : path.resolve(reportDir);
|
|
216
|
+
const base = path.basename(reportDir);
|
|
217
|
+
let logFile = '';
|
|
218
|
+
try { logFile = fs.readdirSync(abs).find((n) => /^agent_.*\.log$/i.test(n)) || ''; } catch (e) { /* unreadable */ }
|
|
219
|
+
let logTail = '';
|
|
220
|
+
if (logFile) {
|
|
221
|
+
try {
|
|
222
|
+
const raw = fs.readFileSync(path.join(abs, logFile), 'utf-8').replace(/\r\n/g, '\n');
|
|
223
|
+
const lines = raw.split('\n');
|
|
224
|
+
if (lines.length > maxTail) {
|
|
225
|
+
logTail = '(… 已截取尾部 ' + maxTail + ' 行 / 共 ' + lines.length + ' 行,完整见「打开完整日志」)\n' + lines.slice(-maxTail).join('\n');
|
|
226
|
+
} else {
|
|
227
|
+
logTail = raw;
|
|
228
|
+
}
|
|
229
|
+
} catch (e) { /* 读取失败,留空 */ }
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
logTail,
|
|
233
|
+
logLink: logFile ? (base + '/' + logFile) : '',
|
|
234
|
+
folderLink: base + '/',
|
|
235
|
+
folderAbs: abs,
|
|
236
|
+
};
|
|
237
|
+
} catch (e) {
|
|
238
|
+
return empty;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function computeStats(rows) {
|
|
243
|
+
const total = rows.length;
|
|
244
|
+
const pass = rows.filter((r) => r.autoStatus === 'PASS').length;
|
|
245
|
+
const fail = total - pass;
|
|
246
|
+
const tp = rows.filter((r) => r.consistency === 'TP').length;
|
|
247
|
+
const tn = rows.filter((r) => r.consistency === 'TN').length;
|
|
248
|
+
const fp = rows.filter((r) => r.consistency === 'FP').length;
|
|
249
|
+
const fn = rows.filter((r) => r.consistency === 'FN').length;
|
|
250
|
+
const judged = tp + tn + fp + fn;
|
|
251
|
+
const accuracy = judged ? ((tp + tn) / judged * 100) : 0;
|
|
252
|
+
const precision = (tp + fp) ? (tp / (tp + fp) * 100) : 0;
|
|
253
|
+
const recall = (tp + fn) ? (tp / (tp + fn) * 100) : 0;
|
|
254
|
+
const f1 = (precision + recall) > 0 ? (2 * precision * recall / (precision + recall) / 100) : 0;
|
|
255
|
+
|
|
256
|
+
const durs = rows.map((r) => r.dur);
|
|
257
|
+
const toks = rows.map((r) => r.tokens).filter((t) => t > 0);
|
|
258
|
+
const totalDur = durs.reduce((a, b) => a + b, 0);
|
|
259
|
+
const totalTok = toks.reduce((a, b) => a + b, 0);
|
|
260
|
+
|
|
261
|
+
// per app
|
|
262
|
+
const appMap = {};
|
|
263
|
+
rows.forEach((r) => {
|
|
264
|
+
const k = r.app || '(未知)';
|
|
265
|
+
if (!appMap[k]) appMap[k] = { app: k, total: 0, pass: 0, fail: 0, tp: 0, tn: 0, fp: 0, fn: 0, dur: 0, tokens: 0, judged: 0 };
|
|
266
|
+
const a = appMap[k];
|
|
267
|
+
a.total++;
|
|
268
|
+
if (r.autoStatus === 'PASS') a.pass++; else a.fail++;
|
|
269
|
+
if (r.consistency) { a.judged++; a[r.consistency.toLowerCase()]++; }
|
|
270
|
+
a.dur += r.dur;
|
|
271
|
+
a.tokens += r.tokens;
|
|
272
|
+
});
|
|
273
|
+
const apps = Object.values(appMap).map((a) => ({
|
|
274
|
+
...a,
|
|
275
|
+
passRate: pct(a.pass, a.total),
|
|
276
|
+
accuracy: a.judged ? pct(a.tp + a.tn, a.judged) : '—',
|
|
277
|
+
})).sort((x, y) => y.total - x.total);
|
|
278
|
+
|
|
279
|
+
return {
|
|
280
|
+
total, pass, fail, passRate: pct(pass, total),
|
|
281
|
+
tp, tn, fp, fn, judged, accuracy, precision, recall, f1,
|
|
282
|
+
correctedCount: rows.filter((r) => r.corrected).length,
|
|
283
|
+
totalDur, avgDur: total ? totalDur / total : 0,
|
|
284
|
+
maxDur: durs.length ? Math.max(...durs) : 0,
|
|
285
|
+
minDur: durs.length ? Math.min(...durs) : 0,
|
|
286
|
+
totalTok, avgTok: toks.length ? totalTok / toks.length : 0,
|
|
287
|
+
maxTok: toks.length ? Math.max(...toks) : 0,
|
|
288
|
+
withTokens: toks.length,
|
|
289
|
+
apps,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function generateReport(rows, stats, opts, meta) {
|
|
294
|
+
const startTime = rows[0]?.startTime || '';
|
|
295
|
+
const endTime = rows[rows.length - 1]?.endTime || '';
|
|
296
|
+
const now = new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' });
|
|
297
|
+
const title = opts.title || '测试用例执行分析报告';
|
|
298
|
+
|
|
299
|
+
const fpRows = rows.filter((r) => r.consistency === 'FP');
|
|
300
|
+
const fnRows = rows.filter((r) => r.consistency === 'FN');
|
|
301
|
+
const maxDur = stats.maxDur || 1;
|
|
302
|
+
const maxTok = stats.maxTok || 1;
|
|
303
|
+
|
|
304
|
+
const kpi = (val, lbl, cls = '') =>
|
|
305
|
+
`<div class="kpi ${cls}"><div class="val">${val}</div><div class="lbl">${lbl}</div></div>`;
|
|
306
|
+
|
|
307
|
+
const appRowsHtml = stats.apps.map((a) => `
|
|
308
|
+
<tr>
|
|
309
|
+
<td class="al">${esc(a.app)}</td><td>${a.total}</td>
|
|
310
|
+
<td><span class="g">${a.pass}</span> / <span class="r">${a.fail}</span></td>
|
|
311
|
+
<td>${a.passRate}%</td><td>${a.accuracy === '—' ? '—' : a.accuracy + '%'}</td>
|
|
312
|
+
<td>${a.fp}</td><td>${a.fn}</td>
|
|
313
|
+
<td>${fmtTime(a.dur)}</td><td>${fmtTok(a.tokens)}</td>
|
|
314
|
+
</tr>`).join('');
|
|
315
|
+
|
|
316
|
+
const issueCard = (r) => {
|
|
317
|
+
const tag = r.consistency;
|
|
318
|
+
const tagCls = tag === 'FP' ? 't-fp' : 't-fn';
|
|
319
|
+
const tagTxt = tag === 'FP' ? '预期通过执行失败' : '预期失败执行通过';
|
|
320
|
+
const expCls = r.expVerdict === 'FAIL' ? 'exp-fail' : 'exp-pass';
|
|
321
|
+
return `<div class="issue" data-num="${r.num}">
|
|
322
|
+
<div class="issue-hd">
|
|
323
|
+
<span class="cm-tag ${tagCls}">${tagTxt}</span>
|
|
324
|
+
<b>#${r.num}</b>
|
|
325
|
+
<span class="app">[${esc(r.app)}]</span>
|
|
326
|
+
<span class="dur">⏱ ${r.dur.toFixed(1)}s</span>
|
|
327
|
+
<span class="tok">◈ ${fmtTok(r.tokens)}</span>
|
|
328
|
+
</div>
|
|
329
|
+
<div class="issue-bd">
|
|
330
|
+
<div><span class="lbl">判定:</span> <b class="${r.autoStatus === 'PASS' ? 'g' : 'r'}">${r.autoStatus}</b>
|
|
331
|
+
<span class="lbl">预期:</span> <span class="${expCls}">${esc(trunc(r.expDetail, 80))}</span></div>
|
|
332
|
+
${r.reason ? `<div class="reason"><span class="lbl">原因:</span> ${esc(trunc(r.reason, 160))}</div>` : ''}
|
|
333
|
+
</div>
|
|
334
|
+
</div>`;
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
return `<!DOCTYPE html>
|
|
338
|
+
<html lang="zh-CN">
|
|
339
|
+
<head>
|
|
340
|
+
<meta charset="UTF-8">
|
|
341
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
342
|
+
<title>${esc(title)} — ${esc(startTime.split(' ')[0] || now)}</title>
|
|
343
|
+
<style>
|
|
344
|
+
*{margin:0;padding:0;box-sizing:border-box}
|
|
345
|
+
body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'PingFang SC','Microsoft YaHei',sans-serif;background:#eef1f6;color:#1f2937;line-height:1.5;font-size:14px}
|
|
346
|
+
.wrap{width:90%;max-width:none;margin:0 auto;padding:18px}
|
|
347
|
+
a{color:#2563eb;text-decoration:none}a:hover{text-decoration:underline}
|
|
348
|
+
.g{color:#16a34a}.r{color:#dc2626}.o{color:#ea580c}.b{color:#2563eb}
|
|
349
|
+
.lbl{color:#9ca3af;font-size:11px}
|
|
350
|
+
|
|
351
|
+
/* header */
|
|
352
|
+
.head{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:10px;margin-bottom:16px}
|
|
353
|
+
.head h1{font-size:22px;font-weight:700;background:linear-gradient(90deg,#2563eb,#7c3aed);-webkit-background-clip:text;background-clip:text;color:transparent}
|
|
354
|
+
.meta{color:#6b7280;font-size:12px}.meta span{margin-right:16px}
|
|
355
|
+
.btn{display:inline-flex;align-items:center;gap:4px;padding:6px 14px;border-radius:8px;font-size:13px;font-weight:600;cursor:pointer;border:none;transition:.15s}
|
|
356
|
+
.btn-primary{background:#2563eb;color:#fff}.btn-primary:hover{background:#1d4ed8}
|
|
357
|
+
.btn-ghost{background:#fff;border:1px solid #d1d5db;color:#374151}.btn-ghost:hover{background:#f3f4f6}
|
|
358
|
+
|
|
359
|
+
/* KPI */
|
|
360
|
+
.kpi-row{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:10px;margin-bottom:16px}
|
|
361
|
+
.kpi{background:#fff;border-radius:12px;padding:14px 12px;text-align:center;box-shadow:0 1px 3px rgba(0,0,0,.06);border:1px solid #f0f1f4}
|
|
362
|
+
.kpi .val{font-size:26px;font-weight:800;letter-spacing:-.5px}
|
|
363
|
+
.kpi .lbl{font-size:11px;color:#9ca3af;margin-top:3px}
|
|
364
|
+
.kpi.green .val{color:#16a34a}.kpi.red .val{color:#dc2626}.kpi.orange .val{color:#ea580c}.kpi.blue .val{color:#2563eb}.kpi.purple .val{color:#7c3aed}
|
|
365
|
+
|
|
366
|
+
/* sections */
|
|
367
|
+
.sec{background:#fff;border-radius:12px;padding:18px;margin-bottom:14px;box-shadow:0 1px 3px rgba(0,0,0,.06);border:1px solid #f0f1f4}
|
|
368
|
+
.sec h2{font-size:15px;font-weight:700;margin-bottom:14px;display:flex;align-items:center;gap:8px}
|
|
369
|
+
.sec h2::before{content:'';width:4px;height:16px;background:linear-gradient(#2563eb,#7c3aed);border-radius:2px;display:inline-block}
|
|
370
|
+
.sec h2 .hint{font-size:12px;font-weight:400;color:#9ca3af}
|
|
371
|
+
|
|
372
|
+
.grid2{display:grid;grid-template-columns:auto 1fr;gap:24px;align-items:start}
|
|
373
|
+
@media(max-width:900px){.grid2{grid-template-columns:1fr}}
|
|
374
|
+
|
|
375
|
+
/* confusion matrix */
|
|
376
|
+
.cm{border-collapse:separate;border-spacing:4px;margin:0 auto}
|
|
377
|
+
.cm th{background:#f3f4f6;padding:7px 16px;font-size:11px;border-radius:5px;font-weight:600;color:#6b7280}
|
|
378
|
+
.cm td{text-align:center;font-size:20px;font-weight:800;padding:12px 20px;border-radius:7px}
|
|
379
|
+
.cm-tp{background:#dcfce7;color:#15803d}.cm-tn{background:#dbeafe;color:#1d4ed8}.cm-fp{background:#fed7aa;color:#c2410c}.cm-fn{background:#fecaca;color:#b91c1c}
|
|
380
|
+
.cm-leg{font-size:11px;color:#6b7280;margin-top:12px;line-height:1.9;text-align:center}
|
|
381
|
+
.cm-leg i{width:9px;height:9px;display:inline-block;border-radius:2px;margin-right:4px;vertical-align:middle}
|
|
382
|
+
|
|
383
|
+
/* metrics list */
|
|
384
|
+
.metrics{display:grid;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:8px}
|
|
385
|
+
.metric{background:#f9fafb;border-radius:8px;padding:9px 12px;border:1px solid #f0f1f4}
|
|
386
|
+
.metric .v{font-size:18px;font-weight:700}.metric .k{font-size:11px;color:#9ca3af}
|
|
387
|
+
|
|
388
|
+
/* app table */
|
|
389
|
+
table.apps{width:100%;border-collapse:collapse;font-size:12px}
|
|
390
|
+
table.apps th{background:#f9fafb;padding:7px 9px;text-align:center;font-weight:600;color:#6b7280;border-bottom:2px solid #e5e7eb}
|
|
391
|
+
table.apps td{padding:6px 9px;text-align:center;border-bottom:1px solid #f3f4f6}
|
|
392
|
+
table.apps td.al{text-align:center;font-weight:600}
|
|
393
|
+
|
|
394
|
+
/* issue quick view */
|
|
395
|
+
.issue-bar{display:flex;gap:10px;margin-bottom:12px;flex-wrap:wrap}
|
|
396
|
+
.chip{padding:5px 13px;border-radius:20px;font-size:12px;font-weight:700;cursor:pointer;border:2px solid transparent;transition:.15s}
|
|
397
|
+
.chip-fp{background:#fff7ed;color:#c2410c;border-color:#fed7aa}.chip-fp.on{background:#c2410c;color:#fff}
|
|
398
|
+
.chip-fn{background:#fef2f2;color:#b91c1c;border-color:#fecaca}.chip-fn.on{background:#b91c1c;color:#fff}
|
|
399
|
+
.chip-all{background:#f3f4f6;color:#374151;border-color:#d1d5db}.chip-all.on{background:#374151;color:#fff}
|
|
400
|
+
.issue-list{display:grid;grid-template-columns:repeat(auto-fill,minmax(380px,1fr));gap:10px;max-height:420px;overflow-y:auto;padding:2px}
|
|
401
|
+
.issue{background:#fafbfc;border:1px solid #e5e7eb;border-radius:9px;padding:10px 12px;cursor:pointer;transition:.12s;border-left:4px solid}
|
|
402
|
+
.issue-fp{border-left-color:#c2410c}.issue-fn{border-left-color:#b91c1c}
|
|
403
|
+
.issue:hover{box-shadow:0 2px 8px rgba(0,0,0,.1);transform:translateY(-1px)}
|
|
404
|
+
.issue-hd{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin-bottom:5px;font-size:12px}
|
|
405
|
+
.issue-hd .app{color:#6b7280}.issue-hd .dur,.issue-hd .tok{color:#9ca3af;font-size:11px}
|
|
406
|
+
.issue-bd{font-size:12px;color:#374151}.issue-bd .reason{margin-top:4px;color:#6b7280}
|
|
407
|
+
.cm-tag{display:inline-block;padding:1px 7px;border-radius:4px;font-size:10px;font-weight:700;color:#fff;white-space:nowrap}
|
|
408
|
+
.t-tp{background:#16a34a}.t-tn{background:#2563eb}.t-fp{background:#ea580c}.t-fn{background:#dc2626}
|
|
409
|
+
|
|
410
|
+
/* filter bar */
|
|
411
|
+
.fbar{display:flex;gap:9px;align-items:center;margin-bottom:11px;flex-wrap:wrap}
|
|
412
|
+
.fbar input{padding:7px 12px;border:1px solid #d1d5db;border-radius:7px;font-size:13px;width:230px;outline:none}
|
|
413
|
+
.fbar input:focus{border-color:#2563eb;box-shadow:0 0 0 2px #dbeafe}
|
|
414
|
+
.fbar select{padding:7px 10px;border:1px solid #d1d5db;border-radius:7px;font-size:13px;background:#fff}
|
|
415
|
+
.fbar .tog{padding:7px 14px;border-radius:7px;font-size:12px;font-weight:700;cursor:pointer;border:2px solid #dc2626;background:#fff;color:#dc2626;transition:.15s}
|
|
416
|
+
.fbar .tog.on{background:#dc2626;color:#fff}
|
|
417
|
+
.fbar .cnt{font-size:12px;color:#9ca3af;margin-left:auto}
|
|
418
|
+
|
|
419
|
+
/* case table */
|
|
420
|
+
.tw{overflow:auto;max-height:680px;border-radius:8px;border:1px solid #e5e7eb}
|
|
421
|
+
table.cases{width:100%;border-collapse:collapse;font-size:12px;min-width:1100px;table-layout:fixed}
|
|
422
|
+
table.cases th{background:#f9fafb;padding:8px 9px;text-align:left;font-weight:600;color:#6b7280;position:sticky;top:0;z-index:2;border-bottom:2px solid #e5e7eb;cursor:pointer;user-select:none;white-space:nowrap}
|
|
423
|
+
table.cases th:hover{background:#eef0f3}
|
|
424
|
+
table.cases td{padding:6px 9px;border-bottom:1px solid #f3f4f6;vertical-align:middle}
|
|
425
|
+
table.cases tr:hover td{background:#fafbfc}
|
|
426
|
+
.badge{display:inline-block;padding:2px 9px;border-radius:11px;color:#fff;font-size:11px;font-weight:700;min-width:42px;text-align:center}
|
|
427
|
+
.b-pass{background:#16a34a}.b-fail{background:#dc2626}
|
|
428
|
+
.fixed-tag{display:inline-block;margin-left:4px;padding:1px 5px;border-radius:4px;font-size:9px;font-weight:700;background:#fef3c7;color:#b45309;vertical-align:middle}
|
|
429
|
+
.bar-wrap{width:70px;height:8px;background:#e5e7eb;border-radius:4px;overflow:hidden;display:inline-block;vertical-align:middle}
|
|
430
|
+
.bar{height:100%;border-radius:4px}
|
|
431
|
+
.bar-dur{background:linear-gradient(90deg,#3b82f6,#2563eb)}.bar-tok{background:linear-gradient(90deg,#a855f7,#7c3aed)}
|
|
432
|
+
.cell-num{color:#9ca3af;font-variant-numeric:tabular-nums}.dur-cell,.tok-cell{font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
433
|
+
.exp-cell{white-space:normal;word-break:break-word;font-size:11px;line-height:1.35}
|
|
434
|
+
.reason-cell{color:#6b7280;line-height:1.35}
|
|
435
|
+
.reason-cell .clamp{display:-webkit-box;-webkit-line-clamp:3;line-clamp:3;-webkit-box-orient:vertical;overflow:hidden;white-space:normal;word-break:break-word}
|
|
436
|
+
.steps-cell{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#6b7280;font-size:11px}
|
|
437
|
+
.app-cell{font-weight:600}
|
|
438
|
+
.mismatch td{background:#fffbeb !important}.mismatch:hover td{background:#fef3c7 !important}
|
|
439
|
+
tr.detail{display:none}tr.detail.show{display:table-row}
|
|
440
|
+
tr.detail td{background:#f9fafb !important;padding:10px 14px}
|
|
441
|
+
.det-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px}
|
|
442
|
+
.det-block{font-size:12px}.det-block h4{font-size:11px;color:#9ca3af;margin-bottom:4px;text-transform:uppercase;letter-spacing:.5px}
|
|
443
|
+
.det-block pre{white-space:pre-wrap;font-family:inherit;font-size:12px;color:#374151;max-height:160px;overflow-y:auto;background:#fff;padding:8px;border-radius:6px;border:1px solid #e5e7eb}
|
|
444
|
+
.empty{padding:30px;text-align:center;color:#9ca3af}
|
|
445
|
+
|
|
446
|
+
/* ops column: compact icon buttons (查看/📄/🗂/📋), icon-only + title tooltip */
|
|
447
|
+
.op{display:inline-block;padding:2px 6px;border:1px solid #d1d5db;border-radius:6px;font-size:13px;line-height:1.4;text-decoration:none;color:#374151;background:#fff;cursor:pointer;vertical-align:middle;transition:.12s;margin-right:2px}
|
|
448
|
+
.op:hover{background:#f3f4f6;border-color:#9ca3af}
|
|
449
|
+
</style>
|
|
450
|
+
</head>
|
|
451
|
+
<body>
|
|
452
|
+
<div class="wrap">
|
|
453
|
+
<div class="head">
|
|
454
|
+
<div>
|
|
455
|
+
<h1>${esc(title)}</h1>
|
|
456
|
+
<div class="meta">
|
|
457
|
+
<span>批次开始: ${esc(startTime)}</span>
|
|
458
|
+
<span>批次结束: ${esc(endTime)}</span>
|
|
459
|
+
<span>总耗时: ${fmtTime(stats.totalDur)}</span>
|
|
460
|
+
<span>报告生成: ${now}</span>
|
|
461
|
+
${meta.dist ? `<span class="b">● 混淆dist构建</span>` : ''}
|
|
462
|
+
<span class="b" title="逐条读取report.json的task_end事件提取真实判定,覆盖batch_runner的运行时status">判定来源: report.json${stats.correctedCount ? `(已修正 ${stats.correctedCount} 条)` : ''}</span>
|
|
463
|
+
</div>
|
|
464
|
+
</div>
|
|
465
|
+
</div>
|
|
466
|
+
|
|
467
|
+
<!-- KPI -->
|
|
468
|
+
<div class="kpi-row">
|
|
469
|
+
${kpi(stats.total, '总用例')}
|
|
470
|
+
${kpi(stats.pass, 'PASS', 'green')}
|
|
471
|
+
${kpi(stats.fail, 'FAIL', 'red')}
|
|
472
|
+
${kpi(stats.passRate + '%', '通过率', 'orange')}
|
|
473
|
+
${stats.judged ? kpi(stats.accuracy.toFixed(1) + '%', '一致性准确率', 'blue') : ''}
|
|
474
|
+
${stats.judged ? kpi(stats.f1.toFixed(3), 'F1 Score', 'purple') : ''}
|
|
475
|
+
${stats.judged ? kpi(stats.fp, '预期通过执行失败', 'orange') : ''}
|
|
476
|
+
${stats.judged ? kpi(stats.fn, '预期失败执行通过', 'red') : ''}
|
|
477
|
+
${kpi(fmtTime(stats.avgDur), '平均耗时')}
|
|
478
|
+
${kpi(fmtTime(stats.maxDur), '最长耗时')}
|
|
479
|
+
${stats.totalTok ? kpi(fmtTok(stats.totalTok), '总 Token', 'blue') : ''}
|
|
480
|
+
${stats.totalTok ? kpi(fmtTok(stats.avgTok), '平均 Token') : ''}
|
|
481
|
+
</div>
|
|
482
|
+
|
|
483
|
+
<!-- confusion + metrics + apps -->
|
|
484
|
+
<div class="sec">
|
|
485
|
+
<h2>一致性与分应用概览</h2>
|
|
486
|
+
<div class="grid2">
|
|
487
|
+
<div>
|
|
488
|
+
${stats.judged ? `<table class="cm">
|
|
489
|
+
<tr><th></th><th>执行通过</th><th>执行失败</th></tr>
|
|
490
|
+
<tr><th>预期通过</th><td class="cm-tp">${stats.tp}</td><td class="cm-fp">${stats.fp}</td></tr>
|
|
491
|
+
<tr><th>预期失败</th><td class="cm-fn">${stats.fn}</td><td class="cm-tn">${stats.tn}</td></tr>
|
|
492
|
+
</table>
|
|
493
|
+
<div class="cm-leg">
|
|
494
|
+
<i style="background:#dcfce7"></i>预期通过执行通过 ${stats.tp}
|
|
495
|
+
<i style="background:#dbeafe"></i>预期失败执行失败 ${stats.tn}<br>
|
|
496
|
+
<i style="background:#fed7aa"></i>预期通过执行失败 ${stats.fp}
|
|
497
|
+
<i style="background:#fecaca"></i>预期失败执行通过 ${stats.fn}
|
|
498
|
+
</div>` : '<div class="empty">未提供真值文件(--truth),无法计算一致性</div>'}
|
|
499
|
+
</div>
|
|
500
|
+
<div>
|
|
501
|
+
<table class="apps">
|
|
502
|
+
<tr><th>应用</th><th>用例</th><th>P/F</th><th>通过率</th><th>准确率</th><th>预期通过执行失败</th><th>预期失败执行通过</th><th>耗时</th><th>Token</th></tr>
|
|
503
|
+
${appRowsHtml}
|
|
504
|
+
</table>
|
|
505
|
+
</div>
|
|
506
|
+
</div>
|
|
507
|
+
</div>
|
|
508
|
+
|
|
509
|
+
<!-- mismatch quick view -->
|
|
510
|
+
${stats.judged ? `
|
|
511
|
+
<div class="sec">
|
|
512
|
+
<h2>不一致用例速览 <span class="hint">执行结果与预期不一致的用例(共 ${stats.fp + stats.fn} 条)—— 点击可定位到下方明细</span></h2>
|
|
513
|
+
<div class="issue-bar">
|
|
514
|
+
<span class="chip chip-all on" onclick="filterIssue('ALL')">全部 ${stats.fp + stats.fn}</span>
|
|
515
|
+
<span class="chip chip-fp" onclick="filterIssue('FP')">预期通过执行失败 ${stats.fp}</span>
|
|
516
|
+
<span class="chip chip-fn" onclick="filterIssue('FN')">预期失败执行通过 ${stats.fn}</span>
|
|
517
|
+
</div>
|
|
518
|
+
<div class="issue-list" id="issueList">
|
|
519
|
+
${(fpRows.concat(fnRows)).map(issueCard).join('') || '<div class="empty">无不一致用例 🎉</div>'}
|
|
520
|
+
</div>
|
|
521
|
+
</div>` : ''}
|
|
522
|
+
|
|
523
|
+
<!-- full case table -->
|
|
524
|
+
<div class="sec">
|
|
525
|
+
<h2>用例明细 <span class="hint">点击行展开步骤/原因 · 点列头排序 · 可搜索/筛选</span></h2>
|
|
526
|
+
<div class="fbar">
|
|
527
|
+
<input type="text" id="search" placeholder="搜索 编号/应用/原因/步骤…" oninput="applyFilter()">
|
|
528
|
+
<select id="fStatus" onchange="applyFilter()"><option value="">全部状态</option><option value="PASS">PASS</option><option value="FAIL">FAIL</option></select>
|
|
529
|
+
<select id="fCons" onchange="applyFilter()"><option value="">全部一致性</option><option value="TP">预期通过执行通过</option><option value="TN">预期失败执行失败</option><option value="FP">预期通过执行失败</option><option value="FN">预期失败执行通过</option><option value="">无真值</option></select>
|
|
530
|
+
<select id="fApp" onchange="applyFilter()"><option value="">全部应用</option>${[...new Set(rows.map(r=>r.app))].filter(Boolean).sort().map(a=>`<option value="${esc(a)}">${esc(a)}</option>`).join('')}</select>
|
|
531
|
+
<button class="tog" id="mismatchBtn" onclick="toggleMismatch()">只看不一致</button>
|
|
532
|
+
<span class="cnt" id="cnt"></span>
|
|
533
|
+
</div>
|
|
534
|
+
<div class="tw">
|
|
535
|
+
<table class="cases" id="tbl">
|
|
536
|
+
<colgroup>
|
|
537
|
+
<col style="width:3%"><col style="width:7%"><col style="width:6%"><col style="width:9%">
|
|
538
|
+
<col style="width:9%"><col style="width:11%"><col style="width:11%"><col style="width:16%">
|
|
539
|
+
<col style="width:18%"><col style="width:10%">
|
|
540
|
+
</colgroup>
|
|
541
|
+
<thead><tr>
|
|
542
|
+
<th data-s="num">#</th>
|
|
543
|
+
<th data-s="app">应用</th>
|
|
544
|
+
<th data-s="autoStatus">判定</th>
|
|
545
|
+
<th data-s="expVerdict">预期</th>
|
|
546
|
+
<th data-s="consistency">一致性</th>
|
|
547
|
+
<th data-s="dur">耗时</th>
|
|
548
|
+
<th data-s="tokens">Token</th>
|
|
549
|
+
<th data-s="reason">失败原因</th>
|
|
550
|
+
<th>步骤预览</th>
|
|
551
|
+
<th>报告</th>
|
|
552
|
+
</tr></thead>
|
|
553
|
+
<tbody id="body"></tbody>
|
|
554
|
+
</table>
|
|
555
|
+
</div>
|
|
556
|
+
</div>
|
|
557
|
+
</div>
|
|
558
|
+
<script>
|
|
559
|
+
const DATA = ${JSON.stringify(rows)};
|
|
560
|
+
const MAXDUR = ${maxDur};
|
|
561
|
+
const MAXTOK = ${maxTok};
|
|
562
|
+
let sortKey = 'num', sortAsc = true, mismatchOnly = false, issueFilter = 'ALL';
|
|
563
|
+
|
|
564
|
+
function esc(s){return String(s==null?'':s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"')}
|
|
565
|
+
function trunc(s,n){s=String(s==null?'':s);return s.length>n?s.slice(0,n)+'…':s}
|
|
566
|
+
function fmtT(s){s=Number(s)||0;return s<60?s.toFixed(1)+'s':Math.floor(s/60)+'m'+Math.round(s%60)+'s'}
|
|
567
|
+
function fmtK(t){t=Number(t)||0;return t>=1000?(t/1000).toFixed(1)+'K':String(t)}
|
|
568
|
+
|
|
569
|
+
function render(rows){
|
|
570
|
+
const tb=document.getElementById('body');
|
|
571
|
+
if(!rows.length){tb.innerHTML='<tr><td colspan="10" class="empty">无匹配用例</td></tr>';document.getElementById('cnt').textContent='0 / '+DATA.length+' 条';return;}
|
|
572
|
+
const isNum=k=>k==='num'||k==='dur'||k==='tokens';
|
|
573
|
+
rows.sort((a,b)=>{let va=a[sortKey],vb=b[sortKey];if(isNum(sortKey))return sortAsc?va-vb:vb-va;return sortAsc?String(va).localeCompare(String(vb),'zh'):String(vb).localeCompare(String(va),'zh')});
|
|
574
|
+
let h='';
|
|
575
|
+
rows.forEach(r=>{
|
|
576
|
+
const mis=r.consistency==='FP'||r.consistency==='FN'?'mismatch':'';
|
|
577
|
+
const cls=r.autoStatus==='PASS'?'b-pass':'b-fail';
|
|
578
|
+
const consMap={TP:'预期通过执行通过',TN:'预期失败执行失败',FP:'预期通过执行失败',FN:'预期失败执行通过'};const cTag=r.consistency?'<span class="cm-tag t-'+r.consistency.toLowerCase()+'">'+(consMap[r.consistency]||r.consistency)+'</span>':'—';
|
|
579
|
+
const expCls=r.expVerdict==='FAIL'?'r':'g';
|
|
580
|
+
const expTxt=r.expVerdict?('<b class="'+expCls+'">'+r.expVerdict+'</b>'+(r.expDetail.length>4?' <span class="lbl">'+esc(trunc(r.expDetail.replace(/^(PASS|FAIL)\s*-\s*/,'$1: '),40))+'</span>':'')):'—';
|
|
581
|
+
const durBar='<div class="bar-wrap"><div class="bar bar-dur" style="width:'+(MAXDUR?Math.max(4,r.dur/MAXDUR*100):0)+'%"></div></div>';
|
|
582
|
+
const tokBar=r.tokens?'<div class="bar-wrap"><div class="bar bar-tok" style="width:'+(MAXTOK?Math.max(4,r.tokens/MAXTOK*100):0)+'%"></div></div>':'';
|
|
583
|
+
const ops=(r.report?'<a class="op" href="'+esc(r.report)+'" target="_blank" title="查看用例报告">查看</a>':'')
|
|
584
|
+
+(r.logLink?'<a class="op" href="'+esc(r.logLink)+'" target="_blank" title="打开完整日志">📄</a>':'')
|
|
585
|
+
+(r.folderLink?'<a class="op" href="'+esc(r.folderLink)+'" target="_blank" title="在浏览器查看文件夹">🗂</a>':'')
|
|
586
|
+
+(r.folderAbs?'<button class="op" onclick="copyFolder('+r.num+')" title="复制文件夹路径: '+esc(r.folderAbs)+'">📋</button>':'');
|
|
587
|
+
h+='<tr class="main '+mis+'" data-num="'+r.num+'" onclick="toggleRow('+r.num+')">';
|
|
588
|
+
h+='<td class="cell-num">'+r.num+'</td>';
|
|
589
|
+
h+='<td class="app-cell">'+esc(r.app)+'</td>';
|
|
590
|
+
h+='<td><span class="badge '+cls+'">'+r.autoStatus+'</span>'+(r.corrected?'<span class="fixed-tag" title="jsonl原记'+r.jsonlStatus+',已按report.json修正">修正</span>':'')+'</td>';
|
|
591
|
+
h+='<td class="exp-cell">'+expTxt+'</td>';
|
|
592
|
+
h+='<td style="text-align:center">'+cTag+'</td>';
|
|
593
|
+
h+='<td class="dur-cell">'+durBar+' '+r.dur.toFixed(1)+'s</td>';
|
|
594
|
+
h+='<td class="tok-cell">'+(r.tokens?tokBar+' '+fmtK(r.tokens):'—')+'</td>';
|
|
595
|
+
h+='<td class="reason-cell" title="'+esc(r.reason)+'"><div class="clamp">'+esc(trunc(r.reason,300))+'</div></td>';
|
|
596
|
+
h+='<td class="steps-cell" title="'+esc(r.steps)+'">'+esc(trunc(r.steps.replace(/\\n/g,' '),50))+'</td>';
|
|
597
|
+
h+='<td style="white-space:nowrap"><span onclick="event.stopPropagation()">'+(ops||'—')+'</span></td>';
|
|
598
|
+
h+='</tr>';
|
|
599
|
+
h+='<tr class="detail" id="d-'+r.num+'"><td colspan="10"><div class="det-grid">';
|
|
600
|
+
h+='<div class="det-block"><h4>测试步骤</h4><pre>'+esc(r.steps)+'</pre></div>';
|
|
601
|
+
h+='<div class="det-block"><h4>预期结果 / 失败原因</h4><pre>'+(r.expDetail?'[预期] '+r.expDetail+'\\n\\n':'')+(r.reason?'[原因] '+r.reason:'(无)')+'</pre></div>';
|
|
602
|
+
h+='</div></td></tr>';
|
|
603
|
+
});
|
|
604
|
+
tb.innerHTML=h;
|
|
605
|
+
document.getElementById('cnt').textContent=rows.length+' / '+DATA.length+' 条';
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function applyFilter(){
|
|
609
|
+
const q=document.getElementById('search').value.toLowerCase();
|
|
610
|
+
const fs=document.getElementById('fStatus').value;
|
|
611
|
+
const fc=document.getElementById('fCons').value;
|
|
612
|
+
const fa=document.getElementById('fApp').value;
|
|
613
|
+
let rows=DATA.filter(r=>{
|
|
614
|
+
if(mismatchOnly&&!(r.consistency==='FP'||r.consistency==='FN'))return false;
|
|
615
|
+
if(fs&&r.autoStatus!==fs)return false;
|
|
616
|
+
if(fc&&r.consistency!==fc)return false;
|
|
617
|
+
if(fa&&r.app!==fa)return false;
|
|
618
|
+
if(q&&!String(r.num).includes(q)&&!r.app.toLowerCase().includes(q)&&!r.reason.toLowerCase().includes(q)&&!r.steps.toLowerCase().includes(q)&&!r.expDetail.toLowerCase().includes(q))return false;
|
|
619
|
+
return true;
|
|
620
|
+
});
|
|
621
|
+
render(rows);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
function toggleMismatch(){
|
|
625
|
+
mismatchOnly=!mismatchOnly;
|
|
626
|
+
const b=document.getElementById('mismatchBtn');
|
|
627
|
+
b.classList.toggle('on',mismatchOnly);
|
|
628
|
+
applyFilter();
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
function colorLog(tail){
|
|
632
|
+
if(!tail)return '';
|
|
633
|
+
return tail.split('\\n').map(function(line){
|
|
634
|
+
var m=line.match(/ - (INFO|WARNING|ERROR|DEBUG) - /);
|
|
635
|
+
var lvl=m?m[1]:'';
|
|
636
|
+
var cls=lvl==='ERROR'?'log-err':lvl==='WARNING'?'log-warn':lvl==='INFO'?'log-info':lvl==='DEBUG'?'log-debug':'log-other';
|
|
637
|
+
return '<span class="'+cls+'">'+esc(line)+'</span>';
|
|
638
|
+
}).join('\\n');
|
|
639
|
+
}
|
|
640
|
+
function copyFolder(num){
|
|
641
|
+
var r=DATA.find(function(x){return x.num===num;});
|
|
642
|
+
if(!r||!r.folderAbs)return;
|
|
643
|
+
if(navigator.clipboard&&navigator.clipboard.writeText){
|
|
644
|
+
navigator.clipboard.writeText(r.folderAbs).then(function(){
|
|
645
|
+
var b=document.querySelector('#tbl .main[data-num="'+num+'"] button.op');
|
|
646
|
+
if(b){b.textContent='✓';setTimeout(function(){b.textContent='📋'},1200);}
|
|
647
|
+
},function(){prompt('复制失败,请手动复制用例文件夹路径:',r.folderAbs);});
|
|
648
|
+
}else{
|
|
649
|
+
prompt('浏览器不支持自动复制,请手动复制用例文件夹路径:',r.folderAbs);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
function toggleRow(num){
|
|
653
|
+
const d=document.getElementById('d-'+num);
|
|
654
|
+
if(d)d.classList.toggle('show');
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
function jumpTo(num){
|
|
658
|
+
mismatchOnly=true;
|
|
659
|
+
document.getElementById('mismatchBtn').classList.add('on');
|
|
660
|
+
document.getElementById('search').value='';
|
|
661
|
+
document.getElementById('fStatus').value='';
|
|
662
|
+
document.getElementById('fCons').value='';
|
|
663
|
+
document.getElementById('fApp').value='';
|
|
664
|
+
applyFilter();
|
|
665
|
+
const row=document.querySelector('#tbl .main[data-num="'+num+'"]');
|
|
666
|
+
if(row){row.scrollIntoView({behavior:'smooth',block:'center'});row.style.background='#fef3c7';setTimeout(()=>{row.style.background='';toggleRow(num);},400)}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
document.querySelectorAll('#tbl th[data-s]').forEach(th=>th.addEventListener('click',()=>{
|
|
670
|
+
const k=th.dataset.s;if(sortKey===k)sortAsc=!sortAsc;else{sortKey=k;sortAsc=true}applyFilter();
|
|
671
|
+
}));
|
|
672
|
+
|
|
673
|
+
function filterIssue(t){
|
|
674
|
+
issueFilter=t;
|
|
675
|
+
document.querySelectorAll('.chip').forEach(c=>c.classList.remove('on'));
|
|
676
|
+
document.querySelector('.chip-'+t.toLowerCase()).classList.add('on');
|
|
677
|
+
const list=document.getElementById('issueList');
|
|
678
|
+
const items=[...list.querySelectorAll('.issue')];
|
|
679
|
+
items.forEach(it=>{const isFp=it.classList.contains('issue-fp');const show=t==='ALL'||(t==='FP'&&isFp)||(t==='FN'&&!isFp);it.style.display=show?'':'none';});
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
document.querySelectorAll('.issue').forEach(el=>el.addEventListener('click',()=>jumpTo(Number(el.dataset.num))));
|
|
683
|
+
|
|
684
|
+
applyFilter();
|
|
685
|
+
</script>
|
|
686
|
+
</body>
|
|
687
|
+
</html>`;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
function main() {
|
|
691
|
+
const opts = parseArgs(process.argv);
|
|
692
|
+
if (!opts.input) {
|
|
693
|
+
console.error('用法: node gen_analysis_report.js <task_results.jsonl> --truth <case_file.json> --reports <reports.json> [--output <path.html>] [--title "标题"]');
|
|
694
|
+
process.exit(1);
|
|
695
|
+
}
|
|
696
|
+
const results = loadJsonl(opts.input);
|
|
697
|
+
const truthArr = loadJson(opts.truth);
|
|
698
|
+
const reportsArr = loadJson(opts.reports);
|
|
699
|
+
const rows = buildRows(results, truthArr, reportsArr);
|
|
700
|
+
const stats = computeStats(rows);
|
|
701
|
+
|
|
702
|
+
const outDir = path.dirname(opts.input);
|
|
703
|
+
const outputPath = opts.output || path.join(outDir, 'analysis_report.html');
|
|
704
|
+
const meta = { dist: true };
|
|
705
|
+
|
|
706
|
+
const html = generateReport(rows, stats, opts, meta);
|
|
707
|
+
fs.writeFileSync(outputPath, html, 'utf-8');
|
|
708
|
+
|
|
709
|
+
console.log('✓ 报告已生成: ' + outputPath);
|
|
710
|
+
console.log(' 总用例: ' + stats.total + ' | PASS: ' + stats.pass + ' | FAIL: ' + stats.fail + ' | 通过率: ' + stats.passRate + '%');
|
|
711
|
+
if (stats.correctedCount) {
|
|
712
|
+
console.log(' ⚠ 判定修正: ' + stats.correctedCount + ' 条(batch_runner运行时status误判,已按report.json的task_end真实结论修正)');
|
|
713
|
+
}
|
|
714
|
+
if (stats.judged) {
|
|
715
|
+
console.log(' 一致性: 准确率=' + stats.accuracy.toFixed(1) + '% | F1=' + stats.f1.toFixed(3) + ' | 预期通过执行通过=' + stats.tp + ' 预期失败执行失败=' + stats.tn + ' 预期通过执行失败=' + stats.fp + ' 预期失败执行通过=' + stats.fn);
|
|
716
|
+
console.log(' 不一致用例: ' + (stats.fp + stats.fn) + ' 条 (预期通过执行失败=' + stats.fp + ', 预期失败执行通过=' + stats.fn + ')');
|
|
717
|
+
}
|
|
718
|
+
console.log(' 耗时: 总=' + fmtTime(stats.totalDur) + ' | 平均=' + fmtTime(stats.avgDur) + ' | 最长=' + fmtTime(stats.maxDur));
|
|
719
|
+
if (stats.totalTok) {
|
|
720
|
+
console.log(' Token: 总=' + fmtTok(stats.totalTok) + ' | 平均=' + fmtTok(stats.avgTok) + ' | 覆盖 ' + stats.withTokens + '/' + stats.total + ' 条');
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
main();
|