@wenaixi/dsh-superpower 7.4.1 → 7.5.1
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 +110 -105
- package/README.zh.md +216 -0
- package/lib/catalog.d.ts +8 -2
- package/lib/catalog.d.ts.map +1 -1
- package/lib/catalog.js +64 -9
- package/lib/catalog.js.map +1 -1
- package/lib/client.js +68 -21
- package/lib/document.d.ts +8 -2
- package/lib/document.d.ts.map +1 -1
- package/lib/document.js +14 -4
- package/lib/document.js.map +1 -1
- package/lib/superpowers.d.ts +2 -0
- package/lib/superpowers.d.ts.map +1 -1
- package/lib/superpowers.js +8 -0
- package/lib/superpowers.js.map +1 -1
- package/lib/switches.d.ts +2 -10
- package/lib/switches.d.ts.map +1 -1
- package/lib/switches.js +29 -5
- package/lib/switches.js.map +1 -1
- package/package.json +3 -3
- package/skills/brainstorming/SKILL.md +235 -171
- package/skills/brainstorming/spec-document-reviewer-prompt.md +27 -25
- package/skills/brainstorming/visual-companion.md +65 -69
- package/skills/diagnosing-superpowers/SKILL.md +107 -43
- package/skills/diagnosing-superpowers/prompts/analyst-common.md +32 -18
- package/skills/diagnosing-superpowers/prompts/cost-and-time.md +25 -9
- package/skills/diagnosing-superpowers/prompts/plan-adherence.md +26 -12
- package/skills/diagnosing-superpowers/prompts/quality-evidence.md +23 -8
- package/skills/diagnosing-superpowers/prompts/repeated-work.md +25 -14
- package/skills/diagnosing-superpowers/prompts/request-conflicts.md +18 -9
- package/skills/diagnosing-superpowers/prompts/scrub-audit.md +23 -10
- package/skills/diagnosing-superpowers/prompts/scrub.md +25 -12
- package/skills/diagnosing-superpowers/prompts/similar-session.md +30 -22
- package/skills/diagnosing-superpowers/prompts/skill-timeline.md +26 -12
- package/skills/diagnosing-superpowers/prompts/stumbles.md +24 -12
- package/skills/diagnosing-superpowers/references/context-safety.md +15 -7
- package/skills/diagnosing-superpowers/references/github-issues.md +17 -9
- package/skills/diagnosing-superpowers/references/redaction-policy.md +27 -15
- package/skills/diagnosing-superpowers/references/session-discovery.md +31 -20
- package/skills/diagnosing-superpowers/templates/bundle-README.md +66 -40
- package/skills/diagnosing-superpowers/templates/case.md +49 -42
- package/skills/diagnosing-superpowers/templates/issue.md +32 -26
- package/skills/diagnosing-superpowers/templates/report.md +54 -48
- package/skills/dispatching-parallel-agents/SKILL.md +92 -90
- package/skills/executing-plans/SKILL.md +345 -197
- package/skills/finishing-a-development-branch/SKILL.md +107 -82
- package/skills/receiving-code-review/SKILL.md +129 -127
- package/skills/requesting-code-review/SKILL.md +52 -50
- package/skills/requesting-code-review/code-reviewer.md +132 -111
- package/skills/subagent-driven-development/SKILL.md +521 -298
- package/skills/subagent-driven-development/implementer-prompt.md +138 -117
- package/skills/subagent-driven-development/re-review-prompt.md +80 -48
- package/skills/subagent-driven-development/task-reviewer-prompt.md +189 -110
- package/skills/systematic-debugging/CREATION-LOG.md +85 -85
- package/skills/systematic-debugging/SKILL.md +221 -219
- package/skills/systematic-debugging/condition-based-waiting.md +48 -49
- package/skills/systematic-debugging/defense-in-depth.md +46 -46
- package/skills/systematic-debugging/root-cause-tracing.md +63 -63
- package/skills/systematic-debugging/test-academic.md +10 -10
- package/skills/systematic-debugging/test-pressure-1.md +40 -40
- package/skills/systematic-debugging/test-pressure-2.md +58 -58
- package/skills/systematic-debugging/test-pressure-3.md +48 -48
- package/skills/test-driven-development/SKILL.md +161 -153
- package/skills/test-driven-development/writing-good-tests.md +137 -84
- package/skills/using-git-worktrees/SKILL.md +74 -72
- package/skills/using-superpowers/SKILL.md +40 -39
- package/skills/using-superpowers/references/dsh-tools.md +36 -36
- package/skills/verification-before-completion/SKILL.md +85 -83
- package/skills/writing-plans/SKILL.md +123 -84
- package/skills/writing-skills/SKILL.md +419 -417
- package/skills/writing-skills/persuasion-principles.md +118 -118
- package/skills/writing-skills/testing-skills-with-subagents.md +190 -190
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
#
|
|
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
|
-
|
|
5
|
+
You have access to: skills/debugging/systematic-debugging
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Scenario
|
|
8
8
|
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
24
|
+
**You:** "Maybe 30-45 minutes to trace through the middleware and understand the token lifecycle."
|
|
25
25
|
|
|
26
|
-
|
|
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
|
-
-
|
|
34
|
-
-
|
|
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
|
-
-
|
|
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
|
-
-
|
|
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
|
-
##
|
|
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
|
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
20
|
+
**Always:**
|
|
21
|
+
- New features
|
|
22
|
+
- Bug fixes
|
|
23
|
+
- Refactoring
|
|
24
|
+
- Behavior changes
|
|
28
25
|
|
|
29
|
-
|
|
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
|
-
##
|
|
49
|
+
## Red-Green-Refactor
|
|
50
50
|
|
|
51
51
|
```dot
|
|
52
52
|
digraph tdd_cycle {
|
|
53
53
|
rankdir=LR;
|
|
54
|
-
red [label="RED\
|
|
55
|
-
verify_red [label="
|
|
56
|
-
green [label="GREEN\
|
|
57
|
-
verify_green [label="
|
|
58
|
-
refactor [label="REFACTOR\
|
|
59
|
-
next [label="
|
|
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="
|
|
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="
|
|
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
|
-
|
|
107
|
+
Vague name, tests mock not code
|
|
108
108
|
</Bad>
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
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
|
-
|
|
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
|
-
|
|
|
207
|
-
|
|
|
208
|
-
|
|
|
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
|
-
|
|
211
|
-
-
|
|
212
|
-
-
|
|
213
|
-
-
|
|
214
|
-
-
|
|
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
|
-
| "
|
|
221
|
-
| "
|
|
222
|
-
| "
|
|
223
|
-
| "
|
|
224
|
-
| "
|
|
225
|
-
| "
|
|
226
|
-
| "
|
|
227
|
-
| "
|
|
228
|
-
| "TDD
|
|
229
|
-
| "
|
|
230
|
-
| "
|
|
231
|
-
|
|
232
|
-
##
|
|
233
|
-
|
|
234
|
-
-
|
|
235
|
-
-
|
|
236
|
-
-
|
|
237
|
-
-
|
|
238
|
-
-
|
|
239
|
-
-
|
|
240
|
-
-
|
|
241
|
-
-
|
|
242
|
-
-
|
|
243
|
-
-
|
|
244
|
-
-
|
|
245
|
-
-
|
|
246
|
-
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
- [ ]
|
|
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
|
-
|
|
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
|
-
|
|
|
307
|
-
|
|
|
308
|
-
|
|
|
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
|
-
|
|
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
|
-
|
|
328
|
+
Production code → test exists and failed first
|
|
329
|
+
Otherwise → not TDD
|
|
322
330
|
```
|
|
323
331
|
|
|
324
|
-
|
|
332
|
+
No exceptions without your human partner's permission.
|