bros-harness 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +21 -0
  3. package/README.md +183 -0
  4. package/SECURITY.md +16 -0
  5. package/assets/agents.manifest.json +55 -0
  6. package/assets/commands.manifest.json +35 -0
  7. package/assets/docs.manifest.json +20 -0
  8. package/assets/import-report.md +25 -0
  9. package/assets/manifest.json +799 -0
  10. package/assets/opencode/agents/README.md +3 -0
  11. package/assets/opencode/agents/bro-build.md +256 -0
  12. package/assets/opencode/agents/bro-design.md +77 -0
  13. package/assets/opencode/agents/bro-docs.md +72 -0
  14. package/assets/opencode/agents/bro-explore.md +143 -0
  15. package/assets/opencode/agents/bro-ops.md +195 -0
  16. package/assets/opencode/agents/bro-shield.md +77 -0
  17. package/assets/opencode/agents/bro-test.md +204 -0
  18. package/assets/opencode/agents/bro-ui.md +135 -0
  19. package/assets/opencode/agents/mighty-bro.md +252 -0
  20. package/assets/opencode/commands/README.md +3 -0
  21. package/assets/opencode/commands/bros-assemble.md +32 -0
  22. package/assets/opencode/commands/bros-build.md +58 -0
  23. package/assets/opencode/commands/bros-plan.md +83 -0
  24. package/assets/opencode/commands/bros-review.md +38 -0
  25. package/assets/opencode/commands/bros-status.md +26 -0
  26. package/assets/opencode/docs/README.md +3 -0
  27. package/assets/opencode/docs/bros-builtin-skills.md +63 -0
  28. package/assets/opencode/docs/bros-harness.md +194 -0
  29. package/assets/opencode/skills/README.md +3 -0
  30. package/assets/opencode/skills/agent-architecture-audit/SKILL.md +256 -0
  31. package/assets/opencode/skills/agent-harness-construction/.openskills.json +7 -0
  32. package/assets/opencode/skills/agent-harness-construction/SKILL.md +73 -0
  33. package/assets/opencode/skills/agent-introspection-debugging/.openskills.json +7 -0
  34. package/assets/opencode/skills/agent-introspection-debugging/SKILL.md +153 -0
  35. package/assets/opencode/skills/api-design/.openskills.json +7 -0
  36. package/assets/opencode/skills/api-design/agents/openai.yaml +7 -0
  37. package/assets/opencode/skills/architecture-decision-records/.openskills.json +7 -0
  38. package/assets/opencode/skills/architecture-decision-records/SKILL.md +179 -0
  39. package/assets/opencode/skills/article-writing/.openskills.json +7 -0
  40. package/assets/opencode/skills/article-writing/SKILL.md +79 -0
  41. package/assets/opencode/skills/article-writing/agents/openai.yaml +7 -0
  42. package/assets/opencode/skills/automation-audit-ops/.openskills.json +7 -0
  43. package/assets/opencode/skills/automation-audit-ops/SKILL.md +142 -0
  44. package/assets/opencode/skills/backend-patterns/.openskills.json +7 -0
  45. package/assets/opencode/skills/backend-patterns/SKILL.md +561 -0
  46. package/assets/opencode/skills/backend-patterns/agents/openai.yaml +7 -0
  47. package/assets/opencode/skills/benchmark/.openskills.json +7 -0
  48. package/assets/opencode/skills/benchmark/SKILL.md +93 -0
  49. package/assets/opencode/skills/bros-orchestrate/SKILL.md +455 -0
  50. package/assets/opencode/skills/browser-qa/.openskills.json +7 -0
  51. package/assets/opencode/skills/browser-qa/SKILL.md +87 -0
  52. package/assets/opencode/skills/canary-watch/.openskills.json +7 -0
  53. package/assets/opencode/skills/canary-watch/SKILL.md +107 -0
  54. package/assets/opencode/skills/code-review-expert/SKILL.md +155 -0
  55. package/assets/opencode/skills/code-review-expert/agents/agent.yaml +7 -0
  56. package/assets/opencode/skills/code-review-expert/references/code-quality-checklist.md +130 -0
  57. package/assets/opencode/skills/code-review-expert/references/removal-plan.md +52 -0
  58. package/assets/opencode/skills/code-review-expert/references/security-checklist.md +118 -0
  59. package/assets/opencode/skills/code-review-expert/references/solid-checklist.md +65 -0
  60. package/assets/opencode/skills/code-tour/.openskills.json +7 -0
  61. package/assets/opencode/skills/code-tour/SKILL.md +236 -0
  62. package/assets/opencode/skills/coding-standards/.openskills.json +7 -0
  63. package/assets/opencode/skills/coding-standards/SKILL.md +549 -0
  64. package/assets/opencode/skills/coding-standards/agents/openai.yaml +7 -0
  65. package/assets/opencode/skills/context-budget/.openskills.json +7 -0
  66. package/assets/opencode/skills/context-budget/SKILL.md +135 -0
  67. package/assets/opencode/skills/database-migrations/.openskills.json +7 -0
  68. package/assets/opencode/skills/database-migrations/SKILL.md +429 -0
  69. package/assets/opencode/skills/deployment-patterns/.openskills.json +7 -0
  70. package/assets/opencode/skills/deployment-patterns/SKILL.md +427 -0
  71. package/assets/opencode/skills/design-system/.openskills.json +7 -0
  72. package/assets/opencode/skills/design-system/SKILL.md +82 -0
  73. package/assets/opencode/skills/docker-patterns/.openskills.json +7 -0
  74. package/assets/opencode/skills/docker-patterns/SKILL.md +364 -0
  75. package/assets/opencode/skills/documentation-lookup/.openskills.json +7 -0
  76. package/assets/opencode/skills/documentation-lookup/SKILL.md +90 -0
  77. package/assets/opencode/skills/documentation-lookup/agents/openai.yaml +7 -0
  78. package/assets/opencode/skills/e2e-testing/.openskills.json +7 -0
  79. package/assets/opencode/skills/e2e-testing/SKILL.md +326 -0
  80. package/assets/opencode/skills/e2e-testing/agents/openai.yaml +7 -0
  81. package/assets/opencode/skills/error-handling/SKILL.md +376 -0
  82. package/assets/opencode/skills/frontend-design/.openskills.json +7 -0
  83. package/assets/opencode/skills/frontend-design/SKILL.md +145 -0
  84. package/assets/opencode/skills/frontend-design-direction/SKILL.md +92 -0
  85. package/assets/opencode/skills/frontend-patterns/.openskills.json +7 -0
  86. package/assets/opencode/skills/frontend-patterns/SKILL.md +642 -0
  87. package/assets/opencode/skills/frontend-patterns/agents/openai.yaml +7 -0
  88. package/assets/opencode/skills/gateguard/.openskills.json +7 -0
  89. package/assets/opencode/skills/gateguard/SKILL.md +125 -0
  90. package/assets/opencode/skills/git-master/SKILL.md +60 -0
  91. package/assets/opencode/skills/golang-patterns/.openskills.json +7 -0
  92. package/assets/opencode/skills/golang-patterns/SKILL.md +674 -0
  93. package/assets/opencode/skills/golang-testing/.openskills.json +7 -0
  94. package/assets/opencode/skills/golang-testing/SKILL.md +720 -0
  95. package/assets/opencode/skills/grafana-dashboard-design/SKILL.md +65 -0
  96. package/assets/opencode/skills/hexagonal-architecture/.openskills.json +7 -0
  97. package/assets/opencode/skills/hexagonal-architecture/SKILL.md +276 -0
  98. package/assets/opencode/skills/java-coding-standards/.openskills.json +7 -0
  99. package/assets/opencode/skills/java-coding-standards/SKILL.md +383 -0
  100. package/assets/opencode/skills/jpa-patterns/.openskills.json +7 -0
  101. package/assets/opencode/skills/jpa-patterns/SKILL.md +151 -0
  102. package/assets/opencode/skills/knowledge-ops/.openskills.json +7 -0
  103. package/assets/opencode/skills/knowledge-ops/SKILL.md +154 -0
  104. package/assets/opencode/skills/make-interfaces-feel-better/SKILL.md +151 -0
  105. package/assets/opencode/skills/mysql-patterns/SKILL.md +412 -0
  106. package/assets/opencode/skills/nestjs-patterns/.openskills.json +7 -0
  107. package/assets/opencode/skills/nestjs-patterns/SKILL.md +230 -0
  108. package/assets/opencode/skills/nextjs-turbopack/.openskills.json +7 -0
  109. package/assets/opencode/skills/nextjs-turbopack/SKILL.md +57 -0
  110. package/assets/opencode/skills/nextjs-turbopack/agents/openai.yaml +7 -0
  111. package/assets/opencode/skills/parallel-execution-optimizer/SKILL.md +72 -0
  112. package/assets/opencode/skills/postgres-patterns/.openskills.json +7 -0
  113. package/assets/opencode/skills/postgres-patterns/SKILL.md +147 -0
  114. package/assets/opencode/skills/prisma-patterns/SKILL.md +371 -0
  115. package/assets/opencode/skills/product-capability/.openskills.json +7 -0
  116. package/assets/opencode/skills/product-capability/SKILL.md +141 -0
  117. package/assets/opencode/skills/product-lens/.openskills.json +7 -0
  118. package/assets/opencode/skills/product-lens/SKILL.md +92 -0
  119. package/assets/opencode/skills/production-audit/SKILL.md +206 -0
  120. package/assets/opencode/skills/python-patterns/.openskills.json +7 -0
  121. package/assets/opencode/skills/python-patterns/SKILL.md +750 -0
  122. package/assets/opencode/skills/python-testing/.openskills.json +7 -0
  123. package/assets/opencode/skills/python-testing/SKILL.md +816 -0
  124. package/assets/opencode/skills/redis-patterns/SKILL.md +403 -0
  125. package/assets/opencode/skills/requirements-clarity/README.md +260 -0
  126. package/assets/opencode/skills/requirements-clarity/SKILL.md +324 -0
  127. package/assets/opencode/skills/rust-patterns/.openskills.json +7 -0
  128. package/assets/opencode/skills/rust-patterns/SKILL.md +499 -0
  129. package/assets/opencode/skills/rust-testing/.openskills.json +7 -0
  130. package/assets/opencode/skills/rust-testing/SKILL.md +500 -0
  131. package/assets/opencode/skills/safety-guard/.openskills.json +7 -0
  132. package/assets/opencode/skills/safety-guard/SKILL.md +75 -0
  133. package/assets/opencode/skills/search-first/.openskills.json +7 -0
  134. package/assets/opencode/skills/search-first/SKILL.md +181 -0
  135. package/assets/opencode/skills/security-review/.openskills.json +7 -0
  136. package/assets/opencode/skills/security-review/agents/openai.yaml +7 -0
  137. package/assets/opencode/skills/security-review/cloud-infrastructure-security.md +361 -0
  138. package/assets/opencode/skills/security-scan/.openskills.json +7 -0
  139. package/assets/opencode/skills/security-scan/SKILL.md +165 -0
  140. package/assets/opencode/skills/springboot-patterns/.openskills.json +7 -0
  141. package/assets/opencode/skills/springboot-patterns/SKILL.md +314 -0
  142. package/assets/opencode/skills/springboot-tdd/.openskills.json +7 -0
  143. package/assets/opencode/skills/springboot-tdd/SKILL.md +158 -0
  144. package/assets/opencode/skills/springboot-verification/.openskills.json +7 -0
  145. package/assets/opencode/skills/springboot-verification/SKILL.md +231 -0
  146. package/assets/opencode/skills/strategic-compact/.openskills.json +7 -0
  147. package/assets/opencode/skills/strategic-compact/SKILL.md +131 -0
  148. package/assets/opencode/skills/strategic-compact/agents/openai.yaml +7 -0
  149. package/assets/opencode/skills/strategic-compact/suggest-compact.sh +54 -0
  150. package/assets/opencode/skills/tdd-workflow/.openskills.json +7 -0
  151. package/assets/opencode/skills/tdd-workflow/SKILL.md +463 -0
  152. package/assets/opencode/skills/tdd-workflow/agents/openai.yaml +7 -0
  153. package/assets/opencode/skills/verification-loop/.openskills.json +7 -0
  154. package/assets/opencode/skills/verification-loop/SKILL.md +126 -0
  155. package/assets/opencode/skills/verification-loop/agents/openai.yaml +7 -0
  156. package/assets/opencode/skills/vite-patterns/SKILL.md +449 -0
  157. package/assets/opencode/skills/web-doc-search/SKILL.md +51 -0
  158. package/assets/opencode/templates/README.md +3 -0
  159. package/assets/opencode/templates/bros/adr.md +39 -0
  160. package/assets/opencode/templates/bros/delivery-report.md +71 -0
  161. package/assets/opencode/templates/bros/explorer-evidence-packet.md +51 -0
  162. package/assets/opencode/templates/bros/prd.md +72 -0
  163. package/assets/opencode/templates/bros/security-review.md +48 -0
  164. package/assets/opencode/templates/bros/status-board.md +33 -0
  165. package/assets/opencode/templates/bros/task-packet.md +94 -0
  166. package/assets/opencode/templates/bros/test-strategy.md +57 -0
  167. package/assets/opencode/templates/bros/ui-implementation-packet.md +64 -0
  168. package/assets/skills.manifest.json +650 -0
  169. package/assets/templates.manifest.json +55 -0
  170. package/bin/bros.mjs +122 -0
  171. package/docs/compatibility.md +9 -0
  172. package/docs/installation.md +66 -0
  173. package/docs/integrations/claude.md +5 -0
  174. package/docs/integrations/codex.md +5 -0
  175. package/docs/integrations/opencode.md +39 -0
  176. package/docs/migration/from-local-opencode-config.md +10 -0
  177. package/docs/release-process.md +11 -0
  178. package/docs/repository-structure.md +15 -0
  179. package/docs/roadmap.md +20 -0
  180. package/docs/security.md +18 -0
  181. package/docs/testing.md +9 -0
  182. package/examples/opencode/README.md +11 -0
  183. package/examples/opencode/opencode.example.jsonc +4 -0
  184. package/package.json +43 -0
  185. package/scripts/validate-assets.mjs +22 -0
  186. package/scripts/verify-no-secrets.mjs +38 -0
  187. package/src/plugin.mjs +98 -0
@@ -0,0 +1,326 @@
1
+ ---
2
+ name: e2e-testing
3
+ description: Playwright E2E testing patterns, Page Object Model, configuration, CI/CD integration, artifact management, and flaky test strategies.
4
+ origin: ECC
5
+ ---
6
+
7
+ # E2E Testing Patterns
8
+
9
+ Comprehensive Playwright patterns for building stable, fast, and maintainable E2E test suites.
10
+
11
+ ## Test File Organization
12
+
13
+ ```
14
+ tests/
15
+ ├── e2e/
16
+ │ ├── auth/
17
+ │ │ ├── login.spec.ts
18
+ │ │ ├── logout.spec.ts
19
+ │ │ └── register.spec.ts
20
+ │ ├── features/
21
+ │ │ ├── browse.spec.ts
22
+ │ │ ├── search.spec.ts
23
+ │ │ └── create.spec.ts
24
+ │ └── api/
25
+ │ └── endpoints.spec.ts
26
+ ├── fixtures/
27
+ │ ├── auth.ts
28
+ │ └── data.ts
29
+ └── playwright.config.ts
30
+ ```
31
+
32
+ ## Page Object Model (POM)
33
+
34
+ ```typescript
35
+ import { Page, Locator } from '@playwright/test'
36
+
37
+ export class ItemsPage {
38
+ readonly page: Page
39
+ readonly searchInput: Locator
40
+ readonly itemCards: Locator
41
+ readonly createButton: Locator
42
+
43
+ constructor(page: Page) {
44
+ this.page = page
45
+ this.searchInput = page.locator('[data-testid="search-input"]')
46
+ this.itemCards = page.locator('[data-testid="item-card"]')
47
+ this.createButton = page.locator('[data-testid="create-btn"]')
48
+ }
49
+
50
+ async goto() {
51
+ await this.page.goto('/items')
52
+ await this.page.waitForLoadState('networkidle')
53
+ }
54
+
55
+ async search(query: string) {
56
+ await this.searchInput.fill(query)
57
+ await this.page.waitForResponse(resp => resp.url().includes('/api/search'))
58
+ await this.page.waitForLoadState('networkidle')
59
+ }
60
+
61
+ async getItemCount() {
62
+ return await this.itemCards.count()
63
+ }
64
+ }
65
+ ```
66
+
67
+ ## Test Structure
68
+
69
+ ```typescript
70
+ import { test, expect } from '@playwright/test'
71
+ import { ItemsPage } from '../../pages/ItemsPage'
72
+
73
+ test.describe('Item Search', () => {
74
+ let itemsPage: ItemsPage
75
+
76
+ test.beforeEach(async ({ page }) => {
77
+ itemsPage = new ItemsPage(page)
78
+ await itemsPage.goto()
79
+ })
80
+
81
+ test('should search by keyword', async ({ page }) => {
82
+ await itemsPage.search('test')
83
+
84
+ const count = await itemsPage.getItemCount()
85
+ expect(count).toBeGreaterThan(0)
86
+
87
+ await expect(itemsPage.itemCards.first()).toContainText(/test/i)
88
+ await page.screenshot({ path: 'artifacts/search-results.png' })
89
+ })
90
+
91
+ test('should handle no results', async ({ page }) => {
92
+ await itemsPage.search('xyznonexistent123')
93
+
94
+ await expect(page.locator('[data-testid="no-results"]')).toBeVisible()
95
+ expect(await itemsPage.getItemCount()).toBe(0)
96
+ })
97
+ })
98
+ ```
99
+
100
+ ## Playwright Configuration
101
+
102
+ ```typescript
103
+ import { defineConfig, devices } from '@playwright/test'
104
+
105
+ export default defineConfig({
106
+ testDir: './tests/e2e',
107
+ fullyParallel: true,
108
+ forbidOnly: !!process.env.CI,
109
+ retries: process.env.CI ? 2 : 0,
110
+ workers: process.env.CI ? 1 : undefined,
111
+ reporter: [
112
+ ['html', { outputFolder: 'playwright-report' }],
113
+ ['junit', { outputFile: 'playwright-results.xml' }],
114
+ ['json', { outputFile: 'playwright-results.json' }]
115
+ ],
116
+ use: {
117
+ baseURL: process.env.BASE_URL || 'http://localhost:3000',
118
+ trace: 'on-first-retry',
119
+ screenshot: 'only-on-failure',
120
+ video: 'retain-on-failure',
121
+ actionTimeout: 10000,
122
+ navigationTimeout: 30000,
123
+ },
124
+ projects: [
125
+ { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
126
+ { name: 'firefox', use: { ...devices['Desktop Firefox'] } },
127
+ { name: 'webkit', use: { ...devices['Desktop Safari'] } },
128
+ { name: 'mobile-chrome', use: { ...devices['Pixel 5'] } },
129
+ ],
130
+ webServer: {
131
+ command: 'npm run dev',
132
+ url: 'http://localhost:3000',
133
+ reuseExistingServer: !process.env.CI,
134
+ timeout: 120000,
135
+ },
136
+ })
137
+ ```
138
+
139
+ ## Flaky Test Patterns
140
+
141
+ ### Quarantine
142
+
143
+ ```typescript
144
+ test('flaky: complex search', async ({ page }) => {
145
+ test.fixme(true, 'Flaky - Issue #123')
146
+ // test code...
147
+ })
148
+
149
+ test('conditional skip', async ({ page }) => {
150
+ test.skip(process.env.CI, 'Flaky in CI - Issue #123')
151
+ // test code...
152
+ })
153
+ ```
154
+
155
+ ### Identify Flakiness
156
+
157
+ ```bash
158
+ npx playwright test tests/search.spec.ts --repeat-each=10
159
+ npx playwright test tests/search.spec.ts --retries=3
160
+ ```
161
+
162
+ ### Common Causes & Fixes
163
+
164
+ **Race conditions:**
165
+ ```typescript
166
+ // Bad: assumes element is ready
167
+ await page.click('[data-testid="button"]')
168
+
169
+ // Good: auto-wait locator
170
+ await page.locator('[data-testid="button"]').click()
171
+ ```
172
+
173
+ **Network timing:**
174
+ ```typescript
175
+ // Bad: arbitrary timeout
176
+ await page.waitForTimeout(5000)
177
+
178
+ // Good: wait for specific condition
179
+ await page.waitForResponse(resp => resp.url().includes('/api/data'))
180
+ ```
181
+
182
+ **Animation timing:**
183
+ ```typescript
184
+ // Bad: click during animation
185
+ await page.click('[data-testid="menu-item"]')
186
+
187
+ // Good: wait for stability
188
+ await page.locator('[data-testid="menu-item"]').waitFor({ state: 'visible' })
189
+ await page.waitForLoadState('networkidle')
190
+ await page.locator('[data-testid="menu-item"]').click()
191
+ ```
192
+
193
+ ## Artifact Management
194
+
195
+ ### Screenshots
196
+
197
+ ```typescript
198
+ await page.screenshot({ path: 'artifacts/after-login.png' })
199
+ await page.screenshot({ path: 'artifacts/full-page.png', fullPage: true })
200
+ await page.locator('[data-testid="chart"]').screenshot({ path: 'artifacts/chart.png' })
201
+ ```
202
+
203
+ ### Traces
204
+
205
+ ```typescript
206
+ await browser.startTracing(page, {
207
+ path: 'artifacts/trace.json',
208
+ screenshots: true,
209
+ snapshots: true,
210
+ })
211
+ // ... test actions ...
212
+ await browser.stopTracing()
213
+ ```
214
+
215
+ ### Video
216
+
217
+ ```typescript
218
+ // In playwright.config.ts
219
+ use: {
220
+ video: 'retain-on-failure',
221
+ videosPath: 'artifacts/videos/'
222
+ }
223
+ ```
224
+
225
+ ## CI/CD Integration
226
+
227
+ ```yaml
228
+ # .github/workflows/e2e.yml
229
+ name: E2E Tests
230
+ on: [push, pull_request]
231
+
232
+ jobs:
233
+ test:
234
+ runs-on: ubuntu-latest
235
+ steps:
236
+ - uses: actions/checkout@v4
237
+ - uses: actions/setup-node@v4
238
+ with:
239
+ node-version: 20
240
+ - run: npm ci
241
+ - run: npx playwright install --with-deps
242
+ - run: npx playwright test
243
+ env:
244
+ BASE_URL: ${{ vars.STAGING_URL }}
245
+ - uses: actions/upload-artifact@v4
246
+ if: always()
247
+ with:
248
+ name: playwright-report
249
+ path: playwright-report/
250
+ retention-days: 30
251
+ ```
252
+
253
+ ## Test Report Template
254
+
255
+ ```markdown
256
+ # E2E Test Report
257
+
258
+ **Date:** YYYY-MM-DD HH:MM
259
+ **Duration:** Xm Ys
260
+ **Status:** PASSING / FAILING
261
+
262
+ ## Summary
263
+ - Total: X | Passed: Y (Z%) | Failed: A | Flaky: B | Skipped: C
264
+
265
+ ## Failed Tests
266
+
267
+ ### test-name
268
+ **File:** `tests/e2e/feature.spec.ts:45`
269
+ **Error:** Expected element to be visible
270
+ **Screenshot:** artifacts/failed.png
271
+ **Recommended Fix:** [description]
272
+
273
+ ## Artifacts
274
+ - HTML Report: playwright-report/index.html
275
+ - Screenshots: artifacts/*.png
276
+ - Videos: artifacts/videos/*.webm
277
+ - Traces: artifacts/*.zip
278
+ ```
279
+
280
+ ## Wallet / Web3 Testing
281
+
282
+ ```typescript
283
+ test('wallet connection', async ({ page, context }) => {
284
+ // Mock wallet provider
285
+ await context.addInitScript(() => {
286
+ window.ethereum = {
287
+ isMetaMask: true,
288
+ request: async ({ method }) => {
289
+ if (method === 'eth_requestAccounts')
290
+ return ['0x1234567890123456789012345678901234567890']
291
+ if (method === 'eth_chainId') return '0x1'
292
+ }
293
+ }
294
+ })
295
+
296
+ await page.goto('/')
297
+ await page.locator('[data-testid="connect-wallet"]').click()
298
+ await expect(page.locator('[data-testid="wallet-address"]')).toContainText('0x1234')
299
+ })
300
+ ```
301
+
302
+ ## Financial / Critical Flow Testing
303
+
304
+ ```typescript
305
+ test('trade execution', async ({ page }) => {
306
+ // Skip on production — real money
307
+ test.skip(process.env.NODE_ENV === 'production', 'Skip on production')
308
+
309
+ await page.goto('/markets/test-market')
310
+ await page.locator('[data-testid="position-yes"]').click()
311
+ await page.locator('[data-testid="trade-amount"]').fill('1.0')
312
+
313
+ // Verify preview
314
+ const preview = page.locator('[data-testid="trade-preview"]')
315
+ await expect(preview).toContainText('1.0')
316
+
317
+ // Confirm and wait for blockchain
318
+ await page.locator('[data-testid="confirm-trade"]').click()
319
+ await page.waitForResponse(
320
+ resp => resp.url().includes('/api/trade') && resp.status() === 200,
321
+ { timeout: 30000 }
322
+ )
323
+
324
+ await expect(page.locator('[data-testid="trade-success"]')).toBeVisible()
325
+ })
326
+ ```
@@ -0,0 +1,7 @@
1
+ interface:
2
+ display_name: "E2E Testing"
3
+ short_description: "Playwright end-to-end testing"
4
+ brand_color: "#06B6D4"
5
+ default_prompt: "Generate Playwright E2E tests with Page Object Model"
6
+ policy:
7
+ allow_implicit_invocation: true
@@ -0,0 +1,376 @@
1
+ ---
2
+ name: error-handling
3
+ description: Patterns for robust error handling across TypeScript, Python, and Go. Covers typed errors, error boundaries, retries, circuit breakers, and user-facing error messages.
4
+ origin: ECC
5
+ ---
6
+
7
+ # Error Handling Patterns
8
+
9
+ Consistent, robust error handling patterns for production applications.
10
+
11
+ ## When to Activate
12
+
13
+ - Designing error types or exception hierarchies for a new module or service
14
+ - Adding retry logic or circuit breakers for unreliable external dependencies
15
+ - Reviewing API endpoints for missing error handling
16
+ - Implementing user-facing error messages and feedback
17
+ - Debugging cascading failures or silent error swallowing
18
+
19
+ ## Core Principles
20
+
21
+ 1. **Fail fast and loudly** — surface errors at the boundary where they occur; don't bury them
22
+ 2. **Typed errors over string messages** — errors are first-class values with structure
23
+ 3. **User messages ≠ developer messages** — show friendly text to users, log full context server-side
24
+ 4. **Never swallow errors silently** — every `catch` block must either handle, re-throw, or log
25
+ 5. **Errors are part of your API contract** — document every error code a client may receive
26
+
27
+ ## TypeScript / JavaScript
28
+
29
+ ### Typed Error Classes
30
+
31
+ ```typescript
32
+ // Define an error hierarchy for your domain
33
+ export class AppError extends Error {
34
+ constructor(
35
+ message: string,
36
+ public readonly code: string,
37
+ public readonly statusCode: number = 500,
38
+ public readonly details?: unknown,
39
+ ) {
40
+ super(message)
41
+ this.name = this.constructor.name
42
+ // Maintain correct prototype chain in transpiled ES5 JavaScript.
43
+ // Required for `instanceof` checks (e.g., `error instanceof NotFoundError`)
44
+ // to work correctly when extending the built-in Error class.
45
+ Object.setPrototypeOf(this, new.target.prototype)
46
+ }
47
+ }
48
+
49
+ export class NotFoundError extends AppError {
50
+ constructor(resource: string, id: string) {
51
+ super(`${resource} not found: ${id}`, 'NOT_FOUND', 404)
52
+ }
53
+ }
54
+
55
+ export class ValidationError extends AppError {
56
+ constructor(message: string, details: { field: string; message: string }[]) {
57
+ super(message, 'VALIDATION_ERROR', 422, details)
58
+ }
59
+ }
60
+
61
+ export class UnauthorizedError extends AppError {
62
+ constructor(reason = 'Authentication required') {
63
+ super(reason, 'UNAUTHORIZED', 401)
64
+ }
65
+ }
66
+
67
+ export class RateLimitError extends AppError {
68
+ constructor(public readonly retryAfterMs: number) {
69
+ super('Rate limit exceeded', 'RATE_LIMITED', 429)
70
+ }
71
+ }
72
+ ```
73
+
74
+ ### Result Pattern (no-throw style)
75
+
76
+ For operations where failure is expected and common (parsing, external calls):
77
+
78
+ ```typescript
79
+ type Result<T, E = AppError> =
80
+ | { ok: true; value: T }
81
+ | { ok: false; error: E }
82
+
83
+ function ok<T>(value: T): Result<T> {
84
+ return { ok: true, value }
85
+ }
86
+
87
+ function err<E>(error: E): Result<never, E> {
88
+ return { ok: false, error }
89
+ }
90
+
91
+ // Usage
92
+ async function fetchUser(id: string): Promise<Result<User>> {
93
+ try {
94
+ const user = await db.users.findUnique({ where: { id } })
95
+ if (!user) return err(new NotFoundError('User', id))
96
+ return ok(user)
97
+ } catch (e) {
98
+ return err(new AppError('Database error', 'DB_ERROR'))
99
+ }
100
+ }
101
+
102
+ const result = await fetchUser('abc-123')
103
+ if (!result.ok) {
104
+ // TypeScript knows result.error here
105
+ logger.error('Failed to fetch user', { error: result.error })
106
+ return
107
+ }
108
+ // TypeScript knows result.value here
109
+ console.log(result.value.email)
110
+ ```
111
+
112
+ ### API Error Handler (Next.js / Express)
113
+
114
+ ```typescript
115
+ import { NextRequest, NextResponse } from 'next/server'
116
+
117
+ function handleApiError(error: unknown): NextResponse {
118
+ // Known application error
119
+ if (error instanceof AppError) {
120
+ return NextResponse.json(
121
+ {
122
+ error: {
123
+ code: error.code,
124
+ message: error.message,
125
+ ...(error.details ? { details: error.details } : {}),
126
+ },
127
+ },
128
+ { status: error.statusCode },
129
+ )
130
+ }
131
+
132
+ // Zod validation error
133
+ if (error instanceof z.ZodError) {
134
+ return NextResponse.json(
135
+ {
136
+ error: {
137
+ code: 'VALIDATION_ERROR',
138
+ message: 'Request validation failed',
139
+ details: error.issues.map(i => ({
140
+ field: i.path.join('.'),
141
+ message: i.message,
142
+ })),
143
+ },
144
+ },
145
+ { status: 422 },
146
+ )
147
+ }
148
+
149
+ // Unexpected error — log details, return generic message
150
+ console.error('Unexpected error:', error)
151
+ return NextResponse.json(
152
+ { error: { code: 'INTERNAL_ERROR', message: 'An unexpected error occurred' } },
153
+ { status: 500 },
154
+ )
155
+ }
156
+
157
+ export async function POST(req: NextRequest) {
158
+ try {
159
+ // ... handler logic
160
+ } catch (error) {
161
+ return handleApiError(error)
162
+ }
163
+ }
164
+ ```
165
+
166
+ ### React Error Boundary
167
+
168
+ ```typescript
169
+ import { Component, ErrorInfo, ReactNode } from 'react'
170
+
171
+ interface Props {
172
+ fallback: ReactNode
173
+ onError?: (error: Error, info: ErrorInfo) => void
174
+ children: ReactNode
175
+ }
176
+
177
+ interface State {
178
+ hasError: boolean
179
+ error: Error | null
180
+ }
181
+
182
+ export class ErrorBoundary extends Component<Props, State> {
183
+ state: State = { hasError: false, error: null }
184
+
185
+ static getDerivedStateFromError(error: Error): State {
186
+ return { hasError: true, error }
187
+ }
188
+
189
+ componentDidCatch(error: Error, info: ErrorInfo) {
190
+ this.props.onError?.(error, info)
191
+ console.error('Unhandled React error:', error, info)
192
+ }
193
+
194
+ render() {
195
+ if (this.state.hasError) return this.props.fallback
196
+ return this.props.children
197
+ }
198
+ }
199
+
200
+ // Usage
201
+ <ErrorBoundary fallback={<p>Something went wrong. Please refresh.</p>}>
202
+ <MyComponent />
203
+ </ErrorBoundary>
204
+ ```
205
+
206
+ ## Python
207
+
208
+ ### Custom Exception Hierarchy
209
+
210
+ ```python
211
+ class AppError(Exception):
212
+ """Base application error."""
213
+ def __init__(self, message: str, code: str, status_code: int = 500):
214
+ super().__init__(message)
215
+ self.code = code
216
+ self.status_code = status_code
217
+
218
+ class NotFoundError(AppError):
219
+ def __init__(self, resource: str, id: str):
220
+ super().__init__(f"{resource} not found: {id}", "NOT_FOUND", 404)
221
+
222
+ class ValidationError(AppError):
223
+ def __init__(self, message: str, details: list[dict] | None = None):
224
+ super().__init__(message, "VALIDATION_ERROR", 422)
225
+ self.details = details or []
226
+ ```
227
+
228
+ ### FastAPI Global Exception Handler
229
+
230
+ ```python
231
+ from fastapi import FastAPI, Request
232
+ from fastapi.responses import JSONResponse
233
+
234
+ app = FastAPI()
235
+
236
+ @app.exception_handler(AppError)
237
+ async def app_error_handler(request: Request, exc: AppError) -> JSONResponse:
238
+ return JSONResponse(
239
+ status_code=exc.status_code,
240
+ content={"error": {"code": exc.code, "message": str(exc)}},
241
+ )
242
+
243
+ @app.exception_handler(Exception)
244
+ async def generic_error_handler(request: Request, exc: Exception) -> JSONResponse:
245
+ # Log full details, return generic message
246
+ logger.exception("Unexpected error", exc_info=exc)
247
+ return JSONResponse(
248
+ status_code=500,
249
+ content={"error": {"code": "INTERNAL_ERROR", "message": "An unexpected error occurred"}},
250
+ )
251
+ ```
252
+
253
+ ## Go
254
+
255
+ ### Sentinel Errors and Error Wrapping
256
+
257
+ ```go
258
+ package domain
259
+
260
+ import "errors"
261
+
262
+ // Sentinel errors for type-checking
263
+ var (
264
+ ErrNotFound = errors.New("not found")
265
+ ErrUnauthorized = errors.New("unauthorized")
266
+ ErrConflict = errors.New("conflict")
267
+ )
268
+
269
+ // Wrap errors with context — never lose the original
270
+ func (r *UserRepository) FindByID(ctx context.Context, id string) (*User, error) {
271
+ user, err := r.db.QueryRow(ctx, "SELECT * FROM users WHERE id = $1", id)
272
+ if errors.Is(err, sql.ErrNoRows) {
273
+ return nil, fmt.Errorf("user %s: %w", id, ErrNotFound)
274
+ }
275
+ if err != nil {
276
+ return nil, fmt.Errorf("querying user %s: %w", id, err)
277
+ }
278
+ return user, nil
279
+ }
280
+
281
+ // At the handler level, unwrap to determine response
282
+ func (h *Handler) GetUser(w http.ResponseWriter, r *http.Request) {
283
+ user, err := h.service.GetUser(r.Context(), chi.URLParam(r, "id"))
284
+ if err != nil {
285
+ switch {
286
+ case errors.Is(err, domain.ErrNotFound):
287
+ writeError(w, http.StatusNotFound, "not_found", err.Error())
288
+ case errors.Is(err, domain.ErrUnauthorized):
289
+ writeError(w, http.StatusForbidden, "forbidden", "Access denied")
290
+ default:
291
+ slog.Error("unexpected error", "err", err)
292
+ writeError(w, http.StatusInternalServerError, "internal_error", "An unexpected error occurred")
293
+ }
294
+ return
295
+ }
296
+ writeJSON(w, http.StatusOK, user)
297
+ }
298
+ ```
299
+
300
+ ## Retry with Exponential Backoff
301
+
302
+ ```typescript
303
+ interface RetryOptions {
304
+ maxAttempts?: number
305
+ baseDelayMs?: number
306
+ maxDelayMs?: number
307
+ retryIf?: (error: unknown) => boolean
308
+ }
309
+
310
+ async function withRetry<T>(
311
+ fn: () => Promise<T>,
312
+ options: RetryOptions = {},
313
+ ): Promise<T> {
314
+ const {
315
+ maxAttempts = 3,
316
+ baseDelayMs = 500,
317
+ maxDelayMs = 10_000,
318
+ retryIf = () => true,
319
+ } = options
320
+
321
+ let lastError: unknown
322
+
323
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
324
+ try {
325
+ return await fn()
326
+ } catch (error) {
327
+ lastError = error
328
+ if (attempt === maxAttempts || !retryIf(error)) throw error
329
+
330
+ const jitter = Math.random() * baseDelayMs
331
+ const delay = Math.min(baseDelayMs * 2 ** (attempt - 1) + jitter, maxDelayMs)
332
+ await new Promise(resolve => setTimeout(resolve, delay))
333
+ }
334
+ }
335
+
336
+ throw lastError
337
+ }
338
+
339
+ // Usage: retry transient network errors, not 4xx
340
+ const data = await withRetry(() => fetch('/api/data').then(r => r.json()), {
341
+ maxAttempts: 3,
342
+ retryIf: (error) => !(error instanceof AppError && error.statusCode < 500),
343
+ })
344
+ ```
345
+
346
+ ## User-Facing Error Messages
347
+
348
+ Map error codes to human-readable messages. Keep technical details out of user-visible text.
349
+
350
+ ```typescript
351
+ const USER_ERROR_MESSAGES: Record<string, string> = {
352
+ NOT_FOUND: 'The requested item could not be found.',
353
+ UNAUTHORIZED: 'Please sign in to continue.',
354
+ FORBIDDEN: "You don't have permission to do that.",
355
+ VALIDATION_ERROR: 'Please check your input and try again.',
356
+ RATE_LIMITED: 'Too many requests. Please wait a moment and try again.',
357
+ INTERNAL_ERROR: 'Something went wrong on our end. Please try again later.',
358
+ }
359
+
360
+ export function getUserMessage(code: string): string {
361
+ return USER_ERROR_MESSAGES[code] ?? USER_ERROR_MESSAGES.INTERNAL_ERROR
362
+ }
363
+ ```
364
+
365
+ ## Error Handling Checklist
366
+
367
+ Before merging any code that touches error handling:
368
+
369
+ - [ ] Every `catch` block handles, re-throws, or logs — no silent swallowing
370
+ - [ ] API errors follow the standard envelope `{ error: { code, message } }`
371
+ - [ ] User-facing messages contain no stack traces or internal details
372
+ - [ ] Full error context is logged server-side
373
+ - [ ] Custom error classes extend a base `AppError` with a `code` field
374
+ - [ ] Async functions surface errors to callers — no fire-and-forget without fallback
375
+ - [ ] Retry logic only retries retriable errors (not 4xx client errors)
376
+ - [ ] React components are wrapped in `ErrorBoundary` for rendering errors
@@ -0,0 +1,7 @@
1
+ {
2
+ "source": "affaan-m/everything-claude-code",
3
+ "sourceType": "git",
4
+ "repoUrl": "https://github.com/affaan-m/everything-claude-code",
5
+ "subpath": "skills/frontend-design",
6
+ "installedAt": "2026-04-16T03:02:23.968Z"
7
+ }