@haposoft/cafekit 0.3.1 → 0.3.5
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 +3 -3
- package/bin/install.js +1 -0
- package/package.json +1 -1
- package/src/antigravity/workflows/impact-analysis-output-example.md +313 -0
- package/src/antigravity/workflows/impact-analysis.md +735 -0
- package/src/claude/migration-manifest.json +2 -1
- package/src/common/skills/impact-analysis/SKILL.md +271 -0
- package/src/common/skills/impact-analysis/references/change-detection.md +270 -0
- package/src/common/skills/impact-analysis/references/dependency-scouting.md +337 -0
- package/src/common/skills/impact-analysis/references/edge-case-identification.md +439 -0
- package/src/common/skills/impact-analysis/references/industry-techniques.md +695 -0
- package/src/common/skills/impact-analysis/references/practical-techniques-guide.md +753 -0
- package/src/common/skills/impact-analysis/references/project-detection.md +704 -0
- package/src/common/skills/impact-analysis/references/react-native-customization.md +508 -0
- package/src/common/skills/impact-analysis/references/report-template.md +604 -0
- package/src/common/skills/impact-analysis/references/test-scenario-generation.md +459 -0
- package/src/common/skills/impact-analysis/scripts/README.md +476 -0
- package/src/common/skills/impact-analysis/scripts/ast-analyze.js +403 -0
- package/src/common/skills/impact-analysis/scripts/calculate-risk.js +475 -0
- package/src/common/skills/impact-analysis/scripts/find-dependencies.sh +202 -0
- package/src/common/skills/impact-analysis/scripts/run-analysis.sh +312 -0
|
@@ -0,0 +1,753 @@
|
|
|
1
|
+
# Practical Techniques Guide - Hướng Dẫn Áp Dụng Thực Tế
|
|
2
|
+
|
|
3
|
+
Hướng dẫn chi tiết cách áp dụng các industry techniques vào Impact Analysis.
|
|
4
|
+
|
|
5
|
+
## 📋 Overview
|
|
6
|
+
|
|
7
|
+
Document này cung cấp:
|
|
8
|
+
- Scripts và commands thực tế cho từng technique
|
|
9
|
+
- Ví dụ cụ thể cho từng loại project
|
|
10
|
+
- Integration với existing workflow
|
|
11
|
+
- Troubleshooting và best practices
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 🎯 Technique #1: Dependency Analysis (MUST HAVE)
|
|
16
|
+
|
|
17
|
+
### Mục Đích
|
|
18
|
+
Tìm tất cả files bị ảnh hưởng bởi code changes.
|
|
19
|
+
|
|
20
|
+
### Tools & Commands
|
|
21
|
+
|
|
22
|
+
#### JavaScript/TypeScript Projects
|
|
23
|
+
|
|
24
|
+
**1. Find Direct Imports**
|
|
25
|
+
```bash
|
|
26
|
+
# Tìm files import module đã sửa
|
|
27
|
+
grep -r "from.*authService" src/ --include="*.ts" --include="*.tsx"
|
|
28
|
+
grep -r "import.*authService" src/ --include="*.ts" --include="*.tsx"
|
|
29
|
+
|
|
30
|
+
# Hoặc dùng ripgrep (nhanh hơn)
|
|
31
|
+
rg "from.*authService" src/ -t ts -t tsx
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**2. Find Function Calls**
|
|
35
|
+
```bash
|
|
36
|
+
# Tìm files gọi function đã sửa
|
|
37
|
+
grep -r "login\(" src/ --include="*.ts" --include="*.tsx"
|
|
38
|
+
|
|
39
|
+
# Exclude test files
|
|
40
|
+
grep -r "login\(" src/ --include="*.ts" --include="*.tsx" --exclude="*.test.*"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**3. Build Dependency Graph**
|
|
44
|
+
```bash
|
|
45
|
+
# Install madge
|
|
46
|
+
npm install -g madge
|
|
47
|
+
|
|
48
|
+
# Generate dependency graph
|
|
49
|
+
madge --image graph.png src/
|
|
50
|
+
|
|
51
|
+
# Find circular dependencies
|
|
52
|
+
madge --circular src/
|
|
53
|
+
|
|
54
|
+
# Show dependencies for specific file
|
|
55
|
+
madge src/services/authService.ts
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**4. Find API Consumers**
|
|
59
|
+
```bash
|
|
60
|
+
# Tìm frontend components gọi API
|
|
61
|
+
grep -r "fetch.*\/api\/auth" src/
|
|
62
|
+
grep -r "axios.*\/api\/auth" src/
|
|
63
|
+
grep -r "\/api\/auth" src/ --include="*.ts" --include="*.tsx"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### React/React Native Projects
|
|
67
|
+
|
|
68
|
+
**Find Component Usage**
|
|
69
|
+
```bash
|
|
70
|
+
# Tìm components sử dụng component đã sửa
|
|
71
|
+
grep -r "<LoginButton" src/ --include="*.tsx"
|
|
72
|
+
grep -r "LoginButton" src/ --include="*.tsx" | grep "import"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### Python Projects
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Find imports
|
|
79
|
+
grep -r "from.*auth_service" . --include="*.py"
|
|
80
|
+
grep -r "import auth_service" . --include="*.py"
|
|
81
|
+
|
|
82
|
+
# Find function calls
|
|
83
|
+
grep -r "login(" . --include="*.py"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Output Format
|
|
87
|
+
|
|
88
|
+
```markdown
|
|
89
|
+
## 🔗 Dependencies & Affected Files
|
|
90
|
+
|
|
91
|
+
### Direct Imports (5 files)
|
|
92
|
+
- `src/screens/Auth/LoginScreen.tsx` → imports `authService`
|
|
93
|
+
- `src/hooks/useAuth.ts` → imports `authService`
|
|
94
|
+
- `src/api/client.ts` → imports `authService`
|
|
95
|
+
- `src/utils/session.ts` → imports `authService`
|
|
96
|
+
- `src/services/userService.ts` → imports `authService`
|
|
97
|
+
|
|
98
|
+
### Function Calls (8 locations)
|
|
99
|
+
- `src/screens/Auth/LoginScreen.tsx:45` → calls `login()`
|
|
100
|
+
- `src/screens/Auth/SignupScreen.tsx:67` → calls `login()`
|
|
101
|
+
- `src/hooks/useAuth.ts:23` → calls `login()`
|
|
102
|
+
- ...
|
|
103
|
+
|
|
104
|
+
### API Consumers (3 components)
|
|
105
|
+
- `src/screens/Profile/ProfileScreen.tsx` → calls `/api/auth/me`
|
|
106
|
+
- `src/components/Header.tsx` → calls `/api/auth/logout`
|
|
107
|
+
- `src/screens/Settings/SettingsScreen.tsx` → calls `/api/auth/change-password`
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## 🎯 Technique #2: AST-Based Analysis (NICE TO HAVE)
|
|
113
|
+
|
|
114
|
+
### Mục Đích
|
|
115
|
+
Phát hiện semantic changes (function signature, type changes, breaking changes).
|
|
116
|
+
|
|
117
|
+
### Tools & Setup
|
|
118
|
+
|
|
119
|
+
#### JavaScript/TypeScript
|
|
120
|
+
|
|
121
|
+
**Install Dependencies**
|
|
122
|
+
```bash
|
|
123
|
+
npm install --save-dev @babel/parser @babel/traverse
|
|
124
|
+
# Or
|
|
125
|
+
npm install --save-dev typescript
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**Script: Detect Function Signature Changes**
|
|
129
|
+
|
|
130
|
+
Create `scripts/ast-analyze.js`:
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
const fs = require('fs');
|
|
134
|
+
const parser = require('@babel/parser');
|
|
135
|
+
const traverse = require('@babel/traverse').default;
|
|
136
|
+
|
|
137
|
+
function analyzeFunctionSignatures(filePath) {
|
|
138
|
+
const code = fs.readFileSync(filePath, 'utf-8');
|
|
139
|
+
|
|
140
|
+
const ast = parser.parse(code, {
|
|
141
|
+
sourceType: 'module',
|
|
142
|
+
plugins: ['typescript', 'jsx']
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const functions = [];
|
|
146
|
+
|
|
147
|
+
traverse(ast, {
|
|
148
|
+
FunctionDeclaration(path) {
|
|
149
|
+
functions.push({
|
|
150
|
+
name: path.node.id.name,
|
|
151
|
+
params: path.node.params.length,
|
|
152
|
+
async: path.node.async,
|
|
153
|
+
line: path.node.loc.start.line
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
ArrowFunctionExpression(path) {
|
|
157
|
+
if (path.parent.type === 'VariableDeclarator') {
|
|
158
|
+
functions.push({
|
|
159
|
+
name: path.parent.id.name,
|
|
160
|
+
params: path.node.params.length,
|
|
161
|
+
async: path.node.async,
|
|
162
|
+
line: path.node.loc.start.line
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return functions;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Usage
|
|
172
|
+
const file = process.argv[2];
|
|
173
|
+
const functions = analyzeFunctionSignatures(file);
|
|
174
|
+
console.log(JSON.stringify(functions, null, 2));
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Usage**
|
|
178
|
+
```bash
|
|
179
|
+
node scripts/ast-analyze.js src/services/authService.ts
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Compare Before/After**
|
|
183
|
+
```bash
|
|
184
|
+
# Analyze before
|
|
185
|
+
git show HEAD~1:src/services/authService.ts > /tmp/before.ts
|
|
186
|
+
node scripts/ast-analyze.js /tmp/before.ts > /tmp/before.json
|
|
187
|
+
|
|
188
|
+
# Analyze after
|
|
189
|
+
node scripts/ast-analyze.js src/services/authService.ts > /tmp/after.json
|
|
190
|
+
|
|
191
|
+
# Compare
|
|
192
|
+
diff /tmp/before.json /tmp/after.json
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Output Format
|
|
196
|
+
|
|
197
|
+
```markdown
|
|
198
|
+
## 🔍 Semantic Changes Detected (AST Analysis)
|
|
199
|
+
|
|
200
|
+
### Function Signature Changes
|
|
201
|
+
|
|
202
|
+
**1. `login()` - BREAKING CHANGE**
|
|
203
|
+
- **Before**: `login(email, password)` (2 params)
|
|
204
|
+
- **After**: `login(email, password, rememberMe)` (3 params)
|
|
205
|
+
- **Impact**: All 8 callers need update
|
|
206
|
+
- **Files affected**: [list]
|
|
207
|
+
|
|
208
|
+
**2. `validateUser()` - Non-breaking**
|
|
209
|
+
- **Before**: `validateUser(email)` (1 param)
|
|
210
|
+
- **After**: `validateUser(email, options = {})` (2 params, optional)
|
|
211
|
+
- **Impact**: Backward compatible, no changes needed
|
|
212
|
+
|
|
213
|
+
### Type Changes
|
|
214
|
+
|
|
215
|
+
**1. `User` interface - BREAKING CHANGE**
|
|
216
|
+
- **Added fields**: `biometricEnabled: boolean`
|
|
217
|
+
- **Impact**: Serialization/deserialization affected
|
|
218
|
+
- **Files affected**: [list]
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## 🎯 Technique #3: Static Analysis (NICE TO HAVE)
|
|
224
|
+
|
|
225
|
+
### Mục Đích
|
|
226
|
+
Phát hiện code quality issues, security issues, và potential bugs.
|
|
227
|
+
|
|
228
|
+
### Tools
|
|
229
|
+
|
|
230
|
+
#### ESLint (JavaScript/TypeScript)
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
# Run ESLint on changed files
|
|
234
|
+
eslint src/services/authService.ts --format json > eslint-report.json
|
|
235
|
+
|
|
236
|
+
# Check specific rules
|
|
237
|
+
eslint src/ --rule 'no-console: error' --rule 'no-unused-vars: error'
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
#### TypeScript Compiler
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
# Type check
|
|
244
|
+
tsc --noEmit
|
|
245
|
+
|
|
246
|
+
# Type check specific file
|
|
247
|
+
tsc --noEmit src/services/authService.ts
|
|
248
|
+
|
|
249
|
+
# Get diagnostics
|
|
250
|
+
tsc --noEmit --pretty false 2>&1 | grep "error TS"
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
#### SonarQube (Advanced)
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
# Run SonarQube scanner
|
|
257
|
+
sonar-scanner \
|
|
258
|
+
-Dsonar.projectKey=my-project \
|
|
259
|
+
-Dsonar.sources=src \
|
|
260
|
+
-Dsonar.host.url=http://localhost:9000
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Output Format
|
|
264
|
+
|
|
265
|
+
```markdown
|
|
266
|
+
## 🔍 Static Analysis Results
|
|
267
|
+
|
|
268
|
+
### Type Errors (3)
|
|
269
|
+
1. **src/services/authService.ts:45**
|
|
270
|
+
- Error: Property 'biometricEnabled' does not exist on type 'User'
|
|
271
|
+
- Fix: Add field to User interface
|
|
272
|
+
|
|
273
|
+
2. **src/hooks/useAuth.ts:23**
|
|
274
|
+
- Error: Argument of type 'string' is not assignable to parameter of type 'User'
|
|
275
|
+
- Fix: Update function call
|
|
276
|
+
|
|
277
|
+
### Code Quality Issues (5)
|
|
278
|
+
1. **Unused variable** - `src/services/authService.ts:67`
|
|
279
|
+
2. **Missing error handling** - `src/services/authService.ts:89`
|
|
280
|
+
3. **Console.log in production** - `src/services/authService.ts:102`
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## 🎯 Technique #4: Test Coverage Analysis (SHOULD HAVE)
|
|
286
|
+
|
|
287
|
+
### Mục Đích
|
|
288
|
+
Tìm tests bị ảnh hưởng và identify untested code.
|
|
289
|
+
|
|
290
|
+
### Tools & Commands
|
|
291
|
+
|
|
292
|
+
#### Jest (JavaScript/TypeScript)
|
|
293
|
+
|
|
294
|
+
**1. Find Related Tests**
|
|
295
|
+
```bash
|
|
296
|
+
# Find tests covering changed files
|
|
297
|
+
jest --findRelatedTests src/services/authService.ts
|
|
298
|
+
|
|
299
|
+
# Run with coverage
|
|
300
|
+
jest --coverage --collectCoverageFrom="src/services/authService.ts"
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
**2. Generate Coverage Report**
|
|
304
|
+
```bash
|
|
305
|
+
# HTML report
|
|
306
|
+
jest --coverage --coverageReporters=html
|
|
307
|
+
|
|
308
|
+
# JSON report
|
|
309
|
+
jest --coverage --coverageReporters=json
|
|
310
|
+
|
|
311
|
+
# View report
|
|
312
|
+
open coverage/index.html
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
**3. Coverage Thresholds**
|
|
316
|
+
```bash
|
|
317
|
+
# Check if coverage meets threshold
|
|
318
|
+
jest --coverage --coverageThreshold='{"global":{"branches":80,"functions":80,"lines":80}}'
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
#### Python (pytest + coverage)
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
# Run tests with coverage
|
|
325
|
+
pytest --cov=src/services --cov-report=html
|
|
326
|
+
|
|
327
|
+
# Find tests for specific file
|
|
328
|
+
pytest --collect-only | grep auth_service
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Output Format
|
|
332
|
+
|
|
333
|
+
```markdown
|
|
334
|
+
## 🧪 Test Coverage Analysis
|
|
335
|
+
|
|
336
|
+
### Affected Tests (12 tests)
|
|
337
|
+
|
|
338
|
+
**Unit Tests** (5 tests)
|
|
339
|
+
- `authService.test.ts` - 8 tests
|
|
340
|
+
- ✅ login() with valid credentials
|
|
341
|
+
- ✅ login() with invalid credentials
|
|
342
|
+
- ✅ logout()
|
|
343
|
+
- ❌ login() with biometric (NEW - not covered)
|
|
344
|
+
- ❌ biometric permission handling (NEW - not covered)
|
|
345
|
+
|
|
346
|
+
**Integration Tests** (4 tests)
|
|
347
|
+
- `auth.integration.test.ts` - 4 tests
|
|
348
|
+
- ✅ Full login flow
|
|
349
|
+
- ✅ Session persistence
|
|
350
|
+
- ❌ Biometric login flow (NEW - not covered)
|
|
351
|
+
|
|
352
|
+
**E2E Tests** (3 tests)
|
|
353
|
+
- `e2e/auth.spec.ts` - 3 tests
|
|
354
|
+
- ✅ User can login
|
|
355
|
+
- ✅ User can logout
|
|
356
|
+
- ❌ User can login with biometric (NEW - not covered)
|
|
357
|
+
|
|
358
|
+
### Coverage Gaps
|
|
359
|
+
|
|
360
|
+
**Uncovered Lines** (45 lines)
|
|
361
|
+
- `src/services/authService.ts:89-102` - Biometric authentication logic
|
|
362
|
+
- `src/services/authService.ts:145-156` - Permission handling
|
|
363
|
+
- `src/utils/biometric/biometricHelper.ts:23-67` - Entire file
|
|
364
|
+
|
|
365
|
+
**Coverage**: 67% (target: 80%)
|
|
366
|
+
**Action**: Add 8 new tests to reach 80%
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
|
|
371
|
+
## 🎯 Technique #5: Feature Mapping (MUST HAVE)
|
|
372
|
+
|
|
373
|
+
### Mục Đích
|
|
374
|
+
Map code changes về features và user actions.
|
|
375
|
+
|
|
376
|
+
### Implementation
|
|
377
|
+
|
|
378
|
+
**Pattern-Based Mapping**
|
|
379
|
+
|
|
380
|
+
Create `scripts/map-features.js`:
|
|
381
|
+
|
|
382
|
+
```javascript
|
|
383
|
+
const featurePatterns = {
|
|
384
|
+
'Authentication & Login': {
|
|
385
|
+
patterns: [
|
|
386
|
+
'**/api/auth**',
|
|
387
|
+
'**/auth**',
|
|
388
|
+
'**/login**',
|
|
389
|
+
'**/services/auth*'
|
|
390
|
+
],
|
|
391
|
+
keywords: ['login', 'signin', 'authenticate', 'token', 'session'],
|
|
392
|
+
userActions: [
|
|
393
|
+
'Login',
|
|
394
|
+
'Logout',
|
|
395
|
+
'Sign Up',
|
|
396
|
+
'Password Reset',
|
|
397
|
+
'Session Management',
|
|
398
|
+
'2FA',
|
|
399
|
+
'Biometric Authentication'
|
|
400
|
+
]
|
|
401
|
+
},
|
|
402
|
+
'User Profile Management': {
|
|
403
|
+
patterns: [
|
|
404
|
+
'**/api/users**',
|
|
405
|
+
'**/user**',
|
|
406
|
+
'**/profile**'
|
|
407
|
+
],
|
|
408
|
+
keywords: ['profile', 'avatar', 'bio', 'settings'],
|
|
409
|
+
userActions: [
|
|
410
|
+
'View Profile',
|
|
411
|
+
'Edit Profile',
|
|
412
|
+
'Upload Avatar',
|
|
413
|
+
'Change Settings',
|
|
414
|
+
'Update Bio'
|
|
415
|
+
]
|
|
416
|
+
},
|
|
417
|
+
// ... more features
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
function mapFeatures(changedFiles) {
|
|
421
|
+
const affectedFeatures = [];
|
|
422
|
+
|
|
423
|
+
for (const [featureName, config] of Object.entries(featurePatterns)) {
|
|
424
|
+
const matched = changedFiles.some(file =>
|
|
425
|
+
config.patterns.some(pattern =>
|
|
426
|
+
minimatch(file, pattern)
|
|
427
|
+
)
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
if (matched) {
|
|
431
|
+
affectedFeatures.push({
|
|
432
|
+
name: featureName,
|
|
433
|
+
userActions: config.userActions,
|
|
434
|
+
files: changedFiles.filter(file =>
|
|
435
|
+
config.patterns.some(pattern => minimatch(file, pattern))
|
|
436
|
+
)
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return affectedFeatures;
|
|
442
|
+
}
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### Output Format
|
|
446
|
+
|
|
447
|
+
```markdown
|
|
448
|
+
## 🎯 Feature Impact Map
|
|
449
|
+
|
|
450
|
+
### Feature 1: Authentication & Login (HIGH IMPACT)
|
|
451
|
+
|
|
452
|
+
**Files Changed** (3):
|
|
453
|
+
- src/services/authService.ts
|
|
454
|
+
- src/utils/biometric/biometricHelper.ts
|
|
455
|
+
- src/screens/Auth/LoginScreen.tsx
|
|
456
|
+
|
|
457
|
+
**User Actions Affected** (7):
|
|
458
|
+
- ✓ Login (modified)
|
|
459
|
+
- ✓ Logout (no change)
|
|
460
|
+
- ✓ Sign Up (no change)
|
|
461
|
+
- ✓ Password Reset (no change)
|
|
462
|
+
- ✓ Session Management (modified)
|
|
463
|
+
- ✓ 2FA (no change)
|
|
464
|
+
- 🆕 Biometric Authentication (NEW)
|
|
465
|
+
|
|
466
|
+
**Impact Scenarios**:
|
|
467
|
+
1. **When user tries to login**
|
|
468
|
+
- Can now use biometric (Face ID/Touch ID)
|
|
469
|
+
- Password login still works
|
|
470
|
+
- Session storage changed (may need re-login)
|
|
471
|
+
|
|
472
|
+
2. **When user opens app**
|
|
473
|
+
- May see biometric prompt
|
|
474
|
+
- May need to re-login after update
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
---
|
|
478
|
+
|
|
479
|
+
## 🎯 Technique #6: Risk Scoring (SHOULD HAVE)
|
|
480
|
+
|
|
481
|
+
### Mục Đích
|
|
482
|
+
Đánh giá mức độ risk của changes.
|
|
483
|
+
|
|
484
|
+
### Algorithm
|
|
485
|
+
|
|
486
|
+
```javascript
|
|
487
|
+
function calculateRiskScore(changes) {
|
|
488
|
+
let score = 0;
|
|
489
|
+
|
|
490
|
+
// File type risk
|
|
491
|
+
if (changes.database.length > 0) score += 5; // Database changes = high risk
|
|
492
|
+
if (changes.api.length > 0) score += 3; // API changes = medium risk
|
|
493
|
+
if (changes.frontend.length > 0) score += 1; // Frontend = low risk
|
|
494
|
+
|
|
495
|
+
// Change size risk
|
|
496
|
+
const totalLines = changes.linesAdded + changes.linesRemoved;
|
|
497
|
+
if (totalLines > 500) score += 3;
|
|
498
|
+
else if (totalLines > 200) score += 2;
|
|
499
|
+
else if (totalLines > 50) score += 1;
|
|
500
|
+
|
|
501
|
+
// Dependency risk
|
|
502
|
+
const affectedFiles = changes.dependencies.length;
|
|
503
|
+
if (affectedFiles > 20) score += 3;
|
|
504
|
+
else if (affectedFiles > 10) score += 2;
|
|
505
|
+
else if (affectedFiles > 5) score += 1;
|
|
506
|
+
|
|
507
|
+
// Feature risk
|
|
508
|
+
const criticalFeatures = ['auth', 'payment', 'security'];
|
|
509
|
+
const hasCritical = changes.features.some(f =>
|
|
510
|
+
criticalFeatures.some(cf => f.toLowerCase().includes(cf))
|
|
511
|
+
);
|
|
512
|
+
if (hasCritical) score += 5;
|
|
513
|
+
|
|
514
|
+
// Breaking changes
|
|
515
|
+
if (changes.breakingChanges > 0) score += 5;
|
|
516
|
+
|
|
517
|
+
// Test coverage
|
|
518
|
+
if (changes.testCoverage < 50) score += 2;
|
|
519
|
+
else if (changes.testCoverage < 70) score += 1;
|
|
520
|
+
|
|
521
|
+
return {
|
|
522
|
+
score,
|
|
523
|
+
level: score >= 15 ? 'CRITICAL' : score >= 10 ? 'HIGH' : score >= 5 ? 'MEDIUM' : 'LOW'
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
### Output Format
|
|
529
|
+
|
|
530
|
+
```markdown
|
|
531
|
+
## 🎯 Risk Assessment
|
|
532
|
+
|
|
533
|
+
**Risk Score**: 18/25
|
|
534
|
+
**Risk Level**: CRITICAL ⚠️⚠️⚠️
|
|
535
|
+
|
|
536
|
+
### Risk Breakdown
|
|
537
|
+
|
|
538
|
+
| Factor | Score | Reason |
|
|
539
|
+
|--------|-------|--------|
|
|
540
|
+
| Database Changes | 5 | Schema migration required |
|
|
541
|
+
| API Changes | 3 | Breaking changes in auth API |
|
|
542
|
+
| Change Size | 2 | 250 lines changed |
|
|
543
|
+
| Dependencies | 2 | 12 files affected |
|
|
544
|
+
| Critical Feature | 5 | Authentication system |
|
|
545
|
+
| Breaking Changes | 5 | Function signature changed |
|
|
546
|
+
| Test Coverage | 0 | 75% coverage (good) |
|
|
547
|
+
|
|
548
|
+
### Mitigation Recommendations
|
|
549
|
+
|
|
550
|
+
1. **Database Migration**
|
|
551
|
+
- Create rollback script
|
|
552
|
+
- Test migration on staging
|
|
553
|
+
- Backup production data
|
|
554
|
+
|
|
555
|
+
2. **Breaking Changes**
|
|
556
|
+
- Update all 8 callers
|
|
557
|
+
- Add deprecation warnings
|
|
558
|
+
- Document migration guide
|
|
559
|
+
|
|
560
|
+
3. **Testing**
|
|
561
|
+
- Add 8 new test scenarios
|
|
562
|
+
- Run full regression suite
|
|
563
|
+
- Test on multiple devices
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
---
|
|
567
|
+
|
|
568
|
+
## 🔄 Integration với Workflow
|
|
569
|
+
|
|
570
|
+
### Step-by-Step Integration
|
|
571
|
+
|
|
572
|
+
**1. Detect Changes** (existing)
|
|
573
|
+
```bash
|
|
574
|
+
git diff HEAD --name-only
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
**2. Dependency Analysis** (NEW - Technique #1)
|
|
578
|
+
```bash
|
|
579
|
+
# For each changed file
|
|
580
|
+
for file in $(git diff HEAD --name-only); do
|
|
581
|
+
echo "=== Dependencies for $file ==="
|
|
582
|
+
grep -r "from.*$(basename $file .ts)" src/
|
|
583
|
+
done
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
**3. AST Analysis** (NEW - Technique #2)
|
|
587
|
+
```bash
|
|
588
|
+
# Analyze function signatures
|
|
589
|
+
node scripts/ast-analyze.js src/services/authService.ts
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
**4. Feature Mapping** (NEW - Technique #5)
|
|
593
|
+
```bash
|
|
594
|
+
# Map to features
|
|
595
|
+
node scripts/map-features.js $(git diff HEAD --name-only)
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
**5. Test Coverage** (NEW - Technique #4)
|
|
599
|
+
```bash
|
|
600
|
+
# Find related tests
|
|
601
|
+
jest --findRelatedTests $(git diff HEAD --name-only | grep -E '\.(ts|tsx)$')
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
**6. Risk Scoring** (NEW - Technique #6)
|
|
605
|
+
```bash
|
|
606
|
+
# Calculate risk
|
|
607
|
+
node scripts/calculate-risk.js
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
**7. Generate Report** (existing)
|
|
611
|
+
```bash
|
|
612
|
+
# Combine all findings into report
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
---
|
|
616
|
+
|
|
617
|
+
## 📊 Complete Example
|
|
618
|
+
|
|
619
|
+
### Scenario: Added Biometric Authentication
|
|
620
|
+
|
|
621
|
+
**Input**:
|
|
622
|
+
```bash
|
|
623
|
+
/impact-analysis biometric-auth
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
**Execution**:
|
|
627
|
+
|
|
628
|
+
```bash
|
|
629
|
+
# 1. Detect changes
|
|
630
|
+
git diff feature/biometric-auth --name-only
|
|
631
|
+
# Output: 5 files changed
|
|
632
|
+
|
|
633
|
+
# 2. Dependency analysis
|
|
634
|
+
grep -r "from.*authService" src/
|
|
635
|
+
# Output: 12 files import authService
|
|
636
|
+
|
|
637
|
+
# 3. AST analysis
|
|
638
|
+
node scripts/ast-analyze.js src/services/authService.ts
|
|
639
|
+
# Output: login() signature changed (2 → 3 params)
|
|
640
|
+
|
|
641
|
+
# 4. Feature mapping
|
|
642
|
+
node scripts/map-features.js
|
|
643
|
+
# Output: Authentication & Login feature affected
|
|
644
|
+
|
|
645
|
+
# 5. Test coverage
|
|
646
|
+
jest --findRelatedTests src/services/authService.ts
|
|
647
|
+
# Output: 8 tests found, 3 new scenarios needed
|
|
648
|
+
|
|
649
|
+
# 6. Risk scoring
|
|
650
|
+
node scripts/calculate-risk.js
|
|
651
|
+
# Output: Risk = HIGH (score: 18)
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
**Output Report**: See `impact-analysis-output-example.md`
|
|
655
|
+
|
|
656
|
+
---
|
|
657
|
+
|
|
658
|
+
## 🛠️ Helper Scripts
|
|
659
|
+
|
|
660
|
+
### Create All Helper Scripts
|
|
661
|
+
|
|
662
|
+
```bash
|
|
663
|
+
# Create scripts directory
|
|
664
|
+
mkdir -p scripts/impact-analysis
|
|
665
|
+
|
|
666
|
+
# Create scripts
|
|
667
|
+
touch scripts/impact-analysis/ast-analyze.js
|
|
668
|
+
touch scripts/impact-analysis/map-features.js
|
|
669
|
+
touch scripts/impact-analysis/calculate-risk.js
|
|
670
|
+
touch scripts/impact-analysis/find-dependencies.sh
|
|
671
|
+
touch scripts/impact-analysis/analyze-coverage.sh
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
### Master Script
|
|
675
|
+
|
|
676
|
+
Create `scripts/impact-analysis/run-all.sh`:
|
|
677
|
+
|
|
678
|
+
```bash
|
|
679
|
+
#!/bin/bash
|
|
680
|
+
|
|
681
|
+
echo "🔍 Running Impact Analysis..."
|
|
682
|
+
|
|
683
|
+
# 1. Detect changes
|
|
684
|
+
echo "📝 Detecting changes..."
|
|
685
|
+
CHANGED_FILES=$(git diff HEAD --name-only)
|
|
686
|
+
echo "$CHANGED_FILES"
|
|
687
|
+
|
|
688
|
+
# 2. Find dependencies
|
|
689
|
+
echo "🔗 Finding dependencies..."
|
|
690
|
+
./scripts/impact-analysis/find-dependencies.sh "$CHANGED_FILES"
|
|
691
|
+
|
|
692
|
+
# 3. AST analysis
|
|
693
|
+
echo "🌳 Running AST analysis..."
|
|
694
|
+
for file in $CHANGED_FILES; do
|
|
695
|
+
if [[ $file == *.ts ]] || [[ $file == *.tsx ]]; then
|
|
696
|
+
node scripts/impact-analysis/ast-analyze.js "$file"
|
|
697
|
+
fi
|
|
698
|
+
done
|
|
699
|
+
|
|
700
|
+
# 4. Feature mapping
|
|
701
|
+
echo "🎯 Mapping features..."
|
|
702
|
+
node scripts/impact-analysis/map-features.js "$CHANGED_FILES"
|
|
703
|
+
|
|
704
|
+
# 5. Test coverage
|
|
705
|
+
echo "🧪 Analyzing test coverage..."
|
|
706
|
+
./scripts/impact-analysis/analyze-coverage.sh "$CHANGED_FILES"
|
|
707
|
+
|
|
708
|
+
# 6. Risk scoring
|
|
709
|
+
echo "⚠️ Calculating risk..."
|
|
710
|
+
node scripts/impact-analysis/calculate-risk.js
|
|
711
|
+
|
|
712
|
+
echo "✅ Analysis complete!"
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
---
|
|
716
|
+
|
|
717
|
+
## 💡 Best Practices
|
|
718
|
+
|
|
719
|
+
### 1. Start Simple
|
|
720
|
+
- Begin với Dependency Analysis (Technique #1)
|
|
721
|
+
- Add Feature Mapping (Technique #5)
|
|
722
|
+
- Gradually add advanced techniques
|
|
723
|
+
|
|
724
|
+
### 2. Automate
|
|
725
|
+
- Create helper scripts
|
|
726
|
+
- Integrate vào CI/CD
|
|
727
|
+
- Run on pre-commit hook
|
|
728
|
+
|
|
729
|
+
### 3. Customize
|
|
730
|
+
- Adjust patterns cho project
|
|
731
|
+
- Tune risk scoring thresholds
|
|
732
|
+
- Add project-specific checks
|
|
733
|
+
|
|
734
|
+
### 4. Iterate
|
|
735
|
+
- Review findings
|
|
736
|
+
- Improve detection logic
|
|
737
|
+
- Add missing patterns
|
|
738
|
+
|
|
739
|
+
---
|
|
740
|
+
|
|
741
|
+
## 🚀 Next Steps
|
|
742
|
+
|
|
743
|
+
1. ✅ Read this guide
|
|
744
|
+
2. ⚠️ Create helper scripts
|
|
745
|
+
3. ✅ Test on sample changes
|
|
746
|
+
4. ✅ Integrate vào workflow
|
|
747
|
+
5. ✅ Customize cho project
|
|
748
|
+
|
|
749
|
+
---
|
|
750
|
+
|
|
751
|
+
**Estimated setup time**: 2-3 hours
|
|
752
|
+
**Estimated time saved per analysis**: 30-60 minutes
|
|
753
|
+
**ROI**: High (prevents regression bugs)
|