dsh-flakefinder 0.4.7 → 0.4.9

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/lib/tools.js CHANGED
@@ -52,20 +52,37 @@ function verdictLabel(verdict) {
52
52
  default: return verdict;
53
53
  }
54
54
  }
55
- function resultSummary(result) {
56
- const lines = [
57
- '判定:' + verdictLabel(result.verdict),
58
- '重复运行:' + String(result.runs.length) + ' 次;总耗时:' + String(Math.round(result.durationMs / 100) / 10) + ' 秒',
59
- '稳定通过:' + String(result.stablePassCount) + ';稳定失败:' + String(result.stableFailCount) + ';flaky:' + String(result.flakyCount) + ';跳过:' + String(result.skippedCount),
60
- ];
55
+ function resultSummary(result, runs = [], subject) {
56
+ const lines = [];
57
+ if (subject !== undefined)
58
+ lines.push('目标:' + subject.target + '(framework=' + subject.framework + ')');
59
+ lines.push('判定:' + verdictLabel(result.verdict), '重复运行:' + String(result.runs.length) + ' 次;总耗时:' + String(Math.round(result.durationMs / 100) / 10) + ' 秒', '稳定通过:' + String(result.stablePassCount) + ';稳定失败:' + String(result.stableFailCount) + ';flaky:' + String(result.flakyCount) + ';跳过:' + String(result.skippedCount));
61
60
  if (result.flakyCount > 0) {
62
61
  lines.push('flaky 用例:');
63
62
  for (const test of result.tests.filter(item => item.verdict === 'flaky')) {
64
63
  lines.push('- ' + formatRef(test) + '(失败率 ' + String(test.failureRate) + '%)');
65
64
  }
66
65
  }
66
+ // 部分运行崩溃时 aggregate 不抛错,但错误原文只在 run.error 里;不带到摘要里用户只能看到「flaky」而不知道进程挂了。
67
+ const crashed = runs.filter(run => run.report === null);
68
+ if (crashed.length > 0) {
69
+ const first = crashed.find(run => run.error !== undefined)?.error ?? '未产出报告(stderr:' + (crashed[0].stderr.trim().split(/\r?\n/).slice(-3).join(' | ') || '无输出') + ')';
70
+ lines.push('有 ' + String(crashed.length) + ' 次运行未产出报告:' + first);
71
+ }
72
+ lines.push('下一步:' + nextStepOf(result.verdict));
67
73
  return lines.join('\n');
68
74
  }
75
+ /** 按判定给出下一步;文案复用 tools 里已有的工具名,避免另造词汇。 */
76
+ function nextStepOf(verdict) {
77
+ switch (verdict) {
78
+ case 'flaky': return '先用 flaky_quarantine 把这些用例写进隔离清单(写清原因),再单跑定位竞态;修复后用 flaky_detect 复查并 flaky_clear。';
79
+ case 'stable-fail': return '先单独跑一次这个测试看失败原因;若每次运行都崩溃(提示未产出报告),检查框架 CLI、reporter 与 pytest 的 junitxml 依赖。';
80
+ case 'stable-pass': return '多轮全部通过;若此前隔离过这些用例,可用 flaky_clear 移除。';
81
+ case 'skipped': return '所有用例被跳过:检查测试文件里的 skip / 条件编译,或 target 是否只匹配到空壳文件。';
82
+ case 'empty': return '没有解析到用例:确认 target 指向存在的测试文件或目录(可用 glob,如 test/**/*.test.mjs),必要时显式指定 framework。';
83
+ default: return '可运行 flaky_history / flaky_report 查看历史趋势。';
84
+ }
85
+ }
69
86
  const testSchema = {
70
87
  type: 'object',
71
88
  properties: {
@@ -169,7 +186,7 @@ function buildWorkspaceTools(cfg, runner, store, cwd = process.cwd(), signal) {
169
186
  runResults: result.runs,
170
187
  tests: result.tests,
171
188
  flakyTests: flaky,
172
- summary: resultSummary(result),
189
+ summary: resultSummary(result, executed, { target, framework }),
173
190
  };
174
191
  },
175
192
  timeoutMs: runsTimeout(cfg),
@@ -190,11 +207,16 @@ function buildWorkspaceTools(cfg, runner, store, cwd = process.cwd(), signal) {
190
207
  render: (_args, value) => {
191
208
  const rec = asRecord(value);
192
209
  const entries = Array.isArray(rec.entries) ? rec.entries : [];
193
- const lines = ['历史记录 ' + String(entries.length) + ' 条:'];
210
+ if (entries.length === 0) {
211
+ return [{ type: 'text', text: '历史记录 0 条:还没有跑过 flaky_detect(或过滤条件没有命中)。下一步:先对目标运行 flaky_detect,再用本工具看趋势。' }];
212
+ }
213
+ const lines = ['历史记录 ' + String(entries.length) + ' 条(新的在前):'];
194
214
  for (const item of entries) {
195
215
  const row = asRecord(item);
196
- lines.push('- ' + row.target + '(' + row.framework + ',' + verdictLabel(String(row.verdict ?? '')) + ',' + String(row.runs ?? '?') + ' 次,' + row.timestamp + ')');
216
+ const flaky = Number(row.flakyCount ?? 0);
217
+ lines.push('- ' + row.timestamp + ' ' + row.target + '(' + row.framework + ',' + verdictLabel(String(row.verdict ?? '')) + ',' + String(row.runs ?? '?') + ' 次' + (flaky > 0 ? ',flaky ' + String(flaky) : '') + ')');
197
218
  }
219
+ lines.push('下一步:需要判定标准/隔离清单汇总时用 flaky_report;修复后重新 flaky_detect 复查。');
198
220
  return [{ type: 'text', text: lines.join('\n') }];
199
221
  },
200
222
  },
@@ -222,7 +244,11 @@ function buildWorkspaceTools(cfg, runner, store, cwd = process.cwd(), signal) {
222
244
  },
223
245
  render: (_args, value) => {
224
246
  const rec = asRecord(value);
225
- return [{ type: 'text', text: '已写入隔离清单 ' + rec.file + ',新增 ' + String(rec.addedCount ?? 0) + ' 条。' }];
247
+ const added = Number(rec.addedCount ?? 0);
248
+ const head = added === 0
249
+ ? '隔离清单 ' + rec.file + ' 未新增条目:这些用例已在清单里(同文件同用例名视为同一条)。'
250
+ : '已写入隔离清单 ' + rec.file + ',新增 ' + String(added) + ' 条。';
251
+ return [{ type: 'text', text: head + '\n下一步:修复后运行 flaky_detect 多轮全部通过,再用 flaky_clear 移除这些条目。' }];
226
252
  },
227
253
  },
228
254
  async execute(rawArgs) {
@@ -248,7 +274,11 @@ function buildWorkspaceTools(cfg, runner, store, cwd = process.cwd(), signal) {
248
274
  },
249
275
  render: (_args, value) => {
250
276
  const rec = asRecord(value);
251
- return [{ type: 'text', text: '已从隔离清单移除 ' + String(rec.removedCount ?? 0) + ' 条。' }];
277
+ const removed = Number(rec.removedCount ?? 0);
278
+ const head = removed === 0
279
+ ? '隔离清单 ' + rec.file + ' 没有匹配条目可移除:请核对测试引用的文件路径与用例名(格式 "文件路径 > 用例名"),可用 flaky_report 查看清单里现有条目。'
280
+ : '已从隔离清单移除 ' + String(removed) + ' 条。';
281
+ return [{ type: 'text', text: head + (removed === 0 ? '' : '\n下一步:建议再跑一次 flaky_detect,确认移除后仍稳定。') }];
252
282
  },
253
283
  },
254
284
  async execute(rawArgs) {
@@ -281,14 +311,28 @@ function buildWorkspaceTools(cfg, runner, store, cwd = process.cwd(), signal) {
281
311
  render: (_args, value) => {
282
312
  const rec = asRecord(value);
283
313
  const quarantined = Array.isArray(rec.quarantined) ? rec.quarantined : [];
314
+ const history = Array.isArray(rec.history) ? rec.history : [];
284
315
  const lines = [
285
316
  '测试稳定性报告',
286
317
  '隔离清单:' + String(rec.quarantineFile ?? '') + '(' + String(rec.quarantinedCount ?? 0) + ' 条)',
287
318
  ];
319
+ if (quarantined.length === 0)
320
+ lines.push('- 清单为空:还没有被隔离的用例。下一步:flaky_detect 判定为 flaky 后用 flaky_quarantine 写入。');
288
321
  for (const item of quarantined) {
289
322
  const row = asRecord(item);
290
323
  lines.push('- ' + formatRef({ file: String(row.file ?? ''), name: typeof row.name === 'string' ? row.name : null }) + ':' + String(row.reason ?? ''));
291
324
  }
325
+ // 报告以前只渲染隔离清单,把 payload 里的检测历史整段丢掉;用户看不到「最近判定」。
326
+ lines.push('', '检测历史:' + String(rec.historyCount ?? history.length) + ' 条');
327
+ if (history.length === 0)
328
+ lines.push('- 还没有检测记录:先对一个目标运行 flaky_detect。');
329
+ for (const item of history.slice(0, 10)) {
330
+ const row = asRecord(item);
331
+ const flaky = Number(row.flakyCount ?? 0);
332
+ lines.push('- ' + row.timestamp + ' ' + row.target + '(' + verdictLabel(String(row.verdict ?? '')) + ',' + String(row.runs ?? '?') + ' 次' + (flaky > 0 ? ',flaky ' + String(flaky) : '') + ')');
333
+ }
334
+ if (history.length > 10)
335
+ lines.push('…仅展示最近 10 条,其余用 flaky_history 查看');
292
336
  return [{ type: 'text', text: lines.join('\n') }];
293
337
  },
294
338
  },
@@ -318,10 +362,17 @@ function buildWorkspaceTools(cfg, runner, store, cwd = process.cwd(), signal) {
318
362
  const rec = asRecord(value);
319
363
  const checks = Array.isArray(rec.checks) ? rec.checks : [];
320
364
  const lines = ['dsh-flakefinder 自检' + (rec.ok === true ? ':正常。' : ':发现问题。')];
365
+ const failed = [];
321
366
  for (const item of checks) {
322
367
  const c = asRecord(item);
323
368
  lines.push('- ' + c.name + ':' + (c.ok === true ? '✅' : '❌ ' + String(c.detail ?? '')));
369
+ if (c.ok !== true)
370
+ failed.push(String(c.name));
324
371
  }
372
+ if (failed.includes('pytest'))
373
+ lines.push('下一步:仅用 vitest / jest / node:test 时 pytest 缺失不影响;需要跑 Python 测试时先 pip install pytest,或把插件配置里的 pythonPath 指到正确的解释器。');
374
+ else if (failed.length > 0)
375
+ lines.push('下一步:按上面 ❌ 项的说明修好解释器/依赖,再运行 flaky_health 复查。');
325
376
  return [{ type: 'text', text: lines.join('\n') }];
326
377
  },
327
378
  },
@@ -437,7 +437,7 @@ function __stardustUpdatesClient(ctx, React, require, shared) {
437
437
  }
438
438
 
439
439
  /* STARDUSTLC_UPDATE_CLIENT_BODY_START */
440
- window.__ModuleLoader__.load(__stardustUpdatesWrap({id:"dsh-flakefinder",factory:require=>({apply(){}})},{"name":"dsh-flakefinder","version":"0.1.0","hasWorkbench":false,"packageVersion":"0.4.7","label":"不稳定测试排查","labelEn":"Flakefinder","suiteComponent":true}));
440
+ window.__ModuleLoader__.load(__stardustUpdatesWrap({id:"dsh-flakefinder",factory:require=>({apply(){}})},{"name":"dsh-flakefinder","version":"0.1.0","hasWorkbench":false,"packageVersion":"0.4.9","label":"不稳定测试排查","labelEn":"Flakefinder","suiteComponent":true}));
441
441
 
442
442
  /* STARDUSTLC_UPDATE_CLIENT_BODY_END */
443
443
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-flakefinder",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "description": "DSH 偶发测试调查:重复运行、失败记录、工作区隔离列表与写操作确认。欢迎提交 issues 和 PR。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -26,8 +26,8 @@
26
26
  "scripts": {
27
27
  "build": "tsc -p tsconfig.json && node scripts/build-updates.mjs",
28
28
  "typecheck": "tsc -p tsconfig.json --noEmit",
29
- "test": "pnpm run build && node --test \"test/*.test.mjs\"",
30
- "prepublishOnly": "pnpm run build"
29
+ "test": "npm run build && node --test \"test/*.test.mjs\"",
30
+ "prepublishOnly": "npm run build"
31
31
  },
32
32
  "dsh": {
33
33
  "bundle": {