@zcy2nn/agent-forge 1.1.3 → 1.1.5

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