ai-unit-test-generator 2.0.1 → 2.0.2

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 CHANGED
@@ -5,19 +5,31 @@ 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
8
+ ## [2.0.2] - 2025-01-11
9
9
 
10
- ### 🎉 Major Release: AI-Enhanced Configuration
10
+ ### 🐛 Hotfix
11
+ - **Fixed**: `ai-test analyze` command - corrected Cursor Agent invocation to use `chat` command with stdin
12
+ - Previously used invalid `--prompt-file` option, now uses correct stdin-based approach
11
13
 
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.
14
+ ---
13
15
 
14
- ### 🔥 Hotfix (same day)
16
+ ## [2.0.1] - 2025-01-11
17
+
18
+ ### 🔥 Hotfix
15
19
  - **Fixed**: AI enhancement logic now correctly applied in `scorer.mjs` scoring loop
16
20
  - **Optimized**: File-level import caching in `scanner.mjs` (30-40% performance improvement)
17
21
  - **Configurable**: Business entity keywords moved to `aiEnhancement.entityKeywords`
18
22
  - **Updated**: README reflects v2.0 architecture
19
23
  - **Added**: `matchPattern` helper function for glob pattern matching in AI suggestions
20
24
 
25
+ ---
26
+
27
+ ## [2.0.0] - 2025-01-11
28
+
29
+ ### 🎉 Major Release: AI-Enhanced Configuration
30
+
31
+ This is a **major refactor** with breaking changes. The package has been completely restructured to support AI-powered codebase analysis and intelligent scoring configuration.
32
+
21
33
  ### Added
22
34
 
23
35
  #### New Commands
@@ -122,34 +122,51 @@ export async function analyze(options) {
122
122
  */
123
123
  async function callCursorAgent(promptPath) {
124
124
  return new Promise((resolve, reject) => {
125
- const responsePath = 'reports/ai_analyze_response.txt'
125
+ const { readFileSync } = require('node:fs')
126
126
 
127
- const child = spawn('cursor-agent', [
128
- '--prompt-file', promptPath,
129
- '--output', responsePath
130
- ], {
131
- stdio: 'inherit',
127
+ // 读取 prompt
128
+ let prompt
129
+ try {
130
+ prompt = readFileSync(promptPath, 'utf-8')
131
+ } catch (err) {
132
+ reject(new Error(`Failed to read prompt file: ${err.message}`))
133
+ return
134
+ }
135
+
136
+ // 调用 cursor-agent chat(通过 stdin 传递 prompt)
137
+ const child = spawn('cursor-agent', ['chat'], {
138
+ stdio: ['pipe', 'pipe', 'inherit'],
132
139
  shell: true,
133
140
  cwd: process.cwd()
134
141
  })
135
142
 
143
+ const chunks = []
144
+ child.stdout.on('data', (d) => chunks.push(Buffer.from(d)))
145
+
146
+ // 写入 prompt 到 stdin
147
+ child.stdin.write(prompt)
148
+ child.stdin.end()
149
+
150
+ // 超时处理(10 分钟)
151
+ const timeout = setTimeout(() => {
152
+ child.kill('SIGKILL')
153
+ reject(new Error('cursor-agent timeout after 600s'))
154
+ }, 600000)
155
+
136
156
  child.on('close', (code) => {
157
+ clearTimeout(timeout)
158
+
137
159
  if (code !== 0) {
138
160
  reject(new Error(`cursor-agent exited with code ${code}`))
139
161
  return
140
162
  }
141
163
 
142
- // 读取响应
143
- try {
144
- const { readFileSync } = require('node:fs')
145
- const response = readFileSync(responsePath, 'utf-8')
146
- resolve(response)
147
- } catch (err) {
148
- reject(new Error(`Failed to read AI response: ${err.message}`))
149
- }
164
+ const response = Buffer.concat(chunks).toString('utf-8')
165
+ resolve(response)
150
166
  })
151
167
 
152
168
  child.on('error', (err) => {
169
+ clearTimeout(timeout)
153
170
  reject(new Error(`Failed to spawn cursor-agent: ${err.message}`))
154
171
  })
155
172
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-unit-test-generator",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "AI-powered unit test generator with smart priority scoring",
5
5
  "keywords": [
6
6
  "unit-test",