agents-templated 2.2.18 → 2.2.20

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.
@@ -1,371 +1,371 @@
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
- ---
7
-
8
- # Testing Guidelines & Best Practices
9
-
10
- Comprehensive testing patterns for maintaining quality across any technology stack.
11
-
12
- ## Core Testing Principles
13
-
14
- - **Test Pyramid**: More unit tests (80%), fewer integration tests (15%), minimal E2E tests (5%)
15
- - **Arrange-Act-Assert**: Structure tests clearly with setup, action, and verification
16
- - **Descriptive Names**: Test names should describe expected behavior
17
- - **Independent Tests**: Each test should be able to run in isolation
18
- - **Fast Feedback**: Unit tests should run quickly (<100ms each)
19
- - **Deterministic**: Tests should pass/fail consistently, not randomly
20
-
21
- ## Unit Testing
22
-
23
- Unit tests verify individual functions, methods, and components in isolation.
24
-
25
- ### Unit Test Pattern
26
-
27
- Unit Test Structure:
28
- 1. Arrange
29
- - Set up test data
30
- - Mock dependencies
31
- - Configure test environment
32
-
33
- 2. Act
34
- - Call the function/method being tested
35
- - Perform the action
36
-
37
- 3. Assert
38
- - Verify the result
39
- - Check side effects
40
- - Validate behavior
41
-
42
- ### What to Unit Test
43
-
44
- - Business logic functions (validation, calculations, transformations)
45
- - Utility functions (helpers, formatters, parsers)
46
- - Service/class methods with clear inputs and outputs
47
- - Error handling and edge cases
48
- - Complex conditional logic
49
-
50
- ### Unit Test Examples (Language-Agnostic)
51
-
52
- **Example 1: Validation Function**
53
- Test: Email validation function
54
- - Test valid email returns true
55
- - Test invalid email format returns false
56
- - Test empty string returns false
57
- - Test whitespace is trimmed
58
- - Test case-insensitive comparison
59
-
60
- **Example 2: Business Logic**
61
- Test: Calculate discount price
62
- - Test standard discount percentage
63
- - Test no discount
64
- - Test maximum discount cap
65
- - Test negative prices handled gracefully
66
- - Test rounding is correct
67
-
68
- **Example 3: Error Handling**
69
- Test: Parse JSON data
70
- - Test valid JSON parses successfully
71
- - Test invalid JSON throws appropriate error
72
- - Test missing required fields throws error
73
- - Test extra fields are handled
74
- - Test error messages are helpful
75
-
76
- ### Mocking & Test Doubles
77
-
78
- Use test doubles (mocks, stubs, fakes) for external dependencies:
79
-
80
- Mocking Strategy:
81
- 1. Identify external dependencies
82
- - Database calls
83
- - API calls
84
- - File system access
85
- - Time/date functions
86
- - Random number generation
87
-
88
- 2. Replace with appropriate test double
89
- - Stub: Return fixed value
90
- - Mock: Verify it was called correctly
91
- - Fake: Simplified working implementation
92
-
93
- 3. Verify interactions when appropriate
94
- - Was the dependency called?
95
- - Was it called with correct arguments?
96
- - Was it called the right number of times?
97
-
98
- ## Integration Testing
99
-
100
- Integration tests verify that multiple components work together correctly.
101
-
102
- ### What to Integration Test
103
-
104
- - API endpoints (request response)
105
- - Database operations (save, query, delete)
106
- - Service-to-service interactions
107
- - Authentication and authorization flows
108
- - Error scenarios and edge cases
109
-
110
- ### Integration Test Pattern
111
-
112
- Integration Test Structure:
113
- 1. Setup
114
- - Create test database/data
115
- - Mock external services if needed
116
- - Set up test user/session
117
-
118
- 2. Execute
119
- - Make API call or trigger operation
120
- - Interact with multiple components
121
-
122
- 3. Verify
123
- - Check response status and data
124
- - Verify database changes
125
- - Check side effects
126
-
127
- ### Integration Test Examples
128
-
129
- **Example 1: User Creation API**
130
- Test: POST /api/users with valid data
131
- - Validate request body
132
- - Create user in database
133
- - Return created user with ID
134
- - User can be retrieved afterward
135
- - Password is hashed (not plaintext)
136
-
137
- **Example 2: Authentication Flow**
138
- Test: User login
139
- - Validate credentials
140
- - Create session/token
141
- - Return session/token to client
142
- - Can use session to access protected endpoints
143
- - Session is invalidated on logout
144
-
145
- **Example 3: Error Handling**
146
- Test: Create user with duplicate email
147
- - Database rejects duplicate
148
- - API returns 400 Bad Request
149
- - Error message is appropriate
150
- - No partial data is written
151
-
152
- ## End-to-End Testing
153
-
154
- E2E tests verify complete user journeys across the entire application.
155
-
156
- ### What to E2E Test
157
-
158
- - Critical user workflows (login, purchase, form submission)
159
- - Happy path scenarios
160
- - Common error scenarios
161
- - Cross-browser compatibility (if applicable)
162
- - Accessibility requirements
163
-
164
- ### E2E Test Examples
165
-
166
- **Example 1: User Registration**
167
- Test: New user can register successfully
168
- 1. Navigate to signup page
169
- 2. Fill in email, password, name
170
- 3. Click submit button
171
- 4. Wait for success message
172
- 5. Redirect to dashboard
173
- 6. User can access protected content
174
-
175
- **Example 2: Login with Invalid Credentials**
176
- Test: Login with wrong password
177
- 1. Navigate to login page
178
- 2. Enter email and wrong password
179
- 3. Click login button
180
- 4. See error message "Invalid credentials"
181
- 5. Still on login page (not redirected)
182
- 6. Can try again
183
-
184
- **Example 3: Multi-step Workflow**
185
- Test: User can complete purchase
186
- 1. Navigate to product page
187
- 2. Add item to cart
188
- 3. Navigate to checkout
189
- 4. Enter shipping information
190
- 5. Enter payment information
191
- 6. Submit order
192
- 7. See confirmation page
193
- 8. Receive confirmation email
194
-
195
- ## Accessibility Testing
196
-
197
- Test that your application meets WCAG 2.1 AA standards.
198
-
199
- ### Automated Accessibility Testing
200
-
201
- Use tools to scan for common accessibility violations:
202
- - Color contrast issues
203
- - Missing alt text for images
204
- - Missing labels for form inputs
205
- - Heading hierarchy problems
206
- - Missing ARIA attributes
207
-
208
- ### Manual Accessibility Testing
209
-
210
- - Keyboard navigation: Can user navigate with Tab and Enter?
211
- - Screen reader: Does content make sense when read aloud?
212
- - Visual clarity: Can text be read at smaller sizes?
213
- - Color dependency: Is information conveyed without color alone?
214
- - Responsiveness: Does layout work on different screen sizes?
215
-
216
- ## Performance Testing
217
-
218
- Test performance requirements and regressions.
219
-
220
- ### Performance Metrics to Monitor
221
-
222
- **Web Applications:**
223
- - First Contentful Paint (FCP)
224
- - Largest Contentful Paint (LCP)
225
- - Cumulative Layout Shift (CLS)
226
- - Time to Interactive (TTI)
227
- - Page load time
228
-
229
- **API Endpoints:**
230
- - Response time (p50, p95, p99)
231
- - Throughput (requests per second)
232
- - Error rate
233
- - Database query time
234
- - Memory usage
235
-
236
- ### Performance Testing Examples
237
-
238
- Test: API response time
239
- - Create 100 users in database
240
- - Query all users endpoint
241
- - Measure response time
242
- - Assert completes in <500ms
243
-
244
- Test: Page load performance
245
- - Navigate to homepage
246
- - Measure First Contentful Paint
247
- - Assert completes in <2 seconds
248
-
249
- Test: Database query optimization
250
- - Insert 10,000 records
251
- - Run query with filter
252
- - Verify query uses index
253
- - Measure execution time
254
- - Assert completes efficiently
255
-
256
- ## Hardening Verification Testing
257
-
258
- When hardening/obfuscation is enabled (see `agents/rules/hardening.mdc`), require additional validation on hardened artifacts.
259
-
260
- ### Required Checks for Hardened Builds
261
-
262
- - Run core functional regression tests against hardened output, not only non-hardened builds.
263
- - Run performance checks and compare against accepted budgets (startup, latency, memory as applicable).
264
- - Validate crash/debug workflow with restricted symbol/mapping artifact access controls.
265
- - Confirm release evidence includes hardening profile rationale and rollback trigger/steps.
266
-
267
- If these checks are missing for a hardening-required profile, release readiness should be treated as blocked.
268
-
269
- ## Security Testing
270
-
271
- Test security requirements and threat scenarios.
272
-
273
- ### Security Tests
274
-
275
- Test: Input Validation
276
- - SQL injection payloads in fields
277
- - XSS payloads in fields
278
- - Extremely long strings
279
- - Special characters
280
- - Wrong data types
281
-
282
- Test: Authentication
283
- - Login with wrong password
284
- - Access protected endpoint without credentials
285
- - Use expired token
286
- - Use modified token
287
-
288
- Test: Authorization
289
- - Access another user''s data
290
- - Perform admin operation as regular user
291
- - Modify resource of different user
292
-
293
- Test: Rate Limiting
294
- - Exceed rate limit on authentication
295
- - Verify 429 response
296
- - Verify retry-after header
297
-
298
- ## Test Organization
299
-
300
- Organize tests logically for easy maintenance:
301
-
302
- Project Structure:
303
- tests/
304
- unit/
305
- utils/ # Utility function tests
306
- services/ # Business logic tests
307
- validators/ # Validation tests
308
- formatters/ # Formatter tests
309
-
310
- integration/
311
- api/ # API endpoint tests
312
- database/ # Database operation tests
313
- auth/ # Authentication tests
314
- services/ # Service integration tests
315
-
316
- e2e/
317
- auth/ # Authentication flows
318
- workflows/ # Critical user journeys
319
- forms/ # Form submission flows
320
- pages/ # Page components (if applicable)
321
-
322
- a11y/ # Accessibility tests
323
- performance/ # Performance tests
324
- fixtures/ # Test data
325
- setup.ts # Test configuration
326
-
327
- ## Test Coverage Guidelines
328
-
329
- ### Coverage Targets
330
-
331
- - **Business Logic**: 80%+ coverage required
332
- - **Controllers/Routes**: 70%+ coverage
333
- - **Utils/Helpers**: 90%+ coverage
334
- - **UI Components**: 60%+ coverage
335
- - **Overall**: 75%+ coverage target
336
-
337
- ### Coverage Measurement
338
-
339
- - Generate coverage reports regularly
340
- - Track coverage trends over time
341
- - Identify uncovered critical code
342
- - The goal is quality, not just high numbers
343
-
344
- ## Best Practices
345
-
346
- ### General Best Practices
347
-
348
- - Write tests as you write code (TDD or regular)
349
- - Make tests as simple as production code
350
- - Use meaningful test names that describe behavior
351
- - Keep tests focused on one thing
352
- - Avoid test interdependencies (order shouldn''t matter)
353
- - Clean up test data (database, files, etc.)
354
- - Use version control for test data when needed
355
-
356
- ### Avoiding Common Mistakes
357
-
358
- - Testing implementation details instead of behavior
359
- - Writing tests that are brittle (break on minor changes)
360
- - Tests that are slower than necessary
361
- - Not testing error cases and edge cases
362
- - Skipping security-related tests
363
- - Skipping accessibility tests
364
- - Not maintaining tests (let them rot)
365
- - Testing too much in E2E when unit tests would work
366
-
367
- ---
368
-
369
- Remember: **Tests are documentation** of how your code should behave.
370
- Write clear, concise tests that describe expected behavior.
371
- Good tests make refactoring and maintenance easier and reduce bugs in production.
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
+ ---
7
+
8
+ # Testing Guidelines & Best Practices
9
+
10
+ Comprehensive testing patterns for maintaining quality across any technology stack.
11
+
12
+ ## Core Testing Principles
13
+
14
+ - **Test Pyramid**: More unit tests (80%), fewer integration tests (15%), minimal E2E tests (5%)
15
+ - **Arrange-Act-Assert**: Structure tests clearly with setup, action, and verification
16
+ - **Descriptive Names**: Test names should describe expected behavior
17
+ - **Independent Tests**: Each test should be able to run in isolation
18
+ - **Fast Feedback**: Unit tests should run quickly (<100ms each)
19
+ - **Deterministic**: Tests should pass/fail consistently, not randomly
20
+
21
+ ## Unit Testing
22
+
23
+ Unit tests verify individual functions, methods, and components in isolation.
24
+
25
+ ### Unit Test Pattern
26
+
27
+ Unit Test Structure:
28
+ 1. Arrange
29
+ - Set up test data
30
+ - Mock dependencies
31
+ - Configure test environment
32
+
33
+ 2. Act
34
+ - Call the function/method being tested
35
+ - Perform the action
36
+
37
+ 3. Assert
38
+ - Verify the result
39
+ - Check side effects
40
+ - Validate behavior
41
+
42
+ ### What to Unit Test
43
+
44
+ - Business logic functions (validation, calculations, transformations)
45
+ - Utility functions (helpers, formatters, parsers)
46
+ - Service/class methods with clear inputs and outputs
47
+ - Error handling and edge cases
48
+ - Complex conditional logic
49
+
50
+ ### Unit Test Examples (Language-Agnostic)
51
+
52
+ **Example 1: Validation Function**
53
+ Test: Email validation function
54
+ - Test valid email returns true
55
+ - Test invalid email format returns false
56
+ - Test empty string returns false
57
+ - Test whitespace is trimmed
58
+ - Test case-insensitive comparison
59
+
60
+ **Example 2: Business Logic**
61
+ Test: Calculate discount price
62
+ - Test standard discount percentage
63
+ - Test no discount
64
+ - Test maximum discount cap
65
+ - Test negative prices handled gracefully
66
+ - Test rounding is correct
67
+
68
+ **Example 3: Error Handling**
69
+ Test: Parse JSON data
70
+ - Test valid JSON parses successfully
71
+ - Test invalid JSON throws appropriate error
72
+ - Test missing required fields throws error
73
+ - Test extra fields are handled
74
+ - Test error messages are helpful
75
+
76
+ ### Mocking & Test Doubles
77
+
78
+ Use test doubles (mocks, stubs, fakes) for external dependencies:
79
+
80
+ Mocking Strategy:
81
+ 1. Identify external dependencies
82
+ - Database calls
83
+ - API calls
84
+ - File system access
85
+ - Time/date functions
86
+ - Random number generation
87
+
88
+ 2. Replace with appropriate test double
89
+ - Stub: Return fixed value
90
+ - Mock: Verify it was called correctly
91
+ - Fake: Simplified working implementation
92
+
93
+ 3. Verify interactions when appropriate
94
+ - Was the dependency called?
95
+ - Was it called with correct arguments?
96
+ - Was it called the right number of times?
97
+
98
+ ## Integration Testing
99
+
100
+ Integration tests verify that multiple components work together correctly.
101
+
102
+ ### What to Integration Test
103
+
104
+ - API endpoints (request response)
105
+ - Database operations (save, query, delete)
106
+ - Service-to-service interactions
107
+ - Authentication and authorization flows
108
+ - Error scenarios and edge cases
109
+
110
+ ### Integration Test Pattern
111
+
112
+ Integration Test Structure:
113
+ 1. Setup
114
+ - Create test database/data
115
+ - Mock external services if needed
116
+ - Set up test user/session
117
+
118
+ 2. Execute
119
+ - Make API call or trigger operation
120
+ - Interact with multiple components
121
+
122
+ 3. Verify
123
+ - Check response status and data
124
+ - Verify database changes
125
+ - Check side effects
126
+
127
+ ### Integration Test Examples
128
+
129
+ **Example 1: User Creation API**
130
+ Test: POST /api/users with valid data
131
+ - Validate request body
132
+ - Create user in database
133
+ - Return created user with ID
134
+ - User can be retrieved afterward
135
+ - Password is hashed (not plaintext)
136
+
137
+ **Example 2: Authentication Flow**
138
+ Test: User login
139
+ - Validate credentials
140
+ - Create session/token
141
+ - Return session/token to client
142
+ - Can use session to access protected endpoints
143
+ - Session is invalidated on logout
144
+
145
+ **Example 3: Error Handling**
146
+ Test: Create user with duplicate email
147
+ - Database rejects duplicate
148
+ - API returns 400 Bad Request
149
+ - Error message is appropriate
150
+ - No partial data is written
151
+
152
+ ## End-to-End Testing
153
+
154
+ E2E tests verify complete user journeys across the entire application.
155
+
156
+ ### What to E2E Test
157
+
158
+ - Critical user workflows (login, purchase, form submission)
159
+ - Happy path scenarios
160
+ - Common error scenarios
161
+ - Cross-browser compatibility (if applicable)
162
+ - Accessibility requirements
163
+
164
+ ### E2E Test Examples
165
+
166
+ **Example 1: User Registration**
167
+ Test: New user can register successfully
168
+ 1. Navigate to signup page
169
+ 2. Fill in email, password, name
170
+ 3. Click submit button
171
+ 4. Wait for success message
172
+ 5. Redirect to dashboard
173
+ 6. User can access protected content
174
+
175
+ **Example 2: Login with Invalid Credentials**
176
+ Test: Login with wrong password
177
+ 1. Navigate to login page
178
+ 2. Enter email and wrong password
179
+ 3. Click login button
180
+ 4. See error message "Invalid credentials"
181
+ 5. Still on login page (not redirected)
182
+ 6. Can try again
183
+
184
+ **Example 3: Multi-step Workflow**
185
+ Test: User can complete purchase
186
+ 1. Navigate to product page
187
+ 2. Add item to cart
188
+ 3. Navigate to checkout
189
+ 4. Enter shipping information
190
+ 5. Enter payment information
191
+ 6. Submit order
192
+ 7. See confirmation page
193
+ 8. Receive confirmation email
194
+
195
+ ## Accessibility Testing
196
+
197
+ Test that your application meets WCAG 2.1 AA standards.
198
+
199
+ ### Automated Accessibility Testing
200
+
201
+ Use tools to scan for common accessibility violations:
202
+ - Color contrast issues
203
+ - Missing alt text for images
204
+ - Missing labels for form inputs
205
+ - Heading hierarchy problems
206
+ - Missing ARIA attributes
207
+
208
+ ### Manual Accessibility Testing
209
+
210
+ - Keyboard navigation: Can user navigate with Tab and Enter?
211
+ - Screen reader: Does content make sense when read aloud?
212
+ - Visual clarity: Can text be read at smaller sizes?
213
+ - Color dependency: Is information conveyed without color alone?
214
+ - Responsiveness: Does layout work on different screen sizes?
215
+
216
+ ## Performance Testing
217
+
218
+ Test performance requirements and regressions.
219
+
220
+ ### Performance Metrics to Monitor
221
+
222
+ **Web Applications:**
223
+ - First Contentful Paint (FCP)
224
+ - Largest Contentful Paint (LCP)
225
+ - Cumulative Layout Shift (CLS)
226
+ - Time to Interactive (TTI)
227
+ - Page load time
228
+
229
+ **API Endpoints:**
230
+ - Response time (p50, p95, p99)
231
+ - Throughput (requests per second)
232
+ - Error rate
233
+ - Database query time
234
+ - Memory usage
235
+
236
+ ### Performance Testing Examples
237
+
238
+ Test: API response time
239
+ - Create 100 users in database
240
+ - Query all users endpoint
241
+ - Measure response time
242
+ - Assert completes in <500ms
243
+
244
+ Test: Page load performance
245
+ - Navigate to homepage
246
+ - Measure First Contentful Paint
247
+ - Assert completes in <2 seconds
248
+
249
+ Test: Database query optimization
250
+ - Insert 10,000 records
251
+ - Run query with filter
252
+ - Verify query uses index
253
+ - Measure execution time
254
+ - Assert completes efficiently
255
+
256
+ ## Hardening Verification Testing
257
+
258
+ When hardening/obfuscation is enabled (see `agents/rules/hardening.mdc`), require additional validation on hardened artifacts.
259
+
260
+ ### Required Checks for Hardened Builds
261
+
262
+ - Run core functional regression tests against hardened output, not only non-hardened builds.
263
+ - Run performance checks and compare against accepted budgets (startup, latency, memory as applicable).
264
+ - Validate crash/debug workflow with restricted symbol/mapping artifact access controls.
265
+ - Confirm release evidence includes hardening profile rationale and rollback trigger/steps.
266
+
267
+ If these checks are missing for a hardening-required profile, release readiness should be treated as blocked.
268
+
269
+ ## Security Testing
270
+
271
+ Test security requirements and threat scenarios.
272
+
273
+ ### Security Tests
274
+
275
+ Test: Input Validation
276
+ - SQL injection payloads in fields
277
+ - XSS payloads in fields
278
+ - Extremely long strings
279
+ - Special characters
280
+ - Wrong data types
281
+
282
+ Test: Authentication
283
+ - Login with wrong password
284
+ - Access protected endpoint without credentials
285
+ - Use expired token
286
+ - Use modified token
287
+
288
+ Test: Authorization
289
+ - Access another user''s data
290
+ - Perform admin operation as regular user
291
+ - Modify resource of different user
292
+
293
+ Test: Rate Limiting
294
+ - Exceed rate limit on authentication
295
+ - Verify 429 response
296
+ - Verify retry-after header
297
+
298
+ ## Test Organization
299
+
300
+ Organize tests logically for easy maintenance:
301
+
302
+ Project Structure:
303
+ tests/
304
+ unit/
305
+ utils/ # Utility function tests
306
+ services/ # Business logic tests
307
+ validators/ # Validation tests
308
+ formatters/ # Formatter tests
309
+
310
+ integration/
311
+ api/ # API endpoint tests
312
+ database/ # Database operation tests
313
+ auth/ # Authentication tests
314
+ services/ # Service integration tests
315
+
316
+ e2e/
317
+ auth/ # Authentication flows
318
+ workflows/ # Critical user journeys
319
+ forms/ # Form submission flows
320
+ pages/ # Page components (if applicable)
321
+
322
+ a11y/ # Accessibility tests
323
+ performance/ # Performance tests
324
+ fixtures/ # Test data
325
+ setup.ts # Test configuration
326
+
327
+ ## Test Coverage Guidelines
328
+
329
+ ### Coverage Targets
330
+
331
+ - **Business Logic**: 80%+ coverage required
332
+ - **Controllers/Routes**: 70%+ coverage
333
+ - **Utils/Helpers**: 90%+ coverage
334
+ - **UI Components**: 60%+ coverage
335
+ - **Overall**: 75%+ coverage target
336
+
337
+ ### Coverage Measurement
338
+
339
+ - Generate coverage reports regularly
340
+ - Track coverage trends over time
341
+ - Identify uncovered critical code
342
+ - The goal is quality, not just high numbers
343
+
344
+ ## Best Practices
345
+
346
+ ### General Best Practices
347
+
348
+ - Write tests as you write code (TDD or regular)
349
+ - Make tests as simple as production code
350
+ - Use meaningful test names that describe behavior
351
+ - Keep tests focused on one thing
352
+ - Avoid test interdependencies (order shouldn''t matter)
353
+ - Clean up test data (database, files, etc.)
354
+ - Use version control for test data when needed
355
+
356
+ ### Avoiding Common Mistakes
357
+
358
+ - Testing implementation details instead of behavior
359
+ - Writing tests that are brittle (break on minor changes)
360
+ - Tests that are slower than necessary
361
+ - Not testing error cases and edge cases
362
+ - Skipping security-related tests
363
+ - Skipping accessibility tests
364
+ - Not maintaining tests (let them rot)
365
+ - Testing too much in E2E when unit tests would work
366
+
367
+ ---
368
+
369
+ Remember: **Tests are documentation** of how your code should behave.
370
+ Write clear, concise tests that describe expected behavior.
371
+ Good tests make refactoring and maintenance easier and reduce bugs in production.