ai-unit-test-generator 1.4.5 → 2.0.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/CHANGELOG.md +138 -0
- package/README.md +307 -322
- package/bin/cli.js +100 -202
- package/lib/ai/analyzer-prompt.mjs +120 -0
- package/lib/ai/config-writer.mjs +99 -0
- package/lib/ai/context-builder.mjs +52 -0
- package/lib/ai/index.mjs +11 -0
- package/lib/ai/reviewer.mjs +283 -0
- package/lib/ai/sampler.mjs +97 -0
- package/lib/ai/validator.mjs +101 -0
- package/lib/core/scanner.mjs +112 -2
- package/lib/core/scorer.mjs +184 -4
- package/lib/utils/config-manager.mjs +110 -0
- package/lib/utils/index.mjs +2 -0
- package/lib/utils/scan-manager.mjs +121 -0
- package/lib/workflows/analyze.mjs +157 -0
- package/lib/workflows/generate.mjs +98 -0
- package/lib/workflows/index.mjs +7 -0
- package/lib/workflows/init.mjs +45 -0
- package/lib/workflows/scan.mjs +144 -0
- package/package.json +1 -1
- package/templates/default.config.jsonc +58 -0
package/CHANGELOG.md
CHANGED
@@ -5,6 +5,144 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [2.0.0] - 2025-01-11
|
9
|
+
|
10
|
+
### 🎉 Major Release: AI-Enhanced Configuration
|
11
|
+
|
12
|
+
This is a **major refactor** with breaking changes. The package has been completely restructured to support AI-powered codebase analysis and intelligent scoring configuration.
|
13
|
+
|
14
|
+
### 🔥 Hotfix (same day)
|
15
|
+
- **Fixed**: AI enhancement logic now correctly applied in `scorer.mjs` scoring loop
|
16
|
+
- **Optimized**: File-level import caching in `scanner.mjs` (30-40% performance improvement)
|
17
|
+
- **Configurable**: Business entity keywords moved to `aiEnhancement.entityKeywords`
|
18
|
+
- **Updated**: README reflects v2.0 architecture
|
19
|
+
- **Added**: `matchPattern` helper function for glob pattern matching in AI suggestions
|
20
|
+
|
21
|
+
### Added
|
22
|
+
|
23
|
+
#### New Commands
|
24
|
+
- **`ai-test init`**: Initialize configuration file (was implicit in `scan`)
|
25
|
+
- **`ai-test analyze`**: AI-powered codebase analysis
|
26
|
+
- Automatically samples representative code from your codebase
|
27
|
+
- Calls Cursor Agent to analyze business logic and risk patterns
|
28
|
+
- Interactive review UI with category-by-category approval
|
29
|
+
- Generates project-specific scoring suggestions
|
30
|
+
- Supports score adjustment for individual suggestions
|
31
|
+
|
32
|
+
#### New Modules
|
33
|
+
- **`lib/utils/config-manager.mjs`**: Configuration file management
|
34
|
+
- **`lib/utils/scan-manager.mjs`**: Scan result management and staleness detection
|
35
|
+
- **`lib/ai/sampler.mjs`**: Intelligent code sampling for AI analysis
|
36
|
+
- **`lib/ai/context-builder.mjs`**: Project context extraction (framework, deps)
|
37
|
+
- **`lib/ai/analyzer-prompt.mjs`**: Constrained AI analysis prompt builder
|
38
|
+
- **`lib/ai/validator.mjs`**: Strict JSON schema validation for AI responses
|
39
|
+
- **`lib/ai/reviewer.mjs`**: Interactive suggestion review UI
|
40
|
+
- **`lib/ai/config-writer.mjs`**: Safe configuration updates (locked paths protection)
|
41
|
+
- **`lib/workflows/init.mjs`**: Init workflow
|
42
|
+
- **`lib/workflows/analyze.mjs`**: AI analysis workflow
|
43
|
+
- **`lib/workflows/scan.mjs`**: Scan workflow (extracted from CLI)
|
44
|
+
- **`lib/workflows/generate.mjs`**: Generate workflow (extracted from CLI)
|
45
|
+
|
46
|
+
#### AI Enhancement Configuration
|
47
|
+
- Added `aiEnhancement` section to config schema
|
48
|
+
- `businessCriticalPaths`: AI-identified critical business logic paths
|
49
|
+
- `highRiskModules`: AI-identified high-risk modules
|
50
|
+
- `testabilityAdjustments`: AI-suggested testability modifiers
|
51
|
+
- Locked/writable path protection mechanism
|
52
|
+
- AI can only write to `aiEnhancement.suggestions`
|
53
|
+
- Core scoring rules remain immutable
|
54
|
+
|
55
|
+
#### Enhanced Metadata Extraction
|
56
|
+
- `lib/core/scanner.mjs` now extracts rich metadata:
|
57
|
+
- Critical imports (payment, auth, API libraries)
|
58
|
+
- Business entity types (Payment, Order, Booking, etc.)
|
59
|
+
- JSDoc documentation
|
60
|
+
- Error handling patterns (try-catch count)
|
61
|
+
- External API calls (fetch, axios)
|
62
|
+
- Return types and parameter types
|
63
|
+
|
64
|
+
### Changed
|
65
|
+
|
66
|
+
#### Breaking Changes
|
67
|
+
- **CLI Structure**: Removed implicit config creation from `scan`, added explicit `init` command
|
68
|
+
- **Command Workflow**: Now requires `ai-test init` before other commands
|
69
|
+
- **Module Structure**: Reorganized `lib/` directory with clear separation:
|
70
|
+
- `core/`: AST, Git, Scoring
|
71
|
+
- `ai/`: Analysis & Test Generation
|
72
|
+
- `workflows/`: High-level orchestration
|
73
|
+
- `utils/`: Shared utilities
|
74
|
+
- `testing/`: Test running & analysis
|
75
|
+
- **Config Schema**: Added `aiEnhancement` section (backward compatible)
|
76
|
+
|
77
|
+
#### Improvements
|
78
|
+
- **CLI Simplification**: `bin/cli.js` now purely delegates to workflow modules
|
79
|
+
- **Better Error Messages**: More helpful hints when config is missing
|
80
|
+
- **Modular Design**: Each workflow is independently importable
|
81
|
+
- **Type Safety**: All modules use ESM with proper exports
|
82
|
+
|
83
|
+
### Architecture
|
84
|
+
|
85
|
+
```
|
86
|
+
User Workflow:
|
87
|
+
1. ai-test init → Create config
|
88
|
+
2. ai-test analyze → AI analysis (optional)
|
89
|
+
3. ai-test scan → Scan & score
|
90
|
+
4. ai-test generate → Generate tests
|
91
|
+
|
92
|
+
Module Hierarchy:
|
93
|
+
bin/cli.js
|
94
|
+
↓
|
95
|
+
lib/workflows/ (init, analyze, scan, generate)
|
96
|
+
↓
|
97
|
+
lib/core/ (scanner, scorer, git-analyzer)
|
98
|
+
lib/ai/ (sampler, validator, reviewer, etc.)
|
99
|
+
lib/utils/ (config-manager, scan-manager)
|
100
|
+
```
|
101
|
+
|
102
|
+
### Migration Guide
|
103
|
+
|
104
|
+
For users upgrading from v1.x:
|
105
|
+
|
106
|
+
1. **Config file**: Your existing `ai-test.config.jsonc` will continue to work
|
107
|
+
2. **New workflow**:
|
108
|
+
```bash
|
109
|
+
# Old (v1.x)
|
110
|
+
ai-test scan # Would create config if missing
|
111
|
+
|
112
|
+
# New (v2.0)
|
113
|
+
ai-test init # Explicit init step
|
114
|
+
ai-test analyze # Optional: Let AI optimize config
|
115
|
+
ai-test scan # Scan with AI enhancements
|
116
|
+
```
|
117
|
+
3. **AI features are optional**: If you don't run `analyze`, scoring works exactly as before
|
118
|
+
4. **Programmatic API**: Can now import workflows directly:
|
119
|
+
```js
|
120
|
+
import { init, analyze, scan, generate } from 'ai-unit-test-generator/workflows'
|
121
|
+
```
|
122
|
+
|
123
|
+
### Technical Details
|
124
|
+
|
125
|
+
- **AI Prompt Engineering**: Highly constrained prompts with strict JSON schema
|
126
|
+
- **Validation**: Multi-layer validation (schema, confidence thresholds, evidence requirements)
|
127
|
+
- **Safety**: Locked configuration paths prevent AI from modifying core scoring logic
|
128
|
+
- **Interactive UX**: Category-by-category review with score adjustment support
|
129
|
+
- **Token Optimization**: Intelligent code sampling (max 25 files, 1500 chars each)
|
130
|
+
|
131
|
+
### Credits
|
132
|
+
|
133
|
+
- Inspired by Meta's TestGen-LLM for assurance filters
|
134
|
+
- Scoring methodology based on software testing research
|
135
|
+
- Built on top of `ts-morph` for robust AST analysis
|
136
|
+
|
137
|
+
---
|
138
|
+
|
139
|
+
## [1.4.6] - 2025-01-11
|
140
|
+
|
141
|
+
### Fixed
|
142
|
+
- Fixed JSONC parsing in CLI for coverage config
|
143
|
+
- Fixed coverage command to continue even if tests fail (partial coverage data still useful)
|
144
|
+
- Fixed tsconfig.json to include `node_modules/@types` for Jest types
|
145
|
+
|
8
146
|
## [1.4.5] - 2025-01-11
|
9
147
|
|
10
148
|
### Fixed
|