@theihtisham/ai-testgen 1.0.0 → 1.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/.editorconfig +12 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +43 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +33 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +18 -0
- package/.github/dependabot.yml +12 -0
- package/.github/workflows/ci.yml +38 -0
- package/.github/workflows/release.yml +23 -0
- package/CODE_OF_CONDUCT.md +27 -0
- package/CONTRIBUTING.md +50 -0
- package/Dockerfile +8 -0
- package/README.md +186 -334
- package/SECURITY.md +22 -0
- package/package.json +12 -8
package/.editorconfig
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: Bug Report
|
|
2
|
+
description: Report a bug or unexpected behavior
|
|
3
|
+
labels: [bug]
|
|
4
|
+
body:
|
|
5
|
+
- type: textarea
|
|
6
|
+
id: description
|
|
7
|
+
attributes:
|
|
8
|
+
label: Bug Description
|
|
9
|
+
description: What happened?
|
|
10
|
+
placeholder: "When I run agent-memory..."
|
|
11
|
+
validations:
|
|
12
|
+
required: true
|
|
13
|
+
|
|
14
|
+
- type: textarea
|
|
15
|
+
id: steps
|
|
16
|
+
attributes:
|
|
17
|
+
label: Steps to Reproduce
|
|
18
|
+
description: How can we reproduce this?
|
|
19
|
+
placeholder: "1. Install...\n2. Configure...\n3. Run..."
|
|
20
|
+
validations:
|
|
21
|
+
required: true
|
|
22
|
+
|
|
23
|
+
- type: textarea
|
|
24
|
+
id: expected
|
|
25
|
+
attributes:
|
|
26
|
+
label: Expected Behavior
|
|
27
|
+
description: What should have happened?
|
|
28
|
+
validations:
|
|
29
|
+
required: true
|
|
30
|
+
|
|
31
|
+
- type: textarea
|
|
32
|
+
id: environment
|
|
33
|
+
attributes:
|
|
34
|
+
label: Environment
|
|
35
|
+
description: Node version, OS, etc.
|
|
36
|
+
placeholder: "Node 20.11.0, macOS 14, agent-memory 1.0.0"
|
|
37
|
+
|
|
38
|
+
- type: textarea
|
|
39
|
+
id: logs
|
|
40
|
+
attributes:
|
|
41
|
+
label: Relevant Logs
|
|
42
|
+
description: Paste any relevant log output
|
|
43
|
+
render: shell
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Feature Request
|
|
2
|
+
description: Suggest a new feature or enhancement
|
|
3
|
+
labels: [enhancement]
|
|
4
|
+
body:
|
|
5
|
+
- type: textarea
|
|
6
|
+
id: problem
|
|
7
|
+
attributes:
|
|
8
|
+
label: Problem
|
|
9
|
+
description: What problem does this feature solve?
|
|
10
|
+
placeholder: "I'm frustrated when..."
|
|
11
|
+
validations:
|
|
12
|
+
required: true
|
|
13
|
+
|
|
14
|
+
- type: textarea
|
|
15
|
+
id: solution
|
|
16
|
+
attributes:
|
|
17
|
+
label: Proposed Solution
|
|
18
|
+
description: How should it work?
|
|
19
|
+
validations:
|
|
20
|
+
required: true
|
|
21
|
+
|
|
22
|
+
- type: dropdown
|
|
23
|
+
id: type
|
|
24
|
+
attributes:
|
|
25
|
+
label: Feature Type
|
|
26
|
+
options:
|
|
27
|
+
- New Tool/Resource
|
|
28
|
+
- Performance Improvement
|
|
29
|
+
- Developer Experience
|
|
30
|
+
- Documentation
|
|
31
|
+
- Other
|
|
32
|
+
validations:
|
|
33
|
+
required: true
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
## Description
|
|
2
|
+
|
|
3
|
+
<!-- Brief description of changes -->
|
|
4
|
+
|
|
5
|
+
## Type of Change
|
|
6
|
+
|
|
7
|
+
- [ ] Bug fix
|
|
8
|
+
- [ ] New feature
|
|
9
|
+
- [ ] Breaking change
|
|
10
|
+
- [ ] Documentation update
|
|
11
|
+
- [ ] Refactor / cleanup
|
|
12
|
+
|
|
13
|
+
## Checklist
|
|
14
|
+
|
|
15
|
+
- [ ] Tests pass (`npm test`)
|
|
16
|
+
- [ ] Type checks pass (`npm run lint`)
|
|
17
|
+
- [ ] No secrets or credentials introduced
|
|
18
|
+
- [ ] Commit messages follow [conventional commits](https://www.conventionalcommits.org/)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build-and-test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
node-version: [18, 20, 22]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- name: Setup Node.js ${{ matrix.node-version }}
|
|
19
|
+
uses: actions/setup-node@v4
|
|
20
|
+
with:
|
|
21
|
+
node-version: ${{ matrix.node-version }}
|
|
22
|
+
cache: npm
|
|
23
|
+
- run: npm ci
|
|
24
|
+
- run: npm run lint
|
|
25
|
+
- run: npm test
|
|
26
|
+
- run: npm run build
|
|
27
|
+
|
|
28
|
+
coverage:
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
needs: build-and-test
|
|
31
|
+
steps:
|
|
32
|
+
- uses: actions/checkout@v4
|
|
33
|
+
- uses: actions/setup-node@v4
|
|
34
|
+
with:
|
|
35
|
+
node-version: 20
|
|
36
|
+
cache: npm
|
|
37
|
+
- run: npm ci
|
|
38
|
+
- run: npm run test:coverage
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
id-token: write
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-node@v4
|
|
16
|
+
with:
|
|
17
|
+
node-version: 20
|
|
18
|
+
registry-url: https://registry.npmjs.org
|
|
19
|
+
- run: npm ci
|
|
20
|
+
- run: npm run build
|
|
21
|
+
- run: npm publish --provenance --access public
|
|
22
|
+
env:
|
|
23
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone.
|
|
6
|
+
|
|
7
|
+
## Our Standards
|
|
8
|
+
|
|
9
|
+
Examples of behavior that contributes to a positive environment:
|
|
10
|
+
- Demonstrating empathy and kindness toward other people
|
|
11
|
+
- Being respectful of differing opinions, viewpoints, and experiences
|
|
12
|
+
- Giving and gracefully accepting constructive feedback
|
|
13
|
+
- Accepting responsibility and apologizing to those affected by our mistakes
|
|
14
|
+
|
|
15
|
+
Examples of unacceptable behavior:
|
|
16
|
+
- The use of sexualized language or imagery
|
|
17
|
+
- Trolling, insulting or derogatory comments
|
|
18
|
+
- Public or private harassment
|
|
19
|
+
- Publishing others' private information without explicit permission
|
|
20
|
+
|
|
21
|
+
## Enforcement
|
|
22
|
+
|
|
23
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to **Theihtisham@outlook.com**.
|
|
24
|
+
|
|
25
|
+
## Attribution
|
|
26
|
+
|
|
27
|
+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/), version 2.1.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Contributing to AI TestGen
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing!
|
|
4
|
+
|
|
5
|
+
## Development Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/theihtisham/ai-testgen.git
|
|
9
|
+
cd ai-testgen
|
|
10
|
+
npm install
|
|
11
|
+
npm run build
|
|
12
|
+
npm test
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Project Structure
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
src/
|
|
19
|
+
cli.ts — Commander CLI entry point
|
|
20
|
+
generator.ts — Test generation engine
|
|
21
|
+
analyzer.ts — Source code analysis (ts-morph)
|
|
22
|
+
config.ts — Configuration loading
|
|
23
|
+
language.ts — Multi-language support
|
|
24
|
+
file-utils.ts — File system utilities
|
|
25
|
+
coverage.ts — Coverage analysis
|
|
26
|
+
watcher.ts — File watcher for incremental mode
|
|
27
|
+
incremental.ts — Incremental test generation
|
|
28
|
+
mutation.ts — Mutation testing utilities
|
|
29
|
+
tests/ — Vitest test suite
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## How to Contribute
|
|
33
|
+
|
|
34
|
+
1. Fork the repository
|
|
35
|
+
2. Create a feature branch: `git checkout -b feature/my-feature`
|
|
36
|
+
3. Make changes and add tests
|
|
37
|
+
4. Run checks: `npm run lint && npm test`
|
|
38
|
+
5. Commit with [conventional commits](https://www.conventionalcommits.org/)
|
|
39
|
+
6. Push and open a Pull Request
|
|
40
|
+
|
|
41
|
+
## Adding New Language Support
|
|
42
|
+
|
|
43
|
+
1. Add language detection in `src/language.ts`
|
|
44
|
+
2. Add test template generator
|
|
45
|
+
3. Add tests in `tests/`
|
|
46
|
+
4. Update README
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
By contributing, you agree that your contributions will be licensed under the MIT License.
|
package/Dockerfile
ADDED
package/README.md
CHANGED
|
@@ -1,383 +1,235 @@
|
|
|
1
|
-
<
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
<a href="#installation">Install</a> ·
|
|
18
|
-
<a href="#quick-start">Quick Start</a> ·
|
|
19
|
-
<a href="#before--after">Before / After</a> ·
|
|
20
|
-
<a href="#configuration">Configuration</a> ·
|
|
21
|
-
<a href="#cli-reference">CLI</a>
|
|
22
|
-
</p>
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img width="100%" height="180" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 960 180'%3E%3Cdefs%3E%3ClinearGradient id='g' x1='0%25' y1='0%25' x2='100%25' y2='100%25'%3E%3Cstop offset='0%25' stop-color='%2300C853'/%3E%3Cstop offset='100%25' stop-color='%2338bdf8'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='960' height='180' fill='%230a0a1a' rx='16'/%3E%3Crect x='2' y='2' width='956' height='176' fill='none' stroke='url(%23g)' stroke-width='2' rx='15'/%3E%3Ctext x='480' y='75' text-anchor='middle' fill='white' font-family='system-ui' font-size='38' font-weight='bold'%3E%F0%9F%A7%AA AI TestGen%3C/text%3E%3Ctext x='480' y='115' text-anchor='middle' fill='%23a5a5c0' font-family='system-ui' font-size='18'%3EAI-Powered Test Generator for Any Language%3C/text%3E%3Ctext x='480' y='148' text-anchor='middle' fill='%236b6b88' font-family='monospace' font-size='13'%3ETypeScript %C2%B7 Python %C2%B7 Go %C2%B7 Java %C2%B7 C# %C2%B7 Mutation %C2%B7 Coverage %C2%B7 Watch%3C/text%3E%3C/svg%3E" alt="AI TestGen Banner"/>
|
|
4
|
+
|
|
5
|
+
[](https://github.com/theihtisham/ai-testgen/actions/workflows/ci.yml)
|
|
6
|
+
[](https://www.npmjs.com/package/@theihtisham/ai-testgen)
|
|
7
|
+
[](https://www.npmjs.com/package/@theihtisham/ai-testgen)
|
|
8
|
+
[](https://github.com/theihtisham/ai-testgen/stargazers)
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+
[](https://www.typescriptlang.org/)
|
|
11
|
+
|
|
12
|
+
**AI-powered test generator that reads your source code and produces comprehensive test suites — unit tests, integration tests, mutation tests, and coverage analysis across TypeScript, Python, Go, Java, and C#.**
|
|
13
|
+
|
|
14
|
+
[Quick Start](#-quick-start) · [CLI Commands](#-cli-commands) · [Architecture](#-architecture) · [Supported Languages](#-supported-languages)
|
|
15
|
+
|
|
16
|
+
</div>
|
|
23
17
|
|
|
24
18
|
---
|
|
25
19
|
|
|
26
|
-
##
|
|
27
|
-
|
|
28
|
-
### Language Support
|
|
29
|
-
- **TypeScript / JavaScript** — Full AST analysis via ts-morph, generates Jest or Vitest test suites
|
|
30
|
-
- **Python** — Regex-based AST analysis, generates pytest test suites
|
|
31
|
-
- **Go** — Struct-aware analysis, generates `go test` compatible files
|
|
32
|
-
- **Rust** — AI-powered generation (coming soon)
|
|
33
|
-
- Auto-detects language from file extension
|
|
34
|
-
|
|
35
|
-
### Test Generation
|
|
36
|
-
- **Unit Tests** — Happy path, type checks, return value verification
|
|
37
|
-
- **Integration Tests** — Cross-module dependency analysis
|
|
38
|
-
- **Edge Case Tests** — Null/undefined, empty arrays, boundary values, NaN, Infinity, special characters
|
|
39
|
-
- **Error Path Tests** — Exception handling, error boundaries, async rejections
|
|
40
|
-
- **Mock Setup** — Auto-generated mocks for external dependencies
|
|
41
|
-
|
|
42
|
-
### Advanced Features
|
|
43
|
-
- **Mutation Testing** — Generates code mutants (arithmetic, comparison, logical, boolean, string) to verify test quality
|
|
44
|
-
- **Coverage Prediction** — Estimates line, branch, and function coverage before running tests
|
|
45
|
-
- **Multi-file Analysis** — Builds dependency graphs across your codebase
|
|
46
|
-
- **Incremental Mode** — Only generates tests for changed files (git-based or hash-based)
|
|
47
|
-
- **Watch Mode** — Auto-generate tests on file save with configurable debounce
|
|
48
|
-
- **AI Enhancement** — Optional OpenAI integration for smarter test generation
|
|
49
|
-
- **Privacy Mode** — Sends only analysis metadata to AI, never raw source code
|
|
50
|
-
|
|
51
|
-
### Security First
|
|
52
|
-
- No code sent to external APIs unless explicitly configured
|
|
53
|
-
- Local AST analysis is the default
|
|
54
|
-
- API keys via environment variables only
|
|
55
|
-
- Privacy mode strips source code before AI calls
|
|
56
|
-
|
|
57
|
-
## Installation
|
|
20
|
+
## Why AI TestGen?
|
|
58
21
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
22
|
+
Writing tests is tedious. AI TestGen reads your source code, understands the structure, and generates meaningful tests — not just boilerplate, but tests that actually exercise edge cases and validate behavior.
|
|
23
|
+
|
|
24
|
+
### What Makes This Different
|
|
25
|
+
|
|
26
|
+
| Feature | AI TestGen | GitHub Copilot | Quicktype |
|
|
27
|
+
|---------|-----------|---------------|-----------|
|
|
28
|
+
| Source Analysis | Deep AST parsing (ts-morph) | Inline suggestions | Schema-based |
|
|
29
|
+
| Multi-Language | TS, Python, Go, Java, C# | All languages | JSON only |
|
|
30
|
+
| Test Types | Unit, Integration, Mutation, Coverage | Manual | N/A |
|
|
31
|
+
| Watch Mode | Auto-generate on file change | No | No |
|
|
32
|
+
| Incremental | Only regenerate changed files | No | No |
|
|
33
|
+
| Mutation Testing | Built-in mutation score | External tool | No |
|
|
34
|
+
| Coverage Analysis | Integrated coverage report | External tool | No |
|
|
35
|
+
| Config File | `.testgenrc.yml` per project | N/A | N/A |
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Architecture
|
|
40
|
+
|
|
41
|
+
```mermaid
|
|
42
|
+
graph TD
|
|
43
|
+
subgraph "Input"
|
|
44
|
+
SRC[Source Files<br/>.ts .py .go .java .cs]
|
|
45
|
+
CFG[Config File<br/>.testgenrc.yml]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
subgraph "AI TestGen Engine"
|
|
49
|
+
CLI[CLI<br/>Commander]
|
|
50
|
+
ANA[Analyzer<br/>ts-morph AST Parser]
|
|
51
|
+
LNG[Language Module<br/>Multi-language Templates]
|
|
52
|
+
GEN[Generator<br/>AI + Template Engine]
|
|
53
|
+
MUT[Mutation Engine<br/>Test Quality Scoring]
|
|
54
|
+
COV[Coverage Analyzer<br/>Branch + Line Coverage]
|
|
55
|
+
WAT[File Watcher<br/>Incremental Mode]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
subgraph "Output"
|
|
59
|
+
TEST[Test Files<br/>Vitest / Pytest / Go Test]
|
|
60
|
+
RPT[Reports<br/>HTML / Console / JSON]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
CLI --> ANA
|
|
64
|
+
CLI --> CFG
|
|
65
|
+
SRC --> ANA
|
|
66
|
+
ANA --> LNG
|
|
67
|
+
LNG --> GEN
|
|
68
|
+
GEN --> TEST
|
|
69
|
+
GEN --> MUT
|
|
70
|
+
GEN --> COV
|
|
71
|
+
MUT --> RPT
|
|
72
|
+
COV --> RPT
|
|
73
|
+
WAT --> ANA
|
|
74
|
+
|
|
75
|
+
style CLI fill:#00C853,color:#fff
|
|
76
|
+
style GEN fill:#38bdf8,color:#fff
|
|
77
|
+
style TEST fill:#f472b6,color:#fff
|
|
78
|
+
```
|
|
65
79
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
80
|
+
### Generation Pipeline
|
|
81
|
+
|
|
82
|
+
```mermaid
|
|
83
|
+
sequenceDiagram
|
|
84
|
+
participant U as Developer
|
|
85
|
+
participant C as CLI
|
|
86
|
+
participant A as Analyzer
|
|
87
|
+
participant G as Generator
|
|
88
|
+
participant O as Output
|
|
89
|
+
|
|
90
|
+
U->>C: ai-testgen generate src/
|
|
91
|
+
C->>A: Parse source files
|
|
92
|
+
A->>A: Extract functions, classes, types
|
|
93
|
+
A->>A: Analyze control flow + branches
|
|
94
|
+
A->>G: Parsed AST + metadata
|
|
95
|
+
G->>G: Generate unit tests
|
|
96
|
+
G->>G: Generate integration tests
|
|
97
|
+
G->>G: Create mutation tests
|
|
98
|
+
G->>O: Write test files
|
|
99
|
+
O-->>U: Report: 42 tests, 87% coverage, 91% mutation score
|
|
69
100
|
```
|
|
70
101
|
|
|
102
|
+
---
|
|
103
|
+
|
|
71
104
|
## Quick Start
|
|
72
105
|
|
|
73
106
|
```bash
|
|
74
|
-
#
|
|
75
|
-
ai-testgen
|
|
107
|
+
# Install
|
|
108
|
+
npm install -g @theihtisham/ai-testgen
|
|
109
|
+
|
|
110
|
+
# Generate tests for a file
|
|
111
|
+
ai-testgen generate src/utils.ts
|
|
112
|
+
|
|
113
|
+
# Generate for entire project
|
|
114
|
+
ai-testgen generate src/ --recursive
|
|
76
115
|
|
|
77
|
-
#
|
|
78
|
-
ai-testgen
|
|
116
|
+
# Watch mode — auto-generate on changes
|
|
117
|
+
ai-testgen watch src/
|
|
79
118
|
|
|
80
|
-
#
|
|
119
|
+
# With coverage analysis
|
|
81
120
|
ai-testgen generate src/ --coverage
|
|
82
121
|
|
|
83
|
-
#
|
|
84
|
-
ai-testgen
|
|
122
|
+
# Mutation testing
|
|
123
|
+
ai-testgen mutate src/utils.test.ts
|
|
124
|
+
```
|
|
85
125
|
|
|
86
|
-
|
|
87
|
-
ai-testgen generate src/ --dry-run
|
|
126
|
+
---
|
|
88
127
|
|
|
89
|
-
|
|
90
|
-
ai-testgen init
|
|
128
|
+
## CLI Commands
|
|
91
129
|
|
|
92
|
-
|
|
93
|
-
ai-testgen analyze src/utils.ts
|
|
130
|
+
### `ai-testgen generate <path>`
|
|
94
131
|
|
|
95
|
-
|
|
96
|
-
ai-testgen watch src/
|
|
132
|
+
Generate test files for source code.
|
|
97
133
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
134
|
+
| Option | Description |
|
|
135
|
+
|--------|-------------|
|
|
136
|
+
| `--recursive` | Process directories recursively |
|
|
137
|
+
| `--framework` | Test framework: `vitest`, `jest`, `pytest`, `go-test`, `junit` |
|
|
138
|
+
| `--coverage` | Run coverage analysis after generation |
|
|
139
|
+
| `--output` | Output directory for test files |
|
|
140
|
+
| `--config` | Path to `.testgenrc.yml` |
|
|
101
141
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
### Before (your source code)
|
|
105
|
-
|
|
106
|
-
```typescript
|
|
107
|
-
// src/calculator.ts
|
|
108
|
-
export function divide(a: number, b: number): number {
|
|
109
|
-
if (b === 0) {
|
|
110
|
-
throw new Error('Division by zero');
|
|
111
|
-
}
|
|
112
|
-
return a / b;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export class Calculator {
|
|
116
|
-
private history: number[] = [];
|
|
117
|
-
|
|
118
|
-
add(a: number, b: number): number {
|
|
119
|
-
const result = a + b;
|
|
120
|
-
this.history.push(result);
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
async fetchRate(currency: string): Promise<number> {
|
|
125
|
-
const response = await fetch(`/api/rates/${currency}`);
|
|
126
|
-
return response.json();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
```
|
|
142
|
+
### `ai-testgen watch <path>`
|
|
130
143
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
it('divide throws on invalid input', () => {
|
|
161
|
-
expect(() => divide('not-a-number', null)).toThrow();
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('divide handles zero for b', () => {
|
|
165
|
-
// edge case: zero value
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('divide handles NaN for a', () => {
|
|
169
|
-
// edge case: NaN
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('divide handles negative number for b', () => {
|
|
173
|
-
// edge case: negative numbers
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
describe('Calculator', () => {
|
|
178
|
-
it('Calculator can be instantiated', () => {
|
|
179
|
-
const instance = new Calculator();
|
|
180
|
-
expect(instance).toBeInstanceOf(Calculator);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('Calculator.add works correctly', () => {
|
|
184
|
-
const instance = new Calculator();
|
|
185
|
-
const result = instance.add(42, 42);
|
|
186
|
-
expect(result).toBeDefined();
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it('Calculator.fetchRate handles async correctly', () => {
|
|
190
|
-
const instance = new Calculator();
|
|
191
|
-
const result = await instance.fetchRate('test-currency');
|
|
192
|
-
expect(result).toBeDefined();
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
```
|
|
144
|
+
Watch for file changes and regenerate tests incrementally.
|
|
145
|
+
|
|
146
|
+
### `ai-testgen mutate <test-path>`
|
|
147
|
+
|
|
148
|
+
Run mutation testing to evaluate test quality.
|
|
149
|
+
|
|
150
|
+
| Option | Description |
|
|
151
|
+
|--------|-------------|
|
|
152
|
+
| `--reporters` | Output: `console`, `html`, `json` |
|
|
153
|
+
| `--threshold` | Minimum mutation score (default: 80) |
|
|
154
|
+
|
|
155
|
+
### `ai-testgen coverage <path>`
|
|
156
|
+
|
|
157
|
+
Analyze test coverage without generating tests.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Supported Languages
|
|
162
|
+
|
|
163
|
+
| Language | Framework | Analysis Depth |
|
|
164
|
+
|----------|-----------|---------------|
|
|
165
|
+
| **TypeScript** | Vitest, Jest | Full AST (ts-morph) |
|
|
166
|
+
| **Python** | pytest | Function/class analysis |
|
|
167
|
+
| **Go** | go test | Function analysis |
|
|
168
|
+
| **Java** | JUnit 5 | Method analysis |
|
|
169
|
+
| **C#** | xUnit, NUnit | Method analysis |
|
|
170
|
+
|
|
171
|
+
---
|
|
197
172
|
|
|
198
173
|
## Configuration
|
|
199
174
|
|
|
200
|
-
Create `.
|
|
175
|
+
Create `.testgenrc.yml` in your project root:
|
|
201
176
|
|
|
202
177
|
```yaml
|
|
203
|
-
language:
|
|
204
|
-
framework:
|
|
205
|
-
outputDir:
|
|
206
|
-
|
|
178
|
+
language: typescript
|
|
179
|
+
framework: vitest
|
|
180
|
+
outputDir: ./tests
|
|
207
181
|
coverage:
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
provider: openai # openai | anthropic | local | none
|
|
214
|
-
model: gpt-4o
|
|
215
|
-
apiKeyEnv: OPENAI_API_KEY
|
|
216
|
-
maxTokens: 4096
|
|
217
|
-
temperature: 0.2
|
|
218
|
-
privacyMode: true # never send raw source code
|
|
219
|
-
|
|
220
|
-
generation:
|
|
221
|
-
unitTests: true
|
|
222
|
-
integrationTests: true
|
|
223
|
-
edgeCaseTests: true
|
|
224
|
-
mockGeneration: true
|
|
225
|
-
mutationTesting: false
|
|
226
|
-
maxTestsPerFunction: 10
|
|
227
|
-
includeComments: true
|
|
228
|
-
|
|
229
|
-
incremental:
|
|
230
|
-
enabled: false
|
|
231
|
-
gitBased: true
|
|
232
|
-
cacheDir: .ai-testgen-cache
|
|
233
|
-
|
|
182
|
+
enabled: true
|
|
183
|
+
threshold: 80
|
|
184
|
+
mutation:
|
|
185
|
+
enabled: true
|
|
186
|
+
threshold: 75
|
|
234
187
|
watch:
|
|
235
|
-
|
|
236
|
-
ignorePatterns:
|
|
188
|
+
ignore:
|
|
237
189
|
- node_modules
|
|
238
190
|
- dist
|
|
239
191
|
- .git
|
|
240
|
-
- coverage
|
|
241
|
-
debounceMs: 300
|
|
242
|
-
|
|
243
|
-
exclude:
|
|
244
|
-
- node_modules/**
|
|
245
|
-
- dist/**
|
|
246
|
-
- coverage/**
|
|
247
|
-
- "**/*.d.ts"
|
|
248
|
-
|
|
249
|
-
include:
|
|
250
|
-
- src/**/*.{ts,tsx,js,jsx}
|
|
251
192
|
```
|
|
252
193
|
|
|
253
|
-
|
|
194
|
+
---
|
|
254
195
|
|
|
255
|
-
|
|
256
|
-
|---------|-------------|
|
|
257
|
-
| `ai-testgen generate <source>` | Generate test suites for source files |
|
|
258
|
-
| `ai-testgen init` | Create a sample `.aitestgen.yml` config |
|
|
259
|
-
| `ai-testgen watch <source>` | Watch mode — auto-generate on file changes |
|
|
260
|
-
| `ai-testgen mutation <source>` | Run mutation testing on a source file |
|
|
261
|
-
| `ai-testgen analyze <source>` | Analyze source code structure |
|
|
196
|
+
## Docker
|
|
262
197
|
|
|
263
|
-
|
|
198
|
+
```bash
|
|
199
|
+
docker build -t ai-testgen .
|
|
200
|
+
docker run -v $(pwd)/src:/app/src ai-testgen generate /app/src
|
|
201
|
+
```
|
|
264
202
|
|
|
265
|
-
|
|
266
|
-
|------|-------------|
|
|
267
|
-
| `-o, --output <dir>` | Output directory for test files |
|
|
268
|
-
| `-c, --config <path>` | Path to config file |
|
|
269
|
-
| `-l, --language <lang>` | Force language detection |
|
|
270
|
-
| `-f, --framework <fw>` | Force test framework |
|
|
271
|
-
| `--no-ai` | Disable AI generation (AST only) |
|
|
272
|
-
| `--dry-run` | Preview without writing files |
|
|
273
|
-
| `--coverage` | Show coverage prediction |
|
|
274
|
-
| `--mutation` | Run mutation testing |
|
|
275
|
-
| `-v, --verbose` | Verbose output |
|
|
203
|
+
---
|
|
276
204
|
|
|
277
|
-
##
|
|
205
|
+
## Development
|
|
278
206
|
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
+------------------+
|
|
286
|
-
|
|
|
287
|
-
v
|
|
288
|
-
+------------------+
|
|
289
|
-
| AST Analysis | ts-morph (JS/TS) or regex-based (Python/Go)
|
|
290
|
-
| - Functions | Extract: exports, params, types, complexity
|
|
291
|
-
| - Classes | Detect: side effects, throws, async
|
|
292
|
-
| - Interfaces |
|
|
293
|
-
+------------------+
|
|
294
|
-
|
|
|
295
|
-
v
|
|
296
|
-
+------------------+
|
|
297
|
-
| Edge Case Engine | Null, undefined, empty, NaN, boundary
|
|
298
|
-
| - Type analysis | Optional params, error paths
|
|
299
|
-
| - Boundary values |
|
|
300
|
-
+------------------+
|
|
301
|
-
|
|
|
302
|
-
v
|
|
303
|
-
+------------------+
|
|
304
|
-
| Test Generation | Framework-specific templates
|
|
305
|
-
| - Unit tests | Jest / Vitest / pytest / go test
|
|
306
|
-
| - Integration |
|
|
307
|
-
| - Mock setup |
|
|
308
|
-
+------------------+
|
|
309
|
-
|
|
|
310
|
-
v
|
|
311
|
-
+------------------+
|
|
312
|
-
| AI Enhancement | (Optional) Refine with OpenAI
|
|
313
|
-
| - Privacy mode | Only sends metadata, not source
|
|
314
|
-
+------------------+
|
|
315
|
-
|
|
|
316
|
-
v
|
|
317
|
-
Generated Test Suite (90%+ coverage estimate)
|
|
207
|
+
```bash
|
|
208
|
+
npm install
|
|
209
|
+
npm run build
|
|
210
|
+
npm test
|
|
211
|
+
npm run test:coverage
|
|
212
|
+
npm run lint
|
|
318
213
|
```
|
|
319
214
|
|
|
320
|
-
|
|
215
|
+
---
|
|
321
216
|
|
|
322
|
-
|
|
217
|
+
## Trending Tags
|
|
323
218
|
|
|
324
|
-
|
|
325
|
-
ai-testgen mutation src/calculator.ts
|
|
326
|
-
```
|
|
219
|
+
`test-generator` `ai` `unit-testing` `integration-testing` `mutation-testing` `code-coverage` `typescript` `python` `golang` `java` `csharp` `vitest` `pytest` `developer-tools` `automation` `ast-parsing` `test-automation` `quality-assurance`
|
|
327
220
|
|
|
328
|
-
|
|
329
|
-
- **Arithmetic**: `+` -> `-`, `*` -> `/`
|
|
330
|
-
- **Comparison**: `===` -> `!==`, `>` -> `<=`
|
|
331
|
-
- **Logical**: `&&` -> `||`
|
|
332
|
-
- **Boolean**: `true` -> `false`
|
|
333
|
-
- **String**: `"hello"` -> `""`
|
|
221
|
+
---
|
|
334
222
|
|
|
335
|
-
##
|
|
223
|
+
## License
|
|
336
224
|
|
|
337
|
-
|
|
338
|
-
ai-testgen/
|
|
339
|
-
src/
|
|
340
|
-
analyzers/ # Language-specific AST analysis
|
|
341
|
-
js-ts-analyzer.ts # TypeScript/JavaScript via ts-morph
|
|
342
|
-
python-analyzer.ts# Python regex-based analysis
|
|
343
|
-
go-analyzer.ts # Go regex-based analysis
|
|
344
|
-
analyzer.ts # Unified interface + edge cases + mocks
|
|
345
|
-
generators/ # Test code generation
|
|
346
|
-
js-ts-generator.ts# Jest/Vitest test generation
|
|
347
|
-
python-generator.ts# pytest test generation
|
|
348
|
-
go-generator.ts # go test generation
|
|
349
|
-
ai-generator.ts # OpenAI-powered generation
|
|
350
|
-
mutation/ # Mutation testing
|
|
351
|
-
mutator.ts # Mutant generation and scoring
|
|
352
|
-
watcher/ # File watching
|
|
353
|
-
watcher.ts # fs.watch wrapper with debounce
|
|
354
|
-
config/ # Configuration management
|
|
355
|
-
defaults.ts # Default config values
|
|
356
|
-
loader.ts # YAML/JSON config loader
|
|
357
|
-
utils/ # Shared utilities
|
|
358
|
-
language.ts # Language/framework detection
|
|
359
|
-
logger.ts # Colored console output
|
|
360
|
-
file.ts # File I/O helpers
|
|
361
|
-
types.ts # TypeScript type definitions
|
|
362
|
-
coverage.ts # Coverage prediction
|
|
363
|
-
incremental.ts # Incremental mode cache
|
|
364
|
-
cli.ts # CLI entry point
|
|
365
|
-
index.ts # Public API exports
|
|
366
|
-
tests/ # Vitest test suite
|
|
367
|
-
```
|
|
225
|
+
MIT License — see [LICENSE](LICENSE) for details.
|
|
368
226
|
|
|
369
|
-
|
|
227
|
+
---
|
|
370
228
|
|
|
371
|
-
|
|
372
|
-
- **ts-morph** — AST parsing for TypeScript/JavaScript
|
|
373
|
-
- **commander** — CLI framework
|
|
374
|
-
- **chalk** — Terminal colors
|
|
375
|
-
- **ora** — Loading spinners
|
|
376
|
-
- **js-yaml** — YAML config parsing
|
|
377
|
-
- **openai** — Optional AI enhancement
|
|
378
|
-
- **fast-glob** — File pattern matching
|
|
379
|
-
- **vitest** — Test framework
|
|
229
|
+
<div align="center">
|
|
380
230
|
|
|
381
|
-
|
|
231
|
+
**Built by [theihtisham](https://github.com/theihtisham)**
|
|
232
|
+
|
|
233
|
+
[GitHub](https://github.com/theihtisham) · [npm](https://www.npmjs.com/~theihtisham) · [Email](mailto:Theihtisham@outlook.com)
|
|
382
234
|
|
|
383
|
-
|
|
235
|
+
</div>
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
| Version | Supported |
|
|
6
|
+
| ------- | --------- |
|
|
7
|
+
| 1.x | Yes |
|
|
8
|
+
|
|
9
|
+
## Reporting a Vulnerability
|
|
10
|
+
|
|
11
|
+
If you discover a security vulnerability, please report it responsibly:
|
|
12
|
+
|
|
13
|
+
- **Email**: Theihtisham@outlook.com
|
|
14
|
+
- **Subject**: [Security] Vulnerability in ai-agent-memory
|
|
15
|
+
|
|
16
|
+
Please include:
|
|
17
|
+
1. Description of the vulnerability
|
|
18
|
+
2. Steps to reproduce
|
|
19
|
+
3. Potential impact
|
|
20
|
+
4. Suggested fix (if any)
|
|
21
|
+
|
|
22
|
+
We aim to respond within 48 hours and patch critical issues within 7 days.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theihtisham/ai-testgen",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "AI-powered test generator that creates comprehensive test suites from source code",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -30,8 +30,11 @@
|
|
|
30
30
|
"pytest",
|
|
31
31
|
"go-test"
|
|
32
32
|
],
|
|
33
|
-
"author": "",
|
|
33
|
+
"author": "theihtisham",
|
|
34
34
|
"license": "MIT",
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
35
38
|
"dependencies": {
|
|
36
39
|
"chalk": "^4.1.2",
|
|
37
40
|
"commander": "^12.1.0",
|
|
@@ -53,11 +56,12 @@
|
|
|
53
56
|
"engines": {
|
|
54
57
|
"node": ">=18.0.0"
|
|
55
58
|
},
|
|
56
|
-
"publishConfig": {
|
|
57
|
-
"access": "public"
|
|
58
|
-
},
|
|
59
59
|
"repository": {
|
|
60
60
|
"type": "git",
|
|
61
|
-
"url": "https://github.com/theihtisham/ai-testgen"
|
|
62
|
-
}
|
|
63
|
-
|
|
61
|
+
"url": "git+https://github.com/theihtisham/ai-testgen.git"
|
|
62
|
+
},
|
|
63
|
+
"bugs": {
|
|
64
|
+
"url": "https://github.com/theihtisham/ai-testgen/issues"
|
|
65
|
+
},
|
|
66
|
+
"homepage": "https://github.com/theihtisham/ai-testgen#readme"
|
|
67
|
+
}
|