๐๏ธ Integrating the Early CLI for Repository Coverage
The Early Repository CLI enables one-shot or scheduled test generation for individual files or entire folders โ ideal for boosting legacy coverage, validating a single module, or running scheduled cleanup jobs.
๐ง Setup Overviewโ
1. Install the CLIโ
- JavaScript / TypeScript
- Python
npm install -g @earlyai/cli
npm install -g @earlyai/cli
pip install py-agent
Both packages are required: @earlyai/cli is the main CLI, and py-agent is the Python test generation engine.
2. Configure Required Inputsโ
Use environment variables or CLI flags:
API_KEYโ Early API keyTOKENโ SCM tokenTARGET_DIRECTORYโ Path to scan (a single file or a directory, e.g.,src/utils/math.ts,src/utils/helpers.py, orsrc/)REF_NAMEโ Branch name
- JavaScript / TypeScript
- Python
Optional: AUTO_COMMIT, MAX_CONCURRENCY, NODE_OPTIONS, etc.
The CLI auto-detects Python projects from file extensions and project markers (pyproject.toml, setup.py, requirements.txt).
Optional: AUTO_COMMIT (default: true), AUTO_COMMIT_SKIP_CI, MAX_CONCURRENCY, GIT_USER_EMAIL, GIT_USER_NAME, etc.
When auto-commit is enabled, TOKEN must have write access and REF_NAME must be an existing branch โ these are used to push generated test files.
3. Run the CLIโ
early generate-for-project
๐งช GitHub Actions Exampleโ
- JavaScript / TypeScript
- Python
name: early-folder-coverage
on:
workflow_dispatch:
schedule:
- cron: "0 9 * * 1"
jobs:
folder-coverage:
runs-on: ubuntu-latest
permissions:
contents: write
packages: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
- name: Install dependencies
run: npm clean-install
- name: Install CLI
run: npm install -g @earlyai/cli
- name: Generate tests
env:
API_KEY: ${{ secrets.EARLY_API_KEY }}
TOKEN: ${{ secrets.REPO_TOKEN }}
TARGET_DIRECTORY: src/
REF_NAME: ${{ github.ref_name }}
NODE_OPTIONS: --max-old-space-size=5120
run: early generate-for-project
name: early-python-coverage
on:
workflow_dispatch:
schedule:
- cron: "0 9 * * 1"
jobs:
python-coverage:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install project dependencies
run: pip install -r requirements.txt
- name: Install Early CLI and py-agent
run: |
npm install -g @earlyai/cli
pip install py-agent
- name: Generate tests
env:
API_KEY: ${{ secrets.EARLY_API_KEY }}
TOKEN: ${{ secrets.REPO_TOKEN }}
TARGET_DIRECTORY: src/
REF_NAME: ${{ github.ref_name }}
run: early generate-for-project
๐งช Jenkins Exampleโ
- JavaScript / TypeScript
- Python
pipeline {
agent any
environment {
API_KEY = credentials('early-api-key')
TOKEN = credentials('github-pat-token')
NPM_TOKEN = credentials('github-npm-token')
TARGET_DIRECTORY = 'src/services'
REF_NAME = 'main'
NODE_OPTIONS = '--max-old-space-size=5120'
}
stages {
stage('Install Node.js') {
steps {
sh 'curl -fsSL https://deb.nodesource.com/setup_20.x | bash -'
sh 'apt-get install -y nodejs'
}
}
stage('Install CLI') {
steps {
sh 'npm install -g @earlyai/cli'
}
}
stage('Generate Folder Tests') {
steps {
sh 'early generate-for-project'
}
}
}
}
pipeline {
agent any
environment {
API_KEY = credentials('early-api-key')
TOKEN = credentials('github-pat-token')
TARGET_DIRECTORY = 'src/'
REF_NAME = 'main'
}
stages {
stage('Install Node.js') {
steps {
sh 'curl -fsSL https://deb.nodesource.com/setup_20.x | bash -'
sh 'apt-get install -y nodejs'
}
}
stage('Install CLI and py-agent') {
steps {
sh 'npm install -g @earlyai/cli'
sh 'pip install py-agent'
}
}
stage('Install Python Dependencies') {
steps {
sh 'pip install -r requirements.txt'
}
}
stage('Generate Tests') {
steps {
sh 'early generate-for-project'
}
}
}
}
โ Success Criteriaโ
- JavaScript / TypeScript
- Python
- New test files appear in the target folder
- Logs include coverage analysis and test generation
- Pipeline exits cleanly with no errors
- Coverage improves for previously low-tested areas
- New test files appear in
.early.test/sibling folders (e.g.,src/utils.early.test/test_my_func_early.py) - Logs show file scanning, function extraction, and test generation progress
- Generated test files are auto-committed and pushed to the branch (when
AUTO_COMMIT=true) - Pipeline exits cleanly with no errors