sdtk-code-kit 0.2.0 → 0.2.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.
Files changed (75) hide show
  1. package/README.md +201 -201
  2. package/assets/manifest/toolkit-bundle.manifest.json +147 -147
  3. package/assets/manifest/toolkit-bundle.sha256.txt +28 -28
  4. package/assets/toolkit/toolkit/AGENTS.md +219 -219
  5. package/assets/toolkit/toolkit/install.ps1 +156 -156
  6. package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +78 -78
  7. package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +150 -150
  8. package/assets/toolkit/toolkit/scripts/uninstall-claude-skills.ps1 +62 -62
  9. package/assets/toolkit/toolkit/scripts/uninstall-codex-skills.ps1 +82 -82
  10. package/assets/toolkit/toolkit/sdtk-spec.config.json +6 -6
  11. package/assets/toolkit/toolkit/sdtk-spec.config.profiles.example.json +12 -12
  12. package/assets/toolkit/toolkit/skills/code-brainstorm/SKILL.md +55 -55
  13. package/assets/toolkit/toolkit/skills/code-debug/SKILL.md +296 -296
  14. package/assets/toolkit/toolkit/skills/code-debug/references/root-cause-tracing.md +68 -68
  15. package/assets/toolkit/toolkit/skills/code-discover/SKILL.md +54 -54
  16. package/assets/toolkit/toolkit/skills/code-execute/SKILL.md +74 -74
  17. package/assets/toolkit/toolkit/skills/code-finish/SKILL.md +205 -205
  18. package/assets/toolkit/toolkit/skills/code-parallel/SKILL.md +64 -64
  19. package/assets/toolkit/toolkit/skills/code-parallel/references/code-quality-reviewer-prompt.md +26 -26
  20. package/assets/toolkit/toolkit/skills/code-parallel/references/implementer-prompt.md +113 -113
  21. package/assets/toolkit/toolkit/skills/code-parallel/references/spec-reviewer-prompt.md +61 -61
  22. package/assets/toolkit/toolkit/skills/code-plan/SKILL.md +85 -85
  23. package/assets/toolkit/toolkit/skills/code-review/SKILL.md +79 -79
  24. package/assets/toolkit/toolkit/skills/code-review/references/checklist.md +125 -125
  25. package/assets/toolkit/toolkit/skills/code-review/references/code-reviewer.md +146 -146
  26. package/assets/toolkit/toolkit/skills/code-ship/SKILL.md +52 -52
  27. package/assets/toolkit/toolkit/skills/code-tdd/SKILL.md +378 -378
  28. package/assets/toolkit/toolkit/skills/code-tdd/references/testing-anti-patterns.md +299 -299
  29. package/assets/toolkit/toolkit/skills/code-verify/SKILL.md +144 -144
  30. package/assets/toolkit/toolkit/skills/code-worktree/SKILL.md +228 -228
  31. package/assets/toolkit/toolkit/templates/CODE_WORKFLOW_TEMPLATE.md +140 -140
  32. package/bin/sdtk-code.js +14 -14
  33. package/package.json +44 -44
  34. package/src/commands/build.js +53 -53
  35. package/src/commands/doctor.js +51 -51
  36. package/src/commands/generate.js +11 -11
  37. package/src/commands/guardrails.js +215 -123
  38. package/src/commands/help.js +244 -244
  39. package/src/commands/init.js +98 -98
  40. package/src/commands/plan.js +53 -53
  41. package/src/commands/readiness.js +77 -77
  42. package/src/commands/resume.js +61 -61
  43. package/src/commands/runtime.js +224 -224
  44. package/src/commands/ship.js +59 -59
  45. package/src/commands/sleep.js +132 -0
  46. package/src/commands/start.js +89 -89
  47. package/src/commands/status.js +77 -77
  48. package/src/commands/update.js +11 -11
  49. package/src/commands/verify.js +71 -71
  50. package/src/index.js +108 -104
  51. package/src/lib/args.js +107 -107
  52. package/src/lib/errors.js +41 -41
  53. package/src/lib/powershell.js +65 -65
  54. package/src/lib/project-target-guard.js +53 -53
  55. package/src/lib/scope.js +72 -72
  56. package/src/lib/ship-readiness.js +281 -281
  57. package/src/lib/sleep-plan.js +175 -0
  58. package/src/lib/sleep-report.js +229 -0
  59. package/src/lib/toolkit-payload.js +72 -72
  60. package/src/lib/trust-events.js +166 -166
  61. package/src/lib/trust-file-scope.js +154 -154
  62. package/src/lib/trust-policy.js +212 -212
  63. package/src/lib/trust-redact.js +35 -35
  64. package/src/lib/trust-trace.js +179 -179
  65. package/src/lib/update.js +344 -344
  66. package/src/lib/workflow-artifact.js +503 -503
  67. package/src/lib/workflow-build.js +127 -127
  68. package/src/lib/workflow-doctor.js +83 -83
  69. package/src/lib/workflow-handoff.js +1029 -1029
  70. package/src/lib/workflow-intake.js +101 -101
  71. package/src/lib/workflow-plan.js +193 -193
  72. package/src/lib/workflow-review-packet.js +650 -650
  73. package/src/lib/workflow-ship.js +213 -213
  74. package/src/lib/workflow-state.js +438 -438
  75. package/src/lib/workflow-verify.js +393 -393
@@ -1,378 +1,378 @@
1
- ---
2
- name: code-tdd
3
- description: Test-driven development. Use before writing any implementation code -- write a failing test first, make it pass, then refactor.
4
- ---
5
-
6
- # Code TDD
7
-
8
- ## Critical Constraints
9
- - I do not write or keep production code unless I watched the relevant test fail first.
10
- - I do not treat tests written after implementation as equivalent to test-first discipline.
11
-
12
-
13
- ## Overview
14
- Write the test first. Watch it fail. Write minimal code to pass.
15
-
16
- **Core principle:** If you didn't watch the test fail, you don't know if it tests the right thing.
17
-
18
- **Violating the letter of the rules is violating the spirit of the rules.**
19
-
20
- ## When to Use
21
-
22
- **Always:**
23
- - New features
24
- - Bug fixes
25
- - Refactoring
26
- - Behavior changes
27
-
28
- **Exceptions (ask the user):**
29
- - Throwaway prototypes
30
- - Generated code
31
- - Configuration files
32
-
33
- Thinking "skip TDD just this once"? Stop. That's rationalization.
34
-
35
- ## Procedure
36
- Run the red-green-refactor loop in order: write one failing test, verify the failure is correct, add the minimum code to pass, then refactor while keeping tests green. If any step is skipped, delete the unverified code and restart from the failing test.
37
-
38
- ## The Iron Law
39
-
40
- ```
41
- NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
42
- ```
43
-
44
- Write code before the test? Delete it. Start over.
45
-
46
- **No exceptions:**
47
- - Don't keep it as "reference"
48
- - Don't "adapt" it while writing tests
49
- - Don't look at it
50
- - Delete means delete
51
-
52
- Implement fresh from tests. Period.
53
-
54
- ## Red-Green-Refactor
55
-
56
- ```dot
57
- digraph tdd_cycle {
58
- rankdir=LR;
59
- red [label="RED\nWrite failing test", shape=box, style=filled, fillcolor="#ffcccc"];
60
- verify_red [label="Verify fails\ncorrectly", shape=diamond];
61
- green [label="GREEN\nMinimal code", shape=box, style=filled, fillcolor="#ccffcc"];
62
- verify_green [label="Verify passes\nAll green", shape=diamond];
63
- refactor [label="REFACTOR\nClean up", shape=box, style=filled, fillcolor="#ccccff"];
64
- next [label="Next", shape=ellipse];
65
-
66
- red -> verify_red;
67
- verify_red -> green [label="yes"];
68
- verify_red -> red [label="wrong\nfailure"];
69
- green -> verify_green;
70
- verify_green -> refactor [label="yes"];
71
- verify_green -> green [label="no"];
72
- refactor -> verify_green [label="stay\ngreen"];
73
- verify_green -> next;
74
- next -> red;
75
- }
76
- ```
77
-
78
- ### RED - Write Failing Test
79
-
80
- Write one minimal test showing what should happen.
81
-
82
- <Good>
83
- ```typescript
84
- test('retries failed operations 3 times', async () => {
85
- let attempts = 0;
86
- const operation = () => {
87
- attempts++;
88
- if (attempts < 3) throw new Error('fail');
89
- return 'success';
90
- };
91
-
92
- const result = await retryOperation(operation);
93
-
94
- expect(result).toBe('success');
95
- expect(attempts).toBe(3);
96
- });
97
- ```
98
- Clear name, tests real behavior, one thing
99
- </Good>
100
-
101
- <Bad>
102
- ```typescript
103
- test('retry works', async () => {
104
- const mock = jest.fn()
105
- .mockRejectedValueOnce(new Error())
106
- .mockRejectedValueOnce(new Error())
107
- .mockResolvedValueOnce('success');
108
- await retryOperation(mock);
109
- expect(mock).toHaveBeenCalledTimes(3);
110
- });
111
- ```
112
- Vague name, tests mock not code
113
- </Bad>
114
-
115
- **Requirements:**
116
- - One behavior
117
- - Clear name
118
- - Real code (no mocks unless unavoidable)
119
-
120
- ### Verify RED - Watch It Fail
121
-
122
- **MANDATORY. Never skip.**
123
-
124
- ```bash
125
- npm test path/to/test.test.ts
126
- ```
127
-
128
- Confirm:
129
- - Test fails (not errors)
130
- - Failure message is expected
131
- - Fails because feature missing (not typos)
132
-
133
- **Test passes?** You're testing existing behavior. Fix test.
134
-
135
- **Test errors?** Fix error, re-run until it fails correctly.
136
-
137
- ### GREEN - Minimal Code
138
-
139
- Write simplest code to pass the test.
140
-
141
- <Good>
142
- ```typescript
143
- async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
144
- for (let i = 0; i < 3; i++) {
145
- try {
146
- return await fn();
147
- } catch (e) {
148
- if (i === 2) throw e;
149
- }
150
- }
151
- throw new Error('unreachable');
152
- }
153
- ```
154
- Just enough to pass
155
- </Good>
156
-
157
- <Bad>
158
- ```typescript
159
- async function retryOperation<T>(
160
- fn: () => Promise<T>,
161
- options?: {
162
- maxRetries?: number;
163
- backoff?: 'linear' | 'exponential';
164
- onRetry?: (attempt: number) => void;
165
- }
166
- ): Promise<T> {
167
- // YAGNI
168
- }
169
- ```
170
- Over-engineered
171
- </Bad>
172
-
173
- Don't add features, refactor other code, or "improve" beyond the test.
174
-
175
- ### Verify GREEN - Watch It Pass
176
-
177
- **MANDATORY.**
178
-
179
- ```bash
180
- npm test path/to/test.test.ts
181
- ```
182
-
183
- Confirm:
184
- - Test passes
185
- - Other tests still pass
186
- - Output pristine (no errors, warnings)
187
-
188
- **Test fails?** Fix code, not test.
189
-
190
- **Other tests fail?** Fix now.
191
-
192
- ### REFACTOR - Clean Up
193
-
194
- After green only:
195
- - Remove duplication
196
- - Improve names
197
- - Extract helpers
198
-
199
- Keep tests green. Don't add behavior.
200
-
201
- ### Repeat
202
-
203
- Next failing test for next feature.
204
-
205
- ## Good Tests
206
-
207
- | Quality | Good | Bad |
208
- |---------|------|-----|
209
- | **Minimal** | One thing. "and" in name? Split it. | `test('validates email and domain and whitespace')` |
210
- | **Clear** | Name describes behavior | `test('test1')` |
211
- | **Shows intent** | Demonstrates desired API | Obscures what code should do |
212
-
213
- ## Why Order Matters
214
-
215
- **"I'll write tests after to verify it works"**
216
-
217
- Tests written after code pass immediately. Passing immediately proves nothing:
218
- - Might test wrong thing
219
- - Might test implementation, not behavior
220
- - Might miss edge cases you forgot
221
- - You never saw it catch the bug
222
-
223
- Test-first forces you to see the test fail, proving it actually tests something.
224
-
225
- **"I already manually tested all the edge cases"**
226
-
227
- Manual testing is ad-hoc. You think you tested everything but:
228
- - No record of what you tested
229
- - Can't re-run when code changes
230
- - Easy to forget cases under pressure
231
- - "It worked when I tried it" comprehensive
232
-
233
- Automated tests are systematic. They run the same way every time.
234
-
235
- **"Deleting X hours of work is wasteful"**
236
-
237
- Sunk cost fallacy. The time is already gone. Your choice now:
238
- - Delete and rewrite with TDD (X more hours, high confidence)
239
- - Keep it and add tests after (30 min, low confidence, likely bugs)
240
-
241
- The "waste" is keeping code you can't trust. Working code without real tests is technical debt.
242
-
243
- **"TDD is dogmatic, being pragmatic means adapting"**
244
-
245
- TDD IS pragmatic:
246
- - Finds bugs before commit (faster than debugging after)
247
- - Prevents regressions (tests catch breaks immediately)
248
- - Documents behavior (tests show how to use code)
249
- - Enables refactoring (change freely, tests catch breaks)
250
-
251
- "Pragmatic" shortcuts = debugging in production = slower.
252
-
253
- **"Tests after achieve the same goals - it's spirit not ritual"**
254
-
255
- No. Tests-after answer "What does this do?" Tests-first answer "What should this do?"
256
-
257
- Tests-after are biased by your implementation. You test what you built, not what's required. You verify remembered edge cases, not discovered ones.
258
-
259
- Tests-first force edge case discovery before implementing. Tests-after verify you remembered everything (you didn't).
260
-
261
- 30 minutes of tests after TDD. You get coverage, lose proof tests work.
262
-
263
- ## Common Rationalizations
264
-
265
- | Excuse | Reality |
266
- |--------|---------|
267
- | "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
268
- | "I'll test after" | Tests passing immediately prove nothing. |
269
- | "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
270
- | "Already manually tested" | Ad-hoc systematic. No record, can't re-run. |
271
- | "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
272
- | "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
273
- | "Need to explore first" | Fine. Throw away exploration, start with TDD. |
274
- | "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
275
- | "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
276
- | "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
277
- | "Existing code has no tests" | You're improving it. Add tests for existing code. |
278
-
279
- ## Red Flags - STOP and Start Over
280
-
281
- - Code before test
282
- - Test after implementation
283
- - Test passes immediately
284
- - Can't explain why test failed
285
- - Tests added "later"
286
- - Rationalizing "just this once"
287
- - "I already manually tested it"
288
- - "Tests after achieve the same purpose"
289
- - "It's about spirit not ritual"
290
- - "Keep as reference" or "adapt existing code"
291
- - "Already spent X hours, deleting is wasteful"
292
- - "TDD is dogmatic, I'm being pragmatic"
293
- - "This is different because..."
294
-
295
- **All of these mean: Delete code. Start over with TDD.**
296
-
297
- ## Example: Bug Fix
298
-
299
- **Bug:** Empty email accepted
300
-
301
- **RED**
302
- ```typescript
303
- test('rejects empty email', async () => {
304
- const result = await submitForm({ email: '' });
305
- expect(result.error).toBe('Email required');
306
- });
307
- ```
308
-
309
- **Verify RED**
310
- ```bash
311
- $ npm test
312
- FAIL: expected 'Email required', got undefined
313
- ```
314
-
315
- **GREEN**
316
- ```typescript
317
- function submitForm(data: FormData) {
318
- if (!data.email?.trim()) {
319
- return { error: 'Email required' };
320
- }
321
- // ...
322
- }
323
- ```
324
-
325
- **Verify GREEN**
326
- ```bash
327
- $ npm test
328
- PASS
329
- ```
330
-
331
- **REFACTOR**
332
- Extract validation for multiple fields if needed.
333
-
334
- ## Verification Checklist
335
-
336
- Before marking work complete:
337
-
338
- - [ ] Every new function/method has a test
339
- - [ ] Watched each test fail before implementing
340
- - [ ] Each test failed for expected reason (feature missing, not typo)
341
- - [ ] Wrote minimal code to pass each test
342
- - [ ] All tests pass
343
- - [ ] Output pristine (no errors, warnings)
344
- - [ ] Tests use real code (mocks only if unavoidable)
345
- - [ ] Edge cases and errors covered
346
-
347
- Can't check all boxes? You skipped TDD. Start over.
348
-
349
- ## When Stuck
350
-
351
- | Problem | Solution |
352
- |---------|----------|
353
- | Don't know how to test | Write wished-for API. Write assertion first. Ask the user. |
354
- | Test too complicated | Design too complicated. Simplify interface. |
355
- | Must mock everything | Code too coupled. Use dependency injection. |
356
- | Test setup huge | Extract helpers. Still complex? Simplify design. |
357
-
358
- ## Debugging Integration
359
-
360
- Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
361
-
362
- Never fix bugs without a test.
363
-
364
- ## Testing Anti-Patterns
365
-
366
- When adding mocks or test utilities, read ./references/testing-anti-patterns.md to avoid common pitfalls:
367
- - Testing mock behavior instead of real behavior
368
- - Adding test-only methods to production classes
369
- - Mocking without understanding dependencies
370
-
371
- ## Final Rule
372
-
373
- ```
374
- Production code -> test exists and failed first
375
- Otherwise -> not TDD
376
- ```
377
-
378
- No exceptions without explicit user permission.
1
+ ---
2
+ name: code-tdd
3
+ description: Test-driven development. Use before writing any implementation code -- write a failing test first, make it pass, then refactor.
4
+ ---
5
+
6
+ # Code TDD
7
+
8
+ ## Critical Constraints
9
+ - I do not write or keep production code unless I watched the relevant test fail first.
10
+ - I do not treat tests written after implementation as equivalent to test-first discipline.
11
+
12
+
13
+ ## Overview
14
+ Write the test first. Watch it fail. Write minimal code to pass.
15
+
16
+ **Core principle:** If you didn't watch the test fail, you don't know if it tests the right thing.
17
+
18
+ **Violating the letter of the rules is violating the spirit of the rules.**
19
+
20
+ ## When to Use
21
+
22
+ **Always:**
23
+ - New features
24
+ - Bug fixes
25
+ - Refactoring
26
+ - Behavior changes
27
+
28
+ **Exceptions (ask the user):**
29
+ - Throwaway prototypes
30
+ - Generated code
31
+ - Configuration files
32
+
33
+ Thinking "skip TDD just this once"? Stop. That's rationalization.
34
+
35
+ ## Procedure
36
+ Run the red-green-refactor loop in order: write one failing test, verify the failure is correct, add the minimum code to pass, then refactor while keeping tests green. If any step is skipped, delete the unverified code and restart from the failing test.
37
+
38
+ ## The Iron Law
39
+
40
+ ```
41
+ NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
42
+ ```
43
+
44
+ Write code before the test? Delete it. Start over.
45
+
46
+ **No exceptions:**
47
+ - Don't keep it as "reference"
48
+ - Don't "adapt" it while writing tests
49
+ - Don't look at it
50
+ - Delete means delete
51
+
52
+ Implement fresh from tests. Period.
53
+
54
+ ## Red-Green-Refactor
55
+
56
+ ```dot
57
+ digraph tdd_cycle {
58
+ rankdir=LR;
59
+ red [label="RED\nWrite failing test", shape=box, style=filled, fillcolor="#ffcccc"];
60
+ verify_red [label="Verify fails\ncorrectly", shape=diamond];
61
+ green [label="GREEN\nMinimal code", shape=box, style=filled, fillcolor="#ccffcc"];
62
+ verify_green [label="Verify passes\nAll green", shape=diamond];
63
+ refactor [label="REFACTOR\nClean up", shape=box, style=filled, fillcolor="#ccccff"];
64
+ next [label="Next", shape=ellipse];
65
+
66
+ red -> verify_red;
67
+ verify_red -> green [label="yes"];
68
+ verify_red -> red [label="wrong\nfailure"];
69
+ green -> verify_green;
70
+ verify_green -> refactor [label="yes"];
71
+ verify_green -> green [label="no"];
72
+ refactor -> verify_green [label="stay\ngreen"];
73
+ verify_green -> next;
74
+ next -> red;
75
+ }
76
+ ```
77
+
78
+ ### RED - Write Failing Test
79
+
80
+ Write one minimal test showing what should happen.
81
+
82
+ <Good>
83
+ ```typescript
84
+ test('retries failed operations 3 times', async () => {
85
+ let attempts = 0;
86
+ const operation = () => {
87
+ attempts++;
88
+ if (attempts < 3) throw new Error('fail');
89
+ return 'success';
90
+ };
91
+
92
+ const result = await retryOperation(operation);
93
+
94
+ expect(result).toBe('success');
95
+ expect(attempts).toBe(3);
96
+ });
97
+ ```
98
+ Clear name, tests real behavior, one thing
99
+ </Good>
100
+
101
+ <Bad>
102
+ ```typescript
103
+ test('retry works', async () => {
104
+ const mock = jest.fn()
105
+ .mockRejectedValueOnce(new Error())
106
+ .mockRejectedValueOnce(new Error())
107
+ .mockResolvedValueOnce('success');
108
+ await retryOperation(mock);
109
+ expect(mock).toHaveBeenCalledTimes(3);
110
+ });
111
+ ```
112
+ Vague name, tests mock not code
113
+ </Bad>
114
+
115
+ **Requirements:**
116
+ - One behavior
117
+ - Clear name
118
+ - Real code (no mocks unless unavoidable)
119
+
120
+ ### Verify RED - Watch It Fail
121
+
122
+ **MANDATORY. Never skip.**
123
+
124
+ ```bash
125
+ npm test path/to/test.test.ts
126
+ ```
127
+
128
+ Confirm:
129
+ - Test fails (not errors)
130
+ - Failure message is expected
131
+ - Fails because feature missing (not typos)
132
+
133
+ **Test passes?** You're testing existing behavior. Fix test.
134
+
135
+ **Test errors?** Fix error, re-run until it fails correctly.
136
+
137
+ ### GREEN - Minimal Code
138
+
139
+ Write simplest code to pass the test.
140
+
141
+ <Good>
142
+ ```typescript
143
+ async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
144
+ for (let i = 0; i < 3; i++) {
145
+ try {
146
+ return await fn();
147
+ } catch (e) {
148
+ if (i === 2) throw e;
149
+ }
150
+ }
151
+ throw new Error('unreachable');
152
+ }
153
+ ```
154
+ Just enough to pass
155
+ </Good>
156
+
157
+ <Bad>
158
+ ```typescript
159
+ async function retryOperation<T>(
160
+ fn: () => Promise<T>,
161
+ options?: {
162
+ maxRetries?: number;
163
+ backoff?: 'linear' | 'exponential';
164
+ onRetry?: (attempt: number) => void;
165
+ }
166
+ ): Promise<T> {
167
+ // YAGNI
168
+ }
169
+ ```
170
+ Over-engineered
171
+ </Bad>
172
+
173
+ Don't add features, refactor other code, or "improve" beyond the test.
174
+
175
+ ### Verify GREEN - Watch It Pass
176
+
177
+ **MANDATORY.**
178
+
179
+ ```bash
180
+ npm test path/to/test.test.ts
181
+ ```
182
+
183
+ Confirm:
184
+ - Test passes
185
+ - Other tests still pass
186
+ - Output pristine (no errors, warnings)
187
+
188
+ **Test fails?** Fix code, not test.
189
+
190
+ **Other tests fail?** Fix now.
191
+
192
+ ### REFACTOR - Clean Up
193
+
194
+ After green only:
195
+ - Remove duplication
196
+ - Improve names
197
+ - Extract helpers
198
+
199
+ Keep tests green. Don't add behavior.
200
+
201
+ ### Repeat
202
+
203
+ Next failing test for next feature.
204
+
205
+ ## Good Tests
206
+
207
+ | Quality | Good | Bad |
208
+ |---------|------|-----|
209
+ | **Minimal** | One thing. "and" in name? Split it. | `test('validates email and domain and whitespace')` |
210
+ | **Clear** | Name describes behavior | `test('test1')` |
211
+ | **Shows intent** | Demonstrates desired API | Obscures what code should do |
212
+
213
+ ## Why Order Matters
214
+
215
+ **"I'll write tests after to verify it works"**
216
+
217
+ Tests written after code pass immediately. Passing immediately proves nothing:
218
+ - Might test wrong thing
219
+ - Might test implementation, not behavior
220
+ - Might miss edge cases you forgot
221
+ - You never saw it catch the bug
222
+
223
+ Test-first forces you to see the test fail, proving it actually tests something.
224
+
225
+ **"I already manually tested all the edge cases"**
226
+
227
+ Manual testing is ad-hoc. You think you tested everything but:
228
+ - No record of what you tested
229
+ - Can't re-run when code changes
230
+ - Easy to forget cases under pressure
231
+ - "It worked when I tried it" comprehensive
232
+
233
+ Automated tests are systematic. They run the same way every time.
234
+
235
+ **"Deleting X hours of work is wasteful"**
236
+
237
+ Sunk cost fallacy. The time is already gone. Your choice now:
238
+ - Delete and rewrite with TDD (X more hours, high confidence)
239
+ - Keep it and add tests after (30 min, low confidence, likely bugs)
240
+
241
+ The "waste" is keeping code you can't trust. Working code without real tests is technical debt.
242
+
243
+ **"TDD is dogmatic, being pragmatic means adapting"**
244
+
245
+ TDD IS pragmatic:
246
+ - Finds bugs before commit (faster than debugging after)
247
+ - Prevents regressions (tests catch breaks immediately)
248
+ - Documents behavior (tests show how to use code)
249
+ - Enables refactoring (change freely, tests catch breaks)
250
+
251
+ "Pragmatic" shortcuts = debugging in production = slower.
252
+
253
+ **"Tests after achieve the same goals - it's spirit not ritual"**
254
+
255
+ No. Tests-after answer "What does this do?" Tests-first answer "What should this do?"
256
+
257
+ Tests-after are biased by your implementation. You test what you built, not what's required. You verify remembered edge cases, not discovered ones.
258
+
259
+ Tests-first force edge case discovery before implementing. Tests-after verify you remembered everything (you didn't).
260
+
261
+ 30 minutes of tests after TDD. You get coverage, lose proof tests work.
262
+
263
+ ## Common Rationalizations
264
+
265
+ | Excuse | Reality |
266
+ |--------|---------|
267
+ | "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
268
+ | "I'll test after" | Tests passing immediately prove nothing. |
269
+ | "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
270
+ | "Already manually tested" | Ad-hoc systematic. No record, can't re-run. |
271
+ | "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
272
+ | "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
273
+ | "Need to explore first" | Fine. Throw away exploration, start with TDD. |
274
+ | "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
275
+ | "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
276
+ | "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
277
+ | "Existing code has no tests" | You're improving it. Add tests for existing code. |
278
+
279
+ ## Red Flags - STOP and Start Over
280
+
281
+ - Code before test
282
+ - Test after implementation
283
+ - Test passes immediately
284
+ - Can't explain why test failed
285
+ - Tests added "later"
286
+ - Rationalizing "just this once"
287
+ - "I already manually tested it"
288
+ - "Tests after achieve the same purpose"
289
+ - "It's about spirit not ritual"
290
+ - "Keep as reference" or "adapt existing code"
291
+ - "Already spent X hours, deleting is wasteful"
292
+ - "TDD is dogmatic, I'm being pragmatic"
293
+ - "This is different because..."
294
+
295
+ **All of these mean: Delete code. Start over with TDD.**
296
+
297
+ ## Example: Bug Fix
298
+
299
+ **Bug:** Empty email accepted
300
+
301
+ **RED**
302
+ ```typescript
303
+ test('rejects empty email', async () => {
304
+ const result = await submitForm({ email: '' });
305
+ expect(result.error).toBe('Email required');
306
+ });
307
+ ```
308
+
309
+ **Verify RED**
310
+ ```bash
311
+ $ npm test
312
+ FAIL: expected 'Email required', got undefined
313
+ ```
314
+
315
+ **GREEN**
316
+ ```typescript
317
+ function submitForm(data: FormData) {
318
+ if (!data.email?.trim()) {
319
+ return { error: 'Email required' };
320
+ }
321
+ // ...
322
+ }
323
+ ```
324
+
325
+ **Verify GREEN**
326
+ ```bash
327
+ $ npm test
328
+ PASS
329
+ ```
330
+
331
+ **REFACTOR**
332
+ Extract validation for multiple fields if needed.
333
+
334
+ ## Verification Checklist
335
+
336
+ Before marking work complete:
337
+
338
+ - [ ] Every new function/method has a test
339
+ - [ ] Watched each test fail before implementing
340
+ - [ ] Each test failed for expected reason (feature missing, not typo)
341
+ - [ ] Wrote minimal code to pass each test
342
+ - [ ] All tests pass
343
+ - [ ] Output pristine (no errors, warnings)
344
+ - [ ] Tests use real code (mocks only if unavoidable)
345
+ - [ ] Edge cases and errors covered
346
+
347
+ Can't check all boxes? You skipped TDD. Start over.
348
+
349
+ ## When Stuck
350
+
351
+ | Problem | Solution |
352
+ |---------|----------|
353
+ | Don't know how to test | Write wished-for API. Write assertion first. Ask the user. |
354
+ | Test too complicated | Design too complicated. Simplify interface. |
355
+ | Must mock everything | Code too coupled. Use dependency injection. |
356
+ | Test setup huge | Extract helpers. Still complex? Simplify design. |
357
+
358
+ ## Debugging Integration
359
+
360
+ Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
361
+
362
+ Never fix bugs without a test.
363
+
364
+ ## Testing Anti-Patterns
365
+
366
+ When adding mocks or test utilities, read ./references/testing-anti-patterns.md to avoid common pitfalls:
367
+ - Testing mock behavior instead of real behavior
368
+ - Adding test-only methods to production classes
369
+ - Mocking without understanding dependencies
370
+
371
+ ## Final Rule
372
+
373
+ ```
374
+ Production code -> test exists and failed first
375
+ Otherwise -> not TDD
376
+ ```
377
+
378
+ No exceptions without explicit user permission.