@wenaixi/dsh-superpower 7.4.1 → 7.5.2

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.
Files changed (72) hide show
  1. package/README.md +112 -105
  2. package/README.zh.md +218 -0
  3. package/lib/catalog.d.ts +8 -2
  4. package/lib/catalog.d.ts.map +1 -1
  5. package/lib/catalog.js +64 -9
  6. package/lib/catalog.js.map +1 -1
  7. package/lib/client.js +68 -22
  8. package/lib/document.d.ts +8 -2
  9. package/lib/document.d.ts.map +1 -1
  10. package/lib/document.js +14 -4
  11. package/lib/document.js.map +1 -1
  12. package/lib/superpowers.d.ts +2 -0
  13. package/lib/superpowers.d.ts.map +1 -1
  14. package/lib/superpowers.js +32 -0
  15. package/lib/superpowers.js.map +1 -1
  16. package/lib/switches.d.ts +2 -10
  17. package/lib/switches.d.ts.map +1 -1
  18. package/lib/switches.js +33 -5
  19. package/lib/switches.js.map +1 -1
  20. package/package.json +3 -3
  21. package/skills/brainstorming/SKILL.md +235 -171
  22. package/skills/brainstorming/spec-document-reviewer-prompt.md +27 -25
  23. package/skills/brainstorming/visual-companion.md +65 -69
  24. package/skills/diagnosing-superpowers/SKILL.md +107 -43
  25. package/skills/diagnosing-superpowers/prompts/analyst-common.md +32 -18
  26. package/skills/diagnosing-superpowers/prompts/cost-and-time.md +25 -9
  27. package/skills/diagnosing-superpowers/prompts/plan-adherence.md +26 -12
  28. package/skills/diagnosing-superpowers/prompts/quality-evidence.md +23 -8
  29. package/skills/diagnosing-superpowers/prompts/repeated-work.md +25 -14
  30. package/skills/diagnosing-superpowers/prompts/request-conflicts.md +18 -9
  31. package/skills/diagnosing-superpowers/prompts/scrub-audit.md +23 -10
  32. package/skills/diagnosing-superpowers/prompts/scrub.md +25 -12
  33. package/skills/diagnosing-superpowers/prompts/similar-session.md +30 -22
  34. package/skills/diagnosing-superpowers/prompts/skill-timeline.md +26 -12
  35. package/skills/diagnosing-superpowers/prompts/stumbles.md +24 -12
  36. package/skills/diagnosing-superpowers/references/context-safety.md +15 -7
  37. package/skills/diagnosing-superpowers/references/github-issues.md +17 -9
  38. package/skills/diagnosing-superpowers/references/redaction-policy.md +27 -15
  39. package/skills/diagnosing-superpowers/references/session-discovery.md +31 -20
  40. package/skills/diagnosing-superpowers/templates/bundle-README.md +66 -40
  41. package/skills/diagnosing-superpowers/templates/case.md +49 -42
  42. package/skills/diagnosing-superpowers/templates/issue.md +32 -26
  43. package/skills/diagnosing-superpowers/templates/report.md +54 -48
  44. package/skills/dispatching-parallel-agents/SKILL.md +92 -90
  45. package/skills/executing-plans/SKILL.md +345 -197
  46. package/skills/finishing-a-development-branch/SKILL.md +107 -82
  47. package/skills/receiving-code-review/SKILL.md +129 -127
  48. package/skills/requesting-code-review/SKILL.md +52 -50
  49. package/skills/requesting-code-review/code-reviewer.md +132 -111
  50. package/skills/subagent-driven-development/SKILL.md +521 -298
  51. package/skills/subagent-driven-development/implementer-prompt.md +138 -117
  52. package/skills/subagent-driven-development/re-review-prompt.md +80 -48
  53. package/skills/subagent-driven-development/task-reviewer-prompt.md +189 -110
  54. package/skills/systematic-debugging/CREATION-LOG.md +85 -85
  55. package/skills/systematic-debugging/SKILL.md +221 -219
  56. package/skills/systematic-debugging/condition-based-waiting.md +48 -49
  57. package/skills/systematic-debugging/defense-in-depth.md +46 -46
  58. package/skills/systematic-debugging/root-cause-tracing.md +63 -63
  59. package/skills/systematic-debugging/test-academic.md +10 -10
  60. package/skills/systematic-debugging/test-pressure-1.md +40 -40
  61. package/skills/systematic-debugging/test-pressure-2.md +58 -58
  62. package/skills/systematic-debugging/test-pressure-3.md +48 -48
  63. package/skills/test-driven-development/SKILL.md +161 -153
  64. package/skills/test-driven-development/writing-good-tests.md +137 -84
  65. package/skills/using-git-worktrees/SKILL.md +74 -72
  66. package/skills/using-superpowers/SKILL.md +40 -39
  67. package/skills/using-superpowers/references/dsh-tools.md +36 -36
  68. package/skills/verification-before-completion/SKILL.md +85 -83
  69. package/skills/writing-plans/SKILL.md +123 -84
  70. package/skills/writing-skills/SKILL.md +419 -417
  71. package/skills/writing-skills/persuasion-principles.md +118 -118
  72. package/skills/writing-skills/testing-skills-with-subagents.md +190 -190
@@ -1,283 +1,285 @@
1
1
  ---
2
2
  name: systematic-debugging
3
- description: "Superpower Skill:遇到缺陷、测试失败或异常行为时使用,要求先完成根因分析再提出修复,确保系统化调试。"
3
+ description: "Superpower Skill: Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes"
4
+ description_zh: "Superpower Skill:遇到缺陷、测试失败或异常行为时使用,要求先完成根因分析再提出修复,确保系统化调试。"
4
5
  ---
5
6
 
6
- # 系统化调试
7
7
 
8
- ## 概览
8
+ # Systematic Debugging
9
9
 
10
- **核心原则:** 始终先找到根因,再尝试修复。只修表象即是失败。
10
+ ## Overview
11
11
 
12
- **违背该流程的字面要求,即是违背调试的精神。**
12
+ **Core principle:** ALWAYS find root cause before attempting fixes. Symptom fixes are failure.
13
13
 
14
- ## 铁律
14
+ **Violating the letter of this process is violating the spirit of debugging.**
15
+
16
+ ## The Iron Law
15
17
 
16
18
  ```
17
- 未完成根因调查前,禁止提出任何修复方案
19
+ NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
18
20
  ```
19
21
 
20
- 若尚未完成阶段一,则不得提出修复建议。
22
+ If you haven't completed Phase 1, you cannot propose fixes.
21
23
 
22
- ## 适用场景
24
+ ## When to Use
23
25
 
24
- 适用于任何技术问题:
25
- - 测试失败
26
- - 生产环境缺陷
27
- - 异常行为
28
- - 性能问题
29
- - 构建失败
30
- - 集成问题
26
+ Use for ANY technical issue:
27
+ - Test failures
28
+ - Bugs in production
29
+ - Unexpected behavior
30
+ - Performance problems
31
+ - Build failures
32
+ - Integration issues
31
33
 
32
- **尤其应在以下情况使用:**
33
- - 时间紧迫时(紧急情况下最容易产生侥幸猜测)
34
- - 看似有“显而易见的快速修复”时
35
- - 已尝试过多种修复方案时
36
- - 此前修复未生效时
37
- - 尚未完全理解问题时
34
+ **Use this ESPECIALLY when:**
35
+ - Under time pressure (emergencies make guessing tempting)
36
+ - "Just one quick fix" seems obvious
37
+ - You've already tried multiple fixes
38
+ - Previous fix didn't work
39
+ - You don't fully understand the issue
38
40
 
39
- **以下情况也不要跳过:**
40
- - 问题看似简单时(简单缺陷同样有根因)
41
- - 时间仓促时(仓促必定导致返工)
42
- - 管理者要求立刻修复时(系统化比盲目试错更快)
41
+ **Don't skip when:**
42
+ - Issue seems simple (simple bugs have root causes too)
43
+ - You're in a hurry (rushing guarantees rework)
44
+ - Manager wants it fixed NOW (systematic is faster than thrashing)
43
45
 
44
- ## 四个阶段
46
+ ## The Four Phases
45
47
 
46
- 必须按顺序完成每个阶段,方可进入下一阶段。
48
+ You MUST complete each phase before proceeding to the next.
47
49
 
48
- ### 阶段一:根因调查
50
+ ### Phase 1: Root Cause Investigation
49
51
 
50
- **在尝试任何修复之前:**
52
+ **BEFORE attempting ANY fix:**
51
53
 
52
- 1. **仔细阅读错误信息**
53
- - 不要跳过错误或警告
54
- - 其中往往包含精确的解决线索
55
- - 完整阅读堆栈跟踪
56
- - 记录行号、文件路径、错误码
54
+ 1. **Read Error Messages Carefully**
55
+ - Don't skip past errors or warnings
56
+ - They often contain the exact solution
57
+ - Read stack traces completely
58
+ - Note line numbers, file paths, error codes
57
59
 
58
- 2. **稳定复现**
59
- - 能否稳定触发?
60
- - 精确的复现步骤是什么?
61
- - 是否每次都会出现?
62
- - 若无法复现 → 先补充数据,切勿猜测
60
+ 2. **Reproduce Consistently**
61
+ - Can you trigger it reliably?
62
+ - What are the exact steps?
63
+ - Does it happen every time?
64
+ - If not reproducible → gather more data, don't guess
63
65
 
64
- 3. **检查近期变更**
65
- - 哪些变更可能引发该问题?
66
- - 查看 git diff、近期提交
67
- - 新增依赖、配置变更
68
- - 环境差异
66
+ 3. **Check Recent Changes**
67
+ - What changed that could cause this?
68
+ - Git diff, recent commits
69
+ - New dependencies, config changes
70
+ - Environmental differences
69
71
 
70
- 4. **在多组件系统中收集证据**
72
+ 4. **Gather Evidence in Multi-Component Systems**
71
73
 
72
- **当系统包含多个组件时(CI → 构建 → 签名,API → 服务 → 数据库):**
74
+ **WHEN system has multiple components (CI → build → signing, API → service → database):**
73
75
 
74
- **在提出修复前,先添加诊断探针:**
75
- ```
76
- 对于每个组件边界:
77
- - 记录进入组件的数据
78
- - 记录离开组件的数据
79
- - 验证环境/配置是否正确传递
80
- - 检查每一层的实际状态
76
+ **BEFORE proposing fixes, add diagnostic instrumentation:**
77
+ ```
78
+ For EACH component boundary:
79
+ - Log what data enters component
80
+ - Log what data exits component
81
+ - Verify environment/config propagation
82
+ - Check state at each layer
81
83
 
82
- 运行一次以收集“在哪一层断裂”的证据
83
- 然后分析证据以定位故障组件
84
- 再针对该组件深入调查
85
- ```
84
+ Run once to gather evidence showing WHERE it breaks
85
+ THEN analyze evidence to identify failing component
86
+ THEN investigate that specific component
87
+ ```
86
88
 
87
- **示例(多层系统):**
88
- ```bash
89
- # Layer 1: Workflow
90
- echo "=== Secrets available in workflow: ==="
91
- echo "IDENTITY: ${IDENTITY:+SET}${IDENTITY:-UNSET}"
89
+ **Example (multi-layer system):**
90
+ ```bash
91
+ # Layer 1: Workflow
92
+ echo "=== Secrets available in workflow: ==="
93
+ echo "IDENTITY: ${IDENTITY:+SET}${IDENTITY:-UNSET}"
92
94
 
93
- # Layer 2: Build script
94
- echo "=== Env vars in build script: ==="
95
- env | grep IDENTITY || echo "IDENTITY not in environment"
96
-
97
- # Layer 3: Signing script
98
- echo "=== Keychain state: ==="
99
- security list-keychains
100
- security find-identity -v
95
+ # Layer 2: Build script
96
+ echo "=== Env vars in build script: ==="
97
+ env | grep IDENTITY || echo "IDENTITY not in environment"
98
+
99
+ # Layer 3: Signing script
100
+ echo "=== Keychain state: ==="
101
+ security list-keychains
102
+ security find-identity -v
101
103
 
102
- # Layer 4: Actual signing
103
- codesign --sign "$IDENTITY" --verbose=4 "$APP"
104
- ```
104
+ # Layer 4: Actual signing
105
+ codesign --sign "$IDENTITY" --verbose=4 "$APP"
106
+ ```
105
107
 
106
- **由此可得:** 哪一层失败(secrets → workflow [OK],workflow → build [FAIL])
107
-
108
- 5. **追踪数据流**
108
+ **This reveals:** Which layer fails (secrets → workflow [OK], workflow → build [FAIL])
109
+
110
+ 5. **Trace Data Flow**
109
111
 
110
- **当错误位于调用栈深处时:**
112
+ **WHEN error is deep in call stack:**
111
113
 
112
- 完整的回溯追踪技巧见本目录下的 `root-cause-tracing.md`。
114
+ See `root-cause-tracing.md` in this directory for the complete backward tracing technique.
113
115
 
114
- **精简版:**
115
- - 异常值从何而来?
116
- - 是谁以错误值调用了此处?
117
- - 持续向上回溯,直至找到源头
118
- - 在源头修复,而非在表象处打补丁
116
+ **Quick version:**
117
+ - Where does bad value originate?
118
+ - What called this with bad value?
119
+ - Keep tracing up until you find the source
120
+ - Fix at source, not at symptom
119
121
 
120
- ### 阶段二:模式分析
121
-
122
- **先找到规律,再动手修复:**
123
-
124
- 1. **寻找可用的参照**
125
- - 在同一代码库中定位相似且正常工作的代码
126
- - 有哪些与故障相似但能正常工作的用例?
127
-
128
- 2. **对照参考实现**
129
- - 若要套用某种模式,请完整阅读参考实现
130
- - 不要走马观花——逐行阅读
131
- - 在套用前彻底理解该模式
132
-
133
- 3. **识别差异**
134
- - 正常与异常之间有何不同?
135
- - 列出每一个差异,哪怕再细微
136
- - 不要想当然地认为“这点不可能有影响”
122
+ ### Phase 2: Pattern Analysis
123
+
124
+ **Find the pattern before fixing:**
125
+
126
+ 1. **Find Working Examples**
127
+ - Locate similar working code in same codebase
128
+ - What works that's similar to what's broken?
129
+
130
+ 2. **Compare Against References**
131
+ - If implementing pattern, read reference implementation COMPLETELY
132
+ - Don't skim - read every line
133
+ - Understand the pattern fully before applying
134
+
135
+ 3. **Identify Differences**
136
+ - What's different between working and broken?
137
+ - List every difference, however small
138
+ - Don't assume "that can't matter"
137
139
 
138
- 4. **理解依赖**
139
- - 该功能还依赖哪些组件?
140
- - 需要哪些设置、配置、环境?
141
- - 它做了哪些隐含假设?
140
+ 4. **Understand Dependencies**
141
+ - What other components does this need?
142
+ - What settings, config, environment?
143
+ - What assumptions does it make?
142
144
 
143
- ### 阶段三:假设与验证
145
+ ### Phase 3: Hypothesis and Testing
144
146
 
145
- **用科学方法推进:**
147
+ **Scientific method:**
146
148
 
147
- 1. **提出单一假设**
148
- - 清晰表述:“我认为根因是 X,理由是 Y”
149
- - 落到纸面
150
- - 要具体,避免含糊
151
-
152
- 2. **最小化验证**
153
- - 为验证假设做最小幅度的改动
154
- - 一次只改变一个变量
155
- - 不要同时修复多个问题
149
+ 1. **Form Single Hypothesis**
150
+ - State clearly: "I think X is the root cause because Y"
151
+ - Write it down
152
+ - Be specific, not vague
153
+
154
+ 2. **Test Minimally**
155
+ - Make the SMALLEST possible change to test hypothesis
156
+ - One variable at a time
157
+ - Don't fix multiple things at once
156
158
 
157
- 3. **验证后再继续**
158
- - 生效了吗?是 → 进入阶段四
159
- - 未生效?提出新的假设
160
- - 不要在原有改动之上继续叠加修复
159
+ 3. **Verify Before Continuing**
160
+ - Did it work? Yes → Phase 4
161
+ - Didn't work? Form NEW hypothesis
162
+ - DON'T add more fixes on top
161
163
 
162
- 4. **当你不确定时**
163
- - 直言“我不理解 X”
164
- - 不要不懂装懂
165
- - 寻求帮助
166
- - 进一步研究
164
+ 4. **When You Don't Know**
165
+ - Say "I don't understand X"
166
+ - Don't pretend to know
167
+ - Ask for help
168
+ - Research more
167
169
 
168
- ### 阶段四:实现
170
+ ### Phase 4: Implementation
169
171
 
170
- **修复根因,而非表象:**
172
+ **Fix the root cause, not the symptom:**
171
173
 
172
- 1. **创建失败用例**
173
- - 用最简方式复现问题
174
- - 如有测试框架则编写自动化测试
175
- - 若无框架则编写一次性复现脚本
176
- - 修复前必须具备该用例
177
- - 编写规范的失败测试请使用 `test-driven-development` 技能
174
+ 1. **Create Failing Test Case**
175
+ - Simplest possible reproduction
176
+ - Automated test if possible
177
+ - One-off test script if no framework
178
+ - MUST have before fixing
179
+ - Use the `superpowers:test-driven-development` skill for writing proper failing tests
178
180
 
179
- 2. **实施单一修复**
180
- - 针对已确认的根因
181
- - 一次只做一处改动
182
- - 不要顺手“顺便优化”
183
- - 不要打包重构
181
+ 2. **Implement Single Fix**
182
+ - Address the root cause identified
183
+ - ONE change at a time
184
+ - No "while I'm here" improvements
185
+ - No bundled refactoring
184
186
 
185
- 3. **验证修复**
186
- - 用例现在通过了吗?
187
- - 是否破坏了其他测试?
188
- - 问题是否真正解决?
189
- - 在宣称成功前,请使用 `verification-before-completion` 技能进行校验
187
+ 3. **Verify Fix**
188
+ - Test passes now?
189
+ - No other tests broken?
190
+ - Issue actually resolved?
191
+ - Use the `superpowers:verification-before-completion` skill before claiming success
190
192
 
191
- 4. **若修复未生效**
192
- - 停下来
193
- - 计数:已尝试几次修复?
194
- - 若 < 3 次:回到阶段一,结合新信息重新分析
195
- - **若 ≥ 3 次:停下来,质疑架构(见下方第 5 步)**
196
- - 在未进行架构讨论前,不要尝试第 4 次修复
193
+ 4. **If Fix Doesn't Work**
194
+ - STOP
195
+ - Count: How many fixes have you tried?
196
+ - If < 3: Return to Phase 1, re-analyze with new information
197
+ - **If ≥ 3: STOP and question the architecture (step 5 below)**
198
+ - DON'T attempt Fix #4 without architectural discussion
197
199
 
198
- 5. **若 3 次以上修复均失败:质疑架构**
200
+ 5. **If 3+ Fixes Failed: Question Architecture**
199
201
 
200
- **指向架构问题的信号:**
201
- - 每次修复都在不同位置暴露出新的共享状态/耦合/问题
202
- - 修复需要“大规模重构”才能落地
203
- - 每次修复都在别处引发新症状
202
+ **Pattern indicating architectural problem:**
203
+ - Each fix reveals new shared state/coupling/problem in different place
204
+ - Fixes require "massive refactoring" to implement
205
+ - Each fix creates new symptoms elsewhere
204
206
 
205
- **停下来,质疑根本:**
206
- - 该模式本身是否合理?
207
- - 是否只是“靠惯性硬撑”?
208
- - 应该重构架构,还是继续修补表象?
207
+ **STOP and question fundamentals:**
208
+ - Is this pattern fundamentally sound?
209
+ - Are we "sticking with it through sheer inertia"?
210
+ - Should we refactor architecture vs. continue fixing symptoms?
209
211
 
210
- **在尝试更多修复前,先与 human partner 讨论**
212
+ **Discuss with your human partner before attempting more fixes**
211
213
 
212
- 这不是假设失败——这是架构错误。
214
+ This is NOT a failed hypothesis - this is a wrong architecture.
213
215
 
214
- ## 危险信号——停下来并回归流程
215
-
216
- 若你发现自己出现以下想法:
217
- - “先快速修一下,之后再调查”
218
- - “先试着改一下 X 看看是否有效”
219
- - “多改几处,一起跑测试”
220
- - “跳过测试,我手动验证就行”
221
- - “大概是 X,我直接修掉”
222
- - “还没完全搞懂,但这个改法也许能行”
223
- - “规范要求是 X,但我换种方式适配一下”
224
- - “主要问题有这些:[未做调查就直接列出修复清单]”
225
- - 在追踪数据流之前就提出解决方案
226
- - **“再试一次修复”(已尝试 2 次以上时)**
227
- - **每次修复都在不同位置暴露新问题**
228
-
229
- **以上全部意味着:停下来,回到阶段一。**
230
-
231
- **若已失败 3 次以上:** 质疑架构(见阶段四第 5 步)
216
+ ## Red Flags - STOP and Follow Process
217
+
218
+ If you catch yourself thinking:
219
+ - "Quick fix for now, investigate later"
220
+ - "Just try changing X and see if it works"
221
+ - "Add multiple changes, run tests"
222
+ - "Skip the test, I'll manually verify"
223
+ - "It's probably X, let me fix that"
224
+ - "I don't fully understand but this might work"
225
+ - "Pattern says X but I'll adapt it differently"
226
+ - "Here are the main problems: [lists fixes without investigation]"
227
+ - Proposing solutions before tracing data flow
228
+ - **"One more fix attempt" (when already tried 2+)**
229
+ - **Each fix reveals new problem in different place**
230
+
231
+ **ALL of these mean: STOP. Return to Phase 1.**
232
+
233
+ **If 3+ fixes failed:** Question the architecture (see Phase 4.5)
232
234
 
233
- ## human partner 提示你做错了的信号
234
-
235
- **留意这些提醒:**
236
- - “这不是没生效吗?”——你在未验证的情况下做了假设
237
- - “它会告诉我们……吗?”——你本应补充证据收集
238
- - “别猜了”——你在未理解问题前就提出修复
239
- - “深入思考一下”——需要质疑根本假设,而非只修表象
240
- - “我们是不是卡住了?”(带有挫败感)——你的方法行不通
235
+ ## your human partner's Signals You're Doing It Wrong
236
+
237
+ **Watch for these redirections:**
238
+ - "Is that not happening?" - You assumed without verifying
239
+ - "Will it show us...?" - You should have added evidence gathering
240
+ - "Stop guessing" - You're proposing fixes without understanding
241
+ - "Ultra-think this" - Question fundamentals, not just symptoms
242
+ - "We're stuck?" (frustrated) - Your approach isn't working
241
243
 
242
- **出现这些信号时:** 停下来,回到阶段一。
243
-
244
- ## 常见借口
245
-
246
- | 借口 | 实际情况 |
244
+ **When you see these:** STOP. Return to Phase 1.
245
+
246
+ ## Common Rationalizations
247
+
248
+ | Excuse | Reality |
247
249
  |--------|---------|
248
- | “问题很简单,不需要走流程” | 简单问题同样有根因。走流程对简单缺陷反而更快。 |
249
- | “紧急情况,没时间走流程” | 系统化调试比猜测试错更快。 |
250
- | “先试一下,之后再调查” | 第一次修复就定下了基调。从一开始就做对。 |
251
- | “确认修复有效后再补测试” | 未经测试的修复不可靠。先写测试才能证明有效。 |
252
- | “一次多修几处更省时间” | 无法定位哪一处真正生效,还会引入新缺陷。 |
253
- | “参考实现太长,我按自己的理解适配一下” | 一知半解必然导致缺陷。必须完整阅读。 |
254
- | “我已经看到问题了,直接修就行” | 看到表象 ≠ 理解根因。 |
255
- | “再试一次修复”(已失败 2 次以上) | 失败 3 次以上即为架构问题。应质疑模式本身,而非再次修补。 |
256
-
257
- ## 快速参考
258
-
259
- | 阶段 | 关键活动 | 成功标准 |
250
+ | "Issue is simple, don't need process" | Simple issues have root causes too. Process is fast for simple bugs. |
251
+ | "Emergency, no time for process" | Systematic debugging is FASTER than guess-and-check thrashing. |
252
+ | "Just try this first, then investigate" | First fix sets the pattern. Do it right from the start. |
253
+ | "I'll write test after confirming fix works" | Untested fixes don't stick. Test first proves it. |
254
+ | "Multiple fixes at once saves time" | Can't isolate what worked. Causes new bugs. |
255
+ | "Reference too long, I'll adapt the pattern" | Partial understanding guarantees bugs. Read it completely. |
256
+ | "I see the problem, let me fix it" | Seeing symptoms ≠ understanding root cause. |
257
+ | "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Question pattern, don't fix again. |
258
+
259
+ ## Quick Reference
260
+
261
+ | Phase | Key Activities | Success Criteria |
260
262
  |-------|---------------|------------------|
261
- | **1. 根因** | 阅读错误、复现、检查变更、收集证据 | 明确是什么、为什么 |
262
- | **2. 模式** | 寻找可用参照、对照比较 | 识别差异 |
263
- | **3. 假设** | 提出假设、最小化验证 | 假设被证实或被推翻并形成新假设 |
264
- | **4. 实现** | 编写用例、修复、验证 | 缺陷已解决、测试通过 |
263
+ | **1. Root Cause** | Read errors, reproduce, check changes, gather evidence | Understand WHAT and WHY |
264
+ | **2. Pattern** | Find working examples, compare | Identify differences |
265
+ | **3. Hypothesis** | Form theory, test minimally | Confirmed or new hypothesis |
266
+ | **4. Implementation** | Create test, fix, verify | Bug resolved, tests pass |
265
267
 
266
- ## 当流程揭示“无根因”时
268
+ ## When Process Reveals "No Root Cause"
267
269
 
268
- 若系统化调查表明问题确实源于环境、时序或外部因素:
270
+ If systematic investigation reveals issue is truly environmental, timing-dependent, or external:
269
271
 
270
- 1. 流程已走完
271
- 2. 记录已调查的内容
272
- 3. 实施相应的容错处理(重试、超时、错误提示)
273
- 4. 补充监控/日志以便后续调查
272
+ 1. You've completed the process
273
+ 2. Document what you investigated
274
+ 3. Implement appropriate handling (retry, timeout, error message)
275
+ 4. Add monitoring/logging for future investigation
274
276
 
275
- **但是:** 95% 所谓“无根因”的情况,都是调查不充分。
277
+ **But:** 95% of "no root cause" cases are incomplete investigation.
276
278
 
277
- ## 辅助技巧
279
+ ## Supporting Techniques
278
280
 
279
- 本目录下提供以下系统化调试的配套技巧:
281
+ These techniques are part of systematic debugging and available in this directory:
280
282
 
281
- - **`root-cause-tracing.md`** - 沿调用栈回溯追踪,直至找到最初触发点
282
- - **`defense-in-depth.md`** - 找到根因后在多层添加校验
283
- - **`condition-based-waiting.md`** - 用条件poll替代固定时延等待
283
+ - **`root-cause-tracing.md`** - Trace bugs backward through call stack to find original trigger
284
+ - **`defense-in-depth.md`** - Add validation at multiple layers after finding root cause
285
+ - **`condition-based-waiting.md`** - Replace arbitrary timeouts with condition polling
@@ -1,12 +1,12 @@
1
- # 基于条件的等待
1
+ # Condition-Based Waiting
2
2
 
3
- ## 概述
3
+ ## Overview
4
4
 
5
- 不稳定的测试往往依赖任意延时来猜测时机。这会引发竞态条件,导致测试在本地快速机器上通过,却在高负载或 CI 环境下失败。
5
+ Flaky tests often guess at timing with arbitrary delays. This creates race conditions where tests pass on fast machines but fail under load or in CI.
6
6
 
7
- **核心原则:** 等待你真正关心的条件满足,而不是猜测它需要多长时间。
7
+ **Core principle:** Wait for the actual condition you care about, not a guess about how long it takes.
8
8
 
9
- ## 适用场景
9
+ ## When to Use
10
10
 
11
11
  ```dot
12
12
  digraph when_to_use {
@@ -21,44 +21,43 @@ digraph when_to_use {
21
21
  }
22
22
  ```
23
23
 
24
- **适用于:**
25
- - 测试中存在任意延时(`setTimeout`、`sleep`、`time.sleep()`)
26
- - 测试表现不稳定(时而通过,在高负载下时而失败)
27
- - 测试在并行运行时超时
28
- - 等待异步操作完成
24
+ **Use when:**
25
+ - Tests have arbitrary delays (`setTimeout`, `sleep`, `time.sleep()`)
26
+ - Tests are flaky (pass sometimes, fail under load)
27
+ - Tests timeout when run in parallel
28
+ - Waiting for async operations to complete
29
29
 
30
- **不适用于:**
31
- - 测试真正的时序行为(防抖、节流间隔等)
32
- - 若使用任意延时,务必注释说明原因
30
+ **Don't use when:**
31
+ - Testing actual timing behavior (debounce, throttle intervals)
32
+ - Always document WHY if using arbitrary timeout
33
33
 
34
- ## 核心模式
34
+ ## Core Pattern
35
35
 
36
36
  ```typescript
37
- // [FAIL] 修改前:猜测时机
37
+ // [FAIL] BEFORE: Guessing at timing
38
38
  await new Promise(r => setTimeout(r, 50));
39
39
  const result = getResult();
40
40
  expect(result).toBeDefined();
41
41
 
42
- // [OK] 修改后:等待条件满足
42
+ // [OK] AFTER: Waiting for condition
43
43
  await waitFor(() => getResult() !== undefined);
44
44
  const result = getResult();
45
45
  expect(result).toBeDefined();
46
46
  ```
47
47
 
48
- ## 常用模式
48
+ ## Quick Patterns
49
49
 
50
- | 场景 | 模式 |
50
+ | Scenario | Pattern |
51
51
  |----------|---------|
52
- | 等待事件 | `waitFor(() => events.find(e => e.type === 'DONE'))` |
53
- | 等待状态 | `waitFor(() => machine.state === 'ready')` |
54
- | 等待数量 | `waitFor(() => items.length >= 5)` |
55
- | 等待文件 | `waitFor(() => fs.existsSync(path))` |
56
- | 复杂条件 | `waitFor(() => obj.ready && obj.value > 10)` |
52
+ | Wait for event | `waitFor(() => events.find(e => e.type === 'DONE'))` |
53
+ | Wait for state | `waitFor(() => machine.state === 'ready')` |
54
+ | Wait for count | `waitFor(() => items.length >= 5)` |
55
+ | Wait for file | `waitFor(() => fs.existsSync(path))` |
56
+ | Complex condition | `waitFor(() => obj.ready && obj.value > 10)` |
57
57
 
58
- ## 实现
59
-
60
- 通用poll函数:
58
+ ## Implementation
61
59
 
60
+ Generic polling function:
62
61
  ```typescript
63
62
  async function waitFor<T>(
64
63
  condition: () => T | undefined | null | false,
@@ -80,37 +79,37 @@ async function waitFor<T>(
80
79
  }
81
80
  ```
82
81
 
83
- 完整实现及领域专用辅助函数(`waitForEvent`、`waitForEventCount`、`waitForEventMatch`)请参阅本目录下的 `condition-based-waiting-example.ts`,均来自真实调试过程。
82
+ See `condition-based-waiting-example.ts` in this directory for complete implementation with domain-specific helpers (`waitForEvent`, `waitForEventCount`, `waitForEventMatch`) from actual debugging session.
84
83
 
85
- ## 常见错误
84
+ ## Common Mistakes
86
85
 
87
- **[FAIL] poll过快:** `setTimeout(check, 1)` - 浪费 CPU
88
- **[OK] 修正:** 每 10ms poll一次
86
+ **[FAIL] Polling too fast:** `setTimeout(check, 1)` - wastes CPU
87
+ **[OK] Fix:** Poll every 10ms
89
88
 
90
- **[FAIL] 无超时:** 条件始终不满足时会无限循环
91
- **[OK] 修正:** 始终设置超时,并给出清晰的错误信息
89
+ **[FAIL] No timeout:** Loop forever if condition never met
90
+ **[OK] Fix:** Always include timeout with clear error
92
91
 
93
- **[FAIL] 数据过期:** 在循环前缓存状态
94
- **[OK] 修正:** 在循环内调用 getter 获取最新数据
92
+ **[FAIL] Stale data:** Cache state before loop
93
+ **[OK] Fix:** Call getter inside loop for fresh data
95
94
 
96
- ## 何时应该使用任意延时
95
+ ## When Arbitrary Timeout IS Correct
97
96
 
98
97
  ```typescript
99
- // 工具每 100ms 触发一次 — 需要 2 次触发来验证部分输出
100
- await waitForEvent(manager, 'TOOL_STARTED'); // 第一步:等待条件满足
101
- await new Promise(r => setTimeout(r, 200)); // 第二步:等待时序行为
102
- // 200ms = 按 100ms 间隔计算的 2 次触发 — 已说明理由并加注注释
98
+ // Tool ticks every 100ms - need 2 ticks to verify partial output
99
+ await waitForEvent(manager, 'TOOL_STARTED'); // First: wait for condition
100
+ await new Promise(r => setTimeout(r, 200)); // Then: wait for timed behavior
101
+ // 200ms = 2 ticks at 100ms intervals - documented and justified
103
102
  ```
104
103
 
105
- **要求:**
106
- 1. 先等待触发条件满足
107
- 2. 基于已知的时序(而非猜测)
108
- 3. 注释说明原因
104
+ **Requirements:**
105
+ 1. First wait for triggering condition
106
+ 2. Based on known timing (not guessing)
107
+ 3. Comment explaining WHY
109
108
 
110
- ## 实际效果
109
+ ## Real-World Impact
111
110
 
112
- 来自调试实践(2025-10-03):
113
- - 横跨 3 个文件修复了 15 个不稳定测试
114
- - 通过率:60% → 100%
115
- - 执行时间:快 40%
116
- - 彻底消除竞态条件
111
+ From debugging session (2025-10-03):
112
+ - Fixed 15 flaky tests across 3 files
113
+ - Pass rate: 60% → 100%
114
+ - Execution time: 40% faster
115
+ - No more race conditions