ai-test-cli
v0.3.1
Published
An autonomous AI software testing engineer that dynamically generates, evaluates, and auto-fixes test suites for complex codebases.
Maintainers
Readme
🌟 Why AI Test CLI?
Most AI coding tools just vomit boilerplate code and give up when tests fail. AI Test CLI is different. It is the first fully autonomous, Zero-Config QA agent that reads the room before it writes code.
- Zero-Config Contextual Style RAG: Whether your team uses
jest,vitest,mocha, or the nativenode:testrunner, the CLI automatically searches your workspace for existing tests, silently feeds them to the LLM as context, and flawlessly mimics your exact in-house importing, mocking, and assertion styles. No configuration required. - Agentic File Routing: Hate writing messy glob patterns in config files? Just add a plain-English instruction to
.aitestrc.json(e.g., "Save tests in a 'test' subfolder right next to the source file"), and the AI will dynamically resolve and route the generated test files to the perfect directory. - Autonomous Auto-Fixing (Self-Healing Loop): It actually runs the tests it writes. If they fail, it reads the error stack trace, maps it back to your source code, and dynamically applies patches until the pipeline turns green.
- Massive File Support: The Agentic Chunking Generator explores massive files function-by-function, incrementally building out coverage without blowing up LLM token limits.
- Bring Your Own Key (BYOK): Supports DeepSeek, OpenAI, Anthropic, Gemini, and Local Models (Ollama/LMStudio) via the Vercel AI SDK.
🚀 Quickstart
Install globally via npm:
npm install -g ai-test-cliInitialize the configuration in your project root. This creates an .aitestrc.json file.
aitest initSet your API key in your .env file, or set it in your environment:
# Depending on your chosen provider:
export DEEPSEEK_API_KEY="sk-..."
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-..."🛠️ Usage
Auto-Fix Broken Tests (Self-Healing)
Got a test suite that's failing because of broken mocks or outdated logic? Unleash the agentic fixer:
aitest fixThe AI will run your entire test suite, isolate the failures, analyze the error stack traces, and patch the broken test file until it turns green. (Note: The CLI currently handles fixing one failing file per run).
Generate Tests
Generate a test suite for a single file:
aitest generate --file src/controllers/userController.tsGenerate tests for your entire project (this will gracefully skip files that already have tests or lack testable logic):
aitest generate --allIterative Coverage: Run aitest generate --coverage to automatically run a coverage report, identify files missing branch coverage, and have the AI rewrite them for 100% coverage!
Generate Global Mocks
Mocking external dependencies (like Stripe or AWS) by hand is incredibly tedious. Tell the AI to read your package.json and generate global __mocks__:
aitest mock --dependenciesContinuous Integration (GitHub Action)
You can automate your team's debugging by dropping ai-test-cli directly into your GitHub Actions! If a developer breaks a test in a Pull Request, the Action will autonomously fix it.
Create .github/workflows/ai-test-fix.yml:
name: AI Test Auto-Fix
on: [pull_request]
jobs:
auto-fix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Dependencies
run: npm install
- name: Run AI Test CLI (Auto-Fix)
uses: aitesthq/cli@main
with:
provider: 'deepseek'
api_key: ${{ secrets.DEEPSEEK_API_KEY }}
command: 'fix'
- name: Create Pull Request with Fixes
uses: peter-evans/create-pull-request@v6
with:
title: "🤖 AI Test CLI: Auto-fixed broken tests"
commit-message: "chore: Auto-fixed broken tests via AI"Advanced Optional Inputs
You can lock down the action with enterprise-grade settings to completely override the developers' local .aitestrc.json configuration during the CI run:
- name: Run AI Test CLI (Auto-Fix)
uses: aitesthq/cli@main
with:
provider: 'custom'
api_key: 'not-needed-for-proxy'
command: 'fix'
model: 'gpt-4o' # Force a specific model in CI
max_loops: '10' # Allow up to 10 files to be fixed automatically
custom_headers: '{"X-Token": "${{ secrets.PROXY }}"}' # Safely inject secret headersGitLab CI (.gitlab-ci.yml)
ai-test-fix:
stage: test
image: node:20
script:
- npm install
- npm install -g ai-test-cli
- aitest fix --ci
variables:
DEEPSEEK_API_KEY: $DEEPSEEK_API_KEY
only:
- merge_requestsBitbucket Pipelines (bitbucket-pipelines.yml)
pipelines:
pull-requests:
'**':
- step:
name: AI Test Auto-Fix
image: node:20
script:
- npm install
- npm install -g ai-test-cli
- aitest fix --ci🎨 Now available for VS Code!
Prefer a beautiful graphical interface over the terminal? We just launched AI Test Studio for VS Code! It bundles the entire AI Test CLI engine into a stunning native sidebar with inline diff previews and 1-click test generation.
📄 License
MIT License. See LICENSE for more information.
