sdtk-code-kit 0.1.0

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 (55) hide show
  1. package/README.md +138 -0
  2. package/assets/manifest/toolkit-bundle.manifest.json +147 -0
  3. package/assets/manifest/toolkit-bundle.sha256.txt +28 -0
  4. package/assets/toolkit/toolkit/AGENTS.md +210 -0
  5. package/assets/toolkit/toolkit/install.ps1 +126 -0
  6. package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +78 -0
  7. package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +127 -0
  8. package/assets/toolkit/toolkit/scripts/uninstall-claude-skills.ps1 +62 -0
  9. package/assets/toolkit/toolkit/scripts/uninstall-codex-skills.ps1 +53 -0
  10. package/assets/toolkit/toolkit/sdtk-spec.config.json +6 -0
  11. package/assets/toolkit/toolkit/sdtk-spec.config.profiles.example.json +12 -0
  12. package/assets/toolkit/toolkit/skills/code-brainstorm/SKILL.md +56 -0
  13. package/assets/toolkit/toolkit/skills/code-debug/SKILL.md +297 -0
  14. package/assets/toolkit/toolkit/skills/code-debug/references/root-cause-tracing.md +69 -0
  15. package/assets/toolkit/toolkit/skills/code-discover/SKILL.md +54 -0
  16. package/assets/toolkit/toolkit/skills/code-execute/SKILL.md +75 -0
  17. package/assets/toolkit/toolkit/skills/code-finish/SKILL.md +206 -0
  18. package/assets/toolkit/toolkit/skills/code-parallel/SKILL.md +65 -0
  19. package/assets/toolkit/toolkit/skills/code-parallel/references/code-quality-reviewer-prompt.md +27 -0
  20. package/assets/toolkit/toolkit/skills/code-parallel/references/implementer-prompt.md +114 -0
  21. package/assets/toolkit/toolkit/skills/code-parallel/references/spec-reviewer-prompt.md +62 -0
  22. package/assets/toolkit/toolkit/skills/code-plan/SKILL.md +86 -0
  23. package/assets/toolkit/toolkit/skills/code-review/SKILL.md +80 -0
  24. package/assets/toolkit/toolkit/skills/code-review/references/checklist.md +126 -0
  25. package/assets/toolkit/toolkit/skills/code-review/references/code-reviewer.md +147 -0
  26. package/assets/toolkit/toolkit/skills/code-ship/SKILL.md +53 -0
  27. package/assets/toolkit/toolkit/skills/code-tdd/SKILL.md +379 -0
  28. package/assets/toolkit/toolkit/skills/code-tdd/references/testing-anti-patterns.md +300 -0
  29. package/assets/toolkit/toolkit/skills/code-verify/SKILL.md +145 -0
  30. package/assets/toolkit/toolkit/skills/code-worktree/SKILL.md +229 -0
  31. package/assets/toolkit/toolkit/templates/CODE_WORKFLOW_TEMPLATE.md +112 -0
  32. package/bin/sdtk-code.js +14 -0
  33. package/package.json +44 -0
  34. package/src/commands/build.js +53 -0
  35. package/src/commands/generate.js +11 -0
  36. package/src/commands/help.js +169 -0
  37. package/src/commands/init.js +86 -0
  38. package/src/commands/plan.js +52 -0
  39. package/src/commands/runtime.js +205 -0
  40. package/src/commands/ship.js +54 -0
  41. package/src/commands/start.js +89 -0
  42. package/src/commands/verify.js +57 -0
  43. package/src/index.js +70 -0
  44. package/src/lib/args.js +107 -0
  45. package/src/lib/errors.js +41 -0
  46. package/src/lib/powershell.js +65 -0
  47. package/src/lib/scope.js +55 -0
  48. package/src/lib/toolkit-payload.js +72 -0
  49. package/src/lib/workflow-artifact.js +453 -0
  50. package/src/lib/workflow-build.js +127 -0
  51. package/src/lib/workflow-handoff.js +427 -0
  52. package/src/lib/workflow-intake.js +100 -0
  53. package/src/lib/workflow-plan.js +96 -0
  54. package/src/lib/workflow-ship.js +163 -0
  55. package/src/lib/workflow-verify.js +212 -0
@@ -0,0 +1,379 @@
1
+ <!-- Based on superpowers by Jesse Vincent (MIT License, 2025). Adapted for SDTK-CODE. See ../../THIRD_PARTY_NOTICES.md for details. -->
2
+ ---
3
+ name: code-tdd
4
+ description: Test-driven development. Use before writing any implementation code -- write a failing test first, make it pass, then refactor.
5
+ ---
6
+
7
+ # Code TDD
8
+
9
+ ## Critical Constraints
10
+ - I do not write or keep production code unless I watched the relevant test fail first.
11
+ - I do not treat tests written after implementation as equivalent to test-first discipline.
12
+
13
+
14
+ ## Overview
15
+ Write the test first. Watch it fail. Write minimal code to pass.
16
+
17
+ **Core principle:** If you didn't watch the test fail, you don't know if it tests the right thing.
18
+
19
+ **Violating the letter of the rules is violating the spirit of the rules.**
20
+
21
+ ## When to Use
22
+
23
+ **Always:**
24
+ - New features
25
+ - Bug fixes
26
+ - Refactoring
27
+ - Behavior changes
28
+
29
+ **Exceptions (ask the user):**
30
+ - Throwaway prototypes
31
+ - Generated code
32
+ - Configuration files
33
+
34
+ Thinking "skip TDD just this once"? Stop. That's rationalization.
35
+
36
+ ## Procedure
37
+ 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.
38
+
39
+ ## The Iron Law
40
+
41
+ ```
42
+ NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
43
+ ```
44
+
45
+ Write code before the test? Delete it. Start over.
46
+
47
+ **No exceptions:**
48
+ - Don't keep it as "reference"
49
+ - Don't "adapt" it while writing tests
50
+ - Don't look at it
51
+ - Delete means delete
52
+
53
+ Implement fresh from tests. Period.
54
+
55
+ ## Red-Green-Refactor
56
+
57
+ ```dot
58
+ digraph tdd_cycle {
59
+ rankdir=LR;
60
+ red [label="RED\nWrite failing test", shape=box, style=filled, fillcolor="#ffcccc"];
61
+ verify_red [label="Verify fails\ncorrectly", shape=diamond];
62
+ green [label="GREEN\nMinimal code", shape=box, style=filled, fillcolor="#ccffcc"];
63
+ verify_green [label="Verify passes\nAll green", shape=diamond];
64
+ refactor [label="REFACTOR\nClean up", shape=box, style=filled, fillcolor="#ccccff"];
65
+ next [label="Next", shape=ellipse];
66
+
67
+ red -> verify_red;
68
+ verify_red -> green [label="yes"];
69
+ verify_red -> red [label="wrong\nfailure"];
70
+ green -> verify_green;
71
+ verify_green -> refactor [label="yes"];
72
+ verify_green -> green [label="no"];
73
+ refactor -> verify_green [label="stay\ngreen"];
74
+ verify_green -> next;
75
+ next -> red;
76
+ }
77
+ ```
78
+
79
+ ### RED - Write Failing Test
80
+
81
+ Write one minimal test showing what should happen.
82
+
83
+ <Good>
84
+ ```typescript
85
+ test('retries failed operations 3 times', async () => {
86
+ let attempts = 0;
87
+ const operation = () => {
88
+ attempts++;
89
+ if (attempts < 3) throw new Error('fail');
90
+ return 'success';
91
+ };
92
+
93
+ const result = await retryOperation(operation);
94
+
95
+ expect(result).toBe('success');
96
+ expect(attempts).toBe(3);
97
+ });
98
+ ```
99
+ Clear name, tests real behavior, one thing
100
+ </Good>
101
+
102
+ <Bad>
103
+ ```typescript
104
+ test('retry works', async () => {
105
+ const mock = jest.fn()
106
+ .mockRejectedValueOnce(new Error())
107
+ .mockRejectedValueOnce(new Error())
108
+ .mockResolvedValueOnce('success');
109
+ await retryOperation(mock);
110
+ expect(mock).toHaveBeenCalledTimes(3);
111
+ });
112
+ ```
113
+ Vague name, tests mock not code
114
+ </Bad>
115
+
116
+ **Requirements:**
117
+ - One behavior
118
+ - Clear name
119
+ - Real code (no mocks unless unavoidable)
120
+
121
+ ### Verify RED - Watch It Fail
122
+
123
+ **MANDATORY. Never skip.**
124
+
125
+ ```bash
126
+ npm test path/to/test.test.ts
127
+ ```
128
+
129
+ Confirm:
130
+ - Test fails (not errors)
131
+ - Failure message is expected
132
+ - Fails because feature missing (not typos)
133
+
134
+ **Test passes?** You're testing existing behavior. Fix test.
135
+
136
+ **Test errors?** Fix error, re-run until it fails correctly.
137
+
138
+ ### GREEN - Minimal Code
139
+
140
+ Write simplest code to pass the test.
141
+
142
+ <Good>
143
+ ```typescript
144
+ async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
145
+ for (let i = 0; i < 3; i++) {
146
+ try {
147
+ return await fn();
148
+ } catch (e) {
149
+ if (i === 2) throw e;
150
+ }
151
+ }
152
+ throw new Error('unreachable');
153
+ }
154
+ ```
155
+ Just enough to pass
156
+ </Good>
157
+
158
+ <Bad>
159
+ ```typescript
160
+ async function retryOperation<T>(
161
+ fn: () => Promise<T>,
162
+ options?: {
163
+ maxRetries?: number;
164
+ backoff?: 'linear' | 'exponential';
165
+ onRetry?: (attempt: number) => void;
166
+ }
167
+ ): Promise<T> {
168
+ // YAGNI
169
+ }
170
+ ```
171
+ Over-engineered
172
+ </Bad>
173
+
174
+ Don't add features, refactor other code, or "improve" beyond the test.
175
+
176
+ ### Verify GREEN - Watch It Pass
177
+
178
+ **MANDATORY.**
179
+
180
+ ```bash
181
+ npm test path/to/test.test.ts
182
+ ```
183
+
184
+ Confirm:
185
+ - Test passes
186
+ - Other tests still pass
187
+ - Output pristine (no errors, warnings)
188
+
189
+ **Test fails?** Fix code, not test.
190
+
191
+ **Other tests fail?** Fix now.
192
+
193
+ ### REFACTOR - Clean Up
194
+
195
+ After green only:
196
+ - Remove duplication
197
+ - Improve names
198
+ - Extract helpers
199
+
200
+ Keep tests green. Don't add behavior.
201
+
202
+ ### Repeat
203
+
204
+ Next failing test for next feature.
205
+
206
+ ## Good Tests
207
+
208
+ | Quality | Good | Bad |
209
+ |---------|------|-----|
210
+ | **Minimal** | One thing. "and" in name? Split it. | `test('validates email and domain and whitespace')` |
211
+ | **Clear** | Name describes behavior | `test('test1')` |
212
+ | **Shows intent** | Demonstrates desired API | Obscures what code should do |
213
+
214
+ ## Why Order Matters
215
+
216
+ **"I'll write tests after to verify it works"**
217
+
218
+ Tests written after code pass immediately. Passing immediately proves nothing:
219
+ - Might test wrong thing
220
+ - Might test implementation, not behavior
221
+ - Might miss edge cases you forgot
222
+ - You never saw it catch the bug
223
+
224
+ Test-first forces you to see the test fail, proving it actually tests something.
225
+
226
+ **"I already manually tested all the edge cases"**
227
+
228
+ Manual testing is ad-hoc. You think you tested everything but:
229
+ - No record of what you tested
230
+ - Can't re-run when code changes
231
+ - Easy to forget cases under pressure
232
+ - "It worked when I tried it" comprehensive
233
+
234
+ Automated tests are systematic. They run the same way every time.
235
+
236
+ **"Deleting X hours of work is wasteful"**
237
+
238
+ Sunk cost fallacy. The time is already gone. Your choice now:
239
+ - Delete and rewrite with TDD (X more hours, high confidence)
240
+ - Keep it and add tests after (30 min, low confidence, likely bugs)
241
+
242
+ The "waste" is keeping code you can't trust. Working code without real tests is technical debt.
243
+
244
+ **"TDD is dogmatic, being pragmatic means adapting"**
245
+
246
+ TDD IS pragmatic:
247
+ - Finds bugs before commit (faster than debugging after)
248
+ - Prevents regressions (tests catch breaks immediately)
249
+ - Documents behavior (tests show how to use code)
250
+ - Enables refactoring (change freely, tests catch breaks)
251
+
252
+ "Pragmatic" shortcuts = debugging in production = slower.
253
+
254
+ **"Tests after achieve the same goals - it's spirit not ritual"**
255
+
256
+ No. Tests-after answer "What does this do?" Tests-first answer "What should this do?"
257
+
258
+ Tests-after are biased by your implementation. You test what you built, not what's required. You verify remembered edge cases, not discovered ones.
259
+
260
+ Tests-first force edge case discovery before implementing. Tests-after verify you remembered everything (you didn't).
261
+
262
+ 30 minutes of tests after TDD. You get coverage, lose proof tests work.
263
+
264
+ ## Common Rationalizations
265
+
266
+ | Excuse | Reality |
267
+ |--------|---------|
268
+ | "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
269
+ | "I'll test after" | Tests passing immediately prove nothing. |
270
+ | "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
271
+ | "Already manually tested" | Ad-hoc systematic. No record, can't re-run. |
272
+ | "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
273
+ | "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
274
+ | "Need to explore first" | Fine. Throw away exploration, start with TDD. |
275
+ | "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
276
+ | "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
277
+ | "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
278
+ | "Existing code has no tests" | You're improving it. Add tests for existing code. |
279
+
280
+ ## Red Flags - STOP and Start Over
281
+
282
+ - Code before test
283
+ - Test after implementation
284
+ - Test passes immediately
285
+ - Can't explain why test failed
286
+ - Tests added "later"
287
+ - Rationalizing "just this once"
288
+ - "I already manually tested it"
289
+ - "Tests after achieve the same purpose"
290
+ - "It's about spirit not ritual"
291
+ - "Keep as reference" or "adapt existing code"
292
+ - "Already spent X hours, deleting is wasteful"
293
+ - "TDD is dogmatic, I'm being pragmatic"
294
+ - "This is different because..."
295
+
296
+ **All of these mean: Delete code. Start over with TDD.**
297
+
298
+ ## Example: Bug Fix
299
+
300
+ **Bug:** Empty email accepted
301
+
302
+ **RED**
303
+ ```typescript
304
+ test('rejects empty email', async () => {
305
+ const result = await submitForm({ email: '' });
306
+ expect(result.error).toBe('Email required');
307
+ });
308
+ ```
309
+
310
+ **Verify RED**
311
+ ```bash
312
+ $ npm test
313
+ FAIL: expected 'Email required', got undefined
314
+ ```
315
+
316
+ **GREEN**
317
+ ```typescript
318
+ function submitForm(data: FormData) {
319
+ if (!data.email?.trim()) {
320
+ return { error: 'Email required' };
321
+ }
322
+ // ...
323
+ }
324
+ ```
325
+
326
+ **Verify GREEN**
327
+ ```bash
328
+ $ npm test
329
+ PASS
330
+ ```
331
+
332
+ **REFACTOR**
333
+ Extract validation for multiple fields if needed.
334
+
335
+ ## Verification Checklist
336
+
337
+ Before marking work complete:
338
+
339
+ - [ ] Every new function/method has a test
340
+ - [ ] Watched each test fail before implementing
341
+ - [ ] Each test failed for expected reason (feature missing, not typo)
342
+ - [ ] Wrote minimal code to pass each test
343
+ - [ ] All tests pass
344
+ - [ ] Output pristine (no errors, warnings)
345
+ - [ ] Tests use real code (mocks only if unavoidable)
346
+ - [ ] Edge cases and errors covered
347
+
348
+ Can't check all boxes? You skipped TDD. Start over.
349
+
350
+ ## When Stuck
351
+
352
+ | Problem | Solution |
353
+ |---------|----------|
354
+ | Don't know how to test | Write wished-for API. Write assertion first. Ask the user. |
355
+ | Test too complicated | Design too complicated. Simplify interface. |
356
+ | Must mock everything | Code too coupled. Use dependency injection. |
357
+ | Test setup huge | Extract helpers. Still complex? Simplify design. |
358
+
359
+ ## Debugging Integration
360
+
361
+ Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
362
+
363
+ Never fix bugs without a test.
364
+
365
+ ## Testing Anti-Patterns
366
+
367
+ When adding mocks or test utilities, read ./references/testing-anti-patterns.md to avoid common pitfalls:
368
+ - Testing mock behavior instead of real behavior
369
+ - Adding test-only methods to production classes
370
+ - Mocking without understanding dependencies
371
+
372
+ ## Final Rule
373
+
374
+ ```
375
+ Production code -> test exists and failed first
376
+ Otherwise -> not TDD
377
+ ```
378
+
379
+ No exceptions without explicit user permission.
@@ -0,0 +1,300 @@
1
+ <!-- Based on superpowers by Jesse Vincent (MIT License, 2025). Adapted for SDTK-CODE. See ../../../THIRD_PARTY_NOTICES.md for details. -->
2
+ # Testing Anti-Patterns
3
+
4
+ **Load this reference when:** writing or changing tests, adding mocks, or tempted to add test-only methods to production code.
5
+
6
+ ## Overview
7
+
8
+ Tests must verify real behavior, not mock behavior. Mocks are a means to isolate, not the thing being tested.
9
+
10
+ **Core principle:** Test what the code does, not what the mocks do.
11
+
12
+ **Following strict TDD prevents these anti-patterns.**
13
+
14
+ ## The Iron Laws
15
+
16
+ ```
17
+ 1. NEVER test mock behavior
18
+ 2. NEVER add test-only methods to production classes
19
+ 3. NEVER mock without understanding dependencies
20
+ ```
21
+
22
+ ## Anti-Pattern 1: Testing Mock Behavior
23
+
24
+ **The violation:**
25
+ ```typescript
26
+ // BAD: Testing that the mock exists
27
+ test('renders sidebar', () => {
28
+ render(<Page />);
29
+ expect(screen.getByTestId('sidebar-mock')).toBeInTheDocument();
30
+ });
31
+ ```
32
+
33
+ **Why this is wrong:**
34
+ - You're verifying the mock works, not that the component works
35
+ - Test passes when mock is present, fails when it's not
36
+ - Tells you nothing about real behavior
37
+
38
+ **the user's correction:** "Are we testing the behavior of a mock?"
39
+
40
+ **The fix:**
41
+ ```typescript
42
+ // GOOD: Test real component or don't mock it
43
+ test('renders sidebar', () => {
44
+ render(<Page />); // Don't mock sidebar
45
+ expect(screen.getByRole('navigation')).toBeInTheDocument();
46
+ });
47
+
48
+ // OR if sidebar must be mocked for isolation:
49
+ // Don't assert on the mock - test Page's behavior with sidebar present
50
+ ```
51
+
52
+ ### Gate Function
53
+
54
+ ```
55
+ BEFORE asserting on any mock element:
56
+ Ask: "Am I testing real component behavior or just mock existence?"
57
+
58
+ IF testing mock existence:
59
+ STOP - Delete the assertion or unmock the component
60
+
61
+ Test real behavior instead
62
+ ```
63
+
64
+ ## Anti-Pattern 2: Test-Only Methods in Production
65
+
66
+ **The violation:**
67
+ ```typescript
68
+ // BAD: destroy() only used in tests
69
+ class Session {
70
+ async destroy() { // Looks like production API!
71
+ await this._workspaceManager?.destroyWorkspace(this.id);
72
+ // ... cleanup
73
+ }
74
+ }
75
+
76
+ // In tests
77
+ afterEach(() => session.destroy());
78
+ ```
79
+
80
+ **Why this is wrong:**
81
+ - Production class polluted with test-only code
82
+ - Dangerous if accidentally called in production
83
+ - Violates YAGNI and separation of concerns
84
+ - Confuses object lifecycle with entity lifecycle
85
+
86
+ **The fix:**
87
+ ```typescript
88
+ // GOOD: Test utilities handle test cleanup
89
+ // Session has no destroy() - it's stateless in production
90
+
91
+ // In test-utils/
92
+ export async function cleanupSession(session: Session) {
93
+ const workspace = session.getWorkspaceInfo();
94
+ if (workspace) {
95
+ await workspaceManager.destroyWorkspace(workspace.id);
96
+ }
97
+ }
98
+
99
+ // In tests
100
+ afterEach(() => cleanupSession(session));
101
+ ```
102
+
103
+ ### Gate Function
104
+
105
+ ```
106
+ BEFORE adding any method to production class:
107
+ Ask: "Is this only used by tests?"
108
+
109
+ IF yes:
110
+ STOP - Don't add it
111
+ Put it in test utilities instead
112
+
113
+ Ask: "Does this class own this resource's lifecycle?"
114
+
115
+ IF no:
116
+ STOP - Wrong class for this method
117
+ ```
118
+
119
+ ## Anti-Pattern 3: Mocking Without Understanding
120
+
121
+ **The violation:**
122
+ ```typescript
123
+ // BAD: Mock breaks test logic
124
+ test('detects duplicate server', () => {
125
+ // Mock prevents config write that test depends on!
126
+ vi.mock('ToolCatalog', () => ({
127
+ discoverAndCacheTools: vi.fn().mockResolvedValue(undefined)
128
+ }));
129
+
130
+ await addServer(config);
131
+ await addServer(config); // Should throw - but won't!
132
+ });
133
+ ```
134
+
135
+ **Why this is wrong:**
136
+ - Mocked method had side effect test depended on (writing config)
137
+ - Over-mocking to "be safe" breaks actual behavior
138
+ - Test passes for wrong reason or fails mysteriously
139
+
140
+ **The fix:**
141
+ ```typescript
142
+ // GOOD: Mock at correct level
143
+ test('detects duplicate server', () => {
144
+ // Mock the slow part, preserve behavior test needs
145
+ vi.mock('MCPServerManager'); // Just mock slow server startup
146
+
147
+ await addServer(config); // Config written
148
+ await addServer(config); // Duplicate detected
149
+ });
150
+ ```
151
+
152
+ ### Gate Function
153
+
154
+ ```
155
+ BEFORE mocking any method:
156
+ STOP - Don't mock yet
157
+
158
+ 1. Ask: "What side effects does the real method have?"
159
+ 2. Ask: "Does this test depend on any of those side effects?"
160
+ 3. Ask: "Do I fully understand what this test needs?"
161
+
162
+ IF depends on side effects:
163
+ Mock at lower level (the actual slow/external operation)
164
+ OR use test doubles that preserve necessary behavior
165
+ NOT the high-level method the test depends on
166
+
167
+ IF unsure what test depends on:
168
+ Run test with real implementation FIRST
169
+ Observe what actually needs to happen
170
+ THEN add minimal mocking at the right level
171
+
172
+ Red flags:
173
+ - "I'll mock this to be safe"
174
+ - "This might be slow, better mock it"
175
+ - Mocking without understanding the dependency chain
176
+ ```
177
+
178
+ ## Anti-Pattern 4: Incomplete Mocks
179
+
180
+ **The violation:**
181
+ ```typescript
182
+ // BAD: Partial mock - only fields you think you need
183
+ const mockResponse = {
184
+ status: 'success',
185
+ data: { userId: '123', name: 'Alice' }
186
+ // Missing: metadata that downstream code uses
187
+ };
188
+
189
+ // Later: breaks when code accesses response.metadata.requestId
190
+ ```
191
+
192
+ **Why this is wrong:**
193
+ - **Partial mocks hide structural assumptions** - You only mocked fields you know about
194
+ - **Downstream code may depend on fields you didn't include** - Silent failures
195
+ - **Tests pass but integration fails** - Mock incomplete, real API complete
196
+ - **False confidence** - Test proves nothing about real behavior
197
+
198
+ **The Iron Rule:** Mock the COMPLETE data structure as it exists in reality, not just fields your immediate test uses.
199
+
200
+ **The fix:**
201
+ ```typescript
202
+ // GOOD: Mirror real API completeness
203
+ const mockResponse = {
204
+ status: 'success',
205
+ data: { userId: '123', name: 'Alice' },
206
+ metadata: { requestId: 'req-789', timestamp: 1234567890 }
207
+ // All fields real API returns
208
+ };
209
+ ```
210
+
211
+ ### Gate Function
212
+
213
+ ```
214
+ BEFORE creating mock responses:
215
+ Check: "What fields does the real API response contain?"
216
+
217
+ Actions:
218
+ 1. Examine actual API response from docs/examples
219
+ 2. Include ALL fields system might consume downstream
220
+ 3. Verify mock matches real response schema completely
221
+
222
+ Critical:
223
+ If you're creating a mock, you must understand the ENTIRE structure
224
+ Partial mocks fail silently when code depends on omitted fields
225
+
226
+ If uncertain: Include all documented fields
227
+ ```
228
+
229
+ ## Anti-Pattern 5: Integration Tests as Afterthought
230
+
231
+ **The violation:**
232
+ ```
233
+ Implementation complete
234
+ No tests written
235
+ "Ready for testing"
236
+ ```
237
+
238
+ **Why this is wrong:**
239
+ - Testing is part of implementation, not optional follow-up
240
+ - TDD would have caught this
241
+ - Can't claim complete without tests
242
+
243
+ **The fix:**
244
+ ```
245
+ TDD cycle:
246
+ 1. Write failing test
247
+ 2. Implement to pass
248
+ 3. Refactor
249
+ 4. THEN claim complete
250
+ ```
251
+
252
+ ## When Mocks Become Too Complex
253
+
254
+ **Warning signs:**
255
+ - Mock setup longer than test logic
256
+ - Mocking everything to make test pass
257
+ - Mocks missing methods real components have
258
+ - Test breaks when mock changes
259
+
260
+ **the user's question:** "Do we need to be using a mock here?"
261
+
262
+ **Consider:** Integration tests with real components often simpler than complex mocks
263
+
264
+ ## TDD Prevents These Anti-Patterns
265
+
266
+ **Why TDD helps:**
267
+ 1. **Write test first** -> Forces you to think about what you're actually testing
268
+ 2. **Watch it fail** -> Confirms test tests real behavior, not mocks
269
+ 3. **Minimal implementation** -> No test-only methods creep in
270
+ 4. **Real dependencies** -> You see what the test actually needs before mocking
271
+
272
+ **If you're testing mock behavior, you violated TDD** - you added mocks without watching test fail against real code first.
273
+
274
+ ## Quick Reference
275
+
276
+ | Anti-Pattern | Fix |
277
+ |--------------|-----|
278
+ | Assert on mock elements | Test real component or unmock it |
279
+ | Test-only methods in production | Move to test utilities |
280
+ | Mock without understanding | Understand dependencies first, mock minimally |
281
+ | Incomplete mocks | Mirror real API completely |
282
+ | Tests as afterthought | TDD - tests first |
283
+ | Over-complex mocks | Consider integration tests |
284
+
285
+ ## Red Flags
286
+
287
+ - Assertion checks for `*-mock` test IDs
288
+ - Methods only called in test files
289
+ - Mock setup is >50% of test
290
+ - Test fails when you remove mock
291
+ - Can't explain why mock is needed
292
+ - Mocking "just to be safe"
293
+
294
+ ## The Bottom Line
295
+
296
+ **Mocks are tools to isolate, not things to test.**
297
+
298
+ If TDD reveals you're testing mock behavior, you've gone wrong.
299
+
300
+ Fix: Test real behavior or question why you're mocking at all.