openhermes 1.2.2

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 (69) hide show
  1. package/README.md +281 -0
  2. package/autorecall.mjs +167 -0
  3. package/bootstrap.mjs +255 -0
  4. package/curator.mjs +470 -0
  5. package/harness/commands/build-fix.md +60 -0
  6. package/harness/commands/code-review.md +71 -0
  7. package/harness/commands/doctor.md +42 -0
  8. package/harness/commands/learn.md +37 -0
  9. package/harness/commands/memory-search.md +37 -0
  10. package/harness/commands/plan.md +53 -0
  11. package/harness/commands/security.md +93 -0
  12. package/harness/constitution/soul.md +76 -0
  13. package/harness/instructions/RUNTIME.md +21 -0
  14. package/harness/prompts/architect.txt +175 -0
  15. package/harness/prompts/build-error-resolver.md +37 -0
  16. package/harness/prompts/code-reviewer.md +33 -0
  17. package/harness/prompts/e2e-runner.txt +305 -0
  18. package/harness/prompts/explore.md +29 -0
  19. package/harness/prompts/planner.md +30 -0
  20. package/harness/prompts/security-reviewer.md +35 -0
  21. package/harness/rules/audit.md +84 -0
  22. package/harness/rules/checkpointing.md +75 -0
  23. package/harness/rules/context-loading.md +33 -0
  24. package/harness/rules/credential-exposure.md +0 -0
  25. package/harness/rules/delegation.md +76 -0
  26. package/harness/rules/memory-management.md +28 -0
  27. package/harness/rules/precedence.md +52 -0
  28. package/harness/rules/promotion.md +46 -0
  29. package/harness/rules/ranking.md +64 -0
  30. package/harness/rules/retrieval.md +94 -0
  31. package/harness/rules/runtime-guards.md +196 -0
  32. package/harness/rules/self-heal.md +79 -0
  33. package/harness/rules/session-start.md +34 -0
  34. package/harness/rules/skills-management.md +165 -0
  35. package/harness/rules/state-drift.md +192 -0
  36. package/harness/rules/verification.md +88 -0
  37. package/harness/skills/.bundled_manifest +17 -0
  38. package/harness/skills/.usage.json +6 -0
  39. package/harness/skills/api-design/SKILL.md +523 -0
  40. package/harness/skills/backend-patterns/SKILL.md +598 -0
  41. package/harness/skills/coding-standards/SKILL.md +549 -0
  42. package/harness/skills/e2e-testing/SKILL.md +326 -0
  43. package/harness/skills/frontend-patterns/SKILL.md +642 -0
  44. package/harness/skills/frontend-slides/SKILL.md +184 -0
  45. package/harness/skills/security-review/SKILL.md +495 -0
  46. package/harness/skills/strategic-compact/SKILL.md +131 -0
  47. package/harness/skills/tdd-workflow/SKILL.md +463 -0
  48. package/harness/skills/verification-loop/SKILL.md +126 -0
  49. package/index.mjs +5 -0
  50. package/lib/hardening.mjs +113 -0
  51. package/lib/memory-tools-plugin.mjs +265 -0
  52. package/lib/schema-validator.mjs +77 -0
  53. package/lib/tools/_memory.mjs +230 -0
  54. package/lib/tools/hm_get.mjs +13 -0
  55. package/lib/tools/hm_latest.mjs +12 -0
  56. package/lib/tools/hm_list.mjs +13 -0
  57. package/lib/tools/hm_put.mjs +14 -0
  58. package/lib/tools/hm_search.mjs +16 -0
  59. package/package.json +49 -0
  60. package/schemas/audit.schema.json +61 -0
  61. package/schemas/backlog.schema.json +42 -0
  62. package/schemas/checkpoint.schema.json +44 -0
  63. package/schemas/constraint.schema.json +41 -0
  64. package/schemas/decision.schema.json +42 -0
  65. package/schemas/instinct.schema.json +42 -0
  66. package/schemas/loop-state.schema.json +33 -0
  67. package/schemas/mistake.schema.json +43 -0
  68. package/schemas/verification_receipt.schema.json +67 -0
  69. package/skill-builder.mjs +113 -0
@@ -0,0 +1,131 @@
1
+ ---
2
+ name: strategic-compact
3
+ description: Suggests manual context compaction at logical intervals to preserve context through task phases rather than arbitrary auto-compaction.
4
+ origin: ECC
5
+ ---
6
+
7
+ # Strategic Compact Skill
8
+
9
+ Suggests manual `/compact` at strategic points in your workflow rather than relying on arbitrary auto-compaction.
10
+
11
+ ## When to Activate
12
+
13
+ - Running long sessions that approach context limits (200K+ tokens)
14
+ - Working on multi-phase tasks (research → plan → implement → test)
15
+ - Switching between unrelated tasks within the same session
16
+ - After completing a major milestone and starting new work
17
+ - When responses slow down or become less coherent (context pressure)
18
+
19
+ ## Why Strategic Compaction?
20
+
21
+ Auto-compaction triggers at arbitrary points:
22
+ - Often mid-task, losing important context
23
+ - No awareness of logical task boundaries
24
+ - Can interrupt complex multi-step operations
25
+
26
+ Strategic compaction at logical boundaries:
27
+ - **After exploration, before execution** — Compact research context, keep implementation plan
28
+ - **After completing a milestone** — Fresh start for next phase
29
+ - **Before major context shifts** — Clear exploration context before different task
30
+
31
+ ## How It Works
32
+
33
+ The `suggest-compact.js` script runs on PreToolUse (Edit/Write) and:
34
+
35
+ 1. **Tracks tool calls** — Counts tool invocations in session
36
+ 2. **Threshold detection** — Suggests at configurable threshold (default: 50 calls)
37
+ 3. **Periodic reminders** — Reminds every 25 calls after threshold
38
+
39
+ ## Hook Setup
40
+
41
+ Add to your `~/.claude/settings.json`:
42
+
43
+ ```json
44
+ {
45
+ "hooks": {
46
+ "PreToolUse": [
47
+ {
48
+ "matcher": "Edit",
49
+ "hooks": [{ "type": "command", "command": "node ~/.claude/skills/strategic-compact/suggest-compact.js" }]
50
+ },
51
+ {
52
+ "matcher": "Write",
53
+ "hooks": [{ "type": "command", "command": "node ~/.claude/skills/strategic-compact/suggest-compact.js" }]
54
+ }
55
+ ]
56
+ }
57
+ }
58
+ ```
59
+
60
+ ## Configuration
61
+
62
+ Environment variables:
63
+ - `COMPACT_THRESHOLD` — Tool calls before first suggestion (default: 50)
64
+
65
+ ## Compaction Decision Guide
66
+
67
+ Use this table to decide when to compact:
68
+
69
+ | Phase Transition | Compact? | Why |
70
+ |-----------------|----------|-----|
71
+ | Research → Planning | Yes | Research context is bulky; plan is the distilled output |
72
+ | Planning → Implementation | Yes | Plan is in TodoWrite or a file; free up context for code |
73
+ | Implementation → Testing | Maybe | Keep if tests reference recent code; compact if switching focus |
74
+ | Debugging → Next feature | Yes | Debug traces pollute context for unrelated work |
75
+ | Mid-implementation | No | Losing variable names, file paths, and partial state is costly |
76
+ | After a failed approach | Yes | Clear the dead-end reasoning before trying a new approach |
77
+
78
+ ## What Survives Compaction
79
+
80
+ Understanding what persists helps you compact with confidence:
81
+
82
+ | Persists | Lost |
83
+ |----------|------|
84
+ | CLAUDE.md instructions | Intermediate reasoning and analysis |
85
+ | TodoWrite task list | File contents you previously read |
86
+ | Memory files (`~/.claude/memory/`) | Multi-step conversation context |
87
+ | Git state (commits, branches) | Tool call history and counts |
88
+ | Files on disk | Nuanced user preferences stated verbally |
89
+
90
+ ## Best Practices
91
+
92
+ 1. **Compact after planning** — Once plan is finalized in TodoWrite, compact to start fresh
93
+ 2. **Compact after debugging** — Clear error-resolution context before continuing
94
+ 3. **Don't compact mid-implementation** — Preserve context for related changes
95
+ 4. **Read the suggestion** — The hook tells you *when*, you decide *if*
96
+ 5. **Write before compacting** — Save important context to files or memory before compacting
97
+ 6. **Use `/compact` with a summary** — Add a custom message: `/compact Focus on implementing auth middleware next`
98
+
99
+ ## Token Optimization Patterns
100
+
101
+ ### Trigger-Table Lazy Loading
102
+ Instead of loading full skill content at session start, use a trigger table that maps keywords to skill paths. Skills load only when triggered, reducing baseline context by 50%+:
103
+
104
+ | Trigger | Skill | Load When |
105
+ |---------|-------|-----------|
106
+ | "test", "tdd", "coverage" | tdd-workflow | User mentions testing |
107
+ | "security", "auth", "xss" | security-review | Security-related work |
108
+ | "deploy", "ci/cd" | deployment-patterns | Deployment context |
109
+
110
+ ### Context Composition Awareness
111
+ Monitor what's consuming your context window:
112
+ - **CLAUDE.md files** — Always loaded, keep lean
113
+ - **Loaded skills** — Each skill adds 1-5K tokens
114
+ - **Conversation history** — Grows with each exchange
115
+ - **Tool results** — File reads, search results add bulk
116
+
117
+ ### Duplicate Instruction Detection
118
+ Common sources of duplicate context:
119
+ - Same rules in both `~/.claude/rules/` and project `.claude/rules/`
120
+ - Skills that repeat CLAUDE.md instructions
121
+ - Multiple skills covering overlapping domains
122
+
123
+ ### Context Optimization Tools
124
+ - `token-optimizer` MCP — Automated 95%+ token reduction via content deduplication
125
+ - `context-mode` — Context virtualization (315KB to 5.4KB demonstrated)
126
+
127
+ ## Related
128
+
129
+ - [The Longform Guide](https://x.com/affaanmustafa/status/2014040193557471352) — Token optimization section
130
+ - Memory persistence hooks — For state that survives compaction
131
+ - `continuous-learning` skill — Extracts patterns before session ends
@@ -0,0 +1,463 @@
1
+ ---
2
+ name: tdd-workflow
3
+ description: Use this skill when writing new features, fixing bugs, or refactoring code. Enforces test-driven development with 80%+ coverage including unit, integration, and E2E tests.
4
+ origin: ECC
5
+ ---
6
+
7
+ # Test-Driven Development Workflow
8
+
9
+ This skill ensures all code development follows TDD principles with comprehensive test coverage.
10
+
11
+ ## When to Activate
12
+
13
+ - Writing new features or functionality
14
+ - Fixing bugs or issues
15
+ - Refactoring existing code
16
+ - Adding API endpoints
17
+ - Creating new components
18
+
19
+ ## Core Principles
20
+
21
+ ### 1. Tests BEFORE Code
22
+ ALWAYS write tests first, then implement code to make tests pass.
23
+
24
+ ### 2. Coverage Requirements
25
+ - Minimum 80% coverage (unit + integration + E2E)
26
+ - All edge cases covered
27
+ - Error scenarios tested
28
+ - Boundary conditions verified
29
+
30
+ ### 3. Test Types
31
+
32
+ #### Unit Tests
33
+ - Individual functions and utilities
34
+ - Component logic
35
+ - Pure functions
36
+ - Helpers and utilities
37
+
38
+ #### Integration Tests
39
+ - API endpoints
40
+ - Database operations
41
+ - Service interactions
42
+ - External API calls
43
+
44
+ #### E2E Tests (Playwright)
45
+ - Critical user flows
46
+ - Complete workflows
47
+ - Browser automation
48
+ - UI interactions
49
+
50
+ ### 4. Git Checkpoints
51
+ - If the repository is under Git, create a checkpoint commit after each TDD stage
52
+ - Do not squash or rewrite these checkpoint commits until the workflow is complete
53
+ - Each checkpoint commit message must describe the stage and the exact evidence captured
54
+ - Count only commits created on the current active branch for the current task
55
+ - Do not treat commits from other branches, earlier unrelated work, or distant branch history as valid checkpoint evidence
56
+ - Before treating a checkpoint as satisfied, verify that the commit is reachable from the current `HEAD` on the active branch and belongs to the current task sequence
57
+ - The preferred compact workflow is:
58
+ - one commit for failing test added and RED validated
59
+ - one commit for minimal fix applied and GREEN validated
60
+ - one optional commit for refactor complete
61
+ - Separate evidence-only commits are not required if the test commit clearly corresponds to RED and the fix commit clearly corresponds to GREEN
62
+
63
+ ## TDD Workflow Steps
64
+
65
+ ### Step 1: Write User Journeys
66
+ ```
67
+ As a [role], I want to [action], so that [benefit]
68
+
69
+ Example:
70
+ As a user, I want to search for markets semantically,
71
+ so that I can find relevant markets even without exact keywords.
72
+ ```
73
+
74
+ ### Step 2: Generate Test Cases
75
+ For each user journey, create comprehensive test cases:
76
+
77
+ ```typescript
78
+ describe('Semantic Search', () => {
79
+ it('returns relevant markets for query', async () => {
80
+ // Test implementation
81
+ })
82
+
83
+ it('handles empty query gracefully', async () => {
84
+ // Test edge case
85
+ })
86
+
87
+ it('falls back to substring search when Redis unavailable', async () => {
88
+ // Test fallback behavior
89
+ })
90
+
91
+ it('sorts results by similarity score', async () => {
92
+ // Test sorting logic
93
+ })
94
+ })
95
+ ```
96
+
97
+ ### Step 3: Run Tests (They Should Fail)
98
+ ```bash
99
+ npm test
100
+ # Tests should fail - we haven't implemented yet
101
+ ```
102
+
103
+ This step is mandatory and is the RED gate for all production changes.
104
+
105
+ Before modifying business logic or other production code, you must verify a valid RED state via one of these paths:
106
+ - Runtime RED:
107
+ - The relevant test target compiles successfully
108
+ - The new or changed test is actually executed
109
+ - The result is RED
110
+ - Compile-time RED:
111
+ - The new test newly instantiates, references, or exercises the buggy code path
112
+ - The compile failure is itself the intended RED signal
113
+ - In either case, the failure is caused by the intended business-logic bug, undefined behavior, or missing implementation
114
+ - The failure is not caused only by unrelated syntax errors, broken test setup, missing dependencies, or unrelated regressions
115
+
116
+ A test that was only written but not compiled and executed does not count as RED.
117
+
118
+ Do not edit production code until this RED state is confirmed.
119
+
120
+ If the repository is under Git, create a checkpoint commit immediately after this stage is validated.
121
+ Recommended commit message format:
122
+ - `test: add reproducer for <feature or bug>`
123
+ - This commit may also serve as the RED validation checkpoint if the reproducer was compiled and executed and failed for the intended reason
124
+ - Verify that this checkpoint commit is on the current active branch before continuing
125
+
126
+ ### Step 4: Implement Code
127
+ Write minimal code to make tests pass:
128
+
129
+ ```typescript
130
+ // Implementation guided by tests
131
+ export async function searchMarkets(query: string) {
132
+ // Implementation here
133
+ }
134
+ ```
135
+
136
+ If the repository is under Git, stage the minimal fix now but defer the checkpoint commit until GREEN is validated in Step 5.
137
+
138
+ ### Step 5: Run Tests Again
139
+ ```bash
140
+ npm test
141
+ # Tests should now pass
142
+ ```
143
+
144
+ Rerun the same relevant test target after the fix and confirm the previously failing test is now GREEN.
145
+
146
+ Only after a valid GREEN result may you proceed to refactor.
147
+
148
+ If the repository is under Git, create a checkpoint commit immediately after GREEN is validated.
149
+ Recommended commit message format:
150
+ - `fix: <feature or bug>`
151
+ - The fix commit may also serve as the GREEN validation checkpoint if the same relevant test target was rerun and passed
152
+ - Verify that this checkpoint commit is on the current active branch before continuing
153
+
154
+ ### Step 6: Refactor
155
+ Improve code quality while keeping tests green:
156
+ - Remove duplication
157
+ - Improve naming
158
+ - Optimize performance
159
+ - Enhance readability
160
+
161
+ If the repository is under Git, create a checkpoint commit immediately after refactoring is complete and tests remain green.
162
+ Recommended commit message format:
163
+ - `refactor: clean up after <feature or bug> implementation`
164
+ - Verify that this checkpoint commit is on the current active branch before considering the TDD cycle complete
165
+
166
+ ### Step 7: Verify Coverage
167
+ ```bash
168
+ npm run test:coverage
169
+ # Verify 80%+ coverage achieved
170
+ ```
171
+
172
+ ## Testing Patterns
173
+
174
+ ### Unit Test Pattern (Jest/Vitest)
175
+ ```typescript
176
+ import { render, screen, fireEvent } from '@testing-library/react'
177
+ import { Button } from './Button'
178
+
179
+ describe('Button Component', () => {
180
+ it('renders with correct text', () => {
181
+ render(<Button>Click me</Button>)
182
+ expect(screen.getByText('Click me')).toBeInTheDocument()
183
+ })
184
+
185
+ it('calls onClick when clicked', () => {
186
+ const handleClick = jest.fn()
187
+ render(<Button onClick={handleClick}>Click</Button>)
188
+
189
+ fireEvent.click(screen.getByRole('button'))
190
+
191
+ expect(handleClick).toHaveBeenCalledTimes(1)
192
+ })
193
+
194
+ it('is disabled when disabled prop is true', () => {
195
+ render(<Button disabled>Click</Button>)
196
+ expect(screen.getByRole('button')).toBeDisabled()
197
+ })
198
+ })
199
+ ```
200
+
201
+ ### API Integration Test Pattern
202
+ ```typescript
203
+ import { NextRequest } from 'next/server'
204
+ import { GET } from './route'
205
+
206
+ describe('GET /api/markets', () => {
207
+ it('returns markets successfully', async () => {
208
+ const request = new NextRequest('http://localhost/api/markets')
209
+ const response = await GET(request)
210
+ const data = await response.json()
211
+
212
+ expect(response.status).toBe(200)
213
+ expect(data.success).toBe(true)
214
+ expect(Array.isArray(data.data)).toBe(true)
215
+ })
216
+
217
+ it('validates query parameters', async () => {
218
+ const request = new NextRequest('http://localhost/api/markets?limit=invalid')
219
+ const response = await GET(request)
220
+
221
+ expect(response.status).toBe(400)
222
+ })
223
+
224
+ it('handles database errors gracefully', async () => {
225
+ // Mock database failure
226
+ const request = new NextRequest('http://localhost/api/markets')
227
+ // Test error handling
228
+ })
229
+ })
230
+ ```
231
+
232
+ ### E2E Test Pattern (Playwright)
233
+ ```typescript
234
+ import { test, expect } from '@playwright/test'
235
+
236
+ test('user can search and filter markets', async ({ page }) => {
237
+ // Navigate to markets page
238
+ await page.goto('/')
239
+ await page.click('a[href="/markets"]')
240
+
241
+ // Verify page loaded
242
+ await expect(page.locator('h1')).toContainText('Markets')
243
+
244
+ // Search for markets
245
+ await page.fill('input[placeholder="Search markets"]', 'election')
246
+
247
+ // Wait for debounce and results
248
+ await page.waitForTimeout(600)
249
+
250
+ // Verify search results displayed
251
+ const results = page.locator('[data-testid="market-card"]')
252
+ await expect(results).toHaveCount(5, { timeout: 5000 })
253
+
254
+ // Verify results contain search term
255
+ const firstResult = results.first()
256
+ await expect(firstResult).toContainText('election', { ignoreCase: true })
257
+
258
+ // Filter by status
259
+ await page.click('button:has-text("Active")')
260
+
261
+ // Verify filtered results
262
+ await expect(results).toHaveCount(3)
263
+ })
264
+
265
+ test('user can create a new market', async ({ page }) => {
266
+ // Login first
267
+ await page.goto('/creator-dashboard')
268
+
269
+ // Fill market creation form
270
+ await page.fill('input[name="name"]', 'Test Market')
271
+ await page.fill('textarea[name="description"]', 'Test description')
272
+ await page.fill('input[name="endDate"]', '2025-12-31')
273
+
274
+ // Submit form
275
+ await page.click('button[type="submit"]')
276
+
277
+ // Verify success message
278
+ await expect(page.locator('text=Market created successfully')).toBeVisible()
279
+
280
+ // Verify redirect to market page
281
+ await expect(page).toHaveURL(/\/markets\/test-market/)
282
+ })
283
+ ```
284
+
285
+ ## Test File Organization
286
+
287
+ ```
288
+ src/
289
+ ├── components/
290
+ │ ├── Button/
291
+ │ │ ├── Button.tsx
292
+ │ │ ├── Button.test.tsx # Unit tests
293
+ │ │ └── Button.stories.tsx # Storybook
294
+ │ └── MarketCard/
295
+ │ ├── MarketCard.tsx
296
+ │ └── MarketCard.test.tsx
297
+ ├── app/
298
+ │ └── api/
299
+ │ └── markets/
300
+ │ ├── route.ts
301
+ │ └── route.test.ts # Integration tests
302
+ └── e2e/
303
+ ├── markets.spec.ts # E2E tests
304
+ ├── trading.spec.ts
305
+ └── auth.spec.ts
306
+ ```
307
+
308
+ ## Mocking External Services
309
+
310
+ ### Supabase Mock
311
+ ```typescript
312
+ jest.mock('@/lib/supabase', () => ({
313
+ supabase: {
314
+ from: jest.fn(() => ({
315
+ select: jest.fn(() => ({
316
+ eq: jest.fn(() => Promise.resolve({
317
+ data: [{ id: 1, name: 'Test Market' }],
318
+ error: null
319
+ }))
320
+ }))
321
+ }))
322
+ }
323
+ }))
324
+ ```
325
+
326
+ ### Redis Mock
327
+ ```typescript
328
+ jest.mock('@/lib/redis', () => ({
329
+ searchMarketsByVector: jest.fn(() => Promise.resolve([
330
+ { slug: 'test-market', similarity_score: 0.95 }
331
+ ])),
332
+ checkRedisHealth: jest.fn(() => Promise.resolve({ connected: true }))
333
+ }))
334
+ ```
335
+
336
+ ### OpenAI Mock
337
+ ```typescript
338
+ jest.mock('@/lib/openai', () => ({
339
+ generateEmbedding: jest.fn(() => Promise.resolve(
340
+ new Array(1536).fill(0.1) // Mock 1536-dim embedding
341
+ ))
342
+ }))
343
+ ```
344
+
345
+ ## Test Coverage Verification
346
+
347
+ ### Run Coverage Report
348
+ ```bash
349
+ npm run test:coverage
350
+ ```
351
+
352
+ ### Coverage Thresholds
353
+ ```json
354
+ {
355
+ "jest": {
356
+ "coverageThresholds": {
357
+ "global": {
358
+ "branches": 80,
359
+ "functions": 80,
360
+ "lines": 80,
361
+ "statements": 80
362
+ }
363
+ }
364
+ }
365
+ }
366
+ ```
367
+
368
+ ## Common Testing Mistakes to Avoid
369
+
370
+ ### FAIL: WRONG: Testing Implementation Details
371
+ ```typescript
372
+ // Don't test internal state
373
+ expect(component.state.count).toBe(5)
374
+ ```
375
+
376
+ ### PASS: CORRECT: Test User-Visible Behavior
377
+ ```typescript
378
+ // Test what users see
379
+ expect(screen.getByText('Count: 5')).toBeInTheDocument()
380
+ ```
381
+
382
+ ### FAIL: WRONG: Brittle Selectors
383
+ ```typescript
384
+ // Breaks easily
385
+ await page.click('.css-class-xyz')
386
+ ```
387
+
388
+ ### PASS: CORRECT: Semantic Selectors
389
+ ```typescript
390
+ // Resilient to changes
391
+ await page.click('button:has-text("Submit")')
392
+ await page.click('[data-testid="submit-button"]')
393
+ ```
394
+
395
+ ### FAIL: WRONG: No Test Isolation
396
+ ```typescript
397
+ // Tests depend on each other
398
+ test('creates user', () => { /* ... */ })
399
+ test('updates same user', () => { /* depends on previous test */ })
400
+ ```
401
+
402
+ ### PASS: CORRECT: Independent Tests
403
+ ```typescript
404
+ // Each test sets up its own data
405
+ test('creates user', () => {
406
+ const user = createTestUser()
407
+ // Test logic
408
+ })
409
+
410
+ test('updates user', () => {
411
+ const user = createTestUser()
412
+ // Update logic
413
+ })
414
+ ```
415
+
416
+ ## Continuous Testing
417
+
418
+ ### Watch Mode During Development
419
+ ```bash
420
+ npm test -- --watch
421
+ # Tests run automatically on file changes
422
+ ```
423
+
424
+ ### Pre-Commit Hook
425
+ ```bash
426
+ # Runs before every commit
427
+ npm test && npm run lint
428
+ ```
429
+
430
+ ### CI/CD Integration
431
+ ```yaml
432
+ # GitHub Actions
433
+ - name: Run Tests
434
+ run: npm test -- --coverage
435
+ - name: Upload Coverage
436
+ uses: codecov/codecov-action@v3
437
+ ```
438
+
439
+ ## Best Practices
440
+
441
+ 1. **Write Tests First** - Always TDD
442
+ 2. **One Assert Per Test** - Focus on single behavior
443
+ 3. **Descriptive Test Names** - Explain what's tested
444
+ 4. **Arrange-Act-Assert** - Clear test structure
445
+ 5. **Mock External Dependencies** - Isolate unit tests
446
+ 6. **Test Edge Cases** - Null, undefined, empty, large
447
+ 7. **Test Error Paths** - Not just happy paths
448
+ 8. **Keep Tests Fast** - Unit tests < 50ms each
449
+ 9. **Clean Up After Tests** - No side effects
450
+ 10. **Review Coverage Reports** - Identify gaps
451
+
452
+ ## Success Metrics
453
+
454
+ - 80%+ code coverage achieved
455
+ - All tests passing (green)
456
+ - No skipped or disabled tests
457
+ - Fast test execution (< 30s for unit tests)
458
+ - E2E tests cover critical user flows
459
+ - Tests catch bugs before production
460
+
461
+ ---
462
+
463
+ **Remember**: Tests are not optional. They are the safety net that enables confident refactoring, rapid development, and production reliability.