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
package/CHANGELOG.md
ADDED
@@ -0,0 +1,264 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [1.0.0] - 2025-01-10
|
9
|
+
|
10
|
+
### Breaking Changes
|
11
|
+
- **Package renamed**: `ut-priority-scorer` → `ai-test-generator`
|
12
|
+
- **CLI renamed**: `ut-score` → `ai-test`
|
13
|
+
- Better reflects the package's core value: AI-powered test generation
|
14
|
+
|
15
|
+
### Added
|
16
|
+
- **AI Test Generation Tools**: Complete workflow for batch test generation
|
17
|
+
- `ai-test gen-prompt`: Generate AI prompts with function source code context
|
18
|
+
- `ai-test extract-tests`: Extract and create test files from AI responses
|
19
|
+
- `ai-test mark-done`: Mark functions as DONE/SKIP for progress tracking
|
20
|
+
- **Progress Tracking**: Status column (TODO/DONE/SKIP) in all reports
|
21
|
+
- **Batch Generation**: Support for pagination with `--skip` option for large codebases
|
22
|
+
- **Flexible Framework Support**: Customizable framework hints in prompts via `--framework` option
|
23
|
+
- **Multiple AI Formats**: Test extraction supports various AI response formats
|
24
|
+
|
25
|
+
### Changed
|
26
|
+
- Reports now sorted by score (highest priority first) for better UX
|
27
|
+
- Enhanced CLI with comprehensive help messages and examples
|
28
|
+
- Improved documentation with end-to-end AI test generation workflow
|
29
|
+
- Better error messages and validation across all commands
|
30
|
+
|
31
|
+
### Fixed
|
32
|
+
- Test extraction regex now supports multiple response formats (with/without backticks)
|
33
|
+
- Improved function source code extraction for various code patterns
|
34
|
+
- Better error handling in all CLI commands
|
35
|
+
|
36
|
+
## Previous Versions (as ut-priority-scorer)
|
37
|
+
|
38
|
+
### [1.0.3] - 2025-10-10
|
39
|
+
- Sort output by total score (descending) for better prioritization
|
40
|
+
- Added `Status` column (TODO/DONE/SKIP) for tracking test completion
|
41
|
+
- Added Summary section with priority distribution statistics
|
42
|
+
- Improved Markdown output with AI-friendly format
|
43
|
+
|
44
|
+
### [1.0.2] - 2025-10-10
|
45
|
+
- Fixed missing `esprima` dependency
|
46
|
+
|
47
|
+
### [1.0.1] - 2025-10-10
|
48
|
+
- Fixed missing `escomplex` dependency
|
49
|
+
|
50
|
+
### [1.0.0] - 2025-10-10 (Initial Release as ut-priority-scorer)
|
51
|
+
|
52
|
+
### Added
|
53
|
+
- Initial release
|
54
|
+
- Layered architecture scoring system (Foundation, Business Logic, State Management, UI)
|
55
|
+
- CLI commands: `init`, `scan`
|
56
|
+
- Flexible JSON configuration with sensible defaults
|
57
|
+
- Comprehensive scoring metrics:
|
58
|
+
- Testability (pure function detection, mock complexity)
|
59
|
+
- Dependency count (module reference analysis)
|
60
|
+
- Complexity (cyclomatic + cognitive via ESLint)
|
61
|
+
- Business criticality (keyword-based detection)
|
62
|
+
- Error risk (Git history analysis)
|
63
|
+
- Report generation in Markdown and CSV formats
|
64
|
+
- Priority levels: P0 (≥7.5), P1 (6.0-7.4), P2 (4.0-5.9), P3 (<4.0)
|
65
|
+
- AST-based target scanning using ts-morph
|
66
|
+
- Git signal analysis using simple-git
|
67
|
+
- ESLint + sonarjs integration for cognitive complexity
|
68
|
+
- Dependency graph analysis for module references
|
69
|
+
- Programmatic API for workflow integration
|
70
|
+
- Comprehensive documentation and examples
|
71
|
+
|
72
|
+
### Features
|
73
|
+
- 🎯 AI-optimized scoring weights for test generation efficiency
|
74
|
+
- 📊 Layered priority system aligned with testing pyramid principles
|
75
|
+
- 🔧 Flexible JSON-based configuration
|
76
|
+
- 🚀 Fast scanning and scoring (handles 300+ targets in seconds)
|
77
|
+
- 📈 Rich reporting with detailed metrics breakdown
|
78
|
+
- 🤖 Designed for AI-powered test generation workflows
|
79
|
+
|
80
|
+
### Technical Details
|
81
|
+
- Node.js ≥18.0.0 required
|
82
|
+
- ES Module format
|
83
|
+
- Zero runtime dependencies for core functionality
|
84
|
+
- Minimal npm package size (~50KB)
|
85
|
+
|
86
|
+
## [1.1.0] - 2025-01-11
|
87
|
+
|
88
|
+
### Added
|
89
|
+
- **Coverage Delta Validation**: `run-batch` now validates coverage improvement (P0: ≥2%, P1: ≥1%)
|
90
|
+
- **Enhanced AI Output Parsing**: `extract-tests` supports 5+ response formats with fuzzy matching
|
91
|
+
- **Stability Reruns**: P0 targets automatically rerun Jest once for flakiness detection
|
92
|
+
- **Failure Hints Loop**: Jest failures auto-generate actionable hints for next batch
|
93
|
+
|
94
|
+
### Changed
|
95
|
+
- **Prompt Constraints**: Added "禁止修改源码/新增依赖/真实时间网络" stability guidelines
|
96
|
+
- **Reports**: Coverage delta displayed in run-batch output (before/after/delta)
|
97
|
+
- **Extract Robustness**: Support markdown variations (中/英文标题、有/无反引号、宽松路径匹配)
|
98
|
+
|
99
|
+
### Inspired By
|
100
|
+
- Meta TestGen-LLM: assurance filters (build/stability/coverage) - https://arxiv.org/abs/2402.09171
|
101
|
+
- Airbnb: large-scale batching strategies
|
102
|
+
- TestART: iterative generation and template-based repair - https://arxiv.org/abs/2408.03095
|
103
|
+
- Midscene.js: stability practices - https://github.com/web-infra-dev/midscene
|
104
|
+
|
105
|
+
### Technical
|
106
|
+
- Default assurance mode: P0 strong (reruns=1, minCovDelta=2), P1 light, P2/P3 build-only
|
107
|
+
- AI-agnostic: works with any LLM (cursor-agent/GPT/Claude/local models)
|
108
|
+
- Zero breaking changes to existing commands
|
109
|
+
|
110
|
+
## [1.2.0] - 2025-01-11
|
111
|
+
|
112
|
+
### 🎉 Major Refactoring - Modular Architecture
|
113
|
+
|
114
|
+
**Breaking Changes**
|
115
|
+
- **File Structure**: Reorganized `lib/` into layered modules (core/ai/testing/workflows/utils)
|
116
|
+
- **File Naming**: Renamed all lib files for clarity and consistency
|
117
|
+
- `gen-targets.mjs` → `core/scanner.mjs`
|
118
|
+
- `gen-git-signals.mjs` → `core/git-analyzer.mjs`
|
119
|
+
- `score-ut.mjs` → `core/scorer.mjs`
|
120
|
+
- `gen-test-prompt.mjs` → `ai/prompt-builder.mjs`
|
121
|
+
- `ai-generate.mjs` → `ai/client.mjs`
|
122
|
+
- `extract-tests.mjs` → `ai/extractor.mjs`
|
123
|
+
- `jest-runner.mjs` → `testing/runner.mjs`
|
124
|
+
- `jest-failure-analyzer.mjs` → `testing/analyzer.mjs`
|
125
|
+
- `run-batch.mjs` → `workflows/batch.mjs`
|
126
|
+
- `run-all.mjs` → `workflows/all.mjs`
|
127
|
+
- `mark-done.mjs` → `utils/marker.mjs`
|
128
|
+
- **CLI**: Renamed `bin/ai-test.js` → `bin/cli.js` (internal, no user impact)
|
129
|
+
|
130
|
+
### Added
|
131
|
+
- **Modular Architecture**: Clear separation of concerns
|
132
|
+
- `lib/core/`: Code analysis & scoring (no AI dependency)
|
133
|
+
- `lib/ai/`: AI interaction & test generation
|
134
|
+
- `lib/testing/`: Test execution & failure analysis
|
135
|
+
- `lib/workflows/`: End-to-end orchestration
|
136
|
+
- `lib/utils/`: Shared utilities
|
137
|
+
- **Module Exports**: Each layer has an `index.mjs` with clean exports
|
138
|
+
- **Programmatic API**: Package now supports programmatic usage
|
139
|
+
```javascript
|
140
|
+
import { scanCode, scoreTargets } from 'ai-test-generator'
|
141
|
+
import { buildPrompt, callAI } from 'ai-test-generator/ai'
|
142
|
+
import { runBatch } from 'ai-test-generator/workflows'
|
143
|
+
```
|
144
|
+
- **Package Exports**: Added `exports` field in package.json for subpath imports
|
145
|
+
|
146
|
+
### Changed
|
147
|
+
- **package.json**: Updated `main` to `lib/index.mjs`, `bin` to `cli.js`, version to 1.2.0
|
148
|
+
- **Internal Paths**: All import paths updated to reflect new structure
|
149
|
+
|
150
|
+
### Non-Breaking
|
151
|
+
- ✅ CLI commands remain unchanged (`ai-test scan`, `ai-test gen-prompt`, etc.)
|
152
|
+
- ✅ Config file format unchanged
|
153
|
+
- ✅ Output formats unchanged
|
154
|
+
- ✅ User workflow unchanged
|
155
|
+
|
156
|
+
### Benefits
|
157
|
+
- 🎯 **Clear Responsibility**: Each module has a single, well-defined purpose
|
158
|
+
- 📦 **Easier Extension**: Add new analyzers, AI clients, or test runners without touching other code
|
159
|
+
- 🧩 **Reusable Components**: Use scoring engine without AI, or AI layer without workflows
|
160
|
+
- 📖 **Better Discoverability**: Flat structure → layered structure improves navigation
|
161
|
+
- 🚀 **Future-Proof**: Prepared for Vitest support, OpenAI client, plugin system
|
162
|
+
|
163
|
+
## [1.3.0] - 2025-01-11
|
164
|
+
|
165
|
+
### 🎉 Major Simplification - 极简 CLI
|
166
|
+
|
167
|
+
**Breaking Changes**
|
168
|
+
- **CLI Commands**: 简化从 7 个命令到 2 个核心命令
|
169
|
+
- ✅ 保留: `scan`, ~~`init`~~ (自动化)
|
170
|
+
- ✅ 新增: `generate` (合并 `gen-prompt` + `extract-tests` + `run-batch` + `mark-done`)
|
171
|
+
- ❌ 移除: `init`, `gen-prompt`, `extract-tests`, `mark-done`, `run-batch`, `run-all`
|
172
|
+
|
173
|
+
### Added
|
174
|
+
- **`ai-test generate`**: 一键生成测试
|
175
|
+
- 默认生成 10 个 P0 TODO 函数
|
176
|
+
- 选项: `-n` 数量, `-p` 优先级, `--all` 全部生成
|
177
|
+
- 自动工作流: 读取 TODO → 生成 → 运行 Jest → 标记 DONE
|
178
|
+
- 智能重试: 失败的函数保持 TODO,下次自动带 hints
|
179
|
+
|
180
|
+
- **状态自动管理**:
|
181
|
+
- 测试通过 → 自动标记 DONE
|
182
|
+
- 测试失败 → 保持 TODO (带失败 hints)
|
183
|
+
- `scan` 重新运行时保留 DONE 状态
|
184
|
+
|
185
|
+
- **增量支持**:
|
186
|
+
- 新扫描保留已有 DONE/SKIP 状态
|
187
|
+
- 已删除的函数自动从报告移除
|
188
|
+
- 新函数自动加入 TODO
|
189
|
+
|
190
|
+
### Changed
|
191
|
+
- **`ai-test scan`**: 自动初始化配置(首次运行时)
|
192
|
+
- **`ai-test scan`**: 显示 TODO/DONE 统计
|
193
|
+
- **状态持久化**: DONE/SKIP 状态在重新扫描后保留
|
194
|
+
- **`workflows/batch.mjs`**:
|
195
|
+
- 只处理 TODO 状态的函数
|
196
|
+
- 成功后自动标记 DONE
|
197
|
+
- 失败保持 TODO 并生成 hints
|
198
|
+
- **`core/scorer.mjs`**:
|
199
|
+
- 读取旧报告的状态
|
200
|
+
- 保留 DONE/SKIP 到新报告
|
201
|
+
|
202
|
+
### Removed
|
203
|
+
- ❌ `ai-test init` - 自动化(scan 时创建)
|
204
|
+
- ❌ `ai-test gen-prompt` - 内部使用
|
205
|
+
- ❌ `ai-test extract-tests` - 内部使用
|
206
|
+
- ❌ `ai-test mark-done` - 自动管理
|
207
|
+
- ❌ `ai-test run-batch` - 合并到 generate
|
208
|
+
- ❌ `ai-test run-all` - 合并到 generate --all
|
209
|
+
|
210
|
+
### Migration Guide
|
211
|
+
|
212
|
+
**v1.2.0 → v1.3.0**
|
213
|
+
|
214
|
+
旧工作流:
|
215
|
+
```bash
|
216
|
+
ai-test init
|
217
|
+
ai-test scan
|
218
|
+
ai-test run-batch P0 10 0
|
219
|
+
ai-test mark-done "funcA,funcB"
|
220
|
+
```
|
221
|
+
|
222
|
+
新工作流:
|
223
|
+
```bash
|
224
|
+
ai-test scan # 自动初始化
|
225
|
+
ai-test generate # 自动生成 + 标记
|
226
|
+
```
|
227
|
+
|
228
|
+
完整示例:
|
229
|
+
```bash
|
230
|
+
# 首次使用
|
231
|
+
ai-test scan # 扫描代码
|
232
|
+
ai-test generate # 生成 10 个 P0
|
233
|
+
ai-test generate -n 20 # 再生成 20 个
|
234
|
+
ai-test generate --all # 跑完所有 TODO
|
235
|
+
|
236
|
+
# 增量更新
|
237
|
+
# (添加新代码后)
|
238
|
+
ai-test scan # 重新扫描(保留 DONE)
|
239
|
+
ai-test generate # 继续生成新的 TODO
|
240
|
+
```
|
241
|
+
|
242
|
+
### Benefits
|
243
|
+
- 🎯 **更简单**: 2 个命令代替 7 个
|
244
|
+
- 🤖 **全自动**: 无需手动标记状态
|
245
|
+
- 🔄 **智能重试**: 失败自动带 hints
|
246
|
+
- 📊 **进度可见**: 实时显示 TODO/DONE
|
247
|
+
- ⚡ **增量友好**: 保留已完成的工作
|
248
|
+
|
249
|
+
## [Unreleased]
|
250
|
+
|
251
|
+
### Planned Features
|
252
|
+
- VS Code extension for inline priority indicators
|
253
|
+
- Watch mode for continuous scoring during development
|
254
|
+
- HTML report with interactive charts
|
255
|
+
- Plugin system for custom metrics
|
256
|
+
- Integration with popular CI/CD platforms
|
257
|
+
- Test coverage correlation analysis
|
258
|
+
- AI test generation templates
|
259
|
+
- Multi-language support (currently TypeScript/JavaScript only)
|
260
|
+
|
261
|
+
---
|
262
|
+
|
263
|
+
For a complete list of changes, see the [commit history](https://github.com/temptrip/ai-test-generator/commits).
|
264
|
+
|
package/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 YuhengZhou
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|