agents-templated 2.2.0 → 2.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.
- package/README.md +9 -9
- package/bin/cli.js +9 -9
- package/index.js +12 -1
- package/lib/instructions.js +20 -6
- package/lib/layout.js +3 -2
- package/package.json +1 -1
- package/templates/{agents/subagents → .claude/agents}/README.md +2 -2
- package/templates/.claude/rules/ai-integration.mdc +60 -0
- package/templates/.claude/rules/core.mdc +180 -0
- package/templates/.claude/rules/database.mdc +291 -0
- package/templates/.claude/rules/frontend.mdc +224 -0
- package/templates/.claude/rules/guardrails.mdc +105 -0
- package/templates/.claude/rules/hardening.mdc +58 -0
- package/templates/.claude/rules/intent-routing.mdc +59 -0
- package/templates/.claude/rules/planning.mdc +75 -0
- package/templates/.claude/rules/security.mdc +286 -0
- package/templates/.claude/rules/style.mdc +306 -0
- package/templates/.claude/rules/system-workflow.mdc +69 -0
- package/templates/.claude/rules/testing.mdc +308 -0
- package/templates/.claude/rules/workflows.mdc +61 -0
- package/templates/.cursorrules +2 -5
- package/templates/CLAUDE.md +37 -37
- package/templates/README.md +3 -3
- package/templates/agent-docs/ARCHITECTURE.md +3 -3
- package/templates/agent-docs/README.md +12 -13
- package/templates/agents/rules/ai-integration.mdc +10 -2
- package/templates/agents/rules/core.mdc +8 -1
- package/templates/agents/rules/database.mdc +10 -2
- package/templates/agents/rules/frontend.mdc +10 -2
- package/templates/agents/rules/guardrails.mdc +10 -2
- package/templates/agents/rules/hardening.mdc +10 -2
- package/templates/agents/rules/intent-routing.mdc +10 -2
- package/templates/agents/rules/planning.mdc +10 -2
- package/templates/agents/rules/security.mdc +11 -2
- package/templates/agents/rules/style.mdc +10 -2
- package/templates/agents/rules/system-workflow.mdc +10 -2
- package/templates/agents/rules/testing.mdc +9 -1
- package/templates/agents/rules/workflows.mdc +10 -2
- package/templates/agents/skills/README.md +6 -6
- package/templates/instructions/source/core.md +0 -219
- /package/templates/{agents/subagents → .claude/agents}/architect.md +0 -0
- /package/templates/{agents/subagents → .claude/agents}/build-error-resolver.md +0 -0
- /package/templates/{agents/subagents → .claude/agents}/code-reviewer.md +0 -0
- /package/templates/{agents/subagents → .claude/agents}/doc-updater.md +0 -0
- /package/templates/{agents/subagents → .claude/agents}/e2e-runner.md +0 -0
- /package/templates/{agents/subagents → .claude/agents}/planner.md +0 -0
- /package/templates/{agents/subagents → .claude/agents}/refactor-cleaner.md +0 -0
- /package/templates/{agents/subagents → .claude/agents}/security-reviewer.md +0 -0
- /package/templates/{agents/subagents → .claude/agents}/tdd-guide.md +0 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Code Style and Standards"
|
|
3
|
+
description: "Apply when organizing code, naming variables, formatting, or improving code clarity and maintainability"
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
version: "3.0.0"
|
|
6
|
+
tags: ["style", "formatting", "naming", "quality"]
|
|
7
|
+
globs:
|
|
8
|
+
- "**/*"
|
|
9
|
+
triggers:
|
|
10
|
+
- "Writing or reviewing code"
|
|
11
|
+
- "Setting up code formatting rules"
|
|
12
|
+
- "Naming variables, functions, or files"
|
|
13
|
+
- "Organizing module structure"
|
|
14
|
+
- "Refactoring or improving readability"
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Code Style and Standards
|
|
18
|
+
|
|
19
|
+
Language and framework-agnostic standards for clean, maintainable code.
|
|
20
|
+
|
|
21
|
+
## General Code Quality
|
|
22
|
+
|
|
23
|
+
### Core Principles
|
|
24
|
+
|
|
25
|
+
- **Readability**: Code should be easy to understand without extensive comments
|
|
26
|
+
- **Consistency**: Follow the same patterns throughout the codebase
|
|
27
|
+
- **Simplicity**: Prefer simple solutions to complex ones
|
|
28
|
+
- **SOLID principles**: Single responsibility, Open/closed, Liskov, Interface segregation, Dependency inversion
|
|
29
|
+
- **DRY**: Don't Repeat Yourself - extract common patterns
|
|
30
|
+
|
|
31
|
+
### Code Review Standards
|
|
32
|
+
|
|
33
|
+
Code should:
|
|
34
|
+
- Do one thing well
|
|
35
|
+
- Be testable
|
|
36
|
+
- Have no dead code
|
|
37
|
+
- Follow established patterns
|
|
38
|
+
- Include appropriate comments
|
|
39
|
+
- Have meaningful names
|
|
40
|
+
- Handle errors appropriately
|
|
41
|
+
- Consider security implications
|
|
42
|
+
- Consider performance implications
|
|
43
|
+
|
|
44
|
+
## Naming Conventions
|
|
45
|
+
|
|
46
|
+
### File Naming
|
|
47
|
+
|
|
48
|
+
Choose from established conventions:
|
|
49
|
+
|
|
50
|
+
**Option 1: kebab-case (Recommended)**
|
|
51
|
+
- File names: `user-profile.ts`, `navigation-bar.tsx`, `date-utils.js`
|
|
52
|
+
- Matches URLs and file systems
|
|
53
|
+
- Language-agnostic
|
|
54
|
+
- Easy to type and read
|
|
55
|
+
|
|
56
|
+
**Option 2: snake_case**
|
|
57
|
+
- File names: `user_profile.py`, `date_utils.go`
|
|
58
|
+
- Common in Python, Go, and Ruby
|
|
59
|
+
- Matches language conventions
|
|
60
|
+
|
|
61
|
+
**Option 3: PascalCase**
|
|
62
|
+
- File names: `UserProfile.tsx`, `DateUtils.ts`
|
|
63
|
+
- Common in C# and some JavaScript frameworks
|
|
64
|
+
- Use consistently if chosen
|
|
65
|
+
|
|
66
|
+
**Consistency rule**: Pick ONE and use it throughout the entire project.
|
|
67
|
+
|
|
68
|
+
### Code Naming
|
|
69
|
+
|
|
70
|
+
Consistent naming patterns:
|
|
71
|
+
|
|
72
|
+
**Variables and Functions**
|
|
73
|
+
- Use camelCase: `getUserData`, `isLoading`, `handleSubmit`
|
|
74
|
+
- Use English words (even in non-English projects)
|
|
75
|
+
- Be descriptive: `user` is worse than `currentUser`
|
|
76
|
+
- Avoid abbreviations: `getDesc` vs `getDescription`
|
|
77
|
+
- Prefix booleans with is/has: `isActive`, `hasPermission`
|
|
78
|
+
|
|
79
|
+
**Constants**
|
|
80
|
+
- Use UPPER_SNAKE_CASE: `MAX_RETRIES`, `API_BASE_URL`
|
|
81
|
+
- Immutable values that don't change
|
|
82
|
+
- Global configuration values
|
|
83
|
+
- Magic numbers should become constants
|
|
84
|
+
|
|
85
|
+
**Classes/Types/Interfaces**
|
|
86
|
+
- Use PascalCase: `UserProfile`, `ApiResponse`, `DatabaseConfig`
|
|
87
|
+
- Descriptive and specific names
|
|
88
|
+
- Avoid generic names like `Data`, `Info`, `Object`
|
|
89
|
+
|
|
90
|
+
**Enums**
|
|
91
|
+
- Type name PascalCase: `UserStatus`
|
|
92
|
+
- Values UPPER_SNAKE_CASE: `ACTIVE`, `INACTIVE`
|
|
93
|
+
- Example: `UserStatus.ACTIVE`, `Theme.DARK_MODE`
|
|
94
|
+
|
|
95
|
+
### Examples
|
|
96
|
+
|
|
97
|
+
Good naming:
|
|
98
|
+
```
|
|
99
|
+
getUserById()
|
|
100
|
+
isValidEmail()
|
|
101
|
+
parseJsonResponse()
|
|
102
|
+
calculateProposedDiscount()
|
|
103
|
+
MAXIMUM_RETRY_ATTEMPTS
|
|
104
|
+
ValidationError
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Bad naming:
|
|
108
|
+
```
|
|
109
|
+
get()
|
|
110
|
+
foo(), bar(), x
|
|
111
|
+
process()
|
|
112
|
+
u1, u2, s
|
|
113
|
+
var1, var2
|
|
114
|
+
handleIt()
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Formatting
|
|
118
|
+
|
|
119
|
+
### Consistent Formatting
|
|
120
|
+
|
|
121
|
+
Use automated tools:
|
|
122
|
+
- **Prettier**: JavaScript/TypeScript/CSS/YAML
|
|
123
|
+
- **Black**: Python
|
|
124
|
+
- **gofmt**: Go
|
|
125
|
+
- **rustfmt**: Rust
|
|
126
|
+
- **clang-format**: C/C++
|
|
127
|
+
- Your language's standard formatter
|
|
128
|
+
|
|
129
|
+
Benefits:
|
|
130
|
+
- No debates about formatting
|
|
131
|
+
- Quick review of actual changes
|
|
132
|
+
- Consistent codebase
|
|
133
|
+
|
|
134
|
+
### Line Length
|
|
135
|
+
|
|
136
|
+
- Target: 80-120 characters
|
|
137
|
+
- Maximum: 120-140 characters
|
|
138
|
+
- Avoid scrolling horizontally
|
|
139
|
+
|
|
140
|
+
### Indentation
|
|
141
|
+
|
|
142
|
+
Choose ONE and use consistently:
|
|
143
|
+
- **2 spaces**: JavaScript, YAML, some Python
|
|
144
|
+
- **4 spaces**: Python, Java, most languages
|
|
145
|
+
- **Tabs**: If configured, consistently
|
|
146
|
+
|
|
147
|
+
### Comments & Documentation
|
|
148
|
+
|
|
149
|
+
Good comments explain:
|
|
150
|
+
- **Why**: The reason for this code
|
|
151
|
+
- **Complex logic**: How it works if not obvious
|
|
152
|
+
- **Edge cases**: Special handling and why
|
|
153
|
+
- **Warnings**: Performance implications or gotchas
|
|
154
|
+
|
|
155
|
+
Bad comments:
|
|
156
|
+
```
|
|
157
|
+
// Increment x
|
|
158
|
+
x = x + 1
|
|
159
|
+
|
|
160
|
+
// Loop through users
|
|
161
|
+
for (user in users) { ... }
|
|
162
|
+
|
|
163
|
+
// This is a variable
|
|
164
|
+
let name = getUserName()
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Good comments:
|
|
168
|
+
```
|
|
169
|
+
// Increment retry counter before exponential backoff
|
|
170
|
+
retryCount = retryCount + 1
|
|
171
|
+
|
|
172
|
+
// Process users in batches to prevent memory overload
|
|
173
|
+
for (batch in users.batches()) { ... }
|
|
174
|
+
|
|
175
|
+
// Fetch fresh name from API to avoid stale cache
|
|
176
|
+
let name = getUserName()
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Comments vs Code
|
|
180
|
+
|
|
181
|
+
Let code speak for itself:
|
|
182
|
+
|
|
183
|
+
Instead of:
|
|
184
|
+
```
|
|
185
|
+
// Get user age
|
|
186
|
+
int age = currentYear - birthYear
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Write:
|
|
190
|
+
```
|
|
191
|
+
int age = calculateAge(currentYear, birthYear)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Code Organization
|
|
195
|
+
|
|
196
|
+
### Module Organization
|
|
197
|
+
|
|
198
|
+
Order within files:
|
|
199
|
+
1. **Imports/Dependencies** - at top
|
|
200
|
+
2. **Constants** - module-level constants
|
|
201
|
+
3. **Types/Interfaces** - type definitions
|
|
202
|
+
4. **Functions/Classes** - main code (public first, private after)
|
|
203
|
+
5. **Exports** - explicit exports at end
|
|
204
|
+
|
|
205
|
+
### Function Organization
|
|
206
|
+
|
|
207
|
+
Function structure:
|
|
208
|
+
1. **Parameters** - at top
|
|
209
|
+
2. **Early returns** - validate inputs early
|
|
210
|
+
3. **Logic** - main implementation
|
|
211
|
+
4. **Return** - return result
|
|
212
|
+
|
|
213
|
+
### Class/Object Organization
|
|
214
|
+
|
|
215
|
+
Class structure:
|
|
216
|
+
1. **Constructor/initializer**
|
|
217
|
+
2. **Public methods**
|
|
218
|
+
3. **Private methods**
|
|
219
|
+
4. **Getters/setters**
|
|
220
|
+
5. **Static methods** (if applicable)
|
|
221
|
+
|
|
222
|
+
## Type Definitions
|
|
223
|
+
|
|
224
|
+
### Clear Type Contracts
|
|
225
|
+
|
|
226
|
+
Document what your types expect:
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
Define data structures clearly:
|
|
230
|
+
- What fields are required
|
|
231
|
+
- What data types
|
|
232
|
+
- What values are valid
|
|
233
|
+
- Any constraints or rules
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Avoid Magic Values
|
|
237
|
+
|
|
238
|
+
Instead of magic numbers/strings:
|
|
239
|
+
```
|
|
240
|
+
if (status === 1) { ... }
|
|
241
|
+
if (timeout === 60000) { ... }
|
|
242
|
+
|
|
243
|
+
const ACTIVE_STATUS = 1
|
|
244
|
+
const DEFAULT_TIMEOUT_MS = 60000
|
|
245
|
+
if (status === ACTIVE_STATUS) { ... }
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Error Handling
|
|
249
|
+
|
|
250
|
+
### Clear Error Messages
|
|
251
|
+
|
|
252
|
+
Error messages should:
|
|
253
|
+
- Describe what went wrong
|
|
254
|
+
- Explain why (if not obvious)
|
|
255
|
+
- Suggest how to fix
|
|
256
|
+
- Use user-friendly language
|
|
257
|
+
|
|
258
|
+
Good error messages:
|
|
259
|
+
- "Email format is invalid. Please enter a valid email address."
|
|
260
|
+
- "Password must be at least 8 characters."
|
|
261
|
+
- "User with this email already exists."
|
|
262
|
+
|
|
263
|
+
Bad error messages:
|
|
264
|
+
- "Error"
|
|
265
|
+
- "Invalid input"
|
|
266
|
+
- "Stack trace here..."
|
|
267
|
+
|
|
268
|
+
### Error Handling Pattern
|
|
269
|
+
|
|
270
|
+
Proper error handling:
|
|
271
|
+
1. Catch/handle errors explicitly
|
|
272
|
+
2. Log error with context
|
|
273
|
+
3. Return appropriate error response
|
|
274
|
+
4. Never expose sensitive data
|
|
275
|
+
5. Include error code for client handling
|
|
276
|
+
|
|
277
|
+
## Security in Code
|
|
278
|
+
|
|
279
|
+
### Dangerous Patterns to Avoid
|
|
280
|
+
|
|
281
|
+
Never:
|
|
282
|
+
- Store secrets in code
|
|
283
|
+
- Log sensitive data
|
|
284
|
+
- Dynamic SQL/query construction
|
|
285
|
+
- Eval user input
|
|
286
|
+
- Hardcoded API keys
|
|
287
|
+
- Return sensitive data in errors
|
|
288
|
+
- Skip input validation
|
|
289
|
+
|
|
290
|
+
Always:
|
|
291
|
+
- Validate all inputs
|
|
292
|
+
- Use parameterized queries
|
|
293
|
+
- Hash sensitive data
|
|
294
|
+
- Use environment variables for secrets
|
|
295
|
+
- Log security events
|
|
296
|
+
- Encode output appropriately
|
|
297
|
+
|
|
298
|
+
## Performance Considerations
|
|
299
|
+
|
|
300
|
+
### Avoid N+1 Queries
|
|
301
|
+
|
|
302
|
+
Good:
|
|
303
|
+
```
|
|
304
|
+
Get all users once with their posts
|
|
305
|
+
Result: 1 query
|
|
306
|
+
```
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "System Workflow Orchestration"
|
|
3
|
+
description: "Apply when planning work phases, defining acceptance criteria, or establishing delivery gates and rollback strategies"
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
tags: ["workflow", "gates", "delivery", "governance"]
|
|
6
|
+
triggers:
|
|
7
|
+
- "Starting a new feature or major change"
|
|
8
|
+
- "Planning implementation phases"
|
|
9
|
+
- "Defining acceptance criteria"
|
|
10
|
+
- "Establishing rollback procedures"
|
|
11
|
+
- "Preparing for release or deployment"
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Purpose
|
|
15
|
+
|
|
16
|
+
Define a repeatable lifecycle so all work is traceable, verifiable, and releasable.
|
|
17
|
+
|
|
18
|
+
## Workflow Phases
|
|
19
|
+
|
|
20
|
+
1. Discover
|
|
21
|
+
2. Plan
|
|
22
|
+
3. Implement
|
|
23
|
+
4. Verify
|
|
24
|
+
5. Release
|
|
25
|
+
|
|
26
|
+
## Phase Requirements
|
|
27
|
+
|
|
28
|
+
### 1) Discover
|
|
29
|
+
- Capture objective, scope boundaries, constraints, and risk profile.
|
|
30
|
+
- Produce: context summary + assumptions.
|
|
31
|
+
|
|
32
|
+
### 2) Plan
|
|
33
|
+
- Break work into atomic units and dependency order.
|
|
34
|
+
- Define acceptance criteria and rollback considerations.
|
|
35
|
+
- Produce: execution plan with checkpoints.
|
|
36
|
+
|
|
37
|
+
### 3) Implement
|
|
38
|
+
- Apply smallest safe changes within declared scope.
|
|
39
|
+
- Keep changes deterministic and reversible when possible.
|
|
40
|
+
- Produce: change summary and affected files.
|
|
41
|
+
|
|
42
|
+
### 4) Verify
|
|
43
|
+
- Run relevant tests/checks (targeted first, broad second).
|
|
44
|
+
- Confirm security and regression impact.
|
|
45
|
+
- Produce: validation evidence.
|
|
46
|
+
|
|
47
|
+
### 5) Release
|
|
48
|
+
- Check gates: tests, security posture, migration safety, rollback readiness.
|
|
49
|
+
- Produce: release decision + rollout/rollback steps.
|
|
50
|
+
|
|
51
|
+
## Required Delivery Artifacts
|
|
52
|
+
|
|
53
|
+
- Objective and scope
|
|
54
|
+
- Acceptance criteria
|
|
55
|
+
- Risk register
|
|
56
|
+
- Validation evidence
|
|
57
|
+
- Rollback strategy (for non-trivial changes)
|
|
58
|
+
|
|
59
|
+
## Gate Rules
|
|
60
|
+
|
|
61
|
+
- Fail any critical gate -> `status: blocked`.
|
|
62
|
+
- Missing rollback for risky changes -> blocked.
|
|
63
|
+
- Missing validation evidence -> blocked.
|
|
64
|
+
|
|
65
|
+
## Rollback Requirements
|
|
66
|
+
|
|
67
|
+
- Identify rollback trigger conditions.
|
|
68
|
+
- Provide explicit rollback steps.
|
|
69
|
+
- Keep backups/version references for destructive changes.
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Testing Guidelines & Best Practices"
|
|
3
|
+
description: "Apply when adding tests, verifying coverage, or validating quality before deployment. Always required for business logic and critical flows"
|
|
4
|
+
version: "3.0.0"
|
|
5
|
+
tags: ["testing", "quality", "coverage", "e2e", "a11y"]
|
|
6
|
+
triggers:
|
|
7
|
+
- "User requests tests for business logic"
|
|
8
|
+
- "Implementing a new feature"
|
|
9
|
+
- "Fixing a bug"
|
|
10
|
+
- "Need to verify API endpoints work"
|
|
11
|
+
- "Checking application behavior"
|
|
12
|
+
- "Hardening release artifacts"
|
|
13
|
+
- "CI/CD validation needed before deployment"
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# Testing Guidelines & Best Practices
|
|
17
|
+
|
|
18
|
+
Comprehensive testing patterns for maintaining quality across any technology stack.
|
|
19
|
+
|
|
20
|
+
## Core Testing Principles
|
|
21
|
+
|
|
22
|
+
- **Test Pyramid**: More unit tests (80%), fewer integration tests (15%), minimal E2E tests (5%)
|
|
23
|
+
- **Arrange-Act-Assert**: Structure tests clearly with setup, action, and verification
|
|
24
|
+
- **Descriptive Names**: Test names should describe expected behavior
|
|
25
|
+
- **Independent Tests**: Each test should be able to run in isolation
|
|
26
|
+
- **Fast Feedback**: Unit tests should run quickly (<100ms each)
|
|
27
|
+
- **Deterministic**: Tests should pass/fail consistently, not randomly
|
|
28
|
+
|
|
29
|
+
## Unit Testing
|
|
30
|
+
|
|
31
|
+
Unit tests verify individual functions, methods, and components in isolation.
|
|
32
|
+
|
|
33
|
+
### Unit Test Pattern
|
|
34
|
+
|
|
35
|
+
Unit Test Structure:
|
|
36
|
+
1. Arrange
|
|
37
|
+
- Set up test data
|
|
38
|
+
- Mock dependencies
|
|
39
|
+
- Configure test environment
|
|
40
|
+
|
|
41
|
+
2. Act
|
|
42
|
+
- Call the function/method being tested
|
|
43
|
+
- Perform the action
|
|
44
|
+
|
|
45
|
+
3. Assert
|
|
46
|
+
- Verify the result
|
|
47
|
+
- Check side effects
|
|
48
|
+
- Validate behavior
|
|
49
|
+
|
|
50
|
+
### What to Unit Test
|
|
51
|
+
|
|
52
|
+
- Business logic functions (validation, calculations, transformations)
|
|
53
|
+
- Utility functions (helpers, formatters, parsers)
|
|
54
|
+
- Service/class methods with clear inputs and outputs
|
|
55
|
+
- Error handling and edge cases
|
|
56
|
+
- Complex conditional logic
|
|
57
|
+
|
|
58
|
+
### Unit Test Examples (Language-Agnostic)
|
|
59
|
+
|
|
60
|
+
**Example 1: Validation Function**
|
|
61
|
+
Test: Email validation function
|
|
62
|
+
- Test valid email returns true
|
|
63
|
+
- Test invalid email format returns false
|
|
64
|
+
- Test empty string returns false
|
|
65
|
+
- Test whitespace is trimmed
|
|
66
|
+
- Test case-insensitive comparison
|
|
67
|
+
|
|
68
|
+
**Example 2: Business Logic**
|
|
69
|
+
Test: Calculate discount price
|
|
70
|
+
- Test standard discount percentage
|
|
71
|
+
- Test no discount
|
|
72
|
+
- Test maximum discount cap
|
|
73
|
+
- Test negative prices handled gracefully
|
|
74
|
+
- Test rounding is correct
|
|
75
|
+
|
|
76
|
+
**Example 3: Error Handling**
|
|
77
|
+
Test: Parse JSON data
|
|
78
|
+
- Test valid JSON parses successfully
|
|
79
|
+
- Test invalid JSON throws appropriate error
|
|
80
|
+
- Test missing required fields throws error
|
|
81
|
+
- Test extra fields are handled
|
|
82
|
+
- Test error messages are helpful
|
|
83
|
+
|
|
84
|
+
### Mocking & Test Doubles
|
|
85
|
+
|
|
86
|
+
Use test doubles (mocks, stubs, fakes) for external dependencies:
|
|
87
|
+
|
|
88
|
+
Mocking Strategy:
|
|
89
|
+
1. Identify external dependencies
|
|
90
|
+
- Database calls
|
|
91
|
+
- API calls
|
|
92
|
+
- File system access
|
|
93
|
+
- Time/date functions
|
|
94
|
+
- Random number generation
|
|
95
|
+
|
|
96
|
+
2. Replace with appropriate test double
|
|
97
|
+
- Stub: Return fixed value
|
|
98
|
+
- Mock: Verify it was called correctly
|
|
99
|
+
- Fake: Simplified working implementation
|
|
100
|
+
|
|
101
|
+
3. Verify interactions when appropriate
|
|
102
|
+
- Was the dependency called?
|
|
103
|
+
- Was it called with correct arguments?
|
|
104
|
+
- Was it called the right number of times?
|
|
105
|
+
|
|
106
|
+
## Integration Testing
|
|
107
|
+
|
|
108
|
+
Integration tests verify that multiple components work together correctly.
|
|
109
|
+
|
|
110
|
+
### What to Integration Test
|
|
111
|
+
|
|
112
|
+
- API endpoints (request response)
|
|
113
|
+
- Database operations (save, query, delete)
|
|
114
|
+
- Service-to-service interactions
|
|
115
|
+
- Authentication and authorization flows
|
|
116
|
+
- Error scenarios and edge cases
|
|
117
|
+
|
|
118
|
+
### Integration Test Pattern
|
|
119
|
+
|
|
120
|
+
Integration Test Structure:
|
|
121
|
+
1. Setup
|
|
122
|
+
- Create test database/data
|
|
123
|
+
- Mock external services if needed
|
|
124
|
+
- Set up test user/session
|
|
125
|
+
|
|
126
|
+
2. Execute
|
|
127
|
+
- Make API call or trigger operation
|
|
128
|
+
- Interact with multiple components
|
|
129
|
+
|
|
130
|
+
3. Verify
|
|
131
|
+
- Check response status and data
|
|
132
|
+
- Verify database changes
|
|
133
|
+
- Check side effects
|
|
134
|
+
|
|
135
|
+
### Integration Test Examples
|
|
136
|
+
|
|
137
|
+
**Example 1: User Creation API**
|
|
138
|
+
Test: POST /api/users with valid data
|
|
139
|
+
- Validate request body
|
|
140
|
+
- Create user in database
|
|
141
|
+
- Return created user with ID
|
|
142
|
+
- User can be retrieved afterward
|
|
143
|
+
- Password is hashed (not plaintext)
|
|
144
|
+
|
|
145
|
+
**Example 2: Authentication Flow**
|
|
146
|
+
Test: User login
|
|
147
|
+
- Validate credentials
|
|
148
|
+
- Create session/token
|
|
149
|
+
- Return session/token to client
|
|
150
|
+
- Can use session to access protected endpoints
|
|
151
|
+
- Session is invalidated on logout
|
|
152
|
+
|
|
153
|
+
**Example 3: Error Handling**
|
|
154
|
+
Test: Create user with duplicate email
|
|
155
|
+
- Database rejects duplicate
|
|
156
|
+
- API returns 400 Bad Request
|
|
157
|
+
- Error message is appropriate
|
|
158
|
+
- No partial data is written
|
|
159
|
+
|
|
160
|
+
## End-to-End Testing
|
|
161
|
+
|
|
162
|
+
E2E tests verify complete user journeys across the entire application.
|
|
163
|
+
|
|
164
|
+
### What to E2E Test
|
|
165
|
+
|
|
166
|
+
- Critical user workflows (login, purchase, form submission)
|
|
167
|
+
- Happy path scenarios
|
|
168
|
+
- Common error scenarios
|
|
169
|
+
- Cross-browser compatibility (if applicable)
|
|
170
|
+
- Accessibility requirements
|
|
171
|
+
|
|
172
|
+
### E2E Test Examples
|
|
173
|
+
|
|
174
|
+
**Example 1: User Registration**
|
|
175
|
+
Test: New user can register successfully
|
|
176
|
+
1. Navigate to signup page
|
|
177
|
+
2. Fill in email, password, name
|
|
178
|
+
3. Click submit button
|
|
179
|
+
4. Wait for success message
|
|
180
|
+
5. Redirect to dashboard
|
|
181
|
+
6. User can access protected content
|
|
182
|
+
|
|
183
|
+
**Example 2: Login with Invalid Credentials**
|
|
184
|
+
Test: Login with wrong password
|
|
185
|
+
1. Navigate to login page
|
|
186
|
+
2. Enter email and wrong password
|
|
187
|
+
3. Click login button
|
|
188
|
+
4. See error message "Invalid credentials"
|
|
189
|
+
5. Still on login page (not redirected)
|
|
190
|
+
6. Can try again
|
|
191
|
+
|
|
192
|
+
**Example 3: Multi-step Workflow**
|
|
193
|
+
Test: User can complete purchase
|
|
194
|
+
1. Navigate to product page
|
|
195
|
+
2. Add item to cart
|
|
196
|
+
3. Navigate to checkout
|
|
197
|
+
4. Enter shipping information
|
|
198
|
+
5. Enter payment information
|
|
199
|
+
6. Submit order
|
|
200
|
+
7. See confirmation page
|
|
201
|
+
8. Receive confirmation email
|
|
202
|
+
|
|
203
|
+
## Accessibility Testing
|
|
204
|
+
|
|
205
|
+
Test that your application meets WCAG 2.1 AA standards.
|
|
206
|
+
|
|
207
|
+
### Automated Accessibility Testing
|
|
208
|
+
|
|
209
|
+
Use tools to scan for common accessibility violations:
|
|
210
|
+
- Color contrast issues
|
|
211
|
+
- Missing alt text for images
|
|
212
|
+
- Missing labels for form inputs
|
|
213
|
+
- Heading hierarchy problems
|
|
214
|
+
- Missing ARIA attributes
|
|
215
|
+
|
|
216
|
+
### Manual Accessibility Testing
|
|
217
|
+
|
|
218
|
+
- Keyboard navigation: Can user navigate with Tab and Enter?
|
|
219
|
+
- Screen reader: Does content make sense when read aloud?
|
|
220
|
+
- Visual clarity: Can text be read at smaller sizes?
|
|
221
|
+
- Color dependency: Is information conveyed without color alone?
|
|
222
|
+
- Responsiveness: Does layout work on different screen sizes?
|
|
223
|
+
|
|
224
|
+
## Performance Testing
|
|
225
|
+
|
|
226
|
+
Test performance requirements and regressions.
|
|
227
|
+
|
|
228
|
+
### Performance Metrics to Monitor
|
|
229
|
+
|
|
230
|
+
**Web Applications:**
|
|
231
|
+
- First Contentful Paint (FCP)
|
|
232
|
+
- Largest Contentful Paint (LCP)
|
|
233
|
+
- Cumulative Layout Shift (CLS)
|
|
234
|
+
- Time to Interactive (TTI)
|
|
235
|
+
- Page load time
|
|
236
|
+
|
|
237
|
+
**API Endpoints:**
|
|
238
|
+
- Response time (p50, p95, p99)
|
|
239
|
+
- Throughput (requests per second)
|
|
240
|
+
- Error rate
|
|
241
|
+
- Database query time
|
|
242
|
+
- Memory usage
|
|
243
|
+
|
|
244
|
+
### Performance Testing Examples
|
|
245
|
+
|
|
246
|
+
Test: API response time
|
|
247
|
+
- Create 100 users in database
|
|
248
|
+
- Query all users endpoint
|
|
249
|
+
- Measure response time
|
|
250
|
+
- Assert completes in <500ms
|
|
251
|
+
|
|
252
|
+
Test: Page load performance
|
|
253
|
+
- Navigate to homepage
|
|
254
|
+
- Measure First Contentful Paint
|
|
255
|
+
- Assert completes in <2 seconds
|
|
256
|
+
|
|
257
|
+
Test: Database query optimization
|
|
258
|
+
- Insert 10,000 records
|
|
259
|
+
- Run query with filter
|
|
260
|
+
- Verify query uses index
|
|
261
|
+
- Measure execution time
|
|
262
|
+
- Assert completes efficiently
|
|
263
|
+
|
|
264
|
+
## Hardening Verification Testing
|
|
265
|
+
|
|
266
|
+
When hardening/obfuscation is enabled (see `.claude/rules/hardening.mdc`), require additional validation on hardened artifacts.
|
|
267
|
+
|
|
268
|
+
### Required Checks for Hardened Builds
|
|
269
|
+
|
|
270
|
+
- Run core functional regression tests against hardened output, not only non-hardened builds.
|
|
271
|
+
- Run performance checks and compare against accepted budgets (startup, latency, memory as applicable).
|
|
272
|
+
- Validate crash/debug workflow with restricted symbol/mapping artifact access controls.
|
|
273
|
+
- Confirm release evidence includes hardening profile rationale and rollback trigger/steps.
|
|
274
|
+
|
|
275
|
+
If these checks are missing for a hardening-required profile, release readiness should be treated as blocked.
|
|
276
|
+
|
|
277
|
+
## Security Testing
|
|
278
|
+
|
|
279
|
+
Test security requirements and threat scenarios.
|
|
280
|
+
|
|
281
|
+
### Security Tests
|
|
282
|
+
|
|
283
|
+
Test: Input Validation
|
|
284
|
+
- SQL injection payloads in fields
|
|
285
|
+
- XSS payloads in fields
|
|
286
|
+
- Extremely long strings
|
|
287
|
+
- Special characters
|
|
288
|
+
- Wrong data types
|
|
289
|
+
|
|
290
|
+
Test: Authentication
|
|
291
|
+
- Login with wrong password
|
|
292
|
+
- Access protected endpoint without credentials
|
|
293
|
+
- Use expired token
|
|
294
|
+
- Use modified token
|
|
295
|
+
|
|
296
|
+
Test: Authorization
|
|
297
|
+
- Access another user's data
|
|
298
|
+
- Perform admin operation as regular user
|
|
299
|
+
- Modify resource of different user
|
|
300
|
+
|
|
301
|
+
Test: Rate Limiting
|
|
302
|
+
- Exceed rate limit on authentication
|
|
303
|
+
- Verify 429 response
|
|
304
|
+
- Verify retry-after header
|
|
305
|
+
|
|
306
|
+
## Test Organization
|
|
307
|
+
|
|
308
|
+
Organize tests logically for easy maintenance:
|