claude-mpm 4.15.6__py3-none-any.whl → 4.21.3__py3-none-any.whl

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.

Potentially problematic release.


This version of claude-mpm might be problematic. Click here for more details.

Files changed (209) hide show
  1. claude_mpm/VERSION +1 -1
  2. claude_mpm/agents/BASE_ENGINEER.md +286 -0
  3. claude_mpm/agents/BASE_PM.md +272 -23
  4. claude_mpm/agents/PM_INSTRUCTIONS.md +49 -0
  5. claude_mpm/agents/agent_loader.py +4 -4
  6. claude_mpm/agents/templates/engineer.json +5 -1
  7. claude_mpm/agents/templates/php-engineer.json +10 -4
  8. claude_mpm/agents/templates/python_engineer.json +8 -3
  9. claude_mpm/agents/templates/rust_engineer.json +12 -7
  10. claude_mpm/agents/templates/svelte-engineer.json +225 -0
  11. claude_mpm/cli/commands/__init__.py +2 -0
  12. claude_mpm/cli/commands/mpm_init/__init__.py +73 -0
  13. claude_mpm/cli/commands/mpm_init/core.py +525 -0
  14. claude_mpm/cli/commands/mpm_init/display.py +341 -0
  15. claude_mpm/cli/commands/mpm_init/git_activity.py +427 -0
  16. claude_mpm/cli/commands/mpm_init/modes.py +397 -0
  17. claude_mpm/cli/commands/mpm_init/prompts.py +442 -0
  18. claude_mpm/cli/commands/mpm_init_cli.py +396 -0
  19. claude_mpm/cli/commands/mpm_init_handler.py +67 -1
  20. claude_mpm/cli/commands/skills.py +488 -0
  21. claude_mpm/cli/executor.py +2 -0
  22. claude_mpm/cli/parsers/base_parser.py +7 -0
  23. claude_mpm/cli/parsers/mpm_init_parser.py +42 -0
  24. claude_mpm/cli/parsers/skills_parser.py +137 -0
  25. claude_mpm/cli/startup.py +57 -0
  26. claude_mpm/commands/mpm-auto-configure.md +52 -0
  27. claude_mpm/commands/mpm-help.md +6 -0
  28. claude_mpm/commands/mpm-init.md +112 -6
  29. claude_mpm/commands/mpm-resume.md +372 -0
  30. claude_mpm/commands/mpm-version.md +113 -0
  31. claude_mpm/commands/mpm.md +2 -0
  32. claude_mpm/config/agent_config.py +2 -2
  33. claude_mpm/constants.py +12 -0
  34. claude_mpm/core/config.py +42 -0
  35. claude_mpm/core/factories.py +1 -1
  36. claude_mpm/core/interfaces.py +56 -1
  37. claude_mpm/core/optimized_agent_loader.py +3 -3
  38. claude_mpm/hooks/__init__.py +8 -0
  39. claude_mpm/hooks/claude_hooks/response_tracking.py +35 -1
  40. claude_mpm/hooks/session_resume_hook.py +121 -0
  41. claude_mpm/models/resume_log.py +340 -0
  42. claude_mpm/services/agents/auto_config_manager.py +1 -1
  43. claude_mpm/services/agents/deployment/agent_configuration_manager.py +1 -1
  44. claude_mpm/services/agents/deployment/agent_record_service.py +1 -1
  45. claude_mpm/services/agents/deployment/agent_validator.py +17 -1
  46. claude_mpm/services/agents/deployment/async_agent_deployment.py +1 -1
  47. claude_mpm/services/agents/deployment/local_template_deployment.py +1 -1
  48. claude_mpm/services/agents/local_template_manager.py +1 -1
  49. claude_mpm/services/agents/recommender.py +47 -0
  50. claude_mpm/services/cli/resume_service.py +617 -0
  51. claude_mpm/services/cli/session_manager.py +87 -0
  52. claude_mpm/services/cli/session_pause_manager.py +504 -0
  53. claude_mpm/services/cli/session_resume_helper.py +372 -0
  54. claude_mpm/services/core/base.py +26 -11
  55. claude_mpm/services/core/interfaces.py +56 -1
  56. claude_mpm/services/core/models/agent_config.py +3 -0
  57. claude_mpm/services/core/models/process.py +4 -0
  58. claude_mpm/services/core/path_resolver.py +1 -1
  59. claude_mpm/services/diagnostics/models.py +21 -0
  60. claude_mpm/services/event_bus/relay.py +23 -7
  61. claude_mpm/services/infrastructure/resume_log_generator.py +439 -0
  62. claude_mpm/services/local_ops/__init__.py +2 -0
  63. claude_mpm/services/mcp_config_manager.py +7 -131
  64. claude_mpm/services/mcp_gateway/auto_configure.py +31 -25
  65. claude_mpm/services/mcp_gateway/core/process_pool.py +19 -10
  66. claude_mpm/services/mcp_gateway/tools/external_mcp_services.py +26 -21
  67. claude_mpm/services/memory/failure_tracker.py +19 -4
  68. claude_mpm/services/session_manager.py +205 -1
  69. claude_mpm/services/unified/deployment_strategies/local.py +1 -1
  70. claude_mpm/services/version_service.py +104 -1
  71. claude_mpm/skills/__init__.py +21 -0
  72. claude_mpm/skills/agent_skills_injector.py +324 -0
  73. claude_mpm/skills/bundled/LICENSE_ATTRIBUTIONS.md +79 -0
  74. claude_mpm/skills/bundled/api-documentation.md +393 -0
  75. claude_mpm/skills/bundled/async-testing.md +571 -0
  76. claude_mpm/skills/bundled/code-review.md +143 -0
  77. claude_mpm/skills/bundled/collaboration/brainstorming/SKILL.md +79 -0
  78. claude_mpm/skills/bundled/collaboration/dispatching-parallel-agents/SKILL.md +178 -0
  79. claude_mpm/skills/bundled/collaboration/dispatching-parallel-agents/references/agent-prompts.md +577 -0
  80. claude_mpm/skills/bundled/collaboration/dispatching-parallel-agents/references/coordination-patterns.md +467 -0
  81. claude_mpm/skills/bundled/collaboration/dispatching-parallel-agents/references/examples.md +537 -0
  82. claude_mpm/skills/bundled/collaboration/dispatching-parallel-agents/references/troubleshooting.md +730 -0
  83. claude_mpm/skills/bundled/collaboration/requesting-code-review/SKILL.md +112 -0
  84. claude_mpm/skills/bundled/collaboration/requesting-code-review/references/code-reviewer-template.md +146 -0
  85. claude_mpm/skills/bundled/collaboration/requesting-code-review/references/review-examples.md +412 -0
  86. claude_mpm/skills/bundled/collaboration/writing-plans/SKILL.md +81 -0
  87. claude_mpm/skills/bundled/collaboration/writing-plans/references/best-practices.md +362 -0
  88. claude_mpm/skills/bundled/collaboration/writing-plans/references/plan-structure-templates.md +312 -0
  89. claude_mpm/skills/bundled/database-migration.md +199 -0
  90. claude_mpm/skills/bundled/debugging/root-cause-tracing/SKILL.md +152 -0
  91. claude_mpm/skills/bundled/debugging/root-cause-tracing/references/advanced-techniques.md +668 -0
  92. claude_mpm/skills/bundled/debugging/root-cause-tracing/references/examples.md +587 -0
  93. claude_mpm/skills/bundled/debugging/root-cause-tracing/references/integration.md +438 -0
  94. claude_mpm/skills/bundled/debugging/root-cause-tracing/references/tracing-techniques.md +391 -0
  95. claude_mpm/skills/bundled/debugging/systematic-debugging/CREATION-LOG.md +119 -0
  96. claude_mpm/skills/bundled/debugging/systematic-debugging/SKILL.md +148 -0
  97. claude_mpm/skills/bundled/debugging/systematic-debugging/references/anti-patterns.md +483 -0
  98. claude_mpm/skills/bundled/debugging/systematic-debugging/references/examples.md +452 -0
  99. claude_mpm/skills/bundled/debugging/systematic-debugging/references/troubleshooting.md +449 -0
  100. claude_mpm/skills/bundled/debugging/systematic-debugging/references/workflow.md +411 -0
  101. claude_mpm/skills/bundled/debugging/systematic-debugging/test-academic.md +14 -0
  102. claude_mpm/skills/bundled/debugging/systematic-debugging/test-pressure-1.md +58 -0
  103. claude_mpm/skills/bundled/debugging/systematic-debugging/test-pressure-2.md +68 -0
  104. claude_mpm/skills/bundled/debugging/systematic-debugging/test-pressure-3.md +69 -0
  105. claude_mpm/skills/bundled/debugging/verification-before-completion/SKILL.md +131 -0
  106. claude_mpm/skills/bundled/debugging/verification-before-completion/references/gate-function.md +325 -0
  107. claude_mpm/skills/bundled/debugging/verification-before-completion/references/integration-and-workflows.md +490 -0
  108. claude_mpm/skills/bundled/debugging/verification-before-completion/references/red-flags-and-failures.md +425 -0
  109. claude_mpm/skills/bundled/debugging/verification-before-completion/references/verification-patterns.md +499 -0
  110. claude_mpm/skills/bundled/docker-containerization.md +194 -0
  111. claude_mpm/skills/bundled/express-local-dev.md +1429 -0
  112. claude_mpm/skills/bundled/fastapi-local-dev.md +1199 -0
  113. claude_mpm/skills/bundled/git-workflow.md +414 -0
  114. claude_mpm/skills/bundled/imagemagick.md +204 -0
  115. claude_mpm/skills/bundled/json-data-handling.md +223 -0
  116. claude_mpm/skills/bundled/main/artifacts-builder/SKILL.md +86 -0
  117. claude_mpm/skills/bundled/main/internal-comms/SKILL.md +43 -0
  118. claude_mpm/skills/bundled/main/internal-comms/examples/3p-updates.md +47 -0
  119. claude_mpm/skills/bundled/main/internal-comms/examples/company-newsletter.md +65 -0
  120. claude_mpm/skills/bundled/main/internal-comms/examples/faq-answers.md +30 -0
  121. claude_mpm/skills/bundled/main/internal-comms/examples/general-comms.md +16 -0
  122. claude_mpm/skills/bundled/main/mcp-builder/SKILL.md +160 -0
  123. claude_mpm/skills/bundled/main/mcp-builder/reference/design_principles.md +412 -0
  124. claude_mpm/skills/bundled/main/mcp-builder/reference/evaluation.md +602 -0
  125. claude_mpm/skills/bundled/main/mcp-builder/reference/mcp_best_practices.md +915 -0
  126. claude_mpm/skills/bundled/main/mcp-builder/reference/node_mcp_server.md +916 -0
  127. claude_mpm/skills/bundled/main/mcp-builder/reference/python_mcp_server.md +752 -0
  128. claude_mpm/skills/bundled/main/mcp-builder/reference/workflow.md +1237 -0
  129. claude_mpm/skills/bundled/main/mcp-builder/scripts/connections.py +157 -0
  130. claude_mpm/skills/bundled/main/mcp-builder/scripts/evaluation.py +425 -0
  131. claude_mpm/skills/bundled/main/skill-creator/SKILL.md +189 -0
  132. claude_mpm/skills/bundled/main/skill-creator/references/best-practices.md +500 -0
  133. claude_mpm/skills/bundled/main/skill-creator/references/creation-workflow.md +464 -0
  134. claude_mpm/skills/bundled/main/skill-creator/references/examples.md +619 -0
  135. claude_mpm/skills/bundled/main/skill-creator/references/progressive-disclosure.md +437 -0
  136. claude_mpm/skills/bundled/main/skill-creator/references/skill-structure.md +231 -0
  137. claude_mpm/skills/bundled/main/skill-creator/scripts/init_skill.py +303 -0
  138. claude_mpm/skills/bundled/main/skill-creator/scripts/package_skill.py +113 -0
  139. claude_mpm/skills/bundled/main/skill-creator/scripts/quick_validate.py +72 -0
  140. claude_mpm/skills/bundled/nextjs-local-dev.md +807 -0
  141. claude_mpm/skills/bundled/pdf.md +141 -0
  142. claude_mpm/skills/bundled/performance-profiling.md +567 -0
  143. claude_mpm/skills/bundled/php/espocrm-development/SKILL.md +170 -0
  144. claude_mpm/skills/bundled/php/espocrm-development/references/architecture.md +602 -0
  145. claude_mpm/skills/bundled/php/espocrm-development/references/common-tasks.md +821 -0
  146. claude_mpm/skills/bundled/php/espocrm-development/references/development-workflow.md +742 -0
  147. claude_mpm/skills/bundled/php/espocrm-development/references/frontend-customization.md +726 -0
  148. claude_mpm/skills/bundled/php/espocrm-development/references/hooks-and-services.md +764 -0
  149. claude_mpm/skills/bundled/php/espocrm-development/references/testing-debugging.md +831 -0
  150. claude_mpm/skills/bundled/refactoring-patterns.md +180 -0
  151. claude_mpm/skills/bundled/rust/desktop-applications/SKILL.md +226 -0
  152. claude_mpm/skills/bundled/rust/desktop-applications/references/architecture-patterns.md +901 -0
  153. claude_mpm/skills/bundled/rust/desktop-applications/references/native-gui-frameworks.md +901 -0
  154. claude_mpm/skills/bundled/rust/desktop-applications/references/platform-integration.md +775 -0
  155. claude_mpm/skills/bundled/rust/desktop-applications/references/state-management.md +937 -0
  156. claude_mpm/skills/bundled/rust/desktop-applications/references/tauri-framework.md +770 -0
  157. claude_mpm/skills/bundled/rust/desktop-applications/references/testing-deployment.md +961 -0
  158. claude_mpm/skills/bundled/security-scanning.md +327 -0
  159. claude_mpm/skills/bundled/systematic-debugging.md +473 -0
  160. claude_mpm/skills/bundled/test-driven-development.md +378 -0
  161. claude_mpm/skills/bundled/testing/condition-based-waiting/SKILL.md +119 -0
  162. claude_mpm/skills/bundled/testing/condition-based-waiting/references/patterns-and-implementation.md +253 -0
  163. claude_mpm/skills/bundled/testing/test-driven-development/SKILL.md +145 -0
  164. claude_mpm/skills/bundled/testing/test-driven-development/references/anti-patterns.md +543 -0
  165. claude_mpm/skills/bundled/testing/test-driven-development/references/examples.md +741 -0
  166. claude_mpm/skills/bundled/testing/test-driven-development/references/integration.md +470 -0
  167. claude_mpm/skills/bundled/testing/test-driven-development/references/philosophy.md +458 -0
  168. claude_mpm/skills/bundled/testing/test-driven-development/references/workflow.md +639 -0
  169. claude_mpm/skills/bundled/testing/testing-anti-patterns/SKILL.md +140 -0
  170. claude_mpm/skills/bundled/testing/testing-anti-patterns/references/completeness-anti-patterns.md +572 -0
  171. claude_mpm/skills/bundled/testing/testing-anti-patterns/references/core-anti-patterns.md +411 -0
  172. claude_mpm/skills/bundled/testing/testing-anti-patterns/references/detection-guide.md +569 -0
  173. claude_mpm/skills/bundled/testing/testing-anti-patterns/references/tdd-connection.md +695 -0
  174. claude_mpm/skills/bundled/testing/webapp-testing/SKILL.md +184 -0
  175. claude_mpm/skills/bundled/testing/webapp-testing/decision-tree.md +459 -0
  176. claude_mpm/skills/bundled/testing/webapp-testing/examples/console_logging.py +35 -0
  177. claude_mpm/skills/bundled/testing/webapp-testing/examples/element_discovery.py +44 -0
  178. claude_mpm/skills/bundled/testing/webapp-testing/examples/static_html_automation.py +34 -0
  179. claude_mpm/skills/bundled/testing/webapp-testing/playwright-patterns.md +479 -0
  180. claude_mpm/skills/bundled/testing/webapp-testing/reconnaissance-pattern.md +687 -0
  181. claude_mpm/skills/bundled/testing/webapp-testing/scripts/with_server.py +129 -0
  182. claude_mpm/skills/bundled/testing/webapp-testing/server-management.md +758 -0
  183. claude_mpm/skills/bundled/testing/webapp-testing/troubleshooting.md +868 -0
  184. claude_mpm/skills/bundled/vite-local-dev.md +1061 -0
  185. claude_mpm/skills/bundled/web-performance-optimization.md +2305 -0
  186. claude_mpm/skills/bundled/xlsx.md +157 -0
  187. claude_mpm/skills/registry.py +97 -9
  188. claude_mpm/skills/skills_registry.py +348 -0
  189. claude_mpm/skills/skills_service.py +739 -0
  190. claude_mpm/tools/code_tree_analyzer/__init__.py +45 -0
  191. claude_mpm/tools/code_tree_analyzer/analysis.py +299 -0
  192. claude_mpm/tools/code_tree_analyzer/cache.py +131 -0
  193. claude_mpm/tools/code_tree_analyzer/core.py +380 -0
  194. claude_mpm/tools/code_tree_analyzer/discovery.py +403 -0
  195. claude_mpm/tools/code_tree_analyzer/events.py +168 -0
  196. claude_mpm/tools/code_tree_analyzer/gitignore.py +308 -0
  197. claude_mpm/tools/code_tree_analyzer/models.py +39 -0
  198. claude_mpm/tools/code_tree_analyzer/multilang_analyzer.py +224 -0
  199. claude_mpm/tools/code_tree_analyzer/python_analyzer.py +284 -0
  200. claude_mpm/utils/agent_dependency_loader.py +2 -2
  201. {claude_mpm-4.15.6.dist-info → claude_mpm-4.21.3.dist-info}/METADATA +211 -33
  202. {claude_mpm-4.15.6.dist-info → claude_mpm-4.21.3.dist-info}/RECORD +206 -64
  203. claude_mpm/agents/INSTRUCTIONS_OLD_DEPRECATED.md +0 -602
  204. claude_mpm/cli/commands/mpm_init.py +0 -2008
  205. claude_mpm/tools/code_tree_analyzer.py +0 -1825
  206. {claude_mpm-4.15.6.dist-info → claude_mpm-4.21.3.dist-info}/WHEEL +0 -0
  207. {claude_mpm-4.15.6.dist-info → claude_mpm-4.21.3.dist-info}/entry_points.txt +0 -0
  208. {claude_mpm-4.15.6.dist-info → claude_mpm-4.21.3.dist-info}/licenses/LICENSE +0 -0
  209. {claude_mpm-4.15.6.dist-info → claude_mpm-4.21.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,378 @@
1
+ ---
2
+ skill_id: test-driven-development
3
+ skill_version: 0.1.0
4
+ description: Comprehensive TDD patterns and practices for all programming languages, eliminating redundant testing guidance per agent.
5
+ updated_at: 2025-10-30T17:00:00Z
6
+ tags: [testing, tdd, best-practices, quality-assurance]
7
+ ---
8
+
9
+ # Test-Driven Development (TDD)
10
+
11
+ Comprehensive TDD patterns and practices for all programming languages. This skill eliminates ~500-800 lines of redundant testing guidance per agent.
12
+
13
+ ## When to Use
14
+
15
+ Apply TDD for:
16
+ - New feature implementation
17
+ - Bug fixes (test the bug first)
18
+ - Code refactoring (tests ensure behavior preservation)
19
+ - API development (test contracts)
20
+ - Complex business logic
21
+
22
+ ## TDD Workflow (Red-Green-Refactor)
23
+
24
+ ### 1. Red Phase: Write Failing Test
25
+ ```
26
+ Write a test that:
27
+ - Describes the desired behavior
28
+ - Fails for the right reason (not due to syntax errors)
29
+ - Is focused on a single behavior
30
+ ```
31
+
32
+ ### 2. Green Phase: Make It Pass
33
+ ```
34
+ Write the minimum code to:
35
+ - Pass the test
36
+ - Not introduce regressions
37
+ - Follow existing patterns
38
+ ```
39
+
40
+ ### 3. Refactor Phase: Improve Code
41
+ ```
42
+ While keeping tests green:
43
+ - Remove duplication
44
+ - Improve naming
45
+ - Simplify logic
46
+ - Extract functions/classes
47
+ ```
48
+
49
+ ## Test Structure Patterns
50
+
51
+ ### Arrange-Act-Assert (AAA)
52
+ ```
53
+ // Arrange: Set up test data and conditions
54
+ const user = createTestUser({ role: 'admin' });
55
+
56
+ // Act: Perform the action being tested
57
+ const result = await authenticateUser(user);
58
+
59
+ // Assert: Verify the outcome
60
+ expect(result.isAuthenticated).toBe(true);
61
+ expect(result.permissions).toContain('admin');
62
+ ```
63
+
64
+ ### Given-When-Then (BDD Style)
65
+ ```
66
+ Given: A user with admin privileges
67
+ When: They attempt to access protected resource
68
+ Then: Access is granted with appropriate permissions
69
+ ```
70
+
71
+ ## Test Naming Conventions
72
+
73
+ ### Pattern: `test_should_<expected_behavior>_when_<condition>`
74
+
75
+ **Examples:**
76
+ - `test_should_return_user_when_id_exists()`
77
+ - `test_should_raise_error_when_user_not_found()`
78
+ - `test_should_validate_email_format_when_creating_account()`
79
+
80
+ ### Language-Specific Conventions
81
+
82
+ **Python (pytest):**
83
+ ```python
84
+ def test_should_calculate_total_when_items_added():
85
+ # Arrange
86
+ cart = ShoppingCart()
87
+ cart.add_item(Item("Book", 10.00))
88
+ cart.add_item(Item("Pen", 1.50))
89
+
90
+ # Act
91
+ total = cart.calculate_total()
92
+
93
+ # Assert
94
+ assert total == 11.50
95
+ ```
96
+
97
+ **JavaScript (Jest):**
98
+ ```javascript
99
+ describe('ShoppingCart', () => {
100
+ test('should calculate total when items added', () => {
101
+ const cart = new ShoppingCart();
102
+ cart.addItem({ name: 'Book', price: 10.00 });
103
+ cart.addItem({ name: 'Pen', price: 1.50 });
104
+
105
+ const total = cart.calculateTotal();
106
+
107
+ expect(total).toBe(11.50);
108
+ });
109
+ });
110
+ ```
111
+
112
+ **Go:**
113
+ ```go
114
+ func TestShouldCalculateTotalWhenItemsAdded(t *testing.T) {
115
+ // Arrange
116
+ cart := NewShoppingCart()
117
+ cart.AddItem(Item{Name: "Book", Price: 10.00})
118
+ cart.AddItem(Item{Name: "Pen", Price: 1.50})
119
+
120
+ // Act
121
+ total := cart.CalculateTotal()
122
+
123
+ // Assert
124
+ if total != 11.50 {
125
+ t.Errorf("Expected 11.50, got %f", total)
126
+ }
127
+ }
128
+ ```
129
+
130
+ ## Test Types and Scope
131
+
132
+ ### Unit Tests
133
+ - **Scope:** Single function/method
134
+ - **Dependencies:** Mocked
135
+ - **Speed:** Fast (< 10ms per test)
136
+ - **Coverage:** 80%+ of code paths
137
+
138
+ ### Integration Tests
139
+ - **Scope:** Multiple components
140
+ - **Dependencies:** Real or test doubles
141
+ - **Speed:** Moderate (< 1s per test)
142
+ - **Coverage:** Critical paths and interfaces
143
+
144
+ ### End-to-End Tests
145
+ - **Scope:** Full user workflows
146
+ - **Dependencies:** Real (in test environment)
147
+ - **Speed:** Slow (seconds to minutes)
148
+ - **Coverage:** Core user journeys
149
+
150
+ ## Mocking and Test Doubles
151
+
152
+ ### When to Mock
153
+ - External APIs and services
154
+ - Database operations (for unit tests)
155
+ - File system operations
156
+ - Time-dependent operations
157
+ - Random number generation
158
+
159
+ ### Mock Types
160
+
161
+ **Stub:** Returns predefined data
162
+ ```python
163
+ def get_user_stub(user_id):
164
+ return User(id=user_id, name="Test User")
165
+ ```
166
+
167
+ **Mock:** Verifies interactions
168
+ ```python
169
+ mock_service = Mock()
170
+ service.process_payment(payment_data)
171
+ mock_service.process_payment.assert_called_once_with(payment_data)
172
+ ```
173
+
174
+ **Fake:** Working implementation (simplified)
175
+ ```python
176
+ class FakeDatabase:
177
+ def __init__(self):
178
+ self.data = {}
179
+
180
+ def save(self, key, value):
181
+ self.data[key] = value
182
+
183
+ def get(self, key):
184
+ return self.data.get(key)
185
+ ```
186
+
187
+ ## Test Coverage Guidelines
188
+
189
+ ### Target Coverage Levels
190
+ - **Critical paths:** 100%
191
+ - **Business logic:** 95%+
192
+ - **Overall project:** 80%+
193
+ - **UI components:** 70%+
194
+
195
+ ### What to Test
196
+ - ✅ Business logic and algorithms
197
+ - ✅ Edge cases and boundary conditions
198
+ - ✅ Error handling and validation
199
+ - ✅ State transitions
200
+ - ✅ Public APIs and interfaces
201
+
202
+ ### What NOT to Test
203
+ - ❌ Framework internals
204
+ - ❌ Third-party libraries
205
+ - ❌ Trivial getters/setters
206
+ - ❌ Generated code
207
+ - ❌ Configuration files
208
+
209
+ ## Testing Best Practices
210
+
211
+ ### 1. One Assertion Per Test (When Possible)
212
+ ```python
213
+ # Good: Focused test
214
+ def test_should_validate_email_format():
215
+ assert is_valid_email("user@example.com") is True
216
+
217
+ # Avoid: Multiple unrelated assertions
218
+ def test_validation():
219
+ assert is_valid_email("user@example.com") is True
220
+ assert is_valid_phone("123-456-7890") is True # Different concept
221
+ ```
222
+
223
+ ### 2. Test Independence
224
+ ```python
225
+ # Good: Each test is self-contained
226
+ def test_user_creation():
227
+ user = create_user("test@example.com")
228
+ assert user.email == "test@example.com"
229
+
230
+ # Avoid: Tests depending on execution order
231
+ shared_user = None
232
+
233
+ def test_create_user():
234
+ global shared_user
235
+ shared_user = create_user("test@example.com")
236
+
237
+ def test_update_user(): # Depends on previous test
238
+ shared_user.name = "Updated"
239
+ ```
240
+
241
+ ### 3. Descriptive Test Failures
242
+ ```python
243
+ # Good: Clear failure message
244
+ assert result.status == 200, f"Expected 200, got {result.status}: {result.body}"
245
+
246
+ # Avoid: Unclear failure
247
+ assert result.status == 200
248
+ ```
249
+
250
+ ### 4. Test Data Builders
251
+ ```python
252
+ # Good: Reusable test data creation
253
+ def create_test_user(**overrides):
254
+ defaults = {
255
+ 'email': 'test@example.com',
256
+ 'name': 'Test User',
257
+ 'role': 'user'
258
+ }
259
+ return User(**{**defaults, **overrides})
260
+
261
+ # Usage
262
+ admin = create_test_user(role='admin')
263
+ guest = create_test_user(email='guest@example.com')
264
+ ```
265
+
266
+ ## Testing Anti-Patterns to Avoid
267
+
268
+ ### ❌ Testing Implementation Details
269
+ ```python
270
+ # Bad: Tests internal structure
271
+ def test_user_storage():
272
+ user = User("test@example.com")
273
+ assert user._internal_cache is not None # Implementation detail
274
+ ```
275
+
276
+ ### ❌ Fragile Tests
277
+ ```python
278
+ # Bad: Breaks with harmless changes
279
+ assert user.to_json() == '{"name":"John","email":"john@example.com"}'
280
+
281
+ # Good: Tests behavior, not format
282
+ data = json.loads(user.to_json())
283
+ assert data['name'] == "John"
284
+ assert data['email'] == "john@example.com"
285
+ ```
286
+
287
+ ### ❌ Slow Tests in Unit Test Suite
288
+ ```python
289
+ # Bad: Real HTTP calls in unit tests
290
+ def test_api_integration():
291
+ response = requests.get("https://api.example.com/users") # Slow!
292
+ assert response.status_code == 200
293
+ ```
294
+
295
+ ### ❌ Testing Everything Through UI
296
+ ```python
297
+ # Bad: Testing business logic through UI
298
+ def test_calculation():
299
+ browser.click("#input1")
300
+ browser.type("5")
301
+ browser.click("#input2")
302
+ browser.type("3")
303
+ browser.click("#calculate")
304
+ assert browser.find("#result").text == "8"
305
+
306
+ # Good: Test logic directly
307
+ def test_calculation():
308
+ assert calculate(5, 3) == 8
309
+ ```
310
+
311
+ ## Quick Reference by Language
312
+
313
+ ### Python (pytest)
314
+ ```python
315
+ # Setup/Teardown
316
+ @pytest.fixture
317
+ def database():
318
+ db = create_test_database()
319
+ yield db
320
+ db.cleanup()
321
+
322
+ # Parametrized tests
323
+ @pytest.mark.parametrize("input,expected", [
324
+ ("user@example.com", True),
325
+ ("invalid-email", False),
326
+ ])
327
+ def test_email_validation(input, expected):
328
+ assert is_valid_email(input) == expected
329
+ ```
330
+
331
+ ### JavaScript (Jest)
332
+ ```javascript
333
+ // Setup/Teardown
334
+ beforeEach(() => {
335
+ database = createTestDatabase();
336
+ });
337
+
338
+ afterEach(() => {
339
+ database.cleanup();
340
+ });
341
+
342
+ // Async tests
343
+ test('should fetch user data', async () => {
344
+ const user = await fetchUser(1);
345
+ expect(user.name).toBe('John');
346
+ });
347
+ ```
348
+
349
+ ### Go
350
+ ```go
351
+ // Table-driven tests
352
+ func TestEmailValidation(t *testing.T) {
353
+ tests := []struct {
354
+ input string
355
+ expected bool
356
+ }{
357
+ {"user@example.com", true},
358
+ {"invalid-email", false},
359
+ }
360
+
361
+ for _, tt := range tests {
362
+ result := IsValidEmail(tt.input)
363
+ if result != tt.expected {
364
+ t.Errorf("IsValidEmail(%s) = %v, want %v",
365
+ tt.input, result, tt.expected)
366
+ }
367
+ }
368
+ }
369
+ ```
370
+
371
+ ## TDD Benefits Realized
372
+
373
+ - **Design Improvement:** Tests drive better API design
374
+ - **Documentation:** Tests serve as executable documentation
375
+ - **Confidence:** Refactoring becomes safe
376
+ - **Debugging:** Tests isolate issues quickly
377
+ - **Coverage:** Ensures comprehensive test coverage
378
+ - **Regression Prevention:** Catches bugs before deployment
@@ -0,0 +1,119 @@
1
+ ---
2
+ name: Condition-Based Waiting
3
+ description: Replace arbitrary timeouts with condition polling for reliable async tests
4
+ when_to_use: when tests have race conditions, timing dependencies, or inconsistent pass/fail behavior
5
+ version: 1.1.0
6
+ languages: all
7
+ progressive_disclosure:
8
+ entry_point:
9
+ summary: "Replace arbitrary timeouts with condition polling for reliable async tests"
10
+ when_to_use: "Tests with setTimeout/sleep, flaky tests, or timing-dependent async operations"
11
+ quick_start: |
12
+ 1. Identify arbitrary delays in tests (setTimeout, sleep, time.sleep())
13
+ 2. Replace with condition-based waiting (waitFor pattern)
14
+ 3. Use domain-specific helpers for common scenarios
15
+ See @example.ts for complete working implementation
16
+ core_pattern: |
17
+ // ❌ Guessing at timing
18
+ await new Promise(r => setTimeout(r, 50));
19
+
20
+ // ✅ Waiting for condition
21
+ await waitFor(() => getResult() !== undefined);
22
+ references:
23
+ - path: references/patterns-and-implementation.md
24
+ purpose: Detailed waiting patterns, implementation guide, and common mistakes
25
+ when_to_read: When implementing waitFor or debugging timing issues
26
+ ---
27
+
28
+ # Condition-Based Waiting
29
+
30
+ ## Overview
31
+
32
+ Flaky tests often guess at timing with arbitrary delays. This creates race conditions where tests pass on fast machines but fail under load or in CI.
33
+
34
+ **Core principle:** Wait for the actual condition you care about, not a guess about how long it takes.
35
+
36
+ ## When to Use
37
+
38
+ ```dot
39
+ digraph when_to_use {
40
+ "Test uses setTimeout/sleep?" [shape=diamond];
41
+ "Testing timing behavior?" [shape=diamond];
42
+ "Document WHY timeout needed" [shape=box];
43
+ "Use condition-based waiting" [shape=box];
44
+
45
+ "Test uses setTimeout/sleep?" -> "Testing timing behavior?" [label="yes"];
46
+ "Testing timing behavior?" -> "Document WHY timeout needed" [label="yes"];
47
+ "Testing timing behavior?" -> "Use condition-based waiting" [label="no"];
48
+ }
49
+ ```
50
+
51
+ **Use when:**
52
+ - Tests have arbitrary delays (`setTimeout`, `sleep`, `time.sleep()`)
53
+ - Tests are flaky (pass sometimes, fail under load)
54
+ - Tests timeout when run in parallel
55
+ - Waiting for async operations to complete
56
+
57
+ **Don't use when:**
58
+ - Testing actual timing behavior (debounce, throttle intervals)
59
+ - Always document WHY if using arbitrary timeout
60
+
61
+ ## Core Pattern
62
+
63
+ ```typescript
64
+ // ❌ BEFORE: Guessing at timing
65
+ await new Promise(r => setTimeout(r, 50));
66
+ const result = getResult();
67
+ expect(result).toBeDefined();
68
+
69
+ // ✅ AFTER: Waiting for condition
70
+ await waitFor(() => getResult() !== undefined);
71
+ const result = getResult();
72
+ expect(result).toBeDefined();
73
+ ```
74
+
75
+ ## Quick Patterns
76
+
77
+ | Scenario | Pattern |
78
+ |----------|---------|
79
+ | Wait for event | `waitFor(() => events.find(e => e.type === 'DONE'))` |
80
+ | Wait for state | `waitFor(() => machine.state === 'ready')` |
81
+ | Wait for count | `waitFor(() => items.length >= 5)` |
82
+ | Wait for file | `waitFor(() => fs.existsSync(path))` |
83
+ | Complex condition | `waitFor(() => obj.ready && obj.value > 10)` |
84
+
85
+ ## Implementation
86
+
87
+ Generic polling function:
88
+ ```typescript
89
+ async function waitFor<T>(
90
+ condition: () => T | undefined | null | false,
91
+ description: string,
92
+ timeoutMs = 5000
93
+ ): Promise<T> {
94
+ const startTime = Date.now();
95
+
96
+ while (true) {
97
+ const result = condition();
98
+ if (result) return result;
99
+
100
+ if (Date.now() - startTime > timeoutMs) {
101
+ throw new Error(`Timeout waiting for ${description} after ${timeoutMs}ms`);
102
+ }
103
+
104
+ await new Promise(r => setTimeout(r, 10)); // Poll every 10ms
105
+ }
106
+ }
107
+ ```
108
+
109
+ See @example.ts for complete implementation with domain-specific helpers (`waitForEvent`, `waitForEventCount`, `waitForEventMatch`).
110
+
111
+ For detailed patterns, implementation guide, and common mistakes, see @references/patterns-and-implementation.md
112
+
113
+ ## Real-World Impact
114
+
115
+ From debugging session (2025-10-03):
116
+ - Fixed 15 flaky tests across 3 files
117
+ - Pass rate: 60% → 100%
118
+ - Execution time: 40% faster
119
+ - No more race conditions