agentic-code 0.5.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/.agents/context-maps/task-rule-matrix.yaml +248 -0
- package/.agents/rules/contextual/architecture/implementation-approach.md +202 -0
- package/.agents/rules/core/ai-development-guide.md +272 -0
- package/.agents/rules/core/documentation-criteria.md +184 -0
- package/.agents/rules/core/integration-e2e-testing.md +76 -0
- package/.agents/rules/core/metacognition.md +153 -0
- package/.agents/rules/core/testing-strategy.md +230 -0
- package/.agents/rules/language/general/rules.md +117 -0
- package/.agents/rules/language/general/testing.md +257 -0
- package/.agents/rules/language/typescript/rules.md +178 -0
- package/.agents/rules/language/typescript/testing.md +284 -0
- package/.agents/tasks/acceptance-test-generation.md +461 -0
- package/.agents/tasks/code-review.md +207 -0
- package/.agents/tasks/implementation.md +199 -0
- package/.agents/tasks/integration-test-review.md +132 -0
- package/.agents/tasks/prd-creation.md +336 -0
- package/.agents/tasks/quality-assurance.md +219 -0
- package/.agents/tasks/task-analysis.md +263 -0
- package/.agents/tasks/technical-design.md +432 -0
- package/.agents/tasks/technical-document-review.md +254 -0
- package/.agents/tasks/work-planning.md +239 -0
- package/.agents/workflows/agentic-coding.md +333 -0
- package/AGENTS.md +156 -0
- package/LICENSE +21 -0
- package/README.md +268 -0
- package/bin/cli.js +117 -0
- package/package.json +45 -0
- package/scripts/setup.js +82 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# TypeScript Development Rules
|
|
2
|
+
|
|
3
|
+
## Basic Principles
|
|
4
|
+
|
|
5
|
+
✅ **Aggressive Refactoring**
|
|
6
|
+
❌ **Unused "Just in Case" Code** - YAGNI principle
|
|
7
|
+
|
|
8
|
+
## Comment Writing Rules
|
|
9
|
+
- **Function Description Focus**: Describe what the code "does"
|
|
10
|
+
- **No Historical Information**: Do not record development history
|
|
11
|
+
- **Timeless**: Write only content that remains valid whenever read
|
|
12
|
+
- **Conciseness**: Keep explanations to necessary minimum
|
|
13
|
+
|
|
14
|
+
## Type Safety
|
|
15
|
+
|
|
16
|
+
**Principle**: Use `unknown` + type guards instead of `any` for full type safety.
|
|
17
|
+
|
|
18
|
+
**any Type Alternatives (Priority Order)**
|
|
19
|
+
1. **unknown Type + Type Guards**
|
|
20
|
+
2. **Generics**
|
|
21
|
+
3. **Union Types・Intersection Types**
|
|
22
|
+
4. **Type Assertions (Last Resort)**: Only when type is certain
|
|
23
|
+
|
|
24
|
+
**Type Guard Implementation Pattern**
|
|
25
|
+
```typescript
|
|
26
|
+
// Safely validate external input
|
|
27
|
+
function isUser(value: unknown): value is User {
|
|
28
|
+
return typeof value === 'object' && value !== null &&
|
|
29
|
+
'id' in value && 'name' in value
|
|
30
|
+
}
|
|
31
|
+
// Usage: if (isUser(data)) { /* data is typed as User */ }
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Modern Type Features**
|
|
35
|
+
- **satisfies Operator**: Type check while preserving type inference
|
|
36
|
+
```typescript
|
|
37
|
+
const config = { port: 3000 } satisfies Config // ✅ Preserves inference
|
|
38
|
+
const config: Config = { port: 3000 } // ❌ Loses inference
|
|
39
|
+
```
|
|
40
|
+
- **const Assertion**: Ensure immutability with literal types
|
|
41
|
+
```typescript
|
|
42
|
+
const ROUTES = { HOME: '/' } as const satisfies Routes // ✅ Immutable and type-safe
|
|
43
|
+
```
|
|
44
|
+
- **Branded Types**: Distinguish meaning for same primitive types
|
|
45
|
+
```typescript
|
|
46
|
+
type UserId = string & { __brand: 'UserId' }
|
|
47
|
+
type OrderId = string & { __brand: 'OrderId' }
|
|
48
|
+
// UserId and OrderId are incompatible - prevents mixing
|
|
49
|
+
```
|
|
50
|
+
- **Template Literal Types**: Express string patterns with types
|
|
51
|
+
```typescript
|
|
52
|
+
type Route = `/${string}`
|
|
53
|
+
type HttpMethod = 'GET' | 'POST'
|
|
54
|
+
type Endpoint = `${HttpMethod} ${Route}`
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Type Safety in Implementation**
|
|
58
|
+
- API Communication: Always receive responses as `unknown`, validate with type guards
|
|
59
|
+
- Form Input: External input as `unknown`, type determined after validation
|
|
60
|
+
- Legacy Integration: Stepwise assertion like `window as unknown as LegacyWindow`
|
|
61
|
+
- Test Code: Always define types for mocks, utilize `Partial<T>` and `vi.fn<[Args], Return>()`
|
|
62
|
+
|
|
63
|
+
**Type Safety in Data Flow**
|
|
64
|
+
Input Layer (`unknown`) → Type Guard → Business Layer (Type Guaranteed) → Output Layer (Serialization)
|
|
65
|
+
|
|
66
|
+
**Type Complexity Management**
|
|
67
|
+
- Field Count: Up to 20 (split by responsibility if exceeded, external API types are exceptions)
|
|
68
|
+
- Optional Ratio: Up to 30% (separate required/optional if exceeded)
|
|
69
|
+
- Nesting Depth: Up to 3 levels (flatten if exceeded)
|
|
70
|
+
- Type Assertions: Review design if used 3+ times
|
|
71
|
+
- **External API Types**: Relax constraints and define according to reality (convert appropriately internally)
|
|
72
|
+
|
|
73
|
+
## Coding Conventions
|
|
74
|
+
|
|
75
|
+
**Class Usage Criteria**
|
|
76
|
+
- **Recommended: Implementation with Functions and Interfaces**
|
|
77
|
+
- Rationale: Improves testability and flexibility of function composition
|
|
78
|
+
- **Classes Allowed**:
|
|
79
|
+
- Framework requirements (NestJS Controller/Service, TypeORM Entity, etc.)
|
|
80
|
+
- Custom error class definitions
|
|
81
|
+
- When state and business logic are tightly coupled (e.g., ShoppingCart, Session, StateMachine)
|
|
82
|
+
- **Decision Criterion**: If "Does this data have behavior?" is Yes, consider using a class
|
|
83
|
+
```typescript
|
|
84
|
+
// ✅ Functions and interfaces
|
|
85
|
+
interface UserService { create(data: UserData): User }
|
|
86
|
+
const userService: UserService = { create: (data) => {...} }
|
|
87
|
+
// ❌ Unnecessary class
|
|
88
|
+
class UserService { create(data: UserData) {...} }
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Function Design**
|
|
92
|
+
- **0-2 parameters maximum**: Use object for 3+ parameters
|
|
93
|
+
```typescript
|
|
94
|
+
// ✅ Object parameter
|
|
95
|
+
function createUser({ name, email, role }: CreateUserParams) {}
|
|
96
|
+
// ❌ Multiple parameters
|
|
97
|
+
function createUser(name: string, email: string, role: string) {}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Dependency Injection**
|
|
101
|
+
- **Inject external dependencies as parameters**: Ensure testability and modularity
|
|
102
|
+
```typescript
|
|
103
|
+
// ✅ Receive dependency as parameter
|
|
104
|
+
function createService(repository: Repository) { return {...} }
|
|
105
|
+
// ❌ Direct import dependency
|
|
106
|
+
import { userRepository } from './infrastructure/repository'
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Asynchronous Processing**
|
|
110
|
+
- Promise Handling: Always use `async/await`
|
|
111
|
+
- Error Handling: Always handle with `try-catch`
|
|
112
|
+
- Type Definition: Explicitly define return value types (e.g., `Promise<Result>`)
|
|
113
|
+
|
|
114
|
+
**Format Rules**
|
|
115
|
+
- Semicolon omission (follow Biome settings)
|
|
116
|
+
- Types in `PascalCase`, variables/functions in `camelCase`
|
|
117
|
+
- Imports use absolute paths (`src/`)
|
|
118
|
+
|
|
119
|
+
**Clean Code Principles**
|
|
120
|
+
- ✅ Delete unused code immediately
|
|
121
|
+
- ✅ Delete debug `console.log()`
|
|
122
|
+
- ❌ Commented-out code (manage history with version control)
|
|
123
|
+
- ✅ Comments explain "why" (not "what")
|
|
124
|
+
|
|
125
|
+
## Error Handling
|
|
126
|
+
|
|
127
|
+
**Absolute Rule**: Error suppression prohibited. All errors must have log output and appropriate handling.
|
|
128
|
+
|
|
129
|
+
**Result Type Pattern**: Express errors with types for explicit handling
|
|
130
|
+
```typescript
|
|
131
|
+
type Result<T, E> = { ok: true; value: T } | { ok: false; error: E }
|
|
132
|
+
|
|
133
|
+
// Example: Express error possibility with types
|
|
134
|
+
function parseUser(data: unknown): Result<User, ValidationError> {
|
|
135
|
+
if (!isValid(data)) return { ok: false, error: new ValidationError() }
|
|
136
|
+
return { ok: true, value: data as User }
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Custom Error Classes**
|
|
141
|
+
```typescript
|
|
142
|
+
export class AppError extends Error {
|
|
143
|
+
constructor(message: string, public readonly code: string, public readonly statusCode = 500) {
|
|
144
|
+
super(message)
|
|
145
|
+
this.name = this.constructor.name
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Purpose-specific: ValidationError(400), BusinessRuleError(400), DatabaseError(500), ExternalServiceError(502)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Layer-Specific Error Handling**
|
|
152
|
+
- API Layer: Convert to HTTP response, log output excluding sensitive information
|
|
153
|
+
- Service Layer: Detect business rule violations, propagate AppError as-is
|
|
154
|
+
- Repository Layer: Convert technical errors to domain errors
|
|
155
|
+
|
|
156
|
+
**Structured Logging and Sensitive Information Protection**
|
|
157
|
+
Never include sensitive information (password, token, apiKey, secret, creditCard) in logs
|
|
158
|
+
|
|
159
|
+
**Asynchronous Error Handling**
|
|
160
|
+
- Global handler setup mandatory: `unhandledRejection`, `uncaughtException`
|
|
161
|
+
- Use try-catch with all async/await
|
|
162
|
+
- Always log and re-throw errors
|
|
163
|
+
|
|
164
|
+
## Refactoring Techniques
|
|
165
|
+
|
|
166
|
+
**Basic Policy**
|
|
167
|
+
- Small Steps: Maintain always-working state through gradual improvements
|
|
168
|
+
- Safe Changes: Minimize the scope of changes at once
|
|
169
|
+
- Behavior Guarantee: Ensure existing behavior remains unchanged while proceeding
|
|
170
|
+
|
|
171
|
+
**Implementation Procedure**: Understand Current State → Gradual Changes → Behavior Verification → Final Validation
|
|
172
|
+
|
|
173
|
+
**Priority**: Duplicate Code Removal > Large Function Division > Complex Conditional Branch Simplification > Type Safety Improvement
|
|
174
|
+
|
|
175
|
+
## Performance Optimization
|
|
176
|
+
|
|
177
|
+
- Streaming Processing: Process large datasets with streams
|
|
178
|
+
- Memory Leak Prevention: Explicitly release unnecessary objects
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# TypeScript Testing Rules
|
|
2
|
+
|
|
3
|
+
## Test Framework
|
|
4
|
+
- **Vitest**: This project uses Vitest
|
|
5
|
+
- Test imports: `import { describe, it, expect, beforeEach, vi } from 'vitest'`
|
|
6
|
+
- Mock creation: Use `vi.mock()`
|
|
7
|
+
|
|
8
|
+
## Basic Testing Policy
|
|
9
|
+
|
|
10
|
+
### Quality Requirements
|
|
11
|
+
- **Coverage**: Unit test coverage must be 80% or higher
|
|
12
|
+
- **Independence**: Each test can run independently
|
|
13
|
+
- **Reproducibility**: Tests are environment-independent
|
|
14
|
+
|
|
15
|
+
### Coverage Requirements
|
|
16
|
+
**Mandatory**: Unit test coverage must be 80% or higher
|
|
17
|
+
**Metrics**: Statements, Branches, Functions, Lines
|
|
18
|
+
|
|
19
|
+
### Test Types and Scope
|
|
20
|
+
1. **Unit Tests**
|
|
21
|
+
- Verify behavior of individual functions or classes
|
|
22
|
+
- Mock all external dependencies
|
|
23
|
+
|
|
24
|
+
2. **Integration Tests**
|
|
25
|
+
- Verify coordination between multiple components
|
|
26
|
+
- Use actual dependencies (DB, API, etc.)
|
|
27
|
+
|
|
28
|
+
3. **E2E Cross-functional Tests** [MANDATORY for new features]
|
|
29
|
+
- Test existing features remain stable after new feature integration
|
|
30
|
+
- Coverage based on Design Doc's Integration Point Map impact levels
|
|
31
|
+
- Verify performance degradation stays within project-defined limits
|
|
32
|
+
|
|
33
|
+
### TypeScript/Vitest Pattern Reference
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
describe('Cross-functional E2E Tests', () => {
|
|
37
|
+
// Pattern 1: Baseline → Change → Verify
|
|
38
|
+
it('should maintain existing behavior after new feature', async () => {
|
|
39
|
+
// 1. Capture baseline
|
|
40
|
+
const baseline = await testExistingFeature()
|
|
41
|
+
|
|
42
|
+
// 2. Enable new feature
|
|
43
|
+
await enableNewFeature()
|
|
44
|
+
|
|
45
|
+
// 3. Verify continuity
|
|
46
|
+
const result = await testExistingFeature()
|
|
47
|
+
expect(result).toEqual(baseline)
|
|
48
|
+
expect(result.responseTime).toBeLessThan(
|
|
49
|
+
baseline.responseTime * 1.2 // Project-specific threshold
|
|
50
|
+
)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
// Pattern 2: Data integrity across features
|
|
54
|
+
it('should preserve data integrity', async () => {
|
|
55
|
+
const data = await createTestData()
|
|
56
|
+
await newFeatureOperation(data.id)
|
|
57
|
+
|
|
58
|
+
const retrieved = await existingFeatureGet(data.id)
|
|
59
|
+
expect(retrieved).toEqual(data) // No unexpected mutations
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
**Note**: LLM outputs naturally vary - test behavior, not exact matches
|
|
64
|
+
|
|
65
|
+
## TDD Process [MANDATORY for all code changes]
|
|
66
|
+
|
|
67
|
+
**Execute this process for every code change:**
|
|
68
|
+
|
|
69
|
+
### RED Phase
|
|
70
|
+
1. Write test that defines expected behavior
|
|
71
|
+
2. Run test
|
|
72
|
+
3. Confirm test FAILS (if it passes, the test is wrong)
|
|
73
|
+
|
|
74
|
+
### GREEN Phase
|
|
75
|
+
1. Write MINIMAL code to make test pass
|
|
76
|
+
2. Run test
|
|
77
|
+
3. Confirm test PASSES
|
|
78
|
+
|
|
79
|
+
### REFACTOR Phase
|
|
80
|
+
1. Improve code quality
|
|
81
|
+
2. Run test
|
|
82
|
+
3. Confirm test STILL PASSES
|
|
83
|
+
|
|
84
|
+
### VERIFY Phase [MANDATORY - 0 ERRORS REQUIRED]
|
|
85
|
+
1. Execute ALL quality check commands below
|
|
86
|
+
2. Fix any errors until ALL commands pass with 0 errors
|
|
87
|
+
3. Confirm no regressions
|
|
88
|
+
4. ENFORCEMENT: Cannot proceed with ANY errors or warnings
|
|
89
|
+
|
|
90
|
+
**Exceptions (TDD not required):**
|
|
91
|
+
|
|
92
|
+
The following cases do NOT require test-first approach:
|
|
93
|
+
|
|
94
|
+
1. **Pure Configuration Files**
|
|
95
|
+
- package.json, tsconfig.json, build configs
|
|
96
|
+
- Environment variable files (.env templates)
|
|
97
|
+
- Linter/formatter configurations
|
|
98
|
+
- Rationale: No business logic to verify
|
|
99
|
+
|
|
100
|
+
2. **Documentation Only Changes**
|
|
101
|
+
- README updates
|
|
102
|
+
- Code comments additions
|
|
103
|
+
- Markdown documentation
|
|
104
|
+
- Rationale: No executable behavior to test
|
|
105
|
+
|
|
106
|
+
3. **Emergency Hotfixes**
|
|
107
|
+
- Production incidents requiring immediate fix
|
|
108
|
+
- Security vulnerabilities requiring urgent patch
|
|
109
|
+
- **REQUIREMENT**: Add tests immediately after deploying fix
|
|
110
|
+
- Rationale: Speed prioritized in crisis, but tests must follow
|
|
111
|
+
|
|
112
|
+
4. **Exploratory Spikes**
|
|
113
|
+
- Time-boxed research (max 2-4 hours)
|
|
114
|
+
- Proof-of-concept for uncertain technology
|
|
115
|
+
- **REQUIREMENT**: Discard spike code or rewrite with tests before merging
|
|
116
|
+
- Rationale: Learning phase, not production code
|
|
117
|
+
|
|
118
|
+
5. **Build/Deployment Scripts**
|
|
119
|
+
- CI/CD pipeline definitions
|
|
120
|
+
- Deployment automation scripts
|
|
121
|
+
- **NOTE**: Complex scripts with business logic DO require tests
|
|
122
|
+
- Rationale: Verified through actual deployment, not unit tests
|
|
123
|
+
|
|
124
|
+
**When in Doubt**: Default to TDD. Exceptions are narrow, not broad.
|
|
125
|
+
|
|
126
|
+
## Test Design Principles
|
|
127
|
+
|
|
128
|
+
### Test Case Structure
|
|
129
|
+
- Tests consist of three stages: "Arrange," "Act," "Assert"
|
|
130
|
+
- Clear naming that shows purpose of each test
|
|
131
|
+
- One test case verifies only one behavior
|
|
132
|
+
|
|
133
|
+
### Test Data Management
|
|
134
|
+
- Manage test data in dedicated directories
|
|
135
|
+
- Define test-specific environment variable values
|
|
136
|
+
- Always mock sensitive information
|
|
137
|
+
- Keep test data minimal, using only data directly related to test case verification purposes
|
|
138
|
+
|
|
139
|
+
### Mock and Stub Usage Policy
|
|
140
|
+
|
|
141
|
+
✅ **Recommended: Mock external dependencies in unit tests**
|
|
142
|
+
- Merit: Ensures test independence and reproducibility
|
|
143
|
+
- Practice: Mock DB, API, file system, and other external dependencies
|
|
144
|
+
|
|
145
|
+
❌ **Avoid: Actual external connections in unit tests**
|
|
146
|
+
- Reason: Slows test speed and causes environment-dependent problems
|
|
147
|
+
|
|
148
|
+
### Test Failure Response Decision Criteria
|
|
149
|
+
|
|
150
|
+
**Fix tests**: Wrong expected values, references to non-existent features, dependence on implementation details, implementation only for tests
|
|
151
|
+
**Fix implementation**: Valid specifications, business logic, important edge cases
|
|
152
|
+
**When in doubt**: Confirm with user
|
|
153
|
+
|
|
154
|
+
## Test Helper Utilization Rules
|
|
155
|
+
|
|
156
|
+
### Basic Principles
|
|
157
|
+
Test helpers are utilized to reduce duplication in test code and improve maintainability.
|
|
158
|
+
|
|
159
|
+
### Decision Criteria
|
|
160
|
+
| Mock Characteristics | Response Policy |
|
|
161
|
+
|---------------------|-----------------|
|
|
162
|
+
| **Simple and stable** | Consolidate in common helpers |
|
|
163
|
+
| **Complex or frequently changing** | Individual implementation |
|
|
164
|
+
| **Duplicated in 3+ places** | Consider consolidation |
|
|
165
|
+
| **Test-specific logic** | Individual implementation |
|
|
166
|
+
|
|
167
|
+
### Test Helper Usage Examples
|
|
168
|
+
```typescript
|
|
169
|
+
// ✅ Recommended: Utilize builder pattern
|
|
170
|
+
const testData = new TestDataBuilder()
|
|
171
|
+
.withDefaults()
|
|
172
|
+
.withName('Test User')
|
|
173
|
+
.build()
|
|
174
|
+
|
|
175
|
+
// ✅ Recommended: Custom assertions
|
|
176
|
+
function assertValidUser(user: unknown): asserts user is User {
|
|
177
|
+
// Validation logic
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ❌ Avoid: Individual implementation of duplicate complex mocks
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Test Implementation Conventions
|
|
184
|
+
|
|
185
|
+
### Directory Structure
|
|
186
|
+
**File structure:**
|
|
187
|
+
- src/application/services/service.ts: Main service file
|
|
188
|
+
- src/application/services/__tests__/service.test.ts: Unit tests
|
|
189
|
+
- src/application/services/__tests__/service.int.test.ts: Integration tests
|
|
190
|
+
|
|
191
|
+
### Naming Conventions
|
|
192
|
+
- Test files: `{target-file-name}.test.ts`
|
|
193
|
+
- Integration test files: `{target-file-name}.int.test.ts`
|
|
194
|
+
- Test suites: Names describing target features or situations
|
|
195
|
+
- Test cases: Names describing expected behavior
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
### Test Code Quality Rules
|
|
199
|
+
|
|
200
|
+
✅ **Recommended: Keep all tests always active**
|
|
201
|
+
- Merit: Guarantees test suite completeness
|
|
202
|
+
- Practice: Fix problematic tests and activate them
|
|
203
|
+
|
|
204
|
+
❌ **Avoid: test.skip() or commenting out**
|
|
205
|
+
- Reason: Creates test gaps and incomplete quality checks
|
|
206
|
+
- Solution: Completely delete unnecessary tests
|
|
207
|
+
|
|
208
|
+
## Test Quality Criteria [MANDATORY]
|
|
209
|
+
|
|
210
|
+
1. **Boundary coverage**: Include empty/zero/max/error cases with happy paths
|
|
211
|
+
2. **Literal expectations**: `expect(calc(100)).toBe(10)` — use literals, not `100 * RATE`
|
|
212
|
+
3. **Result verification**: Assert return values and state, not call order
|
|
213
|
+
4. **Meaningful assertions**: Every test must have at least one `expect()`
|
|
214
|
+
5. **Mock external I/O only**: Mock DB/API/filesystem, use real internal utils
|
|
215
|
+
|
|
216
|
+
## Test Granularity Principles
|
|
217
|
+
|
|
218
|
+
### Core Principle: Observable Behavior Only
|
|
219
|
+
**MUST Test**: Public APIs, return values, exceptions, external calls, persisted state
|
|
220
|
+
**MUST NOT Test**: Private methods, internal state, algorithm implementation details
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
// ✅ Test observable behavior
|
|
224
|
+
expect(calculatePrice(100, 0.1)).toBe(110)
|
|
225
|
+
|
|
226
|
+
// ❌ Test implementation details
|
|
227
|
+
expect((calculator as any).taxRate).toBe(0.1)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Mock Type Safety Enforcement
|
|
231
|
+
|
|
232
|
+
### Minimal Type Definition Requirements
|
|
233
|
+
```typescript
|
|
234
|
+
// ✅ Only required parts
|
|
235
|
+
type TestRepo = Pick<Repository, 'find' | 'save'>
|
|
236
|
+
const mock: TestRepo = { find: vi.fn(), save: vi.fn() }
|
|
237
|
+
|
|
238
|
+
// Only when absolutely necessary, with clear justification
|
|
239
|
+
const sdkMock = {
|
|
240
|
+
call: vi.fn()
|
|
241
|
+
} as unknown as ExternalSDK // Complex external SDK type structure
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Basic Vitest Example
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
|
248
|
+
|
|
249
|
+
// Mock setup example
|
|
250
|
+
vi.mock('./userService', () => ({
|
|
251
|
+
getUserById: vi.fn(),
|
|
252
|
+
updateUser: vi.fn()
|
|
253
|
+
}))
|
|
254
|
+
|
|
255
|
+
describe('ComponentName', () => {
|
|
256
|
+
it('should follow AAA pattern', () => {
|
|
257
|
+
// Arrange
|
|
258
|
+
const input = 'test'
|
|
259
|
+
|
|
260
|
+
// Act
|
|
261
|
+
const result = someFunction(input)
|
|
262
|
+
|
|
263
|
+
// Assert
|
|
264
|
+
expect(result).toBe('expected')
|
|
265
|
+
})
|
|
266
|
+
})
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## Quality Check Commands [MANDATORY for VERIFY phase]
|
|
270
|
+
|
|
271
|
+
**ALL TypeScript/JavaScript commands MUST pass with 0 errors before task completion:**
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
npm test # MUST pass all tests
|
|
275
|
+
npm run build # MUST build successfully
|
|
276
|
+
npm run lint # MUST have 0 lint errors
|
|
277
|
+
npm run type-check # MUST have 0 type errors
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**ENFORCEMENT:**
|
|
281
|
+
- Run ALL applicable commands listed above
|
|
282
|
+
- Fix ANY errors or warnings before marking task complete
|
|
283
|
+
- If command doesn't exist in package.json, skip that specific command
|
|
284
|
+
- Document which commands were run in task completion
|