@amit641/testpilot-ai 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
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.
package/README.md ADDED
@@ -0,0 +1,229 @@
1
+ <p align="center">
2
+ <h1 align="center">testpilot-ai</h1>
3
+ <p align="center">AI-powered test generation that actually works.<br/>Generate, verify, and auto-fix tests with any LLM.</p>
4
+ </p>
5
+
6
+ <p align="center">
7
+ <a href="https://www.npmjs.com/package/@amit641/testpilot-ai"><img src="https://img.shields.io/npm/v/@amit641/testpilot-ai.svg" alt="npm version" /></a>
8
+ <a href="https://www.npmjs.com/package/@amit641/testpilot-ai"><img src="https://img.shields.io/npm/dm/@amit641/testpilot-ai.svg" alt="npm downloads" /></a>
9
+ <a href="https://github.com/amit641/autotest/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/testpilot-ai.svg" alt="license" /></a>
10
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="https://amit641.github.io/autotest/">Docs</a> · <a href="#install">Install</a> · <a href="#quick-start">Quick Start</a> · <a href="https://github.com/amit641/autotest">GitHub</a>
14
+ </p>
15
+
16
+ ---
17
+
18
+ ## Why testpilot-ai?
19
+
20
+ Most AI test generators write tests that **don't pass**. testpilot-ai generates, runs, and auto-fixes tests in a loop until they actually work.
21
+
22
+ - **Self-healing tests** — Verify & auto-fix loop until all tests pass
23
+ - **AST analysis** — TypeScript compiler API extracts functions, classes, types, JSDoc
24
+ - **Coverage-gap filling** — Parse lcov/cobertura, generate tests for uncovered code
25
+ - **Any LLM** — OpenAI, Anthropic, Google, Ollama (local models)
26
+ - **4 frameworks** — Vitest, Jest, Mocha, Node test runner
27
+ - **Context-aware** — Follows relative imports for richer prompts
28
+ - **Analyze command** — Find files that need tests
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ npm install -D @amit641/testpilot-ai
34
+ ```
35
+
36
+ ## Quick Start
37
+
38
+ ```bash
39
+ # Generate tests for a file
40
+ npx testpilot src/utils.ts
41
+
42
+ # Generate AND verify — auto-fix until all tests pass
43
+ npx testpilot src/utils.ts --verify
44
+
45
+ # Use a specific provider
46
+ npx testpilot src/utils.ts --provider anthropic --model claude-sonnet-4-20250514
47
+
48
+ # Analyze your project for untested files
49
+ npx testpilot analyze
50
+
51
+ # Use local models with Ollama (no API key needed)
52
+ npx testpilot src/utils.ts --provider ollama --model llama3
53
+ ```
54
+
55
+ ## The Verify & Auto-Fix Loop
56
+
57
+ The killer feature. With `--verify`, testpilot-ai doesn't just generate tests — it **runs them and fixes failures automatically**:
58
+
59
+ ```bash
60
+ npx testpilot src/utils.ts --verify
61
+ ```
62
+
63
+ ```
64
+ ⚡ testpilot — AI-powered test generation
65
+
66
+ Provider: openai (gpt-4o)
67
+ Framework: vitest
68
+ Verify & fix: enabled
69
+
70
+ ● Generating tests for utils.ts...
71
+
72
+ ✔ wrote src/utils.test.ts
73
+ ▶ Verify iteration 1/3...
74
+ ⚠ 3/12 tests failed — sending to LLM for auto-fix...
75
+ ▶ Verify iteration 2/3...
76
+ ✔ All 12 tests pass!
77
+
78
+ Done! Generated 12 tests across 1 file(s)
79
+ ✔ All tests verified and passing
80
+ ```
81
+
82
+ The loop:
83
+ 1. **Generate** tests using AST analysis + LLM
84
+ 2. **Run** them with your test framework
85
+ 3. **Collect** failures with error messages and stack traces
86
+ 4. **Send** failures back to the LLM: "here's the source code, here's the failing test, here's the error — fix it"
87
+ 5. **Write** the fixed tests and **repeat** (up to 3 iterations by default)
88
+
89
+ ## Analyze Your Project
90
+
91
+ Find files that need tests, optionally using coverage data:
92
+
93
+ ```bash
94
+ npx testpilot analyze
95
+ ```
96
+
97
+ ```
98
+ ⚡ testpilot analyze
99
+
100
+ Coverage: 67.3% (1240/1842 lines)
101
+ Target: 80%
102
+ Files: 23
103
+
104
+ Files below target:
105
+
106
+ File Coverage Tests?
107
+ ──────────────────────────────────────────────────────
108
+ src/utils/parser.ts 12.5% no
109
+ src/services/auth.ts 34.2% yes
110
+ src/handlers/webhook.ts 45.0% no
111
+ src/middleware/cors.ts 61.8% yes
112
+
113
+ Generate tests: testpilot generate <file> --verify
114
+ ```
115
+
116
+ If no coverage data exists, it scans for source files without corresponding test files.
117
+
118
+ ## CLI Reference
119
+
120
+ ```
121
+ Usage: testpilot [options] [command]
122
+
123
+ Commands:
124
+ generate <target> Generate tests for a file or directory (default)
125
+ analyze Analyze project for files needing tests
126
+ help [command] Display help
127
+
128
+ Generate Options:
129
+ -p, --provider <provider> LLM provider (openai, anthropic, google, ollama)
130
+ -m, --model <model> Model to use
131
+ -k, --api-key <key> API key (or use env var)
132
+ -f, --framework <framework> Test framework: vitest, jest, mocha, node
133
+ -o, --out-dir <dir> Output directory for test files
134
+ --overwrite Overwrite existing test files
135
+ --verify Run tests and auto-fix failures
136
+ --fix-iterations <n> Max auto-fix iterations (default: 3)
137
+ --no-edge-cases Skip edge case tests
138
+ --no-error-handling Skip error handling tests
139
+ --instructions <text> Additional instructions for the LLM
140
+ --dry-run Preview without writing files
141
+ -V, --version Output the version number
142
+
143
+ Analyze Options:
144
+ -t, --target <rate> Coverage target (0-1, default: 0.8)
145
+ -l, --limit <n> Max files to show (default: 15)
146
+ ```
147
+
148
+ ## How It Works
149
+
150
+ ```
151
+ Source File → TS Analyzer → Import Context → Prompt Engine → LLM → Test Writer
152
+
153
+ ┌─── Verify Loop ───┐
154
+ │ Run → Fix → Run │
155
+ └───────────────────┘
156
+ ```
157
+
158
+ 1. **Analyze** — TypeScript compiler API extracts functions, classes, parameters, types, JSDoc
159
+ 2. **Context** — Follows relative imports to gather type definitions and related code
160
+ 3. **Prompt** — Builds rich prompts with exact import lines, parameter types, and source code
161
+ 4. **Generate** — Streams output from any LLM provider via [aiclientjs](https://www.npmjs.com/package/aiclientjs)
162
+ 5. **Write** — Strips markdown artifacts, writes clean test file
163
+ 6. **Verify** *(optional)* — Runs tests, collects failures, sends to LLM for fixing, repeats
164
+
165
+ ## Configuration
166
+
167
+ ```json
168
+ {
169
+ "provider": "anthropic",
170
+ "model": "claude-sonnet-4-20250514",
171
+ "framework": "vitest",
172
+ "edgeCases": true,
173
+ "errorHandling": true,
174
+ "maxTokens": 4096,
175
+ "temperature": 0.2
176
+ }
177
+ ```
178
+
179
+ Save as `autotest.config.json`, `.autotestrc`, or add to `package.json` under `"autotest"`.
180
+
181
+ **Priority:** CLI flags > Config file > package.json > Auto-detected framework > Defaults
182
+
183
+ ## Supported Providers
184
+
185
+ | Provider | Models | Env Variable |
186
+ |----------|--------|-------------|
187
+ | **OpenAI** | gpt-4o, gpt-4o-mini, o1 | `OPENAI_API_KEY` |
188
+ | **Anthropic** | claude-sonnet-4-20250514, claude-haiku | `ANTHROPIC_API_KEY` |
189
+ | **Google** | gemini-pro, gemini-1.5-pro | `GOOGLE_API_KEY` |
190
+ | **Ollama** | llama3, codellama, mistral | None (local) |
191
+
192
+ ## Programmatic API
193
+
194
+ ```typescript
195
+ import { generateTests, analyzeFile, resolveConfig } from '@amit641/testpilot-ai';
196
+
197
+ const config = resolveConfig({ provider: 'openai', model: 'gpt-4o' });
198
+
199
+ // Generate with verify & auto-fix
200
+ const result = await generateTests('src/utils.ts', config, {
201
+ verify: true,
202
+ maxFixIterations: 3,
203
+ onStatus: (msg) => console.log(msg),
204
+ });
205
+
206
+ console.log(`${result.testCount} tests, verified: ${result.verified}`);
207
+ ```
208
+
209
+ ## Architecture
210
+
211
+ ```
212
+ src/
213
+ ├── analyzer/ # TS AST analysis + import context gathering
214
+ ├── prompt/ # Framework-aware prompt generation
215
+ ├── llm/ # LLM client (via aiclientjs)
216
+ ├── writer/ # Output parser & file writer
217
+ ├── verify/ # Test runner + auto-fix loop
218
+ ├── coverage/ # LCOV & Cobertura coverage parsing
219
+ ├── frameworks/ # Vitest, Jest, Mocha, Node adapters
220
+ ├── config/ # Config resolution & merging
221
+ ├── generate.ts # Main orchestrator
222
+ ├── cli.ts # Commander-based CLI
223
+ ├── types.ts # Core types
224
+ └── index.ts # Public API
225
+ ```
226
+
227
+ ## License
228
+
229
+ MIT