dsh-flakefinder 0.4.8 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # 更新记录
2
2
 
3
+ ## 0.4.9 (2026-11-03)
4
+
5
+ - flaky_report 渲染检测历史;flaky_detect 补目标、首个错误与按 verdict 的下一步。
6
+ - flaky_report renders detection history; flaky_detect adds target, first error and verdict-specific next steps.
7
+
3
8
  ## 0.4.8 (2026-10-30)
4
9
 
5
10
  - 重整中英文首页:用途、三步流程图、安装入口与操作示例;详细配置与边界集中到完整说明。
package/docs/USAGE.en.md CHANGED
@@ -50,6 +50,20 @@ Agent:
50
50
 
51
51
  See `cordis.patch.yml`; defaults: `defaultRuns=5`, `maxRuns=20`, `timeoutMs=120000`, `writeApproval=true`, `pythonPath=python` (`python3` on Linux/macOS; used for pytest runs).
52
52
 
53
+ ## Troubleshooting
54
+
55
+ Run `flaky_health` first: it checks the Python interpreter and pytest availability and summarizes the defaults.
56
+
57
+ | Symptom | Usual cause | What to do |
58
+ | :-- | :-- | :-- |
59
+ | Verdict says no tests were parsed | `target` matched nothing, or only skipped tests | Point `target` at real test files/directories (globs work), or pass `framework` explicitly |
60
+ | "N runs produced no report" | Framework CLI missing, unsupported reporter flag, pytest lacking junitxml | Run the same command once by hand to see the real error; make sure the temp directory is writable |
61
+ | `framework=vitest` cannot find `node_modules/vitest` | Not installed, or invoked outside the project | Call it from the project that installed the framework, or set `framework` |
62
+ | pytest-related failure | Interpreter or pytest missing | `pip install pytest`, or point `pythonPath` at the right interpreter |
63
+ | Quarantine/clear removed 0 entries | Reference format or path does not match the list | Use `"file path > test name"`; check existing entries with `flaky_report` |
64
+
65
+ The `flaky_detect` summary always ends with the next step: quarantine flaky tests, reproduce stable failures, or clear recovered ones.
66
+
53
67
  ## Development
54
68
 
55
69
  ```bash
package/docs/USAGE.md CHANGED
@@ -108,6 +108,20 @@ Agent:
108
108
  4. 真实 profile 冒烟:全新临时 profile 安装插件 → 真 boot → stderr 零报错
109
109
  5. manifest 自检(bundle patch / exports / files 白名单)
110
110
 
111
+ ## 故障排查
112
+
113
+ 先运行 `flaky_health`:它检查 Python 解释器与 pytest 是否可用,并汇总默认配置。
114
+
115
+ | 现象 | 常见原因 | 处理 |
116
+ | :-- | :-- | :-- |
117
+ | 判定「没有解析到用例」 | target 没匹配到文件,或目标文件里只有被跳过的用例 | 确认 target 指向真实测试文件/目录(支持 glob),必要时显式指定 `framework` |
118
+ | 提示「有 N 次运行未产出报告」 | 框架 CLI 缺失、reporter 参数不被接受、pytest 缺少 junitxml 约束 | 先手动跑一次对应命令看报错;确认临时目录可写 |
119
+ | `framework=vitest` 报找不到 `node_modules/vitest` | 没安装,或不在项目根目录调用 | 在装了框架的项目里调用,或显式指定 `framework` |
120
+ | pytest 相关失败 | 解释器或 pytest 缺失 | `pip install pytest`,或用配置里的 `pythonPath` 指向正确解释器 |
121
+ | 隔离/清除返回 0 条 | 引用格式或路径与清单不一致 | 用 `"文件路径 > 用例名"` 格式;先 `flaky_report` 看清单现有条目 |
122
+
123
+ `flaky_detect` 的摘要会给出下一步:flaky 先隔离,稳定失败先单跑定位,稳定通过可以清除隔离。
124
+
111
125
  ## License
112
126
 
113
127
  MIT
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.8","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,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-flakefinder",
3
- "version": "0.4.8",
4
- "description": "把偶发失败变成有记录、能继续排查的线索。 重复测试会实际执行项目命令。未复现不等于不存在偶发问题。 欢迎提交 issues 和 PR。",
3
+ "version": "0.4.9",
4
+ "description": "DSH 偶发测试调查:重复运行、失败记录、工作区隔离列表与写操作确认。欢迎提交 issues 和 PR。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -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": {