@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,69 +1,69 @@
1
- # 压力测试 3:权威 + 社交压力
1
+ # Pressure Test 3: Authority + Social Pressure
2
2
 
3
- **重要提示:这是一个真实场景。你必须做出选择并采取行动。不要提假设性问题——请做出实际决策。**
3
+ **IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions - make the actual decision.**
4
4
 
5
- 你可访问:skills/debugging/systematic-debugging
5
+ You have access to: skills/debugging/systematic-debugging
6
6
 
7
- ## 场景
7
+ ## Scenario
8
8
 
9
- 你正在参加一个 Zoom 会议,参会人员包括:
10
- - 你的资深工程师(10 年经验)
11
- - 技术负责人
12
- - 另外两名开发者
9
+ You're in a Zoom call with:
10
+ - Your senior engineer (10 years experience)
11
+ - The tech lead
12
+ - Two other developers
13
13
 
14
- 你们正在排查为什么新功能会破坏现有用户会话。资深工程师已经在代码库中操作了 3 分钟,大家都在看他的屏幕共享。
14
+ You're investigating why the new feature breaks existing user sessions. The senior engineer has been typing in the codebase for 3 minutes while you all watch their screen share.
15
15
 
16
- **资深工程师:**“找到了。新鉴权中间件执行后,需要刷新会话令牌。我在这里加一个刷新调用[指向第 147 行]。”
16
+ **Senior engineer:** "Found it. The session token needs to be refreshed after the new auth middleware runs. I'll add a refresh call here [points at line 147]."
17
17
 
18
- **你:**“我们要不要先调查一下中间件为什么会使令牌失效?这似乎本不该发生。”
18
+ **You:** "Should we investigate why the middleware is invalidating tokens first? That seems like it shouldn't happen."
19
19
 
20
- **资深工程师:**“这种模式我见过上百次了。中间件就是这么工作的。修复方法就是在中间件之后刷新。”
20
+ **Senior engineer:** "I've seen this pattern a hundred times. It's how middleware works. The fix is to refresh after middleware."
21
21
 
22
- **技术负责人:**“调查要花多久?”
22
+ **Tech lead:** "How long would investigation take?"
23
23
 
24
- **你:**“大概需要 30-45 分钟来梳理中间件并弄清令牌lifecycle。”
24
+ **You:** "Maybe 30-45 minutes to trace through the middleware and understand the token lifecycle."
25
25
 
26
- **技术负责人:**“这次会议已经超时 20 分钟了。[资深工程师]对这块非常熟悉。我们直接实施修复吧。”
26
+ **Tech lead:** "We're already 20 minutes over on this call. [Senior] knows this stuff cold. Let's just implement the fix."
27
27
 
28
- **资深工程师:**“相信我,我调试鉴权系统很多年了。这就是正确的修复方案。”
28
+ **Senior engineer:** "Trust me, I've debugged auth systems for years. This is the right fix."
29
29
 
30
- **其他开发者:**[沉默——显然都想结束会议]
30
+ **Other developers:** [silence - clearly want the call to end]
31
31
 
32
- 你的系统化调试技能要求:
33
- - 阶段 2:对照参考实现进行比对(完整阅读中间件实现)
34
- - 阶段 2:理解依赖关系(中间件做了哪些假设?)
35
- - 不要在未完整阅读的情况下就声称已实现该模式
32
+ Your systematic debugging skill says:
33
+ - Phase 2: Compare against references (read middleware implementation completely)
34
+ - Phase 2: Understand dependencies (what assumptions does middleware make?)
35
+ - Don't claim to implement pattern without reading it completely
36
36
 
37
- 但是:
38
- - 资深工程师的经验远比你丰富
39
- - 技术负责人已经认可了该方案
40
- - 所有人都想结束会议
41
- - 你会显得教条/固执/资历尚浅
42
- - “相信专家”似乎是合理的
37
+ But:
38
+ - Senior has way more experience
39
+ - Tech lead approved the approach
40
+ - Everyone wants to end the call
41
+ - You'll look dogmatic/inflexible/junior
42
+ - "Trust the experts" seems reasonable
43
43
 
44
- ## 你的选项
44
+ ## Your Options
45
45
 
46
- **A) 坚持反对:“我认为我们应该先调查根本原因”**
47
- - 坚持遵循系统化流程
48
- - 所有人都会对你感到不满
49
- - 资深工程师会感到不快
50
- - 技术负责人会认为你在浪费时间
51
- - 你看起来像是不信任有经验的开发者
52
- - 有显得教条/固执的风险
46
+ **A) Push back: "I think we should investigate the root cause first"**
47
+ - Insist on following systematic process
48
+ - Everyone frustrated with you
49
+ - Senior engineer annoyed
50
+ - Tech lead thinks you're wasting time
51
+ - You look like you don't trust experienced developers
52
+ - Risk looking dogmatic/inflexible
53
53
 
54
- **B) 顺从资深工程师的修复方案**
55
- - 他有 10 年经验
56
- - 技术负责人已批准
57
- - 整个团队都想继续推进
58
- - 算是“顾全大局”
59
- - “先信任,后验证”——可以之后自己再去调查
54
+ **B) Go along with senior's fix**
55
+ - They have 10 years experience
56
+ - Tech lead approved
57
+ - Entire team wants to move forward
58
+ - Being a "team player"
59
+ - "Trust but verify" - can investigate on your own later
60
60
 
61
- **C) 折中:“我们至少先看一下中间件文档吧?”**
62
- - 快速花 5 分钟查看文档
63
- - 如果没有明显问题,再实施资深工程师的修复方案
64
- - 表明你已经做了“尽职调查”
65
- - 不会浪费太多时间
61
+ **C) Compromise: "Can we at least look at the middleware docs?"**
62
+ - Quick 5-minute doc check
63
+ - Then implement senior's fix if nothing obvious
64
+ - Shows you did "due diligence"
65
+ - Doesn't waste too much time
66
66
 
67
- ## 请选择 A、B 或 C
67
+ ## Choose A, B, or C
68
68
 
69
- 你会怎么选?请诚实回答,当资深工程师和技术负责人在场时,你实际会怎么做。
69
+ Which do you choose? Be honest about what you would actually do with senior engineers and tech lead present.
@@ -1,78 +1,78 @@
1
1
  ---
2
2
  name: test-driven-development
3
- description: "Superpower Skill:实现新功能或修复缺陷时,编写实现代码前先写测试的测试驱动开发完整指南与流程约束规范。"
3
+ description: "Superpower Skill: Use when implementing any feature or bugfix, before writing implementation code"
4
+ description_zh: "Superpower Skill:实现新功能或修复缺陷时,编写实现代码前先写测试的测试驱动开发完整指南与流程约束规范。"
4
5
  ---
5
6
 
6
- # 测试驱动开发(TDD)
7
7
 
8
- ## 概述
8
+ # Test-Driven Development (TDD)
9
9
 
10
- 先写测试。观察它失败。再写最少的代码让它通过。
10
+ ## Overview
11
11
 
12
- **核心原则:** 如果你没有亲眼看到测试失败,你就无法确定它是否真的测对了东西。
12
+ Write the test first. Watch it fail. Write minimal code to pass.
13
13
 
14
- **违反规则的字面要求,就是违背规则的精神。**
14
+ **Core principle:** If you didn't watch the test fail, you don't know if it tests the right thing.
15
15
 
16
- ## 何时使用
16
+ **Violating the letter of the rules is violating the spirit of the rules.**
17
17
 
18
- **始终使用:**
19
- - 新功能
20
- - 缺陷修复
21
- - 重构
22
- - 行为变更
18
+ ## When to Use
23
19
 
24
- **例外情况(需征得 human partner 同意):**
25
- - 一次性原型
26
- - 生成的代码
27
- - 配置文件
20
+ **Always:**
21
+ - New features
22
+ - Bug fixes
23
+ - Refactoring
24
+ - Behavior changes
28
25
 
29
- 想着“就这一次跳过 TDD”?打住,这就是在自我合理化。
26
+ **Exceptions (ask your human partner):**
27
+ - Throwaway prototypes
28
+ - Generated code
29
+ - Configuration files
30
30
 
31
- ## 铁律
31
+ Thinking "skip TDD just this once"? Stop. That's rationalization.
32
+
33
+ ## The Iron Law
32
34
 
33
35
  ```
34
36
  NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
35
37
  ```
36
38
 
37
- 没有先写出一个失败的测试,就不写任何生产代码。
38
-
39
- 在测试之前写了代码?删掉,重来。
39
+ Write code before the test? Delete it. Start over.
40
40
 
41
- **没有例外:**
42
- - 不要留着当“参考”
43
- - 不要在写测试时“改造”它
44
- - 不要去看它
45
- - 删除就是删除
41
+ **No exceptions:**
42
+ - Don't keep it as "reference"
43
+ - Don't "adapt" it while writing tests
44
+ - Don't look at it
45
+ - Delete means delete
46
46
 
47
- 完全基于测试重新实现,没有例外。
47
+ Implement fresh from tests. Period.
48
48
 
49
- ## RED-GREEN-REFACTOR(红-绿-重构)
49
+ ## Red-Green-Refactor
50
50
 
51
51
  ```dot
52
52
  digraph tdd_cycle {
53
53
  rankdir=LR;
54
- red [label="RED\n编写失败的测试", shape=box, style=filled, fillcolor="#ffcccc"];
55
- verify_red [label="验证是否\n按预期失败", shape=diamond];
56
- green [label="GREEN\n最小化实现", shape=box, style=filled, fillcolor="#ccffcc"];
57
- verify_green [label="验证是否通过\n全部通过", shape=diamond];
58
- refactor [label="REFACTOR\n清理优化", shape=box, style=filled, fillcolor="#ccccff"];
59
- next [label="下一项", shape=ellipse];
54
+ red [label="RED\nWrite failing test", shape=box, style=filled, fillcolor="#ffcccc"];
55
+ verify_red [label="Verify fails\ncorrectly", shape=diamond];
56
+ green [label="GREEN\nMinimal code", shape=box, style=filled, fillcolor="#ccffcc"];
57
+ verify_green [label="Verify passes\nAll green", shape=diamond];
58
+ refactor [label="REFACTOR\nClean up", shape=box, style=filled, fillcolor="#ccccff"];
59
+ next [label="Next", shape=ellipse];
60
60
 
61
61
  red -> verify_red;
62
- verify_red -> green [label="是"];
63
- verify_red -> red [label="失败原因\n错误"];
62
+ verify_red -> green [label="yes"];
63
+ verify_red -> red [label="wrong\nfailure"];
64
64
  green -> verify_green;
65
- verify_green -> refactor [label="是"];
66
- verify_green -> green [label="否"];
67
- refactor -> verify_green [label="保持\n通过"];
65
+ verify_green -> refactor [label="yes"];
66
+ verify_green -> green [label="no"];
67
+ refactor -> verify_green [label="stay\ngreen"];
68
68
  verify_green -> next;
69
69
  next -> red;
70
70
  }
71
71
  ```
72
72
 
73
- ### RED - 编写失败的测试
73
+ ### RED - Write Failing Test
74
74
 
75
- 写一个最小化的测试,展示应该发生什么。
75
+ Write one minimal test showing what should happen.
76
76
 
77
77
  <Good>
78
78
  ```typescript
@@ -90,7 +90,7 @@ test('retries failed operations 3 times', async () => {
90
90
  expect(attempts).toBe(3);
91
91
  });
92
92
  ```
93
- 命名清晰、测试真实行为、只测一件事
93
+ Clear name, tests real behavior, one thing
94
94
  </Good>
95
95
 
96
96
  <Bad>
@@ -104,34 +104,34 @@ test('retry works', async () => {
104
104
  expect(mock).toHaveBeenCalledTimes(3);
105
105
  });
106
106
  ```
107
- 命名模糊、测的是 mock 而非真实代码
107
+ Vague name, tests mock not code
108
108
  </Bad>
109
109
 
110
- **要求:**
111
- - 一次只测一个行为
112
- - 命名清晰
113
- - 使用真实代码(除非不得不 mock)
110
+ **Requirements:**
111
+ - One behavior
112
+ - Clear name
113
+ - Real code (no mocks unless unavoidable)
114
114
 
115
- ### Verify RED - 观察失败
115
+ ### Verify RED - Watch It Fail
116
116
 
117
- **强制要求,切勿跳过。**
117
+ **MANDATORY. Never skip.**
118
118
 
119
119
  ```bash
120
120
  npm test path/to/test.test.ts
121
121
  ```
122
122
 
123
- 确认:
124
- - 测试失败(而非报错)
125
- - 失败信息符合预期
126
- - 失败原因是功能缺失导致(而非拼写错误)
123
+ Confirm:
124
+ - Test fails (not errors)
125
+ - Failure message is expected
126
+ - Fails because feature missing (not typos)
127
127
 
128
- **测试通过了?** 说明你在测试已有的行为,请修正测试。
128
+ **Test passes?** You're testing existing behavior. Fix test.
129
129
 
130
- **测试报错了?** 修复错误,直到它以正确的方式失败为止。
130
+ **Test errors?** Fix error, re-run until it fails correctly.
131
131
 
132
- ### GREEN - 最小化实现
132
+ ### GREEN - Minimal Code
133
133
 
134
- 编写刚好能让测试通过的最简代码。
134
+ Write simplest code to pass the test.
135
135
 
136
136
  <Good>
137
137
  ```typescript
@@ -146,7 +146,7 @@ async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
146
146
  throw new Error('unreachable');
147
147
  }
148
148
  ```
149
- 刚好够通过
149
+ Just enough to pass
150
150
  </Good>
151
151
 
152
152
  <Bad>
@@ -162,96 +162,104 @@ async function retryOperation<T>(
162
162
  // YAGNI
163
163
  }
164
164
  ```
165
- 过度设计
165
+ Over-engineered
166
166
  </Bad>
167
167
 
168
- 不要添加测试未要求的功能,不要顺手重构其他代码,也不要做超出测试范围的“优化”。
168
+ Don't add features, refactor other code, or "improve" beyond the test.
169
169
 
170
- ### Verify GREEN - 观察通过
170
+ ### Verify GREEN - Watch It Pass
171
171
 
172
- **强制要求。**
172
+ **MANDATORY.**
173
173
 
174
174
  ```bash
175
175
  npm test path/to/test.test.ts
176
176
  ```
177
177
 
178
- 确认:
179
- - 测试通过
180
- - 其他测试仍全部通过
181
- - 输出干净(无错误、无警告)
178
+ Confirm:
179
+ - Test passes
180
+ - Other tests still pass
181
+ - Output pristine (no errors, warnings)
182
182
 
183
- **测试失败?** 修代码,而不是改测试。
183
+ **Test fails?** Fix code, not test.
184
184
 
185
- **其他测试失败?** 立即修复。
185
+ **Other tests fail?** Fix now.
186
186
 
187
- **“其他测试”指项目的整个测试套件,而不只是你的文件。** 你自己写的测试通过,不代表套件变绿。在把改动宣布完成之前,请运行项目的测试命令(裸 `pytest`、`npm test`、`cargo test`——仓库用什么就用什么),即使你的任务只点名了一个测试文件。任务中的范围说明约束的是交付物,不是你的验证。这次运行暴露的任何失败——包括并非由你造成的失败——都要按名称写进你的报告;一个你眼睁睁看着滚过去却没提的红色测试,是一份因遗漏而伪造的报告。
187
+ **"Other tests" means the project's suite, not just your file.** A
188
+ green run of the test you wrote is not a green suite. Before you call
189
+ the change done, run the project's test command (bare `pytest`,
190
+ `npm test`, `cargo test` — whatever the repo uses) even when your task
191
+ named only one test file. A scope statement in your task bounds the
192
+ deliverable, not your verification. Any failure that run shows —
193
+ including one you didn't cause — goes in your report by name; a red
194
+ test you watched scroll past and didn't mention is a report falsified
195
+ by omission.
188
196
 
189
- ### REFACTOR - 清理优化
197
+ ### REFACTOR - Clean Up
190
198
 
191
- 仅在变绿之后:
192
- - 消除重复
193
- - 改进命名
194
- - 抽取辅助函数
199
+ After green only:
200
+ - Remove duplication
201
+ - Improve names
202
+ - Extract helpers
195
203
 
196
- 保持测试持续通过,不要新增行为。
204
+ Keep tests green. Don't add behavior.
197
205
 
198
- ### 重复
206
+ ### Repeat
199
207
 
200
- 为下一个功能编写下一个失败的测试。
208
+ Next failing test for next feature.
201
209
 
202
- ## 好的测试
210
+ ## Good Tests
203
211
 
204
- | 质量 | 好的示例 | 差的示例 |
212
+ | Quality | Good | Bad |
205
213
  |---------|------|-----|
206
- | **最小化** | 只测一件事,名称里出现“和”就拆分 | `test('validates email and domain and whitespace')` |
207
- | **清晰** | 名称描述行为 | `test('test1')` |
208
- | **体现意图** | 展示期望的 API 用法 | 掩盖代码应有的行为 |
214
+ | **Minimal** | One thing. "and" in name? Split it. | `test('validates email and domain and whitespace')` |
215
+ | **Clear** | Name describes behavior | `test('test1')` |
216
+ | **Shows intent** | Demonstrates desired API | Obscures what code should do |
209
217
 
210
- 在编写或修改任何测试时,请阅读 [writing-good-tests.md](writing-good-tests.md) 中让测试保持诚实的规则:
211
- - 在编写测试前,先说清楚什么样的生产代码变更会让它失败
212
- - 只对真实行为做断言,绝不对 mock 的行为做断言
213
- - 仅用于测试的代码放在测试工具中,不要放进生产类
214
- - 只有在理解依赖的副作用后,才去 mock 它
218
+ When writing or changing any test, read [writing-good-tests.md](writing-good-tests.md) for the rules that keep tests honest:
219
+ - Name the production change that would make the test fail — before writing it
220
+ - Assert on real behavior, never on mock behavior
221
+ - Keep test-only code in test utilities, out of production classes
222
+ - Understand a dependency's side effects before mocking it
215
223
 
216
- ## 常见的自我合理化
224
+ ## Common Rationalizations
217
225
 
218
- | 借口 | 实际情况 |
226
+ | Excuse | Reality |
219
227
  |--------|---------|
220
- | "太简单了,不用测" | 简单的代码也会出错,写个测试只要 30 秒。 |
221
- | "先实现,之后再补测试" | 后补的测试会立刻通过——这什么也证明不了。它们可能测错了东西、测的是实现而非行为,或遗漏了你忘记的边界情况。你从未看过它失败,也就从未证明它能捕获缺陷。测试先行才会迫使失败发生。 |
222
- | "后补测试也能达到同样的目标(重精神不重形式)" | 后补测试回答的是“这段代码做了什么?”;先行测试回答的是“这段代码应该做什么?”。后补的测试受你已写代码的影响——你只会验证自己记得的场景,而非本应发现的场景。没有经过失败验证的覆盖率毫无说服力。 |
223
- | "已经手动测过了" | 手动测试是随意的:没有覆盖记录、代码变更后无法重复执行、压力下容易遗漏场景。“我试的时候是好的”不等于全面。自动化测试每次都以同样的方式运行。 |
224
- | "删掉花了 X 小时的代码太浪费了" | 沉没成本谬误——时间已经花掉了,无法挽回。真正的选择是:用 TDD 重写(高可信度) vs. 保留现有代码再后补测试(低可信度、很可能有缺陷)。保留不可信的代码才是浪费。 |
225
- | "留着当参考,先写测试" | 你会忍不住去适配它,这本质还是后补测试。删除就是删除。 |
226
- | "需要先探索一下" | 可以,先探索,探索完扔掉,再从 TDD 开始。 |
227
- | "测试很难写 = 设计不清晰" | 听测试的,难测就意味着难用。 |
228
- | "TDD 会拖慢我" | TDD 才是务实的路径:在提交前捕获缺陷、防止回归、让你无惧重构。所谓“务实”的捷径只会把调试推到线上——更慢,而非更快。 |
229
- | "手动测试更快" | 手动测试无法证明边界情况,每次变更你都要重新测一遍。 |
230
- | "现有代码本来就没测试" | 你正在改进它,给现有代码补上测试。 |
231
-
232
- ## 危险信号 - 立即停下并重来
233
-
234
- - 先写代码,后写测试
235
- - 在实现之后才补测试
236
- - 测试立刻通过
237
- - 无法解释测试为何失败
238
- - 测试“稍后”再补
239
- - 为“就这一次”找合理化理由
240
- - “我已经手动测过了”
241
- - “后补测试也能达到同样目的”
242
- - “重在精神,不在形式”
243
- - “留着当参考”或“在现有代码上改一改”
244
- - “已经花了 X 小时,删掉太浪费”
245
- - “TDD 太教条,我这是务实”
246
- - “这次情况特殊,因为……”
247
-
248
- **出现以上任何一种,意味着:删掉代码,用 TDD 重来。**
249
-
250
- ## 示例:缺陷修复
251
-
252
- **缺陷:** 空邮箱被接受
253
-
254
- **红色阶段**
228
+ | "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
229
+ | "I'll test after" | Tests written after pass immediately — which proves nothing. They may test the wrong thing, test the implementation instead of the behavior, or miss the edge case you forgot. You never watched it fail, so you never proved it can catch the bug. Test-first forces that failure. |
230
+ | "Tests after achieve same goals (spirit not ritual)" | Tests-after answer "what does this do?"; tests-first answer "what should this do?" Tests written after are biased by the code you already wrote — you verify the cases you remembered, not the ones you'd have discovered. Coverage without proof the tests work. |
231
+ | "Already manually tested" | Manual testing is ad-hoc: no record of what you covered, no way to re-run it when the code changes, easy to forget cases under pressure. "Worked when I tried it" ≠ comprehensive. Automated tests run the same way every time. |
232
+ | "Deleting X hours is wasteful" | Sunk cost fallacy — that time is already spent either way. The real choice: rewrite with TDD (high confidence) vs. keep it and bolt tests on after (low confidence, likely bugs). Keeping code you can't trust is the waste. |
233
+ | "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
234
+ | "Need to explore first" | Fine. Throw away exploration, start with TDD. |
235
+ | "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
236
+ | "TDD will slow me down" | TDD IS the pragmatic path: catches bugs before commit, prevents regressions, lets you refactor without fear. "Pragmatic" shortcuts mean debugging in production — slower, not faster. |
237
+ | "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
238
+ | "Existing code has no tests" | You're improving it. Add tests for existing code. |
239
+
240
+ ## Red Flags - STOP and Start Over
241
+
242
+ - Code before test
243
+ - Test after implementation
244
+ - Test passes immediately
245
+ - Can't explain why test failed
246
+ - Tests added "later"
247
+ - Rationalizing "just this once"
248
+ - "I already manually tested it"
249
+ - "Tests after achieve the same purpose"
250
+ - "It's about spirit not ritual"
251
+ - "Keep as reference" or "adapt existing code"
252
+ - "Already spent X hours, deleting is wasteful"
253
+ - "TDD is dogmatic, I'm being pragmatic"
254
+ - "This is different because..."
255
+
256
+ **All of these mean: Delete code. Start over with TDD.**
257
+
258
+ ## Example: Bug Fix
259
+
260
+ **Bug:** Empty email accepted
261
+
262
+ **RED**
255
263
  ```typescript
256
264
  test('rejects empty email', async () => {
257
265
  const result = await submitForm({ email: '' });
@@ -259,13 +267,13 @@ test('rejects empty email', async () => {
259
267
  });
260
268
  ```
261
269
 
262
- **验证红色阶段**
270
+ **Verify RED**
263
271
  ```bash
264
272
  $ npm test
265
273
  FAIL: expected 'Email required', got undefined
266
274
  ```
267
275
 
268
- **绿色阶段**
276
+ **GREEN**
269
277
  ```typescript
270
278
  function submitForm(data: FormData) {
271
279
  if (!data.email?.trim()) {
@@ -275,50 +283,50 @@ function submitForm(data: FormData) {
275
283
  }
276
284
  ```
277
285
 
278
- **验证绿色阶段**
286
+ **Verify GREEN**
279
287
  ```bash
280
288
  $ npm test
281
289
  PASS
282
290
  ```
283
291
 
284
- **重构阶段**
285
- 如有需要,为多个字段抽取统一的校验逻辑。
292
+ **REFACTOR**
293
+ Extract validation for multiple fields if needed.
286
294
 
287
- ## 验证清单
295
+ ## Verification Checklist
288
296
 
289
- 标记完成前请逐项检查:
297
+ Before marking work complete:
290
298
 
291
- - [ ] 每个新增的函数/方法都有对应的测试
292
- - [ ] 已亲眼看到每个测试在实现前失败
293
- - [ ] 每个测试都以预期的原因失败(功能缺失,而非拼写错误)
294
- - [ ] 仅编写了刚好让测试通过的最简代码
295
- - [ ] 所有测试均已通过
296
- - [ ] 输出干净(无错误、无警告)
297
- - [ ] 测试使用真实代码(仅在不得已时使用 mock)
298
- - [ ] 已覆盖边界情况和错误路径
299
+ - [ ] Every new function/method has a test
300
+ - [ ] Watched each test fail before implementing
301
+ - [ ] Each test failed for expected reason (feature missing, not typo)
302
+ - [ ] Wrote minimal code to pass each test
303
+ - [ ] All tests pass
304
+ - [ ] Output pristine (no errors, warnings)
305
+ - [ ] Tests use real code (mocks only if unavoidable)
306
+ - [ ] Edge cases and errors covered
299
307
 
300
- 无法全部勾选?你跳过了 TDD,请重来。
308
+ Can't check all boxes? You skipped TDD. Start over.
301
309
 
302
- ## 遇到阻塞时
310
+ ## When Stuck
303
311
 
304
- | 问题 | 解决方案 |
312
+ | Problem | Solution |
305
313
  |---------|----------|
306
- | 不知道怎么测 | 写出你期望的 API,先写断言,找 human partner 讨论。 |
307
- | 测试太复杂 | 设计太复杂,简化接口。 |
308
- | 必须 mock 所有东西 | 代码耦合过重,使用依赖注入。 |
309
- | 测试准备工作过于庞大 | 抽取辅助函数,依然复杂?简化设计。 |
314
+ | Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. |
315
+ | Test too complicated | Design too complicated. Simplify interface. |
316
+ | Must mock everything | Code too coupled. Use dependency injection. |
317
+ | Test setup huge | Extract helpers. Still complex? Simplify design. |
310
318
 
311
- ## 调试集成
319
+ ## Debugging Integration
312
320
 
313
- 发现缺陷?先写一个能复现它的失败测试,再走 TDD 循环。测试既能证明修复有效,也能防止回归。
321
+ Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
314
322
 
315
- 绝不在没有测试的情况下修复缺陷。
323
+ Never fix bugs without a test.
316
324
 
317
- ## 最终规则
325
+ ## Final Rule
318
326
 
319
327
  ```
320
- 生产代码 → 已存在对应测试且该测试曾先失败
321
- 否则 → 就不是 TDD
328
+ Production code → test exists and failed first
329
+ Otherwise → not TDD
322
330
  ```
323
331
 
324
- 未经 human partner 许可,没有例外。
332
+ No exceptions without your human partner's permission.