start-vibing 2.0.8 → 2.0.10

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 (139) hide show
  1. package/README.md +177 -176
  2. package/dist/cli.js +38 -11
  3. package/package.json +42 -42
  4. package/template/.claude/CLAUDE.md +174 -152
  5. package/template/.claude/agents/01-orchestration/agent-selector.md +130 -123
  6. package/template/.claude/agents/01-orchestration/checkpoint-manager.md +142 -131
  7. package/template/.claude/agents/01-orchestration/context-manager.md +138 -124
  8. package/template/.claude/agents/01-orchestration/error-recovery.md +182 -176
  9. package/template/.claude/agents/01-orchestration/orchestrator.md +114 -107
  10. package/template/.claude/agents/01-orchestration/parallel-coordinator.md +141 -130
  11. package/template/.claude/agents/01-orchestration/task-decomposer.md +121 -118
  12. package/template/.claude/agents/01-orchestration/workflow-router.md +114 -111
  13. package/template/.claude/agents/02-typescript/bun-runtime-expert.md +197 -180
  14. package/template/.claude/agents/02-typescript/esm-resolver.md +193 -187
  15. package/template/.claude/agents/02-typescript/import-alias-enforcer.md +158 -149
  16. package/template/.claude/agents/02-typescript/ts-generics-helper.md +183 -165
  17. package/template/.claude/agents/02-typescript/ts-migration-helper.md +238 -227
  18. package/template/.claude/agents/02-typescript/ts-strict-checker.md +180 -162
  19. package/template/.claude/agents/02-typescript/ts-types-analyzer.md +199 -185
  20. package/template/.claude/agents/02-typescript/type-definition-writer.md +187 -183
  21. package/template/.claude/agents/02-typescript/zod-schema-designer.md +212 -197
  22. package/template/.claude/agents/02-typescript/zod-validator.md +158 -153
  23. package/template/.claude/agents/03-testing/playwright-assertions.md +265 -255
  24. package/template/.claude/agents/03-testing/playwright-e2e.md +247 -245
  25. package/template/.claude/agents/03-testing/playwright-fixtures.md +234 -240
  26. package/template/.claude/agents/03-testing/playwright-multi-viewport.md +256 -261
  27. package/template/.claude/agents/03-testing/playwright-page-objects.md +247 -247
  28. package/template/.claude/agents/03-testing/test-cleanup-manager.md +248 -256
  29. package/template/.claude/agents/03-testing/test-data-generator.md +254 -266
  30. package/template/.claude/agents/03-testing/tester-integration.md +278 -278
  31. package/template/.claude/agents/03-testing/tester-unit.md +207 -204
  32. package/template/.claude/agents/03-testing/vitest-config.md +287 -289
  33. package/template/.claude/agents/04-docker/container-health.md +255 -239
  34. package/template/.claude/agents/04-docker/deployment-validator.md +225 -217
  35. package/template/.claude/agents/04-docker/docker-compose-designer.md +281 -268
  36. package/template/.claude/agents/04-docker/docker-env-manager.md +235 -228
  37. package/template/.claude/agents/04-docker/docker-multi-stage.md +241 -229
  38. package/template/.claude/agents/04-docker/dockerfile-optimizer.md +208 -204
  39. package/template/.claude/agents/05-database/data-migration.md +0 -293
  40. package/template/.claude/agents/05-database/database-seeder.md +273 -270
  41. package/template/.claude/agents/05-database/mongodb-query-optimizer.md +230 -219
  42. package/template/.claude/agents/05-database/mongoose-aggregation.md +306 -280
  43. package/template/.claude/agents/05-database/mongoose-index-optimizer.md +182 -174
  44. package/template/.claude/agents/05-database/mongoose-schema-designer.md +267 -267
  45. package/template/.claude/agents/06-security/auth-session-validator.md +68 -65
  46. package/template/.claude/agents/06-security/input-sanitizer.md +80 -81
  47. package/template/.claude/agents/06-security/owasp-checker.md +97 -87
  48. package/template/.claude/agents/06-security/permission-auditor.md +100 -95
  49. package/template/.claude/agents/06-security/security-auditor.md +84 -82
  50. package/template/.claude/agents/06-security/sensitive-data-scanner.md +83 -85
  51. package/template/.claude/agents/07-documentation/api-documenter.md +136 -131
  52. package/template/.claude/agents/07-documentation/changelog-manager.md +105 -96
  53. package/template/.claude/agents/07-documentation/documenter.md +76 -73
  54. package/template/.claude/agents/07-documentation/domain-updater.md +81 -74
  55. package/template/.claude/agents/07-documentation/jsdoc-generator.md +114 -114
  56. package/template/.claude/agents/07-documentation/readme-generator.md +135 -132
  57. package/template/.claude/agents/08-git/branch-manager.md +58 -58
  58. package/template/.claude/agents/08-git/commit-manager.md +63 -61
  59. package/template/.claude/agents/08-git/pr-creator.md +76 -72
  60. package/template/.claude/agents/09-quality/code-reviewer.md +71 -64
  61. package/template/.claude/agents/09-quality/quality-checker.md +67 -67
  62. package/template/.claude/agents/10-research/best-practices-finder.md +89 -82
  63. package/template/.claude/agents/10-research/competitor-analyzer.md +106 -96
  64. package/template/.claude/agents/10-research/pattern-researcher.md +93 -86
  65. package/template/.claude/agents/10-research/research-cache-manager.md +76 -75
  66. package/template/.claude/agents/10-research/research-web.md +98 -91
  67. package/template/.claude/agents/10-research/tech-evaluator.md +101 -94
  68. package/template/.claude/agents/11-ui-ux/accessibility-auditor.md +136 -128
  69. package/template/.claude/agents/11-ui-ux/design-system-enforcer.md +125 -116
  70. package/template/.claude/agents/11-ui-ux/skeleton-generator.md +118 -120
  71. package/template/.claude/agents/11-ui-ux/ui-desktop.md +132 -126
  72. package/template/.claude/agents/11-ui-ux/ui-mobile.md +98 -94
  73. package/template/.claude/agents/11-ui-ux/ui-tablet.md +110 -111
  74. package/template/.claude/agents/12-performance/api-latency-analyzer.md +156 -149
  75. package/template/.claude/agents/12-performance/bundle-analyzer.md +113 -107
  76. package/template/.claude/agents/12-performance/memory-leak-detector.md +137 -126
  77. package/template/.claude/agents/12-performance/performance-profiler.md +115 -108
  78. package/template/.claude/agents/12-performance/query-optimizer.md +124 -116
  79. package/template/.claude/agents/12-performance/render-optimizer.md +154 -148
  80. package/template/.claude/agents/13-debugging/build-error-fixer.md +207 -188
  81. package/template/.claude/agents/13-debugging/debugger.md +149 -137
  82. package/template/.claude/agents/13-debugging/error-stack-analyzer.md +141 -131
  83. package/template/.claude/agents/13-debugging/network-debugger.md +208 -185
  84. package/template/.claude/agents/13-debugging/runtime-error-fixer.md +181 -173
  85. package/template/.claude/agents/13-debugging/type-error-resolver.md +185 -173
  86. package/template/.claude/agents/14-validation/final-validator.md +93 -83
  87. package/template/.claude/agents/_backup/analyzer.md +134 -125
  88. package/template/.claude/agents/_backup/code-reviewer.md +279 -272
  89. package/template/.claude/agents/_backup/commit-manager.md +219 -212
  90. package/template/.claude/agents/_backup/debugger.md +280 -271
  91. package/template/.claude/agents/_backup/documenter.md +237 -220
  92. package/template/.claude/agents/_backup/domain-updater.md +197 -194
  93. package/template/.claude/agents/_backup/final-validator.md +169 -164
  94. package/template/.claude/agents/_backup/orchestrator.md +149 -138
  95. package/template/.claude/agents/_backup/performance.md +232 -228
  96. package/template/.claude/agents/_backup/quality-checker.md +240 -240
  97. package/template/.claude/agents/_backup/research.md +315 -299
  98. package/template/.claude/agents/_backup/security-auditor.md +192 -186
  99. package/template/.claude/agents/_backup/tester.md +566 -564
  100. package/template/.claude/agents/_backup/ui-ux-reviewer.md +247 -242
  101. package/template/.claude/commands/feature.md +48 -48
  102. package/template/.claude/config/README.md +30 -30
  103. package/template/.claude/config/mcp-config.json +344 -330
  104. package/template/.claude/config/project-config.json +53 -53
  105. package/template/.claude/config/quality-gates.json +46 -46
  106. package/template/.claude/config/security-rules.json +45 -45
  107. package/template/.claude/config/testing-config.json +164 -168
  108. package/template/.claude/hooks/SETUP.md +126 -126
  109. package/template/.claude/hooks/run-hook.ts +176 -172
  110. package/template/.claude/hooks/stop-validator.ts +825 -353
  111. package/template/.claude/hooks/user-prompt-submit.ts +886 -794
  112. package/template/.claude/scripts/mcp-quick-install.ts +151 -151
  113. package/template/.claude/scripts/setup-mcps.ts +651 -628
  114. package/template/.claude/settings.json +275 -276
  115. package/template/.claude/skills/bun-runtime/SKILL.md +430 -430
  116. package/template/.claude/skills/codebase-knowledge/SKILL.md +145 -145
  117. package/template/.claude/skills/codebase-knowledge/domains/claude-system.md +431 -403
  118. package/template/.claude/skills/codebase-knowledge/domains/mcp-integration.md +295 -281
  119. package/template/.claude/skills/debugging-patterns/SKILL.md +485 -484
  120. package/template/.claude/skills/docker-patterns/SKILL.md +555 -547
  121. package/template/.claude/skills/docs-tracker/SKILL.md +239 -239
  122. package/template/.claude/skills/final-check/SKILL.md +284 -284
  123. package/template/.claude/skills/git-workflow/SKILL.md +454 -454
  124. package/template/.claude/skills/mongoose-patterns/SKILL.md +499 -512
  125. package/template/.claude/skills/nextjs-app-router/SKILL.md +327 -337
  126. package/template/.claude/skills/performance-patterns/SKILL.md +547 -549
  127. package/template/.claude/skills/playwright-automation/SKILL.md +438 -438
  128. package/template/.claude/skills/quality-gate/SKILL.md +294 -294
  129. package/template/.claude/skills/react-patterns/SKILL.md +389 -376
  130. package/template/.claude/skills/research-cache/SKILL.md +222 -207
  131. package/template/.claude/skills/security-scan/SKILL.md +222 -222
  132. package/template/.claude/skills/shadcn-ui/SKILL.md +511 -520
  133. package/template/.claude/skills/tailwind-patterns/SKILL.md +465 -467
  134. package/template/.claude/skills/test-coverage/SKILL.md +467 -464
  135. package/template/.claude/skills/trpc-api/SKILL.md +434 -435
  136. package/template/.claude/skills/typescript-strict/SKILL.md +367 -368
  137. package/template/.claude/skills/ui-ux-audit/SKILL.md +254 -254
  138. package/template/.claude/skills/zod-validation/SKILL.md +403 -405
  139. package/template/CLAUDE.md +25 -25
@@ -1,464 +1,467 @@
1
- ---
2
- name: test-coverage
3
- description: Manages test coverage with Playwright E2E and Vitest unit tests. Tracks which files need tests, provides templates with fixture-based cleanup, enforces multi-viewport testing and database validation.
4
- allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
- ---
6
-
7
- # Test Coverage - Testing Management System
8
-
9
- ## Purpose
10
-
11
- This skill manages test coverage with **Playwright E2E** and **Vitest unit tests**:
12
-
13
- - **Detects** new files that need tests
14
- - **Maps** components consuming API routes (tRPC/REST)
15
- - **Tracks** which pages have E2E coverage
16
- - **Generates** test templates with cleanup
17
- - **Validates** real authentication usage (MANDATORY)
18
- - **Ensures** database validation after UI actions
19
- - **Enforces** multi-viewport testing
20
-
21
- ---
22
-
23
- ## CRITICAL RULES
24
-
25
- > **MANDATORY - NO EXCEPTIONS:**
26
-
27
- 1. **CLEANUP ALL TEST DATA** - Use fixture-based tracking
28
- 2. **VERIFY IN DATABASE** - Check DB state after UI actions
29
- 3. **TEST ALL VIEWPORTS** - Desktop, tablet, iPhone SE minimum
30
- 4. **REAL AUTH ONLY** - Never mock authentication
31
- 5. **UNIQUE DATA** - Timestamps in emails/names
32
- 6. **NO SKIP** - Never use `.skip()` or `.only()`
33
-
34
- ---
35
-
36
- ## Test Structure
37
-
38
- ```
39
- tests/
40
- ├── unit/ # Unit tests (Vitest)
41
- │ └── *.test.ts
42
- └── e2e/ # E2E tests (Playwright)
43
- ├── fixtures/
44
- │ ├── index.ts # Custom fixtures (auth, db, cleanup)
45
- │ ├── auth.fixture.ts # Authentication helpers
46
- │ └── db.fixture.ts # Database connection & cleanup
47
- ├── pages/ # Page Object Model
48
- │ ├── base.page.ts # Base page with common methods
49
- │ ├── login.page.ts
50
- │ └── register.page.ts
51
- ├── flows/ # User flow tests
52
- │ ├── auth.spec.ts # Login, register, logout
53
- │ ├── crud.spec.ts # Create, read, update, delete
54
- │ └── permissions.spec.ts
55
- ├── api/ # API-only tests (no UI)
56
- │ ├── rest.spec.ts # REST API tests
57
- │ └── trpc.spec.ts # tRPC API tests
58
- └── playwright.config.ts
59
- ```
60
-
61
- ---
62
-
63
- ## Cleanup Fixture (MANDATORY)
64
-
65
- Every project MUST have cleanup fixtures:
66
-
67
- ```typescript
68
- // tests/e2e/fixtures/index.ts
69
- import { test as base, expect } from '@playwright/test';
70
- import { MongoClient, Db, ObjectId } from 'mongodb';
71
-
72
- type TestFixtures = {
73
- db: Db;
74
- createdIds: Map<string, ObjectId[]>;
75
- trackCreated: (collection: string, id: ObjectId) => void;
76
- };
77
-
78
- export const test = base.extend<TestFixtures>({
79
- db: async ({}, use) => {
80
- const client = await MongoClient.connect(process.env.MONGODB_URI!);
81
- const db = client.db();
82
- await use(db);
83
- await client.close();
84
- },
85
-
86
- createdIds: async ({}, use) => {
87
- const ids = new Map<string, ObjectId[]>();
88
- await use(ids);
89
- },
90
-
91
- trackCreated: async ({ createdIds }, use) => {
92
- const track = (collection: string, id: ObjectId) => {
93
- const existing = createdIds.get(collection) || [];
94
- existing.push(id);
95
- createdIds.set(collection, existing);
96
- };
97
- await use(track);
98
- },
99
-
100
- // AUTO-CLEANUP runs EVEN IF test fails
101
- }, async ({ db, createdIds }, use) => {
102
- await use();
103
-
104
- for (const [collection, ids] of createdIds.entries()) {
105
- if (ids.length > 0) {
106
- await db.collection(collection).deleteMany({
107
- _id: { $in: ids }
108
- });
109
- }
110
- }
111
- });
112
-
113
- export { expect };
114
- ```
115
-
116
- ---
117
-
118
- ## Auth Helper (MANDATORY)
119
-
120
- ```typescript
121
- // tests/e2e/fixtures/auth.fixture.ts
122
- import { Page } from '@playwright/test';
123
-
124
- export interface TestUser {
125
- name: string;
126
- email: string;
127
- password: string;
128
- }
129
-
130
- export function generateTestUser(): TestUser {
131
- const timestamp = Date.now();
132
- const random = Math.random().toString(36).substring(7);
133
- return {
134
- name: `Test User ${timestamp}`,
135
- email: `testuser_${timestamp}_${random}@test.com`,
136
- password: 'TestPassword123!',
137
- };
138
- }
139
-
140
- export async function registerUser(page: Page, user: TestUser): Promise<void> {
141
- await page.goto('/auth/register');
142
- await page.getByTestId('name-input').fill(user.name);
143
- await page.getByTestId('email-input').fill(user.email);
144
- await page.getByTestId('password-input').fill(user.password);
145
- await page.getByTestId('confirm-password-input').fill(user.password);
146
- await page.getByTestId('submit-button').click();
147
- await page.waitForURL(/\/app/, { timeout: 10000 });
148
- }
149
-
150
- export async function loginUser(page: Page, user: TestUser): Promise<void> {
151
- await page.goto('/auth/login');
152
- await page.getByTestId('email-input').fill(user.email);
153
- await page.getByTestId('password-input').fill(user.password);
154
- await page.getByTestId('submit-button').click();
155
- await page.waitForURL(/\/app/, { timeout: 10000 });
156
- }
157
- ```
158
-
159
- ---
160
-
161
- ## Test Templates
162
-
163
- ### E2E Flow Test (with cleanup)
164
-
165
- ```typescript
166
- import { test, expect } from '../fixtures';
167
- import { generateTestUser, registerUser } from '../fixtures/auth.fixture';
168
-
169
- test.describe('[Feature] Flow', () => {
170
- test('complete user journey', async ({ page, db, trackCreated }) => {
171
- const user = generateTestUser();
172
-
173
- // 1. Register
174
- await registerUser(page, user);
175
-
176
- // 2. Verify in database
177
- const dbUser = await db.collection('users').findOne({
178
- email: user.email
179
- });
180
- expect(dbUser).toBeTruthy();
181
- trackCreated('users', dbUser!._id); // TRACK FOR CLEANUP
182
-
183
- // 3. Create item
184
- await page.goto('/items/new');
185
- await page.getByTestId('title-input').fill('Test Item');
186
- await page.getByTestId('submit-button').click();
187
-
188
- // 4. Verify item in DB
189
- const item = await db.collection('items').findOne({
190
- userId: dbUser!._id
191
- });
192
- expect(item).toBeTruthy();
193
- trackCreated('items', item!._id); // TRACK FOR CLEANUP
194
-
195
- // Test continues... cleanup is automatic
196
- });
197
- });
198
- ```
199
-
200
- ### Multi-Viewport Test
201
-
202
- ```typescript
203
- import { test, expect } from '../fixtures';
204
-
205
- test.describe('Responsive Design', () => {
206
- const viewports = [
207
- { name: 'mobile', width: 375, height: 667 },
208
- { name: 'tablet', width: 768, height: 1024 },
209
- { name: 'desktop', width: 1280, height: 800 },
210
- ];
211
-
212
- for (const viewport of viewports) {
213
- test(`layout works on ${viewport.name}`, async ({ page }) => {
214
- await page.setViewportSize(viewport);
215
- await page.goto('/');
216
-
217
- if (viewport.width < 768) {
218
- // Mobile: hamburger menu
219
- await expect(page.getByTestId('hamburger-menu')).toBeVisible();
220
- await expect(page.getByTestId('sidebar')).toBeHidden();
221
- } else {
222
- // Desktop: sidebar visible
223
- await expect(page.getByTestId('sidebar')).toBeVisible();
224
- }
225
- });
226
- }
227
- });
228
- ```
229
-
230
- ### API Test (REST)
231
-
232
- ```typescript
233
- import { test, expect } from '@playwright/test';
234
-
235
- test.describe('REST API', () => {
236
- test('requires authentication', async ({ request }) => {
237
- const response = await request.get('/api/users');
238
- expect(response.status()).toBe(401);
239
- });
240
-
241
- test('validates input', async ({ request }) => {
242
- const response = await request.post('/api/users', {
243
- data: { email: 'invalid' }
244
- });
245
- expect(response.status()).toBe(400);
246
- });
247
- });
248
- ```
249
-
250
- ### API Test (tRPC)
251
-
252
- ```typescript
253
- import { test, expect } from '@playwright/test';
254
-
255
- test.describe('tRPC API', () => {
256
- test('query without auth fails', async ({ request }) => {
257
- const response = await request.get('/api/trpc/user.me');
258
- expect(response.status()).toBe(401);
259
- });
260
-
261
- test('mutation validates input', async ({ request }) => {
262
- const response = await request.post('/api/trpc/user.create', {
263
- data: { json: { name: '' } }
264
- });
265
- const body = await response.json();
266
- expect(body.error).toBeDefined();
267
- });
268
- });
269
- ```
270
-
271
- ### Security Test
272
-
273
- ```typescript
274
- import { test, expect } from '../fixtures';
275
-
276
- test.describe('Security - Forbidden Requests', () => {
277
- test('cannot access other users data', async ({ page, db }) => {
278
- const userA = await createTestUser(db);
279
- const userB = await createTestUser(db);
280
-
281
- await loginAs(page, userA);
282
-
283
- // Try to access user B's data
284
- const response = await page.request.get(`/api/users/${userB._id}`);
285
- expect(response.status()).toBe(403);
286
-
287
- // Verify nothing changed in DB
288
- const unchanged = await db.collection('users').findOne({
289
- _id: userB._id
290
- });
291
- expect(unchanged).toEqual(userB);
292
- });
293
- });
294
- ```
295
-
296
- ### Unit Test
297
-
298
- ```typescript
299
- import { describe, it, expect } from 'vitest';
300
-
301
- describe('[Feature]', () => {
302
- describe('success cases', () => {
303
- it('should [expected behavior] when [condition]', () => {
304
- // Arrange
305
- // Act
306
- // Assert
307
- });
308
- });
309
-
310
- describe('error cases', () => {
311
- it('should throw when [invalid condition]', () => {
312
- expect(() => fn(invalid)).toThrow();
313
- });
314
- });
315
- });
316
- ```
317
-
318
- ---
319
-
320
- ## Files That NEED Tests
321
-
322
- | Type | Location | Test Expected | Required |
323
- | --------- | --------------------- | --------------------- | -------------- |
324
- | API Route | `server/routers/*.ts` | `tests/unit/*.test.ts` | **YES** |
325
- | API Route | `app/api/**/*.ts` | `tests/e2e/api/*.spec.ts` | **YES** |
326
- | Model | `server/models/*.ts` | `tests/unit/*.test.ts` | **YES** |
327
- | Page | `app/**/page.tsx` | `tests/e2e/flows/*.spec.ts` | **YES** |
328
- | Component | `components/**/*.tsx` | `tests/e2e/*.spec.ts` | If interactive |
329
- | Hook | `hooks/*.ts` | `tests/unit/*.test.ts` | YES |
330
- | Util | `lib/*.ts` | `tests/unit/*.test.ts` | If exported |
331
-
332
- ---
333
-
334
- ## Required Flows (E2E)
335
-
336
- Every app MUST have tests for:
337
-
338
- - [ ] **Registration** - Create new user, verify in DB
339
- - [ ] **Login/Logout** - Auth state changes correctly
340
- - [ ] **CRUD Create** - Item created, visible, in DB
341
- - [ ] **CRUD Read** - Item displayed correctly
342
- - [ ] **CRUD Update** - Item updated, changes in DB
343
- - [ ] **CRUD Delete** - Item removed from DB
344
- - [ ] **Permissions** - Forbidden requests blocked
345
- - [ ] **Responsive** - Works on all viewports
346
-
347
- ---
348
-
349
- ## Required data-testid
350
-
351
- ```html
352
- <!-- Forms -->
353
- <input data-testid="name-input" />
354
- <input data-testid="email-input" />
355
- <input data-testid="password-input" />
356
- <input data-testid="confirm-password-input" />
357
- <button data-testid="submit-button" />
358
-
359
- <!-- Feedback -->
360
- <div data-testid="error-message" />
361
- <div data-testid="success-message" />
362
- <div data-testid="loading-spinner" />
363
-
364
- <!-- Navigation -->
365
- <nav data-testid="sidebar" />
366
- <button data-testid="hamburger-menu" />
367
- <nav data-testid="mobile-nav" />
368
- <button data-testid="logout-button" />
369
-
370
- <!-- Actions -->
371
- <button data-testid="delete-button" />
372
- <button data-testid="edit-button" />
373
- <button data-testid="confirm-delete" />
374
- ```
375
-
376
- ---
377
-
378
- ## Playwright Commands
379
-
380
- ```bash
381
- # Install
382
- bun add -D @playwright/test
383
- bunx playwright install
384
-
385
- # Run
386
- bunx playwright test # All tests
387
- bunx playwright test --ui # UI mode (recommended)
388
- bunx playwright test --headed # See browser
389
- bunx playwright test --debug # Debug mode
390
-
391
- # Specific
392
- bunx playwright test flows/auth # Specific folder
393
- bunx playwright test --project="iPhone SE" # Specific viewport
394
-
395
- # Reports
396
- bunx playwright show-report
397
- ```
398
-
399
- ---
400
-
401
- ## Checklist
402
-
403
- ### Before Commit
404
-
405
- - [ ] All new features have E2E tests?
406
- - [ ] Tests use fixtures for cleanup?
407
- - [ ] All created data is tracked and cleaned?
408
- - [ ] Database state verified after UI actions?
409
- - [ ] Tests run on all viewports?
410
- - [ ] Forbidden requests tested?
411
- - [ ] No `.skip()` in tests?
412
- - [ ] `bunx playwright test` passes?
413
- - [ ] `bun run test` passes?
414
-
415
- ---
416
-
417
- ## FORBIDDEN (Never Do)
418
-
419
- ```typescript
420
- // WRONG - Skipping tests
421
- test.skip("should work when authenticated", ...);
422
-
423
- // WRONG - Mocking auth
424
- const mockAuth = () => { /* fake */ };
425
-
426
- // WRONG - Fixed test user
427
- const testUser = { email: "test@test.com" };
428
-
429
- // WRONG - No cleanup
430
- const user = await db.create({ ... }); // Orphaned!
431
-
432
- // WRONG - No DB validation
433
- await page.click('submit');
434
- // Just trust the UI? NO!
435
- ```
436
-
437
- ---
438
-
439
- ## Progressive Disclosure
440
-
441
- For detailed patterns and templates, see:
442
-
443
- - **[reference/playwright-patterns.md](reference/playwright-patterns.md)** - Page Object Model, fixtures, API testing
444
- - **[scripts/coverage-check.sh](scripts/coverage-check.sh)** - Coverage threshold checker
445
-
446
- ### Quick Commands
447
-
448
- ```bash
449
- # Check coverage meets threshold
450
- bash .claude/skills/test-coverage/scripts/coverage-check.sh 80
451
-
452
- # Run E2E tests
453
- bunx playwright test
454
-
455
- # Run with UI
456
- bunx playwright test --ui
457
- ```
458
-
459
- ---
460
-
461
- ## Version
462
-
463
- - **v3.1.0** - Added progressive disclosure with reference files and scripts
464
- - **v3.0.0** - Complete E2E architecture with cleanup, DB validation, multi-viewport
1
+ ---
2
+ name: test-coverage
3
+ description: Manages test coverage with Playwright E2E and Vitest unit tests. Tracks which files need tests, provides templates with fixture-based cleanup, enforces multi-viewport testing and database validation.
4
+ allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
+ ---
6
+
7
+ # Test Coverage - Testing Management System
8
+
9
+ ## Purpose
10
+
11
+ This skill manages test coverage with **Playwright E2E** and **Vitest unit tests**:
12
+
13
+ - **Detects** new files that need tests
14
+ - **Maps** components consuming API routes (tRPC/REST)
15
+ - **Tracks** which pages have E2E coverage
16
+ - **Generates** test templates with cleanup
17
+ - **Validates** real authentication usage (MANDATORY)
18
+ - **Ensures** database validation after UI actions
19
+ - **Enforces** multi-viewport testing
20
+
21
+ ---
22
+
23
+ ## CRITICAL RULES
24
+
25
+ > **MANDATORY - NO EXCEPTIONS:**
26
+
27
+ 1. **CLEANUP ALL TEST DATA** - Use fixture-based tracking
28
+ 2. **VERIFY IN DATABASE** - Check DB state after UI actions
29
+ 3. **TEST ALL VIEWPORTS** - Desktop, tablet, iPhone SE minimum
30
+ 4. **REAL AUTH ONLY** - Never mock authentication
31
+ 5. **UNIQUE DATA** - Timestamps in emails/names
32
+ 6. **NO SKIP** - Never use `.skip()` or `.only()`
33
+
34
+ ---
35
+
36
+ ## Test Structure
37
+
38
+ ```
39
+ tests/
40
+ ├── unit/ # Unit tests (Vitest)
41
+ │ └── *.test.ts
42
+ └── e2e/ # E2E tests (Playwright)
43
+ ├── fixtures/
44
+ │ ├── index.ts # Custom fixtures (auth, db, cleanup)
45
+ │ ├── auth.fixture.ts # Authentication helpers
46
+ │ └── db.fixture.ts # Database connection & cleanup
47
+ ├── pages/ # Page Object Model
48
+ │ ├── base.page.ts # Base page with common methods
49
+ │ ├── login.page.ts
50
+ │ └── register.page.ts
51
+ ├── flows/ # User flow tests
52
+ │ ├── auth.spec.ts # Login, register, logout
53
+ │ ├── crud.spec.ts # Create, read, update, delete
54
+ │ └── permissions.spec.ts
55
+ ├── api/ # API-only tests (no UI)
56
+ │ ├── rest.spec.ts # REST API tests
57
+ │ └── trpc.spec.ts # tRPC API tests
58
+ └── playwright.config.ts
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Cleanup Fixture (MANDATORY)
64
+
65
+ Every project MUST have cleanup fixtures:
66
+
67
+ ```typescript
68
+ // tests/e2e/fixtures/index.ts
69
+ import { test as base, expect } from '@playwright/test';
70
+ import { MongoClient, Db, ObjectId } from 'mongodb';
71
+
72
+ type TestFixtures = {
73
+ db: Db;
74
+ createdIds: Map<string, ObjectId[]>;
75
+ trackCreated: (collection: string, id: ObjectId) => void;
76
+ };
77
+
78
+ export const test = base.extend<TestFixtures>(
79
+ {
80
+ db: async ({}, use) => {
81
+ const client = await MongoClient.connect(process.env.MONGODB_URI!);
82
+ const db = client.db();
83
+ await use(db);
84
+ await client.close();
85
+ },
86
+
87
+ createdIds: async ({}, use) => {
88
+ const ids = new Map<string, ObjectId[]>();
89
+ await use(ids);
90
+ },
91
+
92
+ trackCreated: async ({ createdIds }, use) => {
93
+ const track = (collection: string, id: ObjectId) => {
94
+ const existing = createdIds.get(collection) || [];
95
+ existing.push(id);
96
+ createdIds.set(collection, existing);
97
+ };
98
+ await use(track);
99
+ },
100
+
101
+ // AUTO-CLEANUP runs EVEN IF test fails
102
+ },
103
+ async ({ db, createdIds }, use) => {
104
+ await use();
105
+
106
+ for (const [collection, ids] of createdIds.entries()) {
107
+ if (ids.length > 0) {
108
+ await db.collection(collection).deleteMany({
109
+ _id: { $in: ids },
110
+ });
111
+ }
112
+ }
113
+ }
114
+ );
115
+
116
+ export { expect };
117
+ ```
118
+
119
+ ---
120
+
121
+ ## Auth Helper (MANDATORY)
122
+
123
+ ```typescript
124
+ // tests/e2e/fixtures/auth.fixture.ts
125
+ import { Page } from '@playwright/test';
126
+
127
+ export interface TestUser {
128
+ name: string;
129
+ email: string;
130
+ password: string;
131
+ }
132
+
133
+ export function generateTestUser(): TestUser {
134
+ const timestamp = Date.now();
135
+ const random = Math.random().toString(36).substring(7);
136
+ return {
137
+ name: `Test User ${timestamp}`,
138
+ email: `testuser_${timestamp}_${random}@test.com`,
139
+ password: 'TestPassword123!',
140
+ };
141
+ }
142
+
143
+ export async function registerUser(page: Page, user: TestUser): Promise<void> {
144
+ await page.goto('/auth/register');
145
+ await page.getByTestId('name-input').fill(user.name);
146
+ await page.getByTestId('email-input').fill(user.email);
147
+ await page.getByTestId('password-input').fill(user.password);
148
+ await page.getByTestId('confirm-password-input').fill(user.password);
149
+ await page.getByTestId('submit-button').click();
150
+ await page.waitForURL(/\/app/, { timeout: 10000 });
151
+ }
152
+
153
+ export async function loginUser(page: Page, user: TestUser): Promise<void> {
154
+ await page.goto('/auth/login');
155
+ await page.getByTestId('email-input').fill(user.email);
156
+ await page.getByTestId('password-input').fill(user.password);
157
+ await page.getByTestId('submit-button').click();
158
+ await page.waitForURL(/\/app/, { timeout: 10000 });
159
+ }
160
+ ```
161
+
162
+ ---
163
+
164
+ ## Test Templates
165
+
166
+ ### E2E Flow Test (with cleanup)
167
+
168
+ ```typescript
169
+ import { test, expect } from '../fixtures';
170
+ import { generateTestUser, registerUser } from '../fixtures/auth.fixture';
171
+
172
+ test.describe('[Feature] Flow', () => {
173
+ test('complete user journey', async ({ page, db, trackCreated }) => {
174
+ const user = generateTestUser();
175
+
176
+ // 1. Register
177
+ await registerUser(page, user);
178
+
179
+ // 2. Verify in database
180
+ const dbUser = await db.collection('users').findOne({
181
+ email: user.email,
182
+ });
183
+ expect(dbUser).toBeTruthy();
184
+ trackCreated('users', dbUser!._id); // TRACK FOR CLEANUP
185
+
186
+ // 3. Create item
187
+ await page.goto('/items/new');
188
+ await page.getByTestId('title-input').fill('Test Item');
189
+ await page.getByTestId('submit-button').click();
190
+
191
+ // 4. Verify item in DB
192
+ const item = await db.collection('items').findOne({
193
+ userId: dbUser!._id,
194
+ });
195
+ expect(item).toBeTruthy();
196
+ trackCreated('items', item!._id); // TRACK FOR CLEANUP
197
+
198
+ // Test continues... cleanup is automatic
199
+ });
200
+ });
201
+ ```
202
+
203
+ ### Multi-Viewport Test
204
+
205
+ ```typescript
206
+ import { test, expect } from '../fixtures';
207
+
208
+ test.describe('Responsive Design', () => {
209
+ const viewports = [
210
+ { name: 'mobile', width: 375, height: 667 },
211
+ { name: 'tablet', width: 768, height: 1024 },
212
+ { name: 'desktop', width: 1280, height: 800 },
213
+ ];
214
+
215
+ for (const viewport of viewports) {
216
+ test(`layout works on ${viewport.name}`, async ({ page }) => {
217
+ await page.setViewportSize(viewport);
218
+ await page.goto('/');
219
+
220
+ if (viewport.width < 768) {
221
+ // Mobile: hamburger menu
222
+ await expect(page.getByTestId('hamburger-menu')).toBeVisible();
223
+ await expect(page.getByTestId('sidebar')).toBeHidden();
224
+ } else {
225
+ // Desktop: sidebar visible
226
+ await expect(page.getByTestId('sidebar')).toBeVisible();
227
+ }
228
+ });
229
+ }
230
+ });
231
+ ```
232
+
233
+ ### API Test (REST)
234
+
235
+ ```typescript
236
+ import { test, expect } from '@playwright/test';
237
+
238
+ test.describe('REST API', () => {
239
+ test('requires authentication', async ({ request }) => {
240
+ const response = await request.get('/api/users');
241
+ expect(response.status()).toBe(401);
242
+ });
243
+
244
+ test('validates input', async ({ request }) => {
245
+ const response = await request.post('/api/users', {
246
+ data: { email: 'invalid' },
247
+ });
248
+ expect(response.status()).toBe(400);
249
+ });
250
+ });
251
+ ```
252
+
253
+ ### API Test (tRPC)
254
+
255
+ ```typescript
256
+ import { test, expect } from '@playwright/test';
257
+
258
+ test.describe('tRPC API', () => {
259
+ test('query without auth fails', async ({ request }) => {
260
+ const response = await request.get('/api/trpc/user.me');
261
+ expect(response.status()).toBe(401);
262
+ });
263
+
264
+ test('mutation validates input', async ({ request }) => {
265
+ const response = await request.post('/api/trpc/user.create', {
266
+ data: { json: { name: '' } },
267
+ });
268
+ const body = await response.json();
269
+ expect(body.error).toBeDefined();
270
+ });
271
+ });
272
+ ```
273
+
274
+ ### Security Test
275
+
276
+ ```typescript
277
+ import { test, expect } from '../fixtures';
278
+
279
+ test.describe('Security - Forbidden Requests', () => {
280
+ test('cannot access other users data', async ({ page, db }) => {
281
+ const userA = await createTestUser(db);
282
+ const userB = await createTestUser(db);
283
+
284
+ await loginAs(page, userA);
285
+
286
+ // Try to access user B's data
287
+ const response = await page.request.get(`/api/users/${userB._id}`);
288
+ expect(response.status()).toBe(403);
289
+
290
+ // Verify nothing changed in DB
291
+ const unchanged = await db.collection('users').findOne({
292
+ _id: userB._id,
293
+ });
294
+ expect(unchanged).toEqual(userB);
295
+ });
296
+ });
297
+ ```
298
+
299
+ ### Unit Test
300
+
301
+ ```typescript
302
+ import { describe, it, expect } from 'vitest';
303
+
304
+ describe('[Feature]', () => {
305
+ describe('success cases', () => {
306
+ it('should [expected behavior] when [condition]', () => {
307
+ // Arrange
308
+ // Act
309
+ // Assert
310
+ });
311
+ });
312
+
313
+ describe('error cases', () => {
314
+ it('should throw when [invalid condition]', () => {
315
+ expect(() => fn(invalid)).toThrow();
316
+ });
317
+ });
318
+ });
319
+ ```
320
+
321
+ ---
322
+
323
+ ## Files That NEED Tests
324
+
325
+ | Type | Location | Test Expected | Required |
326
+ | --------- | --------------------- | --------------------------- | -------------- |
327
+ | API Route | `server/routers/*.ts` | `tests/unit/*.test.ts` | **YES** |
328
+ | API Route | `app/api/**/*.ts` | `tests/e2e/api/*.spec.ts` | **YES** |
329
+ | Model | `server/models/*.ts` | `tests/unit/*.test.ts` | **YES** |
330
+ | Page | `app/**/page.tsx` | `tests/e2e/flows/*.spec.ts` | **YES** |
331
+ | Component | `components/**/*.tsx` | `tests/e2e/*.spec.ts` | If interactive |
332
+ | Hook | `hooks/*.ts` | `tests/unit/*.test.ts` | YES |
333
+ | Util | `lib/*.ts` | `tests/unit/*.test.ts` | If exported |
334
+
335
+ ---
336
+
337
+ ## Required Flows (E2E)
338
+
339
+ Every app MUST have tests for:
340
+
341
+ - [ ] **Registration** - Create new user, verify in DB
342
+ - [ ] **Login/Logout** - Auth state changes correctly
343
+ - [ ] **CRUD Create** - Item created, visible, in DB
344
+ - [ ] **CRUD Read** - Item displayed correctly
345
+ - [ ] **CRUD Update** - Item updated, changes in DB
346
+ - [ ] **CRUD Delete** - Item removed from DB
347
+ - [ ] **Permissions** - Forbidden requests blocked
348
+ - [ ] **Responsive** - Works on all viewports
349
+
350
+ ---
351
+
352
+ ## Required data-testid
353
+
354
+ ```html
355
+ <!-- Forms -->
356
+ <input data-testid="name-input" />
357
+ <input data-testid="email-input" />
358
+ <input data-testid="password-input" />
359
+ <input data-testid="confirm-password-input" />
360
+ <button data-testid="submit-button" />
361
+
362
+ <!-- Feedback -->
363
+ <div data-testid="error-message" />
364
+ <div data-testid="success-message" />
365
+ <div data-testid="loading-spinner" />
366
+
367
+ <!-- Navigation -->
368
+ <nav data-testid="sidebar" />
369
+ <button data-testid="hamburger-menu" />
370
+ <nav data-testid="mobile-nav" />
371
+ <button data-testid="logout-button" />
372
+
373
+ <!-- Actions -->
374
+ <button data-testid="delete-button" />
375
+ <button data-testid="edit-button" />
376
+ <button data-testid="confirm-delete" />
377
+ ```
378
+
379
+ ---
380
+
381
+ ## Playwright Commands
382
+
383
+ ```bash
384
+ # Install
385
+ bun add -D @playwright/test
386
+ bunx playwright install
387
+
388
+ # Run
389
+ bunx playwright test # All tests
390
+ bunx playwright test --ui # UI mode (recommended)
391
+ bunx playwright test --headed # See browser
392
+ bunx playwright test --debug # Debug mode
393
+
394
+ # Specific
395
+ bunx playwright test flows/auth # Specific folder
396
+ bunx playwright test --project="iPhone SE" # Specific viewport
397
+
398
+ # Reports
399
+ bunx playwright show-report
400
+ ```
401
+
402
+ ---
403
+
404
+ ## Checklist
405
+
406
+ ### Before Commit
407
+
408
+ - [ ] All new features have E2E tests?
409
+ - [ ] Tests use fixtures for cleanup?
410
+ - [ ] All created data is tracked and cleaned?
411
+ - [ ] Database state verified after UI actions?
412
+ - [ ] Tests run on all viewports?
413
+ - [ ] Forbidden requests tested?
414
+ - [ ] No `.skip()` in tests?
415
+ - [ ] `bunx playwright test` passes?
416
+ - [ ] `bun run test` passes?
417
+
418
+ ---
419
+
420
+ ## FORBIDDEN (Never Do)
421
+
422
+ ```typescript
423
+ // WRONG - Skipping tests
424
+ test.skip("should work when authenticated", ...);
425
+
426
+ // WRONG - Mocking auth
427
+ const mockAuth = () => { /* fake */ };
428
+
429
+ // WRONG - Fixed test user
430
+ const testUser = { email: "test@test.com" };
431
+
432
+ // WRONG - No cleanup
433
+ const user = await db.create({ ... }); // Orphaned!
434
+
435
+ // WRONG - No DB validation
436
+ await page.click('submit');
437
+ // Just trust the UI? NO!
438
+ ```
439
+
440
+ ---
441
+
442
+ ## Progressive Disclosure
443
+
444
+ For detailed patterns and templates, see:
445
+
446
+ - **[reference/playwright-patterns.md](reference/playwright-patterns.md)** - Page Object Model, fixtures, API testing
447
+ - **[scripts/coverage-check.sh](scripts/coverage-check.sh)** - Coverage threshold checker
448
+
449
+ ### Quick Commands
450
+
451
+ ```bash
452
+ # Check coverage meets threshold
453
+ bash .claude/skills/test-coverage/scripts/coverage-check.sh 80
454
+
455
+ # Run E2E tests
456
+ bunx playwright test
457
+
458
+ # Run with UI
459
+ bunx playwright test --ui
460
+ ```
461
+
462
+ ---
463
+
464
+ ## Version
465
+
466
+ - **v3.1.0** - Added progressive disclosure with reference files and scripts
467
+ - **v3.0.0** - Complete E2E architecture with cleanup, DB validation, multi-viewport