claude-mpm 4.15.2__py3-none-any.whl → 4.20.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.
Files changed (203) hide show
  1. claude_mpm/VERSION +1 -1
  2. claude_mpm/agents/BASE_ENGINEER.md +286 -0
  3. claude_mpm/agents/BASE_PM.md +255 -23
  4. claude_mpm/agents/PM_INSTRUCTIONS.md +40 -0
  5. claude_mpm/agents/agent_loader.py +4 -4
  6. claude_mpm/agents/templates/agentic-coder-optimizer.json +9 -2
  7. claude_mpm/agents/templates/api_qa.json +7 -1
  8. claude_mpm/agents/templates/clerk-ops.json +8 -1
  9. claude_mpm/agents/templates/code_analyzer.json +4 -1
  10. claude_mpm/agents/templates/dart_engineer.json +11 -1
  11. claude_mpm/agents/templates/data_engineer.json +11 -1
  12. claude_mpm/agents/templates/documentation.json +6 -1
  13. claude_mpm/agents/templates/engineer.json +18 -1
  14. claude_mpm/agents/templates/gcp_ops_agent.json +8 -1
  15. claude_mpm/agents/templates/golang_engineer.json +11 -1
  16. claude_mpm/agents/templates/java_engineer.json +12 -2
  17. claude_mpm/agents/templates/local_ops_agent.json +216 -37
  18. claude_mpm/agents/templates/nextjs_engineer.json +11 -1
  19. claude_mpm/agents/templates/ops.json +8 -1
  20. claude_mpm/agents/templates/php-engineer.json +11 -1
  21. claude_mpm/agents/templates/project_organizer.json +9 -2
  22. claude_mpm/agents/templates/prompt-engineer.json +5 -1
  23. claude_mpm/agents/templates/python_engineer.json +19 -4
  24. claude_mpm/agents/templates/qa.json +7 -1
  25. claude_mpm/agents/templates/react_engineer.json +11 -1
  26. claude_mpm/agents/templates/refactoring_engineer.json +8 -1
  27. claude_mpm/agents/templates/research.json +4 -1
  28. claude_mpm/agents/templates/ruby-engineer.json +11 -1
  29. claude_mpm/agents/templates/rust_engineer.json +23 -8
  30. claude_mpm/agents/templates/security.json +6 -1
  31. claude_mpm/agents/templates/svelte-engineer.json +225 -0
  32. claude_mpm/agents/templates/ticketing.json +6 -1
  33. claude_mpm/agents/templates/typescript_engineer.json +11 -1
  34. claude_mpm/agents/templates/vercel_ops_agent.json +8 -1
  35. claude_mpm/agents/templates/version_control.json +8 -1
  36. claude_mpm/agents/templates/web_qa.json +7 -1
  37. claude_mpm/agents/templates/web_ui.json +11 -1
  38. claude_mpm/cli/commands/__init__.py +2 -0
  39. claude_mpm/cli/commands/configure.py +164 -16
  40. claude_mpm/cli/commands/configure_agent_display.py +6 -6
  41. claude_mpm/cli/commands/configure_behavior_manager.py +8 -8
  42. claude_mpm/cli/commands/configure_navigation.py +20 -18
  43. claude_mpm/cli/commands/configure_startup_manager.py +14 -14
  44. claude_mpm/cli/commands/configure_template_editor.py +8 -8
  45. claude_mpm/cli/commands/mpm_init.py +109 -24
  46. claude_mpm/cli/commands/skills.py +434 -0
  47. claude_mpm/cli/executor.py +2 -0
  48. claude_mpm/cli/interactive/__init__.py +3 -0
  49. claude_mpm/cli/interactive/skills_wizard.py +491 -0
  50. claude_mpm/cli/parsers/base_parser.py +7 -0
  51. claude_mpm/cli/parsers/skills_parser.py +137 -0
  52. claude_mpm/cli/startup.py +83 -0
  53. claude_mpm/commands/mpm-auto-configure.md +52 -0
  54. claude_mpm/commands/mpm-help.md +3 -0
  55. claude_mpm/commands/mpm-init.md +112 -6
  56. claude_mpm/commands/mpm-version.md +113 -0
  57. claude_mpm/commands/mpm.md +1 -0
  58. claude_mpm/config/agent_config.py +2 -2
  59. claude_mpm/constants.py +12 -0
  60. claude_mpm/core/config.py +42 -0
  61. claude_mpm/core/enums.py +18 -0
  62. claude_mpm/core/factories.py +1 -1
  63. claude_mpm/core/optimized_agent_loader.py +3 -3
  64. claude_mpm/core/types.py +2 -9
  65. claude_mpm/dashboard/static/js/dashboard.js +0 -14
  66. claude_mpm/dashboard/templates/index.html +3 -41
  67. claude_mpm/hooks/__init__.py +8 -0
  68. claude_mpm/hooks/claude_hooks/response_tracking.py +35 -1
  69. claude_mpm/hooks/session_resume_hook.py +121 -0
  70. claude_mpm/models/resume_log.py +340 -0
  71. claude_mpm/services/agents/auto_config_manager.py +1 -1
  72. claude_mpm/services/agents/deployment/agent_configuration_manager.py +1 -1
  73. claude_mpm/services/agents/deployment/agent_record_service.py +1 -1
  74. claude_mpm/services/agents/deployment/agent_validator.py +17 -1
  75. claude_mpm/services/agents/deployment/async_agent_deployment.py +1 -1
  76. claude_mpm/services/agents/deployment/local_template_deployment.py +1 -1
  77. claude_mpm/services/agents/deployment/validation/__init__.py +3 -1
  78. claude_mpm/services/agents/deployment/validation/validation_result.py +1 -9
  79. claude_mpm/services/agents/local_template_manager.py +1 -1
  80. claude_mpm/services/agents/recommender.py +47 -0
  81. claude_mpm/services/cli/resume_service.py +617 -0
  82. claude_mpm/services/cli/session_manager.py +87 -0
  83. claude_mpm/services/cli/session_resume_helper.py +352 -0
  84. claude_mpm/services/core/models/health.py +1 -28
  85. claude_mpm/services/core/path_resolver.py +1 -1
  86. claude_mpm/services/infrastructure/monitoring/__init__.py +1 -1
  87. claude_mpm/services/infrastructure/monitoring/aggregator.py +12 -12
  88. claude_mpm/services/infrastructure/monitoring/base.py +5 -13
  89. claude_mpm/services/infrastructure/monitoring/network.py +7 -6
  90. claude_mpm/services/infrastructure/monitoring/process.py +13 -12
  91. claude_mpm/services/infrastructure/monitoring/resources.py +7 -6
  92. claude_mpm/services/infrastructure/monitoring/service.py +16 -15
  93. claude_mpm/services/infrastructure/resume_log_generator.py +439 -0
  94. claude_mpm/services/local_ops/__init__.py +1 -1
  95. claude_mpm/services/local_ops/crash_detector.py +1 -1
  96. claude_mpm/services/local_ops/health_checks/http_check.py +2 -1
  97. claude_mpm/services/local_ops/health_checks/process_check.py +2 -1
  98. claude_mpm/services/local_ops/health_checks/resource_check.py +2 -1
  99. claude_mpm/services/local_ops/health_manager.py +1 -1
  100. claude_mpm/services/local_ops/restart_manager.py +1 -1
  101. claude_mpm/services/mcp_config_manager.py +7 -131
  102. claude_mpm/services/session_manager.py +205 -1
  103. claude_mpm/services/shared/async_service_base.py +16 -27
  104. claude_mpm/services/shared/lifecycle_service_base.py +1 -14
  105. claude_mpm/services/socketio/handlers/__init__.py +5 -2
  106. claude_mpm/services/socketio/handlers/hook.py +10 -0
  107. claude_mpm/services/socketio/handlers/registry.py +4 -2
  108. claude_mpm/services/socketio/server/main.py +7 -7
  109. claude_mpm/services/unified/deployment_strategies/local.py +1 -1
  110. claude_mpm/services/version_service.py +104 -1
  111. claude_mpm/skills/__init__.py +42 -0
  112. claude_mpm/skills/agent_skills_injector.py +331 -0
  113. claude_mpm/skills/bundled/LICENSE_ATTRIBUTIONS.md +79 -0
  114. claude_mpm/skills/bundled/__init__.py +6 -0
  115. claude_mpm/skills/bundled/api-documentation.md +393 -0
  116. claude_mpm/skills/bundled/async-testing.md +571 -0
  117. claude_mpm/skills/bundled/code-review.md +143 -0
  118. claude_mpm/skills/bundled/collaboration/brainstorming/SKILL.md +75 -0
  119. claude_mpm/skills/bundled/collaboration/dispatching-parallel-agents/SKILL.md +184 -0
  120. claude_mpm/skills/bundled/collaboration/requesting-code-review/SKILL.md +107 -0
  121. claude_mpm/skills/bundled/collaboration/requesting-code-review/code-reviewer.md +146 -0
  122. claude_mpm/skills/bundled/collaboration/writing-plans/SKILL.md +118 -0
  123. claude_mpm/skills/bundled/database-migration.md +199 -0
  124. claude_mpm/skills/bundled/debugging/root-cause-tracing/SKILL.md +177 -0
  125. claude_mpm/skills/bundled/debugging/systematic-debugging/CREATION-LOG.md +119 -0
  126. claude_mpm/skills/bundled/debugging/systematic-debugging/SKILL.md +148 -0
  127. claude_mpm/skills/bundled/debugging/systematic-debugging/references/anti-patterns.md +483 -0
  128. claude_mpm/skills/bundled/debugging/systematic-debugging/references/examples.md +452 -0
  129. claude_mpm/skills/bundled/debugging/systematic-debugging/references/troubleshooting.md +449 -0
  130. claude_mpm/skills/bundled/debugging/systematic-debugging/references/workflow.md +411 -0
  131. claude_mpm/skills/bundled/debugging/systematic-debugging/test-academic.md +14 -0
  132. claude_mpm/skills/bundled/debugging/systematic-debugging/test-pressure-1.md +58 -0
  133. claude_mpm/skills/bundled/debugging/systematic-debugging/test-pressure-2.md +68 -0
  134. claude_mpm/skills/bundled/debugging/systematic-debugging/test-pressure-3.md +69 -0
  135. claude_mpm/skills/bundled/debugging/verification-before-completion/SKILL.md +175 -0
  136. claude_mpm/skills/bundled/debugging/verification-before-completion/references/common-failures.md +213 -0
  137. claude_mpm/skills/bundled/debugging/verification-before-completion/references/gate-function.md +314 -0
  138. claude_mpm/skills/bundled/debugging/verification-before-completion/references/verification-patterns.md +227 -0
  139. claude_mpm/skills/bundled/docker-containerization.md +194 -0
  140. claude_mpm/skills/bundled/express-local-dev.md +1429 -0
  141. claude_mpm/skills/bundled/fastapi-local-dev.md +1199 -0
  142. claude_mpm/skills/bundled/git-workflow.md +414 -0
  143. claude_mpm/skills/bundled/imagemagick.md +204 -0
  144. claude_mpm/skills/bundled/json-data-handling.md +223 -0
  145. claude_mpm/skills/bundled/main/artifacts-builder/SKILL.md +74 -0
  146. claude_mpm/skills/bundled/main/internal-comms/SKILL.md +32 -0
  147. claude_mpm/skills/bundled/main/internal-comms/examples/3p-updates.md +47 -0
  148. claude_mpm/skills/bundled/main/internal-comms/examples/company-newsletter.md +65 -0
  149. claude_mpm/skills/bundled/main/internal-comms/examples/faq-answers.md +30 -0
  150. claude_mpm/skills/bundled/main/internal-comms/examples/general-comms.md +16 -0
  151. claude_mpm/skills/bundled/main/mcp-builder/SKILL.md +328 -0
  152. claude_mpm/skills/bundled/main/mcp-builder/reference/evaluation.md +602 -0
  153. claude_mpm/skills/bundled/main/mcp-builder/reference/mcp_best_practices.md +915 -0
  154. claude_mpm/skills/bundled/main/mcp-builder/reference/node_mcp_server.md +916 -0
  155. claude_mpm/skills/bundled/main/mcp-builder/reference/python_mcp_server.md +752 -0
  156. claude_mpm/skills/bundled/main/mcp-builder/scripts/connections.py +150 -0
  157. claude_mpm/skills/bundled/main/mcp-builder/scripts/evaluation.py +372 -0
  158. claude_mpm/skills/bundled/main/skill-creator/SKILL.md +209 -0
  159. claude_mpm/skills/bundled/main/skill-creator/scripts/init_skill.py +302 -0
  160. claude_mpm/skills/bundled/main/skill-creator/scripts/package_skill.py +111 -0
  161. claude_mpm/skills/bundled/main/skill-creator/scripts/quick_validate.py +65 -0
  162. claude_mpm/skills/bundled/nextjs-local-dev.md +807 -0
  163. claude_mpm/skills/bundled/pdf.md +141 -0
  164. claude_mpm/skills/bundled/performance-profiling.md +567 -0
  165. claude_mpm/skills/bundled/refactoring-patterns.md +180 -0
  166. claude_mpm/skills/bundled/security-scanning.md +327 -0
  167. claude_mpm/skills/bundled/systematic-debugging.md +473 -0
  168. claude_mpm/skills/bundled/test-driven-development.md +378 -0
  169. claude_mpm/skills/bundled/testing/condition-based-waiting/SKILL.md +123 -0
  170. claude_mpm/skills/bundled/testing/test-driven-development/SKILL.md +145 -0
  171. claude_mpm/skills/bundled/testing/test-driven-development/references/anti-patterns.md +543 -0
  172. claude_mpm/skills/bundled/testing/test-driven-development/references/examples.md +741 -0
  173. claude_mpm/skills/bundled/testing/test-driven-development/references/integration.md +470 -0
  174. claude_mpm/skills/bundled/testing/test-driven-development/references/philosophy.md +458 -0
  175. claude_mpm/skills/bundled/testing/test-driven-development/references/workflow.md +639 -0
  176. claude_mpm/skills/bundled/testing/testing-anti-patterns/SKILL.md +304 -0
  177. claude_mpm/skills/bundled/testing/webapp-testing/SKILL.md +96 -0
  178. claude_mpm/skills/bundled/testing/webapp-testing/examples/console_logging.py +35 -0
  179. claude_mpm/skills/bundled/testing/webapp-testing/examples/element_discovery.py +40 -0
  180. claude_mpm/skills/bundled/testing/webapp-testing/examples/static_html_automation.py +34 -0
  181. claude_mpm/skills/bundled/testing/webapp-testing/scripts/with_server.py +107 -0
  182. claude_mpm/skills/bundled/vite-local-dev.md +1061 -0
  183. claude_mpm/skills/bundled/web-performance-optimization.md +2305 -0
  184. claude_mpm/skills/bundled/xlsx.md +157 -0
  185. claude_mpm/skills/registry.py +286 -0
  186. claude_mpm/skills/skill_manager.py +310 -0
  187. claude_mpm/skills/skills_registry.py +351 -0
  188. claude_mpm/skills/skills_service.py +730 -0
  189. claude_mpm/utils/agent_dependency_loader.py +2 -2
  190. {claude_mpm-4.15.2.dist-info → claude_mpm-4.20.3.dist-info}/METADATA +211 -33
  191. {claude_mpm-4.15.2.dist-info → claude_mpm-4.20.3.dist-info}/RECORD +195 -115
  192. claude_mpm/agents/INSTRUCTIONS_OLD_DEPRECATED.md +0 -602
  193. claude_mpm/dashboard/static/css/code-tree.css +0 -1639
  194. claude_mpm/dashboard/static/js/components/code-tree/tree-breadcrumb.js +0 -353
  195. claude_mpm/dashboard/static/js/components/code-tree/tree-constants.js +0 -235
  196. claude_mpm/dashboard/static/js/components/code-tree/tree-search.js +0 -409
  197. claude_mpm/dashboard/static/js/components/code-tree/tree-utils.js +0 -435
  198. claude_mpm/dashboard/static/js/components/code-tree.js +0 -5869
  199. claude_mpm/dashboard/static/js/components/code-viewer.js +0 -1386
  200. {claude_mpm-4.15.2.dist-info → claude_mpm-4.20.3.dist-info}/WHEEL +0 -0
  201. {claude_mpm-4.15.2.dist-info → claude_mpm-4.20.3.dist-info}/entry_points.txt +0 -0
  202. {claude_mpm-4.15.2.dist-info → claude_mpm-4.20.3.dist-info}/licenses/LICENSE +0 -0
  203. {claude_mpm-4.15.2.dist-info → claude_mpm-4.20.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,304 @@
1
+ ---
2
+ name: Testing Anti-Patterns
3
+ description: Never test mock behavior. Never add test-only methods to production classes. Understand dependencies before mocking.
4
+ when_to_use: when writing or changing tests, adding mocks, or tempted to add test-only methods to production code
5
+ version: 1.1.0
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.
@@ -0,0 +1,96 @@
1
+ ---
2
+ name: webapp-testing
3
+ description: Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
4
+ license: Complete terms in LICENSE.txt
5
+ ---
6
+
7
+ # Web Application Testing
8
+
9
+ To test local web applications, write native Python Playwright scripts.
10
+
11
+ **Helper Scripts Available**:
12
+ - `scripts/with_server.py` - Manages server lifecycle (supports multiple servers)
13
+
14
+ **Always run scripts with `--help` first** to see usage. DO NOT read the source until you try running the script first and find that a customized solution is abslutely necessary. These scripts can be very large and thus pollute your context window. They exist to be called directly as black-box scripts rather than ingested into your context window.
15
+
16
+ ## Decision Tree: Choosing Your Approach
17
+
18
+ ```
19
+ User task → Is it static HTML?
20
+ ├─ Yes → Read HTML file directly to identify selectors
21
+ │ ├─ Success → Write Playwright script using selectors
22
+ │ └─ Fails/Incomplete → Treat as dynamic (below)
23
+
24
+ └─ No (dynamic webapp) → Is the server already running?
25
+ ├─ No → Run: python scripts/with_server.py --help
26
+ │ Then use the helper + write simplified Playwright script
27
+
28
+ └─ Yes → Reconnaissance-then-action:
29
+ 1. Navigate and wait for networkidle
30
+ 2. Take screenshot or inspect DOM
31
+ 3. Identify selectors from rendered state
32
+ 4. Execute actions with discovered selectors
33
+ ```
34
+
35
+ ## Example: Using with_server.py
36
+
37
+ To start a server, run `--help` first, then use the helper:
38
+
39
+ **Single server:**
40
+ ```bash
41
+ python scripts/with_server.py --server "npm run dev" --port 5173 -- python your_automation.py
42
+ ```
43
+
44
+ **Multiple servers (e.g., backend + frontend):**
45
+ ```bash
46
+ python scripts/with_server.py \
47
+ --server "cd backend && python server.py" --port 3000 \
48
+ --server "cd frontend && npm run dev" --port 5173 \
49
+ -- python your_automation.py
50
+ ```
51
+
52
+ To create an automation script, include only Playwright logic (servers are managed automatically):
53
+ ```python
54
+ from playwright.sync_api import sync_playwright
55
+
56
+ with sync_playwright() as p:
57
+ browser = p.chromium.launch(headless=True) # Always launch chromium in headless mode
58
+ page = browser.new_page()
59
+ page.goto('http://localhost:5173') # Server already running and ready
60
+ page.wait_for_load_state('networkidle') # CRITICAL: Wait for JS to execute
61
+ # ... your automation logic
62
+ browser.close()
63
+ ```
64
+
65
+ ## Reconnaissance-Then-Action Pattern
66
+
67
+ 1. **Inspect rendered DOM**:
68
+ ```python
69
+ page.screenshot(path='/tmp/inspect.png', full_page=True)
70
+ content = page.content()
71
+ page.locator('button').all()
72
+ ```
73
+
74
+ 2. **Identify selectors** from inspection results
75
+
76
+ 3. **Execute actions** using discovered selectors
77
+
78
+ ## Common Pitfall
79
+
80
+ ❌ **Don't** inspect the DOM before waiting for `networkidle` on dynamic apps
81
+ ✅ **Do** wait for `page.wait_for_load_state('networkidle')` before inspection
82
+
83
+ ## Best Practices
84
+
85
+ - **Use bundled scripts as black boxes** - To accomplish a task, consider whether one of the scripts available in `scripts/` can help. These scripts handle common, complex workflows reliably without cluttering the context window. Use `--help` to see usage, then invoke directly.
86
+ - Use `sync_playwright()` for synchronous scripts
87
+ - Always close the browser when done
88
+ - Use descriptive selectors: `text=`, `role=`, CSS selectors, or IDs
89
+ - Add appropriate waits: `page.wait_for_selector()` or `page.wait_for_timeout()`
90
+
91
+ ## Reference Files
92
+
93
+ - **examples/** - Examples showing common patterns:
94
+ - `element_discovery.py` - Discovering buttons, links, and inputs on a page
95
+ - `static_html_automation.py` - Using file:// URLs for local HTML
96
+ - `console_logging.py` - Capturing console logs during automation
@@ -0,0 +1,35 @@
1
+ from playwright.sync_api import sync_playwright
2
+
3
+ # Example: Capturing console logs during browser automation
4
+
5
+ url = 'http://localhost:5173' # Replace with your URL
6
+
7
+ console_logs = []
8
+
9
+ with sync_playwright() as p:
10
+ browser = p.chromium.launch(headless=True)
11
+ page = browser.new_page(viewport={'width': 1920, 'height': 1080})
12
+
13
+ # Set up console log capture
14
+ def handle_console_message(msg):
15
+ console_logs.append(f"[{msg.type}] {msg.text}")
16
+ print(f"Console: [{msg.type}] {msg.text}")
17
+
18
+ page.on("console", handle_console_message)
19
+
20
+ # Navigate to page
21
+ page.goto(url)
22
+ page.wait_for_load_state('networkidle')
23
+
24
+ # Interact with the page (triggers console logs)
25
+ page.click('text=Dashboard')
26
+ page.wait_for_timeout(1000)
27
+
28
+ browser.close()
29
+
30
+ # Save console logs to file
31
+ with open('/mnt/user-data/outputs/console.log', 'w') as f:
32
+ f.write('\n'.join(console_logs))
33
+
34
+ print(f"\nCaptured {len(console_logs)} console messages")
35
+ print("Logs saved to: /mnt/user-data/outputs/console.log")
@@ -0,0 +1,40 @@
1
+ from playwright.sync_api import sync_playwright
2
+
3
+ # Example: Discovering buttons and other elements on a page
4
+
5
+ with sync_playwright() as p:
6
+ browser = p.chromium.launch(headless=True)
7
+ page = browser.new_page()
8
+
9
+ # Navigate to page and wait for it to fully load
10
+ page.goto('http://localhost:5173')
11
+ page.wait_for_load_state('networkidle')
12
+
13
+ # Discover all buttons on the page
14
+ buttons = page.locator('button').all()
15
+ print(f"Found {len(buttons)} buttons:")
16
+ for i, button in enumerate(buttons):
17
+ text = button.inner_text() if button.is_visible() else "[hidden]"
18
+ print(f" [{i}] {text}")
19
+
20
+ # Discover links
21
+ links = page.locator('a[href]').all()
22
+ print(f"\nFound {len(links)} links:")
23
+ for link in links[:5]: # Show first 5
24
+ text = link.inner_text().strip()
25
+ href = link.get_attribute('href')
26
+ print(f" - {text} -> {href}")
27
+
28
+ # Discover input fields
29
+ inputs = page.locator('input, textarea, select').all()
30
+ print(f"\nFound {len(inputs)} input fields:")
31
+ for input_elem in inputs:
32
+ name = input_elem.get_attribute('name') or input_elem.get_attribute('id') or "[unnamed]"
33
+ input_type = input_elem.get_attribute('type') or 'text'
34
+ print(f" - {name} ({input_type})")
35
+
36
+ # Take screenshot for visual reference
37
+ page.screenshot(path='/tmp/page_discovery.png', full_page=True)
38
+ print("\nScreenshot saved to /tmp/page_discovery.png")
39
+
40
+ browser.close()
@@ -0,0 +1,34 @@
1
+ import os
2
+
3
+ from playwright.sync_api import sync_playwright
4
+
5
+ # Example: Automating interaction with static HTML files using file:// URLs
6
+
7
+ html_file_path = os.path.abspath('path/to/your/file.html')
8
+ file_url = f'file://{html_file_path}'
9
+
10
+ with sync_playwright() as p:
11
+ browser = p.chromium.launch(headless=True)
12
+ page = browser.new_page(viewport={'width': 1920, 'height': 1080})
13
+
14
+ # Navigate to local HTML file
15
+ page.goto(file_url)
16
+
17
+ # Take screenshot
18
+ page.screenshot(path='/mnt/user-data/outputs/static_page.png', full_page=True)
19
+
20
+ # Interact with elements
21
+ page.click('text=Click Me')
22
+ page.fill('#name', 'John Doe')
23
+ page.fill('#email', 'john@example.com')
24
+
25
+ # Submit form
26
+ page.click('button[type="submit"]')
27
+ page.wait_for_timeout(500)
28
+
29
+ # Take final screenshot
30
+ page.screenshot(path='/mnt/user-data/outputs/after_submit.png', full_page=True)
31
+
32
+ browser.close()
33
+
34
+ print("Static HTML automation completed!")
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Start one or more servers, wait for them to be ready, run a command, then clean up.
4
+
5
+ Usage:
6
+ # Single server
7
+ python scripts/with_server.py --server "npm run dev" --port 5173 -- python automation.py
8
+ python scripts/with_server.py --server "npm start" --port 3000 -- python test.py
9
+
10
+ # Multiple servers
11
+ python scripts/with_server.py \
12
+ --server "cd backend && python server.py" --port 3000 \
13
+ --server "cd frontend && npm run dev" --port 5173 \
14
+ -- python test.py
15
+ """
16
+
17
+ import argparse
18
+ import socket
19
+ import subprocess
20
+ import sys
21
+ import time
22
+
23
+
24
+ def is_server_ready(port, timeout=30):
25
+ """Wait for server to be ready by polling the port."""
26
+ start_time = time.time()
27
+ while time.time() - start_time < timeout:
28
+ try:
29
+ with socket.create_connection(('localhost', port), timeout=1):
30
+ return True
31
+ except (OSError, ConnectionRefusedError):
32
+ time.sleep(0.5)
33
+ return False
34
+
35
+
36
+ def main():
37
+ parser = argparse.ArgumentParser(description='Run command with one or more servers')
38
+ parser.add_argument('--server', action='append', dest='servers', required=True, help='Server command (can be repeated)')
39
+ parser.add_argument('--port', action='append', dest='ports', type=int, required=True, help='Port for each server (must match --server count)')
40
+ parser.add_argument('--timeout', type=int, default=30, help='Timeout in seconds per server (default: 30)')
41
+ parser.add_argument('command', nargs=argparse.REMAINDER, help='Command to run after server(s) ready')
42
+
43
+ args = parser.parse_args()
44
+
45
+ # Remove the '--' separator if present
46
+ if args.command and args.command[0] == '--':
47
+ args.command = args.command[1:]
48
+
49
+ if not args.command:
50
+ print("Error: No command specified to run")
51
+ sys.exit(1)
52
+
53
+ # Parse server configurations
54
+ if len(args.servers) != len(args.ports):
55
+ print("Error: Number of --server and --port arguments must match")
56
+ sys.exit(1)
57
+
58
+ servers = []
59
+ for cmd, port in zip(args.servers, args.ports):
60
+ servers.append({'cmd': cmd, 'port': port})
61
+
62
+ server_processes = []
63
+
64
+ try:
65
+ # Start all servers
66
+ for i, server in enumerate(servers):
67
+ print(f"Starting server {i+1}/{len(servers)}: {server['cmd']}")
68
+
69
+ # Use shell=True to support commands with cd and &&
70
+ process = subprocess.Popen(
71
+ server['cmd'],
72
+ shell=True,
73
+ stdout=subprocess.PIPE,
74
+ stderr=subprocess.PIPE
75
+ )
76
+ server_processes.append(process)
77
+
78
+ # Wait for this server to be ready
79
+ print(f"Waiting for server on port {server['port']}...")
80
+ if not is_server_ready(server['port'], timeout=args.timeout):
81
+ raise RuntimeError(f"Server failed to start on port {server['port']} within {args.timeout}s")
82
+
83
+ print(f"Server ready on port {server['port']}")
84
+
85
+ print(f"\nAll {len(servers)} server(s) ready")
86
+
87
+ # Run the command
88
+ print(f"Running: {' '.join(args.command)}\n")
89
+ result = subprocess.run(args.command, check=False)
90
+ sys.exit(result.returncode)
91
+
92
+ finally:
93
+ # Clean up all servers
94
+ print(f"\nStopping {len(server_processes)} server(s)...")
95
+ for i, process in enumerate(server_processes):
96
+ try:
97
+ process.terminate()
98
+ process.wait(timeout=5)
99
+ except subprocess.TimeoutExpired:
100
+ process.kill()
101
+ process.wait()
102
+ print(f"Server {i+1} stopped")
103
+ print("All servers stopped")
104
+
105
+
106
+ if __name__ == '__main__':
107
+ main()