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