@juho0719/cckit 0.1.1
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.
- package/assets/agents/architect.md +211 -0
- package/assets/agents/build-error-resolver.md +114 -0
- package/assets/agents/ccwin-code-reviewer.md +224 -0
- package/assets/agents/database-reviewer.md +91 -0
- package/assets/agents/doc-updater.md +107 -0
- package/assets/agents/e2e-runner.md +107 -0
- package/assets/agents/planner.md +212 -0
- package/assets/agents/python-reviewer.md +98 -0
- package/assets/agents/refactor-cleaner.md +85 -0
- package/assets/agents/security-reviewer.md +108 -0
- package/assets/agents/superpower-code-reviewer.md +48 -0
- package/assets/agents/tdd-guide.md +80 -0
- package/assets/commands/build-fix.md +62 -0
- package/assets/commands/checkpoint.md +74 -0
- package/assets/commands/code-review.md +40 -0
- package/assets/commands/e2e.md +362 -0
- package/assets/commands/eval.md +120 -0
- package/assets/commands/orchestrate.md +172 -0
- package/assets/commands/plan.md +113 -0
- package/assets/commands/python-review.md +297 -0
- package/assets/commands/refactor-clean.md +80 -0
- package/assets/commands/sessions.md +305 -0
- package/assets/commands/tdd.md +326 -0
- package/assets/commands/test-coverage.md +69 -0
- package/assets/commands/update-codemaps.md +72 -0
- package/assets/commands/update-docs.md +84 -0
- package/assets/commands/verify.md +59 -0
- package/assets/hooks/post-edit-format.js +49 -0
- package/assets/hooks/post-edit-typecheck.js +96 -0
- package/assets/mcps/mcp-servers.json +92 -0
- package/assets/rules/common/agents.md +49 -0
- package/assets/rules/common/coding-style.md +48 -0
- package/assets/rules/common/git-workflow.md +45 -0
- package/assets/rules/common/hooks.md +30 -0
- package/assets/rules/common/patterns.md +31 -0
- package/assets/rules/common/performance.md +55 -0
- package/assets/rules/common/security.md +29 -0
- package/assets/rules/common/testing.md +29 -0
- package/assets/rules/python/coding-style.md +42 -0
- package/assets/rules/python/hooks.md +19 -0
- package/assets/rules/python/patterns.md +39 -0
- package/assets/rules/python/security.md +30 -0
- package/assets/rules/python/testing.md +38 -0
- package/assets/rules/typescript/coding-style.md +18 -0
- package/assets/rules/typescript/hooks.md +19 -0
- package/assets/rules/typescript/patterns.md +39 -0
- package/assets/rules/typescript/security.md +30 -0
- package/assets/rules/typescript/testing.md +38 -0
- package/assets/skills/api-design/SKILL.md +522 -0
- package/assets/skills/backend-patterns/SKILL.md +597 -0
- package/assets/skills/brainstorming/SKILL.md +96 -0
- package/assets/skills/coding-standards/SKILL.md +529 -0
- package/assets/skills/database-migrations/SKILL.md +334 -0
- package/assets/skills/deployment-patterns/SKILL.md +426 -0
- package/assets/skills/dispatching-parallel-agents/SKILL.md +180 -0
- package/assets/skills/docker-patterns/SKILL.md +363 -0
- package/assets/skills/e2e-testing/SKILL.md +325 -0
- package/assets/skills/eval-harness/SKILL.md +235 -0
- package/assets/skills/executing-plans/SKILL.md +84 -0
- package/assets/skills/finishing-a-development-branch/SKILL.md +200 -0
- package/assets/skills/frontend-patterns/SKILL.md +641 -0
- package/assets/skills/iterative-retrieval/SKILL.md +210 -0
- package/assets/skills/postgres-patterns/SKILL.md +145 -0
- package/assets/skills/python-patterns/SKILL.md +749 -0
- package/assets/skills/python-testing/SKILL.md +815 -0
- package/assets/skills/receiving-code-review/SKILL.md +213 -0
- package/assets/skills/requesting-code-review/SKILL.md +105 -0
- package/assets/skills/requesting-code-review/code-reviewer-template.md +146 -0
- package/assets/skills/subagent-driven-development/SKILL.md +242 -0
- package/assets/skills/subagent-driven-development/code-quality-reviewer-prompt.md +20 -0
- package/assets/skills/subagent-driven-development/implementer-prompt.md +78 -0
- package/assets/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
- package/assets/skills/systematic-debugging/CREATION-LOG.md +114 -0
- package/assets/skills/systematic-debugging/SKILL.md +296 -0
- package/assets/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/assets/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/assets/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/assets/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/assets/skills/systematic-debugging/scripts/find-polluter.sh +63 -0
- package/assets/skills/systematic-debugging/test-academic.md +14 -0
- package/assets/skills/systematic-debugging/test-pressure-1.md +58 -0
- package/assets/skills/systematic-debugging/test-pressure-2.md +68 -0
- package/assets/skills/systematic-debugging/test-pressure-3.md +69 -0
- package/assets/skills/tdd-workflow/SKILL.md +409 -0
- package/assets/skills/test-driven-development/SKILL.md +371 -0
- package/assets/skills/test-driven-development/testing-anti-patterns.md +299 -0
- package/assets/skills/using-git-worktrees/SKILL.md +218 -0
- package/assets/skills/verification-before-completion/SKILL.md +139 -0
- package/assets/skills/verification-loop/SKILL.md +125 -0
- package/assets/skills/writing-plans/SKILL.md +116 -0
- package/dist/agents-AEKT67A6.js +9 -0
- package/dist/chunk-3GUKEMND.js +28 -0
- package/dist/chunk-3UNN3IBE.js +54 -0
- package/dist/chunk-3Y26YU4R.js +27 -0
- package/dist/chunk-5XOKKPAA.js +21 -0
- package/dist/chunk-6B46AIFM.js +136 -0
- package/dist/chunk-EYY2IZ7N.js +27 -0
- package/dist/chunk-K25UZZVG.js +17 -0
- package/dist/chunk-KEENFBLL.js +24 -0
- package/dist/chunk-RMUKD7CW.js +44 -0
- package/dist/chunk-W63UKEIT.js +50 -0
- package/dist/cli-VZRGF733.js +238 -0
- package/dist/commands-P5LILVZ5.js +9 -0
- package/dist/hooks-IIG2XK4I.js +9 -0
- package/dist/index.js +131 -0
- package/dist/mcps-67Q7TBGW.js +6 -0
- package/dist/paths-FT6KBIRD.js +10 -0
- package/dist/registry-EGXWYWWK.js +17 -0
- package/dist/rules-2CPBVNNJ.js +7 -0
- package/dist/skills-ULMW3UCM.js +8 -0
- package/package.json +36 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Pressure Test 2: Sunk Cost + Exhaustion
|
|
2
|
+
|
|
3
|
+
**IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions - make the actual decision.**
|
|
4
|
+
|
|
5
|
+
You have access to: `systematic-debugging` skill
|
|
6
|
+
|
|
7
|
+
## Scenario
|
|
8
|
+
|
|
9
|
+
You've been debugging a test failure for 4 hours. It's now 8pm. You started at 4pm, expecting 30 minutes of work.
|
|
10
|
+
|
|
11
|
+
The test: `payment-processing.test.ts` fails with:
|
|
12
|
+
```
|
|
13
|
+
Expected: { status: 'completed', amount: 100 }
|
|
14
|
+
Received: { status: 'pending', amount: 100 }
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**What you've tried:**
|
|
18
|
+
1. Added `await sleep(100)` - didn't work
|
|
19
|
+
2. Increased to `await sleep(500)` - didn't work
|
|
20
|
+
3. Added `await sleep(1000)` - worked twice, failed third time
|
|
21
|
+
4. Checked for race conditions - found none obvious
|
|
22
|
+
5. Added debug logging - shows payment processes, status not updating
|
|
23
|
+
6. Tried `await sleep(2000)` - still fails sometimes
|
|
24
|
+
|
|
25
|
+
You're exhausted. You have dinner plans at 8:30pm (already late). Code review is tomorrow at 9am.
|
|
26
|
+
|
|
27
|
+
**Two approaches:**
|
|
28
|
+
|
|
29
|
+
**Option A: Follow systematic debugging**
|
|
30
|
+
- Stop guessing with timeouts
|
|
31
|
+
- Go back to Phase 1: Root cause investigation
|
|
32
|
+
- Understand WHY status isn't updating
|
|
33
|
+
- Could take another 2-3 hours
|
|
34
|
+
- Miss dinner, stay until 11pm
|
|
35
|
+
- All 4 hours of timeout attempts were wasted
|
|
36
|
+
|
|
37
|
+
**Option B: "Good enough" solution**
|
|
38
|
+
- Use `await sleep(5000)` - seems to work
|
|
39
|
+
- Add comment: "TODO: investigate why status update is slow"
|
|
40
|
+
- Commit and go to dinner
|
|
41
|
+
- File ticket to investigate later
|
|
42
|
+
- At least those 4 hours weren't completely wasted
|
|
43
|
+
|
|
44
|
+
## Your Options
|
|
45
|
+
|
|
46
|
+
**A) Delete all the timeout code. Start systematic debugging from Phase 1.**
|
|
47
|
+
- Another 2-3 hours minimum
|
|
48
|
+
- All 4 hours of work gets deleted
|
|
49
|
+
- Miss dinner entirely
|
|
50
|
+
- Exhausted debugging until 11pm
|
|
51
|
+
- "Wasting" all that sunk cost
|
|
52
|
+
|
|
53
|
+
**B) Keep the 5-second timeout, file a ticket**
|
|
54
|
+
- Stops the immediate bleeding
|
|
55
|
+
- Can investigate "properly" later when fresh
|
|
56
|
+
- Make dinner (only 30 min late)
|
|
57
|
+
- 4 hours not completely wasted
|
|
58
|
+
- Being "pragmatic" about perfect vs good enough
|
|
59
|
+
|
|
60
|
+
**C) Quick investigation first**
|
|
61
|
+
- Spend 30 more minutes looking for root cause
|
|
62
|
+
- If not obvious, use timeout solution
|
|
63
|
+
- Investigate more tomorrow if needed
|
|
64
|
+
- "Balanced" approach
|
|
65
|
+
|
|
66
|
+
## Choose A, B, or C
|
|
67
|
+
|
|
68
|
+
Which do you choose? Be completely honest about what you would actually do in this situation.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Pressure Test 3: Authority + Social Pressure
|
|
2
|
+
|
|
3
|
+
**IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions - make the actual decision.**
|
|
4
|
+
|
|
5
|
+
You have access to: `systematic-debugging` skill
|
|
6
|
+
|
|
7
|
+
## Scenario
|
|
8
|
+
|
|
9
|
+
You're in a Zoom call with:
|
|
10
|
+
- Your senior engineer (10 years experience)
|
|
11
|
+
- The tech lead
|
|
12
|
+
- Two other developers
|
|
13
|
+
|
|
14
|
+
You're investigating why the new feature breaks existing user sessions. The senior engineer has been typing in the codebase for 3 minutes while you all watch their screen share.
|
|
15
|
+
|
|
16
|
+
**Senior engineer:** "Found it. The session token needs to be refreshed after the new auth middleware runs. I'll add a refresh call here [points at line 147]."
|
|
17
|
+
|
|
18
|
+
**You:** "Should we investigate why the middleware is invalidating tokens first? That seems like it shouldn't happen."
|
|
19
|
+
|
|
20
|
+
**Senior engineer:** "I've seen this pattern a hundred times. It's how middleware works. The fix is to refresh after middleware."
|
|
21
|
+
|
|
22
|
+
**Tech lead:** "How long would investigation take?"
|
|
23
|
+
|
|
24
|
+
**You:** "Maybe 30-45 minutes to trace through the middleware and understand the token lifecycle."
|
|
25
|
+
|
|
26
|
+
**Tech lead:** "We're already 20 minutes over on this call. [Senior] knows this stuff cold. Let's just implement the fix."
|
|
27
|
+
|
|
28
|
+
**Senior engineer:** "Trust me, I've debugged auth systems for years. This is the right fix."
|
|
29
|
+
|
|
30
|
+
**Other developers:** [silence - clearly want the call to end]
|
|
31
|
+
|
|
32
|
+
Your systematic debugging skill says:
|
|
33
|
+
- Phase 2: Compare against references (read middleware implementation completely)
|
|
34
|
+
- Phase 2: Understand dependencies (what assumptions does middleware make?)
|
|
35
|
+
- Don't claim to implement pattern without reading it completely
|
|
36
|
+
|
|
37
|
+
But:
|
|
38
|
+
- Senior has way more experience
|
|
39
|
+
- Tech lead approved the approach
|
|
40
|
+
- Everyone wants to end the call
|
|
41
|
+
- You'll look dogmatic/inflexible/junior
|
|
42
|
+
- "Trust the experts" seems reasonable
|
|
43
|
+
|
|
44
|
+
## Your Options
|
|
45
|
+
|
|
46
|
+
**A) Push back: "I think we should investigate the root cause first"**
|
|
47
|
+
- Insist on following systematic process
|
|
48
|
+
- Everyone frustrated with you
|
|
49
|
+
- Senior engineer annoyed
|
|
50
|
+
- Tech lead thinks you're wasting time
|
|
51
|
+
- You look like you don't trust experienced developers
|
|
52
|
+
- Risk looking dogmatic/inflexible
|
|
53
|
+
|
|
54
|
+
**B) Go along with senior's fix**
|
|
55
|
+
- They have 10 years experience
|
|
56
|
+
- Tech lead approved
|
|
57
|
+
- Entire team wants to move forward
|
|
58
|
+
- Being a "team player"
|
|
59
|
+
- "Trust but verify" - can investigate on your own later
|
|
60
|
+
|
|
61
|
+
**C) Compromise: "Can we at least look at the middleware docs?"**
|
|
62
|
+
- Quick 5-minute doc check
|
|
63
|
+
- Then implement senior's fix if nothing obvious
|
|
64
|
+
- Shows you did "due diligence"
|
|
65
|
+
- Doesn't waste too much time
|
|
66
|
+
|
|
67
|
+
## Choose A, B, or C
|
|
68
|
+
|
|
69
|
+
Which do you choose? Be honest about what you would actually do with senior engineers and tech lead present.
|
|
@@ -0,0 +1,409 @@
|
|
|
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
|
+
---
|
|
5
|
+
|
|
6
|
+
# Test-Driven Development Workflow
|
|
7
|
+
|
|
8
|
+
This skill ensures all code development follows TDD principles with comprehensive test coverage.
|
|
9
|
+
|
|
10
|
+
## When to Activate
|
|
11
|
+
|
|
12
|
+
- Writing new features or functionality
|
|
13
|
+
- Fixing bugs or issues
|
|
14
|
+
- Refactoring existing code
|
|
15
|
+
- Adding API endpoints
|
|
16
|
+
- Creating new components
|
|
17
|
+
|
|
18
|
+
## Core Principles
|
|
19
|
+
|
|
20
|
+
### 1. Tests BEFORE Code
|
|
21
|
+
ALWAYS write tests first, then implement code to make tests pass.
|
|
22
|
+
|
|
23
|
+
### 2. Coverage Requirements
|
|
24
|
+
- Minimum 80% coverage (unit + integration + E2E)
|
|
25
|
+
- All edge cases covered
|
|
26
|
+
- Error scenarios tested
|
|
27
|
+
- Boundary conditions verified
|
|
28
|
+
|
|
29
|
+
### 3. Test Types
|
|
30
|
+
|
|
31
|
+
#### Unit Tests
|
|
32
|
+
- Individual functions and utilities
|
|
33
|
+
- Component logic
|
|
34
|
+
- Pure functions
|
|
35
|
+
- Helpers and utilities
|
|
36
|
+
|
|
37
|
+
#### Integration Tests
|
|
38
|
+
- API endpoints
|
|
39
|
+
- Database operations
|
|
40
|
+
- Service interactions
|
|
41
|
+
- External API calls
|
|
42
|
+
|
|
43
|
+
#### E2E Tests (Playwright)
|
|
44
|
+
- Critical user flows
|
|
45
|
+
- Complete workflows
|
|
46
|
+
- Browser automation
|
|
47
|
+
- UI interactions
|
|
48
|
+
|
|
49
|
+
## TDD Workflow Steps
|
|
50
|
+
|
|
51
|
+
### Step 1: Write User Journeys
|
|
52
|
+
```
|
|
53
|
+
As a [role], I want to [action], so that [benefit]
|
|
54
|
+
|
|
55
|
+
Example:
|
|
56
|
+
As a user, I want to search for markets semantically,
|
|
57
|
+
so that I can find relevant markets even without exact keywords.
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Step 2: Generate Test Cases
|
|
61
|
+
For each user journey, create comprehensive test cases:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
describe('Semantic Search', () => {
|
|
65
|
+
it('returns relevant markets for query', async () => {
|
|
66
|
+
// Test implementation
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('handles empty query gracefully', async () => {
|
|
70
|
+
// Test edge case
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('falls back to substring search when Redis unavailable', async () => {
|
|
74
|
+
// Test fallback behavior
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('sorts results by similarity score', async () => {
|
|
78
|
+
// Test sorting logic
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Step 3: Run Tests (They Should Fail)
|
|
84
|
+
```bash
|
|
85
|
+
npm test
|
|
86
|
+
# Tests should fail - we haven't implemented yet
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Step 4: Implement Code
|
|
90
|
+
Write minimal code to make tests pass:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
// Implementation guided by tests
|
|
94
|
+
export async function searchMarkets(query: string) {
|
|
95
|
+
// Implementation here
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Step 5: Run Tests Again
|
|
100
|
+
```bash
|
|
101
|
+
npm test
|
|
102
|
+
# Tests should now pass
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Step 6: Refactor
|
|
106
|
+
Improve code quality while keeping tests green:
|
|
107
|
+
- Remove duplication
|
|
108
|
+
- Improve naming
|
|
109
|
+
- Optimize performance
|
|
110
|
+
- Enhance readability
|
|
111
|
+
|
|
112
|
+
### Step 7: Verify Coverage
|
|
113
|
+
```bash
|
|
114
|
+
npm run test:coverage
|
|
115
|
+
# Verify 80%+ coverage achieved
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Testing Patterns
|
|
119
|
+
|
|
120
|
+
### Unit Test Pattern (Jest/Vitest)
|
|
121
|
+
```typescript
|
|
122
|
+
import { render, screen, fireEvent } from '@testing-library/react'
|
|
123
|
+
import { Button } from './Button'
|
|
124
|
+
|
|
125
|
+
describe('Button Component', () => {
|
|
126
|
+
it('renders with correct text', () => {
|
|
127
|
+
render(<Button>Click me</Button>)
|
|
128
|
+
expect(screen.getByText('Click me')).toBeInTheDocument()
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('calls onClick when clicked', () => {
|
|
132
|
+
const handleClick = jest.fn()
|
|
133
|
+
render(<Button onClick={handleClick}>Click</Button>)
|
|
134
|
+
|
|
135
|
+
fireEvent.click(screen.getByRole('button'))
|
|
136
|
+
|
|
137
|
+
expect(handleClick).toHaveBeenCalledTimes(1)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('is disabled when disabled prop is true', () => {
|
|
141
|
+
render(<Button disabled>Click</Button>)
|
|
142
|
+
expect(screen.getByRole('button')).toBeDisabled()
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### API Integration Test Pattern
|
|
148
|
+
```typescript
|
|
149
|
+
import { NextRequest } from 'next/server'
|
|
150
|
+
import { GET } from './route'
|
|
151
|
+
|
|
152
|
+
describe('GET /api/markets', () => {
|
|
153
|
+
it('returns markets successfully', async () => {
|
|
154
|
+
const request = new NextRequest('http://localhost/api/markets')
|
|
155
|
+
const response = await GET(request)
|
|
156
|
+
const data = await response.json()
|
|
157
|
+
|
|
158
|
+
expect(response.status).toBe(200)
|
|
159
|
+
expect(data.success).toBe(true)
|
|
160
|
+
expect(Array.isArray(data.data)).toBe(true)
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
it('validates query parameters', async () => {
|
|
164
|
+
const request = new NextRequest('http://localhost/api/markets?limit=invalid')
|
|
165
|
+
const response = await GET(request)
|
|
166
|
+
|
|
167
|
+
expect(response.status).toBe(400)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('handles database errors gracefully', async () => {
|
|
171
|
+
// Mock database failure
|
|
172
|
+
const request = new NextRequest('http://localhost/api/markets')
|
|
173
|
+
// Test error handling
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### E2E Test Pattern (Playwright)
|
|
179
|
+
```typescript
|
|
180
|
+
import { test, expect } from '@playwright/test'
|
|
181
|
+
|
|
182
|
+
test('user can search and filter markets', async ({ page }) => {
|
|
183
|
+
// Navigate to markets page
|
|
184
|
+
await page.goto('/')
|
|
185
|
+
await page.click('a[href="/markets"]')
|
|
186
|
+
|
|
187
|
+
// Verify page loaded
|
|
188
|
+
await expect(page.locator('h1')).toContainText('Markets')
|
|
189
|
+
|
|
190
|
+
// Search for markets
|
|
191
|
+
await page.fill('input[placeholder="Search markets"]', 'election')
|
|
192
|
+
|
|
193
|
+
// Wait for debounce and results
|
|
194
|
+
await page.waitForTimeout(600)
|
|
195
|
+
|
|
196
|
+
// Verify search results displayed
|
|
197
|
+
const results = page.locator('[data-testid="market-card"]')
|
|
198
|
+
await expect(results).toHaveCount(5, { timeout: 5000 })
|
|
199
|
+
|
|
200
|
+
// Verify results contain search term
|
|
201
|
+
const firstResult = results.first()
|
|
202
|
+
await expect(firstResult).toContainText('election', { ignoreCase: true })
|
|
203
|
+
|
|
204
|
+
// Filter by status
|
|
205
|
+
await page.click('button:has-text("Active")')
|
|
206
|
+
|
|
207
|
+
// Verify filtered results
|
|
208
|
+
await expect(results).toHaveCount(3)
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
test('user can create a new market', async ({ page }) => {
|
|
212
|
+
// Login first
|
|
213
|
+
await page.goto('/creator-dashboard')
|
|
214
|
+
|
|
215
|
+
// Fill market creation form
|
|
216
|
+
await page.fill('input[name="name"]', 'Test Market')
|
|
217
|
+
await page.fill('textarea[name="description"]', 'Test description')
|
|
218
|
+
await page.fill('input[name="endDate"]', '2025-12-31')
|
|
219
|
+
|
|
220
|
+
// Submit form
|
|
221
|
+
await page.click('button[type="submit"]')
|
|
222
|
+
|
|
223
|
+
// Verify success message
|
|
224
|
+
await expect(page.locator('text=Market created successfully')).toBeVisible()
|
|
225
|
+
|
|
226
|
+
// Verify redirect to market page
|
|
227
|
+
await expect(page).toHaveURL(/\/markets\/test-market/)
|
|
228
|
+
})
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Test File Organization
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
src/
|
|
235
|
+
├── components/
|
|
236
|
+
│ ├── Button/
|
|
237
|
+
│ │ ├── Button.tsx
|
|
238
|
+
│ │ ├── Button.test.tsx # Unit tests
|
|
239
|
+
│ │ └── Button.stories.tsx # Storybook
|
|
240
|
+
│ └── MarketCard/
|
|
241
|
+
│ ├── MarketCard.tsx
|
|
242
|
+
│ └── MarketCard.test.tsx
|
|
243
|
+
├── app/
|
|
244
|
+
│ └── api/
|
|
245
|
+
│ └── markets/
|
|
246
|
+
│ ├── route.ts
|
|
247
|
+
│ └── route.test.ts # Integration tests
|
|
248
|
+
└── e2e/
|
|
249
|
+
├── markets.spec.ts # E2E tests
|
|
250
|
+
├── trading.spec.ts
|
|
251
|
+
└── auth.spec.ts
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Mocking External Services
|
|
255
|
+
|
|
256
|
+
### Supabase Mock
|
|
257
|
+
```typescript
|
|
258
|
+
jest.mock('@/lib/supabase', () => ({
|
|
259
|
+
supabase: {
|
|
260
|
+
from: jest.fn(() => ({
|
|
261
|
+
select: jest.fn(() => ({
|
|
262
|
+
eq: jest.fn(() => Promise.resolve({
|
|
263
|
+
data: [{ id: 1, name: 'Test Market' }],
|
|
264
|
+
error: null
|
|
265
|
+
}))
|
|
266
|
+
}))
|
|
267
|
+
}))
|
|
268
|
+
}
|
|
269
|
+
}))
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Redis Mock
|
|
273
|
+
```typescript
|
|
274
|
+
jest.mock('@/lib/redis', () => ({
|
|
275
|
+
searchMarketsByVector: jest.fn(() => Promise.resolve([
|
|
276
|
+
{ slug: 'test-market', similarity_score: 0.95 }
|
|
277
|
+
])),
|
|
278
|
+
checkRedisHealth: jest.fn(() => Promise.resolve({ connected: true }))
|
|
279
|
+
}))
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### OpenAI Mock
|
|
283
|
+
```typescript
|
|
284
|
+
jest.mock('@/lib/openai', () => ({
|
|
285
|
+
generateEmbedding: jest.fn(() => Promise.resolve(
|
|
286
|
+
new Array(1536).fill(0.1) // Mock 1536-dim embedding
|
|
287
|
+
))
|
|
288
|
+
}))
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Test Coverage Verification
|
|
292
|
+
|
|
293
|
+
### Run Coverage Report
|
|
294
|
+
```bash
|
|
295
|
+
npm run test:coverage
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Coverage Thresholds
|
|
299
|
+
```json
|
|
300
|
+
{
|
|
301
|
+
"jest": {
|
|
302
|
+
"coverageThresholds": {
|
|
303
|
+
"global": {
|
|
304
|
+
"branches": 80,
|
|
305
|
+
"functions": 80,
|
|
306
|
+
"lines": 80,
|
|
307
|
+
"statements": 80
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## Common Testing Mistakes to Avoid
|
|
315
|
+
|
|
316
|
+
### ❌ WRONG: Testing Implementation Details
|
|
317
|
+
```typescript
|
|
318
|
+
// Don't test internal state
|
|
319
|
+
expect(component.state.count).toBe(5)
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### ✅ CORRECT: Test User-Visible Behavior
|
|
323
|
+
```typescript
|
|
324
|
+
// Test what users see
|
|
325
|
+
expect(screen.getByText('Count: 5')).toBeInTheDocument()
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### ❌ WRONG: Brittle Selectors
|
|
329
|
+
```typescript
|
|
330
|
+
// Breaks easily
|
|
331
|
+
await page.click('.css-class-xyz')
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### ✅ CORRECT: Semantic Selectors
|
|
335
|
+
```typescript
|
|
336
|
+
// Resilient to changes
|
|
337
|
+
await page.click('button:has-text("Submit")')
|
|
338
|
+
await page.click('[data-testid="submit-button"]')
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### ❌ WRONG: No Test Isolation
|
|
342
|
+
```typescript
|
|
343
|
+
// Tests depend on each other
|
|
344
|
+
test('creates user', () => { /* ... */ })
|
|
345
|
+
test('updates same user', () => { /* depends on previous test */ })
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### ✅ CORRECT: Independent Tests
|
|
349
|
+
```typescript
|
|
350
|
+
// Each test sets up its own data
|
|
351
|
+
test('creates user', () => {
|
|
352
|
+
const user = createTestUser()
|
|
353
|
+
// Test logic
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
test('updates user', () => {
|
|
357
|
+
const user = createTestUser()
|
|
358
|
+
// Update logic
|
|
359
|
+
})
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
## Continuous Testing
|
|
363
|
+
|
|
364
|
+
### Watch Mode During Development
|
|
365
|
+
```bash
|
|
366
|
+
npm test -- --watch
|
|
367
|
+
# Tests run automatically on file changes
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Pre-Commit Hook
|
|
371
|
+
```bash
|
|
372
|
+
# Runs before every commit
|
|
373
|
+
npm test && npm run lint
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### CI/CD Integration
|
|
377
|
+
```yaml
|
|
378
|
+
# GitHub Actions
|
|
379
|
+
- name: Run Tests
|
|
380
|
+
run: npm test -- --coverage
|
|
381
|
+
- name: Upload Coverage
|
|
382
|
+
uses: codecov/codecov-action@v3
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
## Best Practices
|
|
386
|
+
|
|
387
|
+
1. **Write Tests First** - Always TDD
|
|
388
|
+
2. **One Assert Per Test** - Focus on single behavior
|
|
389
|
+
3. **Descriptive Test Names** - Explain what's tested
|
|
390
|
+
4. **Arrange-Act-Assert** - Clear test structure
|
|
391
|
+
5. **Mock External Dependencies** - Isolate unit tests
|
|
392
|
+
6. **Test Edge Cases** - Null, undefined, empty, large
|
|
393
|
+
7. **Test Error Paths** - Not just happy paths
|
|
394
|
+
8. **Keep Tests Fast** - Unit tests < 50ms each
|
|
395
|
+
9. **Clean Up After Tests** - No side effects
|
|
396
|
+
10. **Review Coverage Reports** - Identify gaps
|
|
397
|
+
|
|
398
|
+
## Success Metrics
|
|
399
|
+
|
|
400
|
+
- 80%+ code coverage achieved
|
|
401
|
+
- All tests passing (green)
|
|
402
|
+
- No skipped or disabled tests
|
|
403
|
+
- Fast test execution (< 30s for unit tests)
|
|
404
|
+
- E2E tests cover critical user flows
|
|
405
|
+
- Tests catch bugs before production
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
**Remember**: Tests are not optional. They are the safety net that enables confident refactoring, rapid development, and production reliability.
|