forge-dev-framework 1.0.1 → 1.2.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.
- package/.claude/commands/forge/README.md +281 -0
- package/.claude/commands/forge/add-phase.md +90 -0
- package/.claude/commands/forge/complete-milestone.md +130 -0
- package/.claude/commands/forge/config.md +115 -0
- package/.claude/commands/forge/convert.md +31 -0
- package/.claude/commands/forge/debug.md +31 -0
- package/.claude/commands/forge/discuss.md +78 -0
- package/.claude/commands/forge/execute.md +85 -0
- package/.claude/commands/forge/generate.md +21 -0
- package/.claude/commands/forge/help.md +18 -0
- package/.claude/commands/forge/init.md +21 -0
- package/.claude/commands/forge/insert-phase.md +99 -0
- package/.claude/commands/forge/new-milestone.md +114 -0
- package/.claude/commands/forge/new-project.md +24 -0
- package/.claude/commands/forge/pause-work.md +111 -0
- package/.claude/commands/forge/plan.md +129 -0
- package/.claude/commands/forge/quick.md +41 -0
- package/.claude/commands/forge/remove-phase.md +92 -0
- package/.claude/commands/forge/resume.md +22 -0
- package/.claude/commands/forge/status.md +87 -0
- package/.claude/commands/forge/team-add.md +24 -0
- package/.claude/commands/forge/team-create.md +22 -0
- package/.claude/commands/forge/team-remove.md +24 -0
- package/.claude/commands/forge/team-start.md +22 -0
- package/.claude/commands/forge/team-view.md +18 -0
- package/.claude/commands/forge/verify.md +95 -0
- package/.claude/hooks/forge-context-cleanup.cjs +79 -0
- package/.claude/hooks/forge-event-guard.cjs +36 -0
- package/.claude/hooks/forge-size-guard.cjs +55 -0
- package/.claude/rules/api-patterns.md +13 -98
- package/.claude/rules/context-efficiency.md +10 -0
- package/.claude/rules/security-baseline.md +18 -204
- package/.claude/rules/testing-standards.md +16 -177
- package/.claude/rules/ui-conventions.md +17 -142
- package/README.md +1 -0
- package/bin/forge.js +5 -3
- package/dist/bin/forge.js +5 -3
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +15 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/convert.d.ts +6 -0
- package/dist/commands/convert.d.ts.map +1 -0
- package/dist/commands/convert.js +132 -0
- package/dist/commands/convert.js.map +1 -0
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +3 -2
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/index.d.ts +4 -4
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +4 -4
- package/dist/commands/index.js.map +1 -1
- package/dist/generators/gsd-converter.d.ts +100 -0
- package/dist/generators/gsd-converter.d.ts.map +1 -0
- package/dist/generators/gsd-converter.js +335 -0
- package/dist/generators/gsd-converter.js.map +1 -0
- package/dist/templates/.claude/rules/api-patterns.md.template +212 -0
- package/dist/templates/.claude/rules/security-baseline.md.template +322 -0
- package/dist/templates/.claude/rules/testing-standards.md.template +280 -0
- package/dist/templates/.claude/rules/ui-conventions.md.template +264 -0
- package/dist/templates/.planning/forge.config.json.template +75 -0
- package/dist/templates/CLAUDE.md.template +161 -0
- package/dist/templates/PLAN.md.template +177 -0
- package/dist/templates/PROJECT.md.template +156 -0
- package/dist/templates/REQUIREMENTS.md.template +221 -0
- package/dist/templates/ROADMAP.md.template +130 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -2
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.d.ts +5 -5
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +5 -5
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/template-client.d.ts.map +1 -1
- package/dist/utils/template-client.js +3 -2
- package/dist/utils/template-client.js.map +1 -1
- package/package.json +6 -4
- package/dist/git/__tests__/worktree.test.d.ts +0 -5
- package/dist/git/__tests__/worktree.test.d.ts.map +0 -1
- package/dist/git/__tests__/worktree.test.js +0 -121
- package/dist/git/__tests__/worktree.test.js.map +0 -1
- package/dist/git/codeowners.d.ts +0 -101
- package/dist/git/codeowners.d.ts.map +0 -1
- package/dist/git/codeowners.js +0 -216
- package/dist/git/codeowners.js.map +0 -1
- package/dist/git/commit.d.ts +0 -135
- package/dist/git/commit.d.ts.map +0 -1
- package/dist/git/commit.js +0 -223
- package/dist/git/commit.js.map +0 -1
- package/dist/git/hooks/commit-msg.d.ts +0 -8
- package/dist/git/hooks/commit-msg.d.ts.map +0 -1
- package/dist/git/hooks/commit-msg.js +0 -34
- package/dist/git/hooks/commit-msg.js.map +0 -1
- package/dist/git/hooks/pre-commit.d.ts +0 -8
- package/dist/git/hooks/pre-commit.d.ts.map +0 -1
- package/dist/git/hooks/pre-commit.js +0 -34
- package/dist/git/hooks/pre-commit.js.map +0 -1
- package/dist/git/pre-commit-hooks.d.ts +0 -117
- package/dist/git/pre-commit-hooks.d.ts.map +0 -1
- package/dist/git/pre-commit-hooks.js +0 -270
- package/dist/git/pre-commit-hooks.js.map +0 -1
- package/dist/git/wipe-protocol.d.ts +0 -281
- package/dist/git/wipe-protocol.d.ts.map +0 -1
- package/dist/git/wipe-protocol.js +0 -237
- package/dist/git/wipe-protocol.js.map +0 -1
- package/dist/git/worktree.d.ts +0 -69
- package/dist/git/worktree.d.ts.map +0 -1
- package/dist/git/worktree.js +0 -202
- package/dist/git/worktree.js.map +0 -1
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# Security Baseline — {{projectName}}
|
|
2
|
+
|
|
3
|
+
> **Scope:** Security requirements and practices | **Loaded On-Demand**
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Security Principles
|
|
8
|
+
|
|
9
|
+
{{#if securityPrinciples}}
|
|
10
|
+
{{#each securityPrinciples}}
|
|
11
|
+
- {{this}}
|
|
12
|
+
{{/each}}
|
|
13
|
+
{{else}}
|
|
14
|
+
- **Never trust user input** — Validate, sanitize, verify
|
|
15
|
+
- **Defense in depth** — Multiple layers of security
|
|
16
|
+
- **Least privilege** — Minimal access required
|
|
17
|
+
- **Fail secure** — Error states don't expose data
|
|
18
|
+
- **Security by design** — Built in, not bolted on
|
|
19
|
+
{{/if}}
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Authentication
|
|
24
|
+
|
|
25
|
+
### Password Requirements
|
|
26
|
+
{{#if passwordPolicy}}
|
|
27
|
+
{{passwordPolicy}}
|
|
28
|
+
{{else}}
|
|
29
|
+
- Minimum 12 characters
|
|
30
|
+
- Require: uppercase, lowercase, number, special char
|
|
31
|
+
- Check against common password lists
|
|
32
|
+
- No personal information (name, email)
|
|
33
|
+
{{/if}}
|
|
34
|
+
|
|
35
|
+
### Session Management
|
|
36
|
+
{{#if sessionManagement}}
|
|
37
|
+
{{sessionManagement}}
|
|
38
|
+
{{else}}
|
|
39
|
+
- JWT tokens with short expiration (15 minutes)
|
|
40
|
+
- Refresh tokens with longer expiration (7 days)
|
|
41
|
+
- httpOnly, secure, SameSite cookies
|
|
42
|
+
- Invalidate on logout
|
|
43
|
+
- Rotate tokens periodically
|
|
44
|
+
{{/if}}
|
|
45
|
+
|
|
46
|
+
### Multi-Factor Authentication
|
|
47
|
+
{{#if mfa}}
|
|
48
|
+
{{mfa}}
|
|
49
|
+
{{else}}
|
|
50
|
+
- Require MFA for admin accounts
|
|
51
|
+
- Support TOTP (Google Authenticator)
|
|
52
|
+
- Backup codes for recovery
|
|
53
|
+
{{/if}}
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Authorization
|
|
58
|
+
|
|
59
|
+
### Access Control
|
|
60
|
+
{{#if accessControl}}
|
|
61
|
+
{{accessControl}}
|
|
62
|
+
{{else}}
|
|
63
|
+
- Role-Based Access Control (RBAC)
|
|
64
|
+
- Check permissions at every layer (API, service, data)
|
|
65
|
+
- Default deny: explicit allow only
|
|
66
|
+
- Audit all authorization decisions
|
|
67
|
+
{{/if}}
|
|
68
|
+
|
|
69
|
+
### Role Hierarchy
|
|
70
|
+
{{#if roles}}
|
|
71
|
+
{{#each roles}}
|
|
72
|
+
- **{{this.name}}:** {{this.description}}
|
|
73
|
+
{{/each}}
|
|
74
|
+
{{else}}
|
|
75
|
+
- **guest** — Unauthenticated access
|
|
76
|
+
- **user** — Authenticated, basic access
|
|
77
|
+
- **admin** — Full system access
|
|
78
|
+
- **superadmin** — Emergency access, audit only
|
|
79
|
+
{{/if}}
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Input Validation
|
|
84
|
+
|
|
85
|
+
### Validation Rules
|
|
86
|
+
{{#if inputValidation}}
|
|
87
|
+
{{inputValidation}}
|
|
88
|
+
{{else}}
|
|
89
|
+
- Validate all inputs at API boundary
|
|
90
|
+
- Use schema validation (Zod/Joi/Yup)
|
|
91
|
+
- Whitelist allowed values (don't blacklist)
|
|
92
|
+
- Sanitize HTML (DOMPurify)
|
|
93
|
+
- Truncate excessively long inputs
|
|
94
|
+
{{/if}}
|
|
95
|
+
|
|
96
|
+
### SQL Injection Prevention
|
|
97
|
+
{{#if sqlPrevention}}
|
|
98
|
+
{{sqlPrevention}}
|
|
99
|
+
{{else}}
|
|
100
|
+
- Use parameterized queries only
|
|
101
|
+
- Never concatenate SQL strings
|
|
102
|
+
- Use ORM-provided query builders
|
|
103
|
+
- Enable query logging in development
|
|
104
|
+
{{/if}}
|
|
105
|
+
|
|
106
|
+
### XSS Prevention
|
|
107
|
+
{{#if xssPrevention}}
|
|
108
|
+
{{xssPrevention}}
|
|
109
|
+
{{else}}
|
|
110
|
+
- Escape all user-generated content
|
|
111
|
+
- Use CSP headers (Content-Security-Policy)
|
|
112
|
+
- Set `httpOnly` cookies
|
|
113
|
+
- Validate and sanitize file uploads
|
|
114
|
+
{{/if}}
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Data Protection
|
|
119
|
+
|
|
120
|
+
### Encryption at Rest
|
|
121
|
+
{{#if encryptionAtRest}}
|
|
122
|
+
{{encryptionAtRest}}
|
|
123
|
+
{{else}}
|
|
124
|
+
- Database: {{encryption.db}}
|
|
125
|
+
- File storage: {{encryption.files}}
|
|
126
|
+
- Secrets: {{encryption.secrets}}
|
|
127
|
+
- Backup: {{encryption.backup}}
|
|
128
|
+
{{/if}}
|
|
129
|
+
|
|
130
|
+
### Encryption in Transit
|
|
131
|
+
{{#if encryptionInTransit}}
|
|
132
|
+
{{encryptionInTransit}}
|
|
133
|
+
{{else}}
|
|
134
|
+
- HTTPS only (TLS 1.3+)
|
|
135
|
+
- HSTS headers enabled
|
|
136
|
+
- Secure cipher suites only
|
|
137
|
+
{{/if}}
|
|
138
|
+
|
|
139
|
+
### PII Handling
|
|
140
|
+
{{#if piiHandling}}
|
|
141
|
+
{{piiHandling}}
|
|
142
|
+
{{else}}
|
|
143
|
+
- Identify all PII in code (comment: # PII)
|
|
144
|
+
- Encrypt sensitive fields in database
|
|
145
|
+
- Log PII only when necessary
|
|
146
|
+
- Mask PII in logs (email: u***@example.com)
|
|
147
|
+
{{/if}}
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## API Security
|
|
152
|
+
|
|
153
|
+
### Rate Limiting
|
|
154
|
+
{{#if rateLimiting}}
|
|
155
|
+
{{rateLimiting}}
|
|
156
|
+
{{else}}
|
|
157
|
+
- Per-IP limits for anonymous: 100/min
|
|
158
|
+
- Per-user limits: 1000/min
|
|
159
|
+
- Per-endpoint limits for expensive operations
|
|
160
|
+
- Track with Redis, expire after window
|
|
161
|
+
{{/if}}
|
|
162
|
+
|
|
163
|
+
### API Key Management
|
|
164
|
+
{{#if apiKeyManagement}}
|
|
165
|
+
{{apiKeyManagement}}
|
|
166
|
+
{{else}}
|
|
167
|
+
- Rotate API keys quarterly
|
|
168
|
+
- Include key owner in key metadata
|
|
169
|
+
- Revoke immediately on leak
|
|
170
|
+
- Monitor usage patterns
|
|
171
|
+
{{/if}}
|
|
172
|
+
|
|
173
|
+
### CORS Configuration
|
|
174
|
+
{{#if cors}}
|
|
175
|
+
{{cors}}
|
|
176
|
+
{{else}}
|
|
177
|
+
- Whitelist allowed origins only
|
|
178
|
+
- Don't use `*` in production
|
|
179
|
+
- Expose only necessary headers
|
|
180
|
+
- Max age: 1 hour
|
|
181
|
+
{{/if}}
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Dependencies
|
|
186
|
+
|
|
187
|
+
### Supply Chain Security
|
|
188
|
+
{{#if supplyChain}}
|
|
189
|
+
{{supplyChain}}
|
|
190
|
+
{{else}}
|
|
191
|
+
- Lock dependency versions
|
|
192
|
+
- Run `npm audit` in CI
|
|
193
|
+
- Use Dependabot or Renovate
|
|
194
|
+
- Review PR from dependabots
|
|
195
|
+
- Pin action versions in GitHub Actions
|
|
196
|
+
{{/if}}
|
|
197
|
+
|
|
198
|
+
### Vulnerability Scanning
|
|
199
|
+
{{#if vulnScanning}}
|
|
200
|
+
{{vulnScanning}}
|
|
201
|
+
{{else}}
|
|
202
|
+
- SAST: {{sastTool}} in CI
|
|
203
|
+
- SCA: {{scaTool}} for dependencies
|
|
204
|
+
- DAST: {{dastTool}} on staging
|
|
205
|
+
- Container scan: {{containerScanTool}}
|
|
206
|
+
{{/if}}
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Secrets Management
|
|
211
|
+
|
|
212
|
+
### Secrets Policy
|
|
213
|
+
{{#if secretsPolicy}}
|
|
214
|
+
{{secretsPolicy}}
|
|
215
|
+
{{else}}
|
|
216
|
+
- Never commit secrets to git
|
|
217
|
+
- Use environment variables or vault
|
|
218
|
+
- Rotate secrets quarterly
|
|
219
|
+
- Different secrets per environment
|
|
220
|
+
{{/if}}
|
|
221
|
+
|
|
222
|
+
### Secrets Storage
|
|
223
|
+
{{#if secretsStorage}}
|
|
224
|
+
{{secretsStorage}}
|
|
225
|
+
{{else}}
|
|
226
|
+
- Development: `.env` (gitignored)
|
|
227
|
+
- Production: {{secretsManager}}
|
|
228
|
+
- CI/CD: {{ciSecrets}}
|
|
229
|
+
{{/if}}
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Logging & Monitoring
|
|
234
|
+
|
|
235
|
+
### Security Logging
|
|
236
|
+
{{#if securityLogging}}
|
|
237
|
+
{{securityLogging}}
|
|
238
|
+
{{else}}
|
|
239
|
+
Log all security events:
|
|
240
|
+
- Failed authentication
|
|
241
|
+
- Authorization failures
|
|
242
|
+
- Rate limit violations
|
|
243
|
+
- Admin actions
|
|
244
|
+
- Data exports
|
|
245
|
+
- Configuration changes
|
|
246
|
+
|
|
247
|
+
Include:
|
|
248
|
+
- Timestamp
|
|
249
|
+
- User ID (if available)
|
|
250
|
+
- IP address
|
|
251
|
+
- Action
|
|
252
|
+
- Result
|
|
253
|
+
{{/if}}
|
|
254
|
+
|
|
255
|
+
### Alerting
|
|
256
|
+
{{#if alerting}}
|
|
257
|
+
{{alerting}}
|
|
258
|
+
{{else}}
|
|
259
|
+
Alert on:
|
|
260
|
+
- > 10 failed auth attempts / 5 min / IP
|
|
261
|
+
- > 100 failed auth attempts / 5 min globally
|
|
262
|
+
- New admin account created
|
|
263
|
+
- Database backup accessed
|
|
264
|
+
- Unusual data export volume
|
|
265
|
+
{{/if}}
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## Compliance
|
|
270
|
+
|
|
271
|
+
{{#if compliance}}
|
|
272
|
+
{{#each compliance}}
|
|
273
|
+
### {{this.framework}}
|
|
274
|
+
{{this.requirements}}
|
|
275
|
+
{{/each}}
|
|
276
|
+
{{/if}}
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Security Checklist
|
|
281
|
+
|
|
282
|
+
Before deploying:
|
|
283
|
+
{{#if deploymentChecklist}}
|
|
284
|
+
{{#each deploymentChecklist}}
|
|
285
|
+
- [ ] {{this}}
|
|
286
|
+
{{/each}}
|
|
287
|
+
{{else}}
|
|
288
|
+
- [ ] All dependencies audited
|
|
289
|
+
- [ ] No secrets in code
|
|
290
|
+
- [ ] HTTPS enabled
|
|
291
|
+
- [ ] CORS configured
|
|
292
|
+
- [ ] Rate limiting enabled
|
|
293
|
+
- [ ] Input validation on all endpoints
|
|
294
|
+
- [ ] Authentication required for sensitive operations
|
|
295
|
+
- [ ] Authorization checks on all endpoints
|
|
296
|
+
- [ ] Security headers configured
|
|
297
|
+
- [ ] Logging enabled
|
|
298
|
+
- [ ] Error handling doesn't leak info
|
|
299
|
+
- [ ] File upload validation
|
|
300
|
+
- [ ] Database encryption enabled
|
|
301
|
+
{{/if}}
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## Incident Response
|
|
306
|
+
|
|
307
|
+
{{#if incidentResponse}}
|
|
308
|
+
{{incidentResponse}}
|
|
309
|
+
{{else}}
|
|
310
|
+
### Breach Response
|
|
311
|
+
1. **Detect** — Monitoring/alerts fire
|
|
312
|
+
2. **Contain** — Isolate affected systems
|
|
313
|
+
3. **Investigate** — Determine scope and impact
|
|
314
|
+
4. **Remediate** — Patch vulnerabilities
|
|
315
|
+
5. **Recover** — Restore from backups if needed
|
|
316
|
+
6. **Post-mortem** — Document and improve
|
|
317
|
+
{{/if}}
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
> **Token Budget:** ~1000 tokens max
|
|
322
|
+
> **Loaded On-Demand** — Only when working on security
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# Testing Standards — {{projectName}}
|
|
2
|
+
|
|
3
|
+
> **Scope:** All testing activities | **Loaded On-Demand**
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Testing Philosophy
|
|
8
|
+
|
|
9
|
+
{{#if testingPhilosophy}}
|
|
10
|
+
{{testingPhilosophy}}
|
|
11
|
+
{{else}}
|
|
12
|
+
- **Tests are documentation** — Readability matters
|
|
13
|
+
- **Fast feedback** — Unit tests should run in < 1 second
|
|
14
|
+
- **Test behavior, not implementation** — Black-box over white-box
|
|
15
|
+
- **Arrange-Act-Assert** — Clear test structure
|
|
16
|
+
- **One assertion per test** — When possible
|
|
17
|
+
{{/if}}
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Test Structure
|
|
22
|
+
|
|
23
|
+
### File Organization
|
|
24
|
+
{{#if testStructure}}
|
|
25
|
+
{{testStructure}}
|
|
26
|
+
{{else}}
|
|
27
|
+
```
|
|
28
|
+
src/
|
|
29
|
+
├── features/auth/
|
|
30
|
+
│ ├── auth.service.ts
|
|
31
|
+
│ ├── auth.service.test.ts # Unit tests
|
|
32
|
+
│ ├── auth.controller.ts
|
|
33
|
+
│ └── auth.controller.test.ts # Integration tests
|
|
34
|
+
├── __tests__/
|
|
35
|
+
│ ├── e2e/ # End-to-end tests
|
|
36
|
+
│ └── fixtures/ # Test data, factories
|
|
37
|
+
└── test/
|
|
38
|
+
├── setup.ts # Global test setup
|
|
39
|
+
└── teardown.ts # Global test teardown
|
|
40
|
+
```
|
|
41
|
+
{{/if}}
|
|
42
|
+
|
|
43
|
+
### Test File Naming
|
|
44
|
+
{{#if testNaming}}
|
|
45
|
+
{{testNaming}}
|
|
46
|
+
{{else}}
|
|
47
|
+
- Unit tests: `*.test.ts` or `*.spec.ts`
|
|
48
|
+
- E2E tests: `*.e2e.test.ts`
|
|
49
|
+
- Co-locate tests with source code
|
|
50
|
+
{{/if}}
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Unit Tests
|
|
55
|
+
|
|
56
|
+
### What to Test
|
|
57
|
+
{{#if unitTestScope}}
|
|
58
|
+
{{unitTestScope}}
|
|
59
|
+
{{else}}
|
|
60
|
+
- **Business logic** — Pure functions, services
|
|
61
|
+
- **Utilities** — Helpers, formatters
|
|
62
|
+
- **Components** — React/Vue/Svelte components
|
|
63
|
+
- **Hooks** — Custom React hooks
|
|
64
|
+
|
|
65
|
+
### What NOT to Test
|
|
66
|
+
- Third-party libraries (trust them)
|
|
67
|
+
- Implementation details (private methods)
|
|
68
|
+
- Trivial getters/setters
|
|
69
|
+
{{/if}}
|
|
70
|
+
|
|
71
|
+
### Test Template
|
|
72
|
+
```typescript
|
|
73
|
+
describe('{{feature}}', () => {
|
|
74
|
+
describe('{{scenario}}', () => {
|
|
75
|
+
it('{{expected outcome}}', () => {
|
|
76
|
+
// Arrange
|
|
77
|
+
const input = {
|
|
78
|
+
// setup
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Act
|
|
82
|
+
const result = doSomething(input);
|
|
83
|
+
|
|
84
|
+
// Assert
|
|
85
|
+
expect(result).toBe(expected);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Coverage Requirements
|
|
92
|
+
{{#if coverage}}
|
|
93
|
+
{{coverage}}
|
|
94
|
+
{{else}}
|
|
95
|
+
- Minimum: {{coverage.min}}% overall
|
|
96
|
+
- Critical paths: 100%
|
|
97
|
+
- New code: 100% before merge
|
|
98
|
+
{{/if}}
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Integration Tests
|
|
103
|
+
|
|
104
|
+
### Scope
|
|
105
|
+
{{#if integrationScope}}
|
|
106
|
+
{{integrationScope}}
|
|
107
|
+
{{else}}
|
|
108
|
+
- API endpoints with real database (in-memory)
|
|
109
|
+
- Database interactions and migrations
|
|
110
|
+
- Authentication/authorization flows
|
|
111
|
+
- External service integrations (mocked)
|
|
112
|
+
{{/if}}
|
|
113
|
+
|
|
114
|
+
### Database Testing
|
|
115
|
+
{{#if dbTesting}}
|
|
116
|
+
{{dbTesting}}
|
|
117
|
+
{{else}}
|
|
118
|
+
- Use in-memory database for tests
|
|
119
|
+
- Migrate up/down in `beforeAll`/`afterAll`
|
|
120
|
+
- Seed test data in `beforeEach`
|
|
121
|
+
- Clean tables in `afterEach`
|
|
122
|
+
{{/if}}
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## End-to-End Tests
|
|
127
|
+
|
|
128
|
+
### Framework
|
|
129
|
+
{{#if e2eFramework}}
|
|
130
|
+
{{e2eFramework}}
|
|
131
|
+
{{else}}
|
|
132
|
+
- Use {{e2eTool}} (Playwright/Cypress)
|
|
133
|
+
- Test critical user journeys
|
|
134
|
+
- Run in CI before deployment
|
|
135
|
+
{{/if}}
|
|
136
|
+
|
|
137
|
+
### E2E Test Checklist
|
|
138
|
+
{{#if e2eChecklist}}
|
|
139
|
+
{{e2eChecklist}}
|
|
140
|
+
{{else}}
|
|
141
|
+
{{#each e2eScenarios}}
|
|
142
|
+
- {{this}}
|
|
143
|
+
{{/each}}
|
|
144
|
+
{{/if}}
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Test Data Management
|
|
149
|
+
|
|
150
|
+
### Factories & Fixtures
|
|
151
|
+
{{#if testFactories}}
|
|
152
|
+
{{testFactories}}
|
|
153
|
+
{{else}}
|
|
154
|
+
Use factories for test data:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
// test/factories/user.factory.ts
|
|
158
|
+
export const userFactory = (overrides = {}) => ({
|
|
159
|
+
id: 'user-1',
|
|
160
|
+
email: 'test@example.com',
|
|
161
|
+
name: 'Test User',
|
|
162
|
+
role: 'user',
|
|
163
|
+
...overrides,
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
{{/if}}
|
|
167
|
+
|
|
168
|
+
### Seeding Strategy
|
|
169
|
+
{{#if seedingStrategy}}
|
|
170
|
+
{{seedingStrategy}}
|
|
171
|
+
{{else}}
|
|
172
|
+
- Use deterministic IDs
|
|
173
|
+
- Clean database between tests
|
|
174
|
+
- Use transactions when possible
|
|
175
|
+
{{/if}}
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Mocking & Stubbing
|
|
180
|
+
|
|
181
|
+
### Mocking Guidelines
|
|
182
|
+
{{#if mockingGuidelines}}
|
|
183
|
+
{{mockingGuidelines}}
|
|
184
|
+
{{else}}
|
|
185
|
+
- Mock external services only
|
|
186
|
+
- Prefer real implementations over mocks
|
|
187
|
+
- Clear mocks in `afterEach`
|
|
188
|
+
- Verify mock calls when relevant
|
|
189
|
+
{{/if}}
|
|
190
|
+
|
|
191
|
+
### Example
|
|
192
|
+
```typescript
|
|
193
|
+
jest.mock('./external-api', () => ({
|
|
194
|
+
getData: jest.fn().mockResolvedValue({ data: 'mock' }),
|
|
195
|
+
}));
|
|
196
|
+
|
|
197
|
+
// In test
|
|
198
|
+
await expect(action()).resolves.toEqual(expected);
|
|
199
|
+
expect(externalApi.getData).toHaveBeenCalledWith(expectedArgs);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Performance Tests
|
|
205
|
+
|
|
206
|
+
{{#if performanceTests}}
|
|
207
|
+
{{performanceTests}}
|
|
208
|
+
{{else}}
|
|
209
|
+
- Load test API endpoints (k6, artillery)
|
|
210
|
+
- Benchmark critical functions
|
|
211
|
+
- Test database query performance
|
|
212
|
+
- Set performance budgets in CI
|
|
213
|
+
{{/if}}
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## Security Tests
|
|
218
|
+
|
|
219
|
+
{{#if securityTests}}
|
|
220
|
+
{{securityTests}}
|
|
221
|
+
{{else}}
|
|
222
|
+
- Test authentication bypass attempts
|
|
223
|
+
- Test authorization checks
|
|
224
|
+
- Test input validation (SQL injection, XSS)
|
|
225
|
+
- Test rate limiting
|
|
226
|
+
- Run SAST/DAST scans in CI
|
|
227
|
+
{{/if}}
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Test Commands
|
|
232
|
+
|
|
233
|
+
{{#if testCommands}}
|
|
234
|
+
{{testCommands}}
|
|
235
|
+
{{else}}
|
|
236
|
+
```bash
|
|
237
|
+
# Run all tests
|
|
238
|
+
npm test
|
|
239
|
+
|
|
240
|
+
# Run with coverage
|
|
241
|
+
npm test -- --coverage
|
|
242
|
+
|
|
243
|
+
# Run watch mode
|
|
244
|
+
npm test -- --watch
|
|
245
|
+
|
|
246
|
+
# Run specific test file
|
|
247
|
+
npm test -- auth.service.test
|
|
248
|
+
|
|
249
|
+
# Run E2E tests
|
|
250
|
+
npm run test:e2e
|
|
251
|
+
|
|
252
|
+
# Run performance tests
|
|
253
|
+
npm run test:performance
|
|
254
|
+
```
|
|
255
|
+
{{/if}}
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## CI/CD Integration
|
|
260
|
+
|
|
261
|
+
{{#if ciTesting}}
|
|
262
|
+
{{ciTesting}}
|
|
263
|
+
{{else}}
|
|
264
|
+
### Required Checks
|
|
265
|
+
- Unit tests pass
|
|
266
|
+
- Coverage threshold met
|
|
267
|
+
- E2E tests pass (on main branch)
|
|
268
|
+
- Security scan passes
|
|
269
|
+
- Linting passes
|
|
270
|
+
|
|
271
|
+
### Test Results
|
|
272
|
+
- Upload coverage reports
|
|
273
|
+
- Visualize test trends
|
|
274
|
+
- Report flaky tests
|
|
275
|
+
{{/if}}
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
> **Token Budget:** ~1000 tokens max
|
|
280
|
+
> **Loaded On-Demand** — Only when working on tests
|