ai-unit-test-generator 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +264 -0
- package/LICENSE +22 -0
- package/README.md +432 -0
- package/bin/cli.js +217 -0
- package/lib/ai/client.mjs +79 -0
- package/lib/ai/extractor.mjs +199 -0
- package/lib/ai/index.mjs +11 -0
- package/lib/ai/prompt-builder.mjs +298 -0
- package/lib/core/git-analyzer.mjs +151 -0
- package/lib/core/index.mjs +11 -0
- package/lib/core/scanner.mjs +233 -0
- package/lib/core/scorer.mjs +633 -0
- package/lib/index.js +18 -0
- package/lib/index.mjs +25 -0
- package/lib/testing/analyzer.mjs +43 -0
- package/lib/testing/index.mjs +10 -0
- package/lib/testing/runner.mjs +32 -0
- package/lib/utils/index.mjs +11 -0
- package/lib/utils/marker.mjs +182 -0
- package/lib/workflows/all.mjs +51 -0
- package/lib/workflows/batch.mjs +187 -0
- package/lib/workflows/index.mjs +10 -0
- package/package.json +69 -0
- package/templates/default.config.json +199 -0
@@ -0,0 +1,199 @@
|
|
1
|
+
{
|
2
|
+
"scoringMode": "layered",
|
3
|
+
"round": { "mode": "floor", "digits": 2 },
|
4
|
+
"providers": ["func"],
|
5
|
+
"targetGeneration": {
|
6
|
+
"excludeDirs": []
|
7
|
+
},
|
8
|
+
"internalInclude": true,
|
9
|
+
"internalThresholds": {
|
10
|
+
"minLoc": 15,
|
11
|
+
"bonusLoc": 50,
|
12
|
+
"excludePatterns": ["**/__tests__/**", "**/*.spec.ts", "**/*.spec.tsx"]
|
13
|
+
},
|
14
|
+
"layers": {
|
15
|
+
"foundation": {
|
16
|
+
"name": "Foundation (基础工具层)",
|
17
|
+
"description": "纯函数、工具函数、无依赖的基础代码",
|
18
|
+
"patterns": ["utils/**", "constants/**", "config/**", "types/**"],
|
19
|
+
"characteristics": {
|
20
|
+
"isPure": true,
|
21
|
+
"noDependencies": true,
|
22
|
+
"multipleReferences": true
|
23
|
+
},
|
24
|
+
"weights": {
|
25
|
+
"testability": 0.50,
|
26
|
+
"dependencyCount": 0.30,
|
27
|
+
"complexity": 0.20
|
28
|
+
},
|
29
|
+
"thresholds": { "P0": 7.5, "P1": 6.0, "P2": 4.0 },
|
30
|
+
"coverageTarget": 100,
|
31
|
+
"autoP0": false,
|
32
|
+
"notes": "测试金字塔底层,优先级最高;AI生成友好层"
|
33
|
+
},
|
34
|
+
"business": {
|
35
|
+
"name": "Business Logic (业务逻辑层)",
|
36
|
+
"description": "包含业务规则的函数,不包含UI",
|
37
|
+
"patterns": ["services/**", "stores/**", "hooks/**"],
|
38
|
+
"characteristics": {
|
39
|
+
"hasBusinessRules": true,
|
40
|
+
"noUI": true,
|
41
|
+
"mayDependOnUtils": true
|
42
|
+
},
|
43
|
+
"weights": {
|
44
|
+
"businessCriticality": 0.40,
|
45
|
+
"complexity": 0.30,
|
46
|
+
"errorRisk": 0.30
|
47
|
+
},
|
48
|
+
"thresholds": { "P0": 8.0, "P1": 6.5, "P2": 4.5 },
|
49
|
+
"coverageTarget": 80,
|
50
|
+
"notes": "核心业务逻辑,高优先级"
|
51
|
+
},
|
52
|
+
"state": {
|
53
|
+
"name": "State Management (状态管理层)",
|
54
|
+
"description": "Jotai atoms、Zustand stores等状态管理",
|
55
|
+
"patterns": ["atoms/**", "stores/**"],
|
56
|
+
"characteristics": {
|
57
|
+
"isStateManagement": true,
|
58
|
+
"connectsLogicAndUI": true
|
59
|
+
},
|
60
|
+
"weights": {
|
61
|
+
"businessCriticality": 0.50,
|
62
|
+
"complexity": 0.30,
|
63
|
+
"errorRisk": 0.20
|
64
|
+
},
|
65
|
+
"thresholds": { "P0": 8.0, "P1": 6.5, "P2": 4.5 },
|
66
|
+
"coverageTarget": 70,
|
67
|
+
"notes": "状态管理,连接逻辑和UI"
|
68
|
+
},
|
69
|
+
"ui": {
|
70
|
+
"name": "UI Components (UI组件层)",
|
71
|
+
"description": "React组件、包含交互逻辑",
|
72
|
+
"patterns": ["components/**", "pages/**", "context/**"],
|
73
|
+
"characteristics": {
|
74
|
+
"isReactComponent": true,
|
75
|
+
"hasInteraction": true
|
76
|
+
},
|
77
|
+
"weights": {
|
78
|
+
"businessCriticality": 0.40,
|
79
|
+
"complexity": 0.30,
|
80
|
+
"testability": 0.30
|
81
|
+
},
|
82
|
+
"thresholds": { "P0": 8.5, "P1": 7.0, "P2": 5.0 },
|
83
|
+
"coverageTarget": 50,
|
84
|
+
"notes": "UI层,更适合集成测试"
|
85
|
+
}
|
86
|
+
},
|
87
|
+
"ccFusion": {
|
88
|
+
"useCognitive": true,
|
89
|
+
"cyclomaticT": 15,
|
90
|
+
"cognitiveT": 25,
|
91
|
+
"wC": 0.7,
|
92
|
+
"wK": 0.3,
|
93
|
+
"cap": 10
|
94
|
+
},
|
95
|
+
"ccAdjust": {
|
96
|
+
"depthW": 0.2,
|
97
|
+
"branchesW": 0.2,
|
98
|
+
"paramsW": 0.1,
|
99
|
+
"locBonusThreshold": 50,
|
100
|
+
"locBonus": 1
|
101
|
+
},
|
102
|
+
"bcKeywords": {
|
103
|
+
"10": ["price", "booking", "payment", "checkout"],
|
104
|
+
"9": ["recommend", "search"],
|
105
|
+
"8": ["filter", "list"],
|
106
|
+
"7": ["login", "order", "config"],
|
107
|
+
"5": ["navigation", "seo", "header"],
|
108
|
+
"3": ["log", "trace", "decor"]
|
109
|
+
},
|
110
|
+
"mainChainPaths": [],
|
111
|
+
"bcCapForNonMainChain": 8,
|
112
|
+
"ccMapping": {
|
113
|
+
"cyclomatic": [
|
114
|
+
{ "gt": 15, "score": 10 },
|
115
|
+
{ "gte": 11, "lte": 15, "score": 10 },
|
116
|
+
{ "gte": 6, "lte": 10, "score": 9 },
|
117
|
+
{ "gte": 3, "lte": 5, "score": 7 },
|
118
|
+
{ "lte": 2, "score": 6 }
|
119
|
+
],
|
120
|
+
"adjustments": [
|
121
|
+
{ "field": "maxDepth", "op": ">=", "value": 4, "delta": 1 },
|
122
|
+
{ "field": "branches", "op": ">=", "value": 12, "delta": 1 },
|
123
|
+
{ "field": "params", "op": ">=", "value": 6, "delta": 1 },
|
124
|
+
{ "field": "statements", "op": ">=", "value": 80, "delta": 1 },
|
125
|
+
{ "field": "cognitive", "op": ">=", "value": 25, "delta": 1 }
|
126
|
+
],
|
127
|
+
"cap": 10,
|
128
|
+
"platformAdjust": { "delta": 1, "cap": 10, "skipIfLikelihoodGte": 4 }
|
129
|
+
},
|
130
|
+
"fallbackMapping": {
|
131
|
+
"conditions": [
|
132
|
+
{ "gt": 12, "score": 10 },
|
133
|
+
{ "gte": 8, "lte": 12, "score": 8 },
|
134
|
+
{ "gte": 5, "lte": 7, "score": 6 },
|
135
|
+
{ "gte": 3, "lte": 4, "score": 4 },
|
136
|
+
{ "lte": 2, "score": 2 }
|
137
|
+
],
|
138
|
+
"nesting": [{ "gte": 4, "delta": 2 }, { "eq": 3, "delta": 1 }],
|
139
|
+
"earlyReturns": [{ "gte": 4, "delta": 1 }],
|
140
|
+
"paramsOrSources": [
|
141
|
+
{ "paramsGte": 6, "delta": 1 },
|
142
|
+
{ "sourcesGte": 3, "delta": 1 }
|
143
|
+
],
|
144
|
+
"cap": 10
|
145
|
+
},
|
146
|
+
"depGraph": {
|
147
|
+
"enable": true,
|
148
|
+
"neighborCategoryBoost": 2,
|
149
|
+
"degreeBoost": 8
|
150
|
+
},
|
151
|
+
"erMatrix": {
|
152
|
+
"5": { "5": 10, "4": 9, "3": 8, "2": 7, "1": 6 },
|
153
|
+
"4": { "5": 9, "4": 8, "3": 7, "2": 6, "1": 5 },
|
154
|
+
"3": { "5": 8, "4": 7, "3": 6, "2": 5, "1": 4 },
|
155
|
+
"2": { "5": 7, "4": 6, "3": 5, "2": 4, "1": 3 },
|
156
|
+
"1": { "5": 6, "4": 5, "3": 4, "2": 3, "1": 2 }
|
157
|
+
},
|
158
|
+
"likelihoodRules": [
|
159
|
+
{ "field": "commits30d", "op": ">=", "value": 6, "score": 5 },
|
160
|
+
{ "field": "commits30d", "op": "between", "min": 3, "max": 5, "score": 4 },
|
161
|
+
{ "field": "commits30d", "op": "between", "min": 1, "max": 2, "score": 3 },
|
162
|
+
{ "field": "fallback90d", "op": "gt", "value": 0, "score": 2 },
|
163
|
+
{ "field": "fallback180dZero", "op": "eq", "value": true, "score": 1 }
|
164
|
+
],
|
165
|
+
"boostRules": {
|
166
|
+
"authors30dGte": 3,
|
167
|
+
"crossModule": true,
|
168
|
+
"multiPlatform": true,
|
169
|
+
"cap": 5
|
170
|
+
},
|
171
|
+
"crossModuleCategories": ["components", "hooks", "utils", "services", "pages"],
|
172
|
+
"hintMaps": {
|
173
|
+
"impactLocal": "configs/impact.local.json",
|
174
|
+
"roiLocal": "configs/roi.local.json"
|
175
|
+
},
|
176
|
+
"overrides": "reports/overrides.json",
|
177
|
+
"impactKeywords": {
|
178
|
+
"5": ["payment", "booking", "price"],
|
179
|
+
"4": ["filter", "list", "display"],
|
180
|
+
"3": ["interaction"],
|
181
|
+
"2": ["minor", "ui"],
|
182
|
+
"1": ["decor", "cosmetic"]
|
183
|
+
},
|
184
|
+
"testabilityRules": {
|
185
|
+
"pure": 10,
|
186
|
+
"injectable": 9,
|
187
|
+
"multiContext": 7,
|
188
|
+
"nativeOrNetwork": 5,
|
189
|
+
"needsUI": 3
|
190
|
+
},
|
191
|
+
"dependencyCountMapping": [
|
192
|
+
{ "gte": 10, "score": 10 },
|
193
|
+
{ "gte": 5, "lt": 10, "score": 10 },
|
194
|
+
{ "gte": 3, "lt": 5, "score": 9 },
|
195
|
+
{ "gte": 1, "lt": 3, "score": 7 },
|
196
|
+
{ "eq": 0, "score": 5 }
|
197
|
+
],
|
198
|
+
"fallbacks": { "BC": 6, "CC": 6, "ERLikelihood": 3, "Testability": 6 }
|
199
|
+
}
|