Skip to content

Bhavanishankar606/cortex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Nutest Cortex - Automated Test Bug Fixing System

Automated system that monitors Jira tickets with "nutest_cortex" label, uses AI (Cursor Premium) to analyze test failures, fixes issues in the nutest-py3-tests repository, and automatically creates Gerrit code reviews.

Features

  • πŸ€– AI-Powered Fix Generation: Uses Cursor Premium to automatically generate test fixes
  • πŸ“Š Learning System: Learns from code review feedback and human fixes to improve over time
  • πŸ”„ Iterative Fixes: Responds to CR comments with improved fixes
  • πŸ“ Comprehensive Commit Messages: Auto-generates detailed commit messages with fix summaries
  • πŸ” CR Monitoring: Continuously monitors Gerrit CRs for comments, votes, and updates
  • 🎯 Branch Mapping: Automatically maps Jira fixversions to Git branches

Architecture

The system consists of:

  1. Jira Webhook Listener - Monitors for tickets with "nutest_cortex" label
  2. Ticket Parser - Extracts ticket details, logs from description and attachments
  3. AI Fix Engine - Uses Cursor Premium to analyze failures and generate fixes
  4. Git Automation - Clones repo, applies fixes, commits, and pushes to Gerrit
  5. Branch Mapper - Maps Jira fixversion to Git branch using JSON config
  6. Status Reporter - Updates Jira ticket with progress and CR link
  7. Gerrit CR Monitor - Monitors CR comments and review votes (+1, +2, -1)
  8. Feedback Learning System - Learns from comments, reviews, and human fixes
  9. Iterative Fix Engine - Responds to CR comments with improved fixes

Prerequisites

  • Python 3.9+
  • Git
  • Cursor CLI installed (for AI fix generation)
  • Docker and Docker Compose (for Jira container, optional)
  • Access to:
    • Jira instance (or use Docker container)
    • Gerrit server
    • nutest-py3-tests repository

Installation

1. Clone Repository

git clone <repository_url>
cd nutest_cortex

2. Create Virtual Environment

python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

4. Configure Environment

Copy .env.example to .env and fill in your credentials:

cp .env.example .env

Edit .env with your values:

# Optional - will auto-detect if not set
CURSOR_CLI_PATH=/usr/local/bin/cursor
CURSOR_AGENT_PATH=/usr/local/bin/cursor-agent

# Required
GERRIT_USERNAME=your_username
GERRIT_PASSWORD=your_password
JIRA_API_TOKEN=your_jira_token
CURSOR_API_KEY=your_cursor_api_key

# Optional - defaults to /tmp/nutest_cortex
WORKSPACE_DIR=/tmp/nutest_cortex
LEARNING_DB_PATH=data/learning_db.sqlite

5. Configure Branch Mapping

Edit config/branch_mapping.json to map your fixversions to branches:

{
  "1.0.0": "master",
  "1.1.0": "release/1.1",
  "2.0.0": "release/2.0"
}

6. Configure Application Settings

Edit config/config.yaml with your Jira and Gerrit URLs.

Usage

Start the System

python main.py

The system will:

  1. Validate startup requirements (Cursor CLI, Git, etc.)
  2. Start the webhook server on port 8000
  3. Begin monitoring for Jira tickets with "nutest_cortex" label
  4. Start monitoring active Gerrit CRs

Using with Docker Jira (Optional)

If using the Docker Compose setup for Jira:

cd docker
docker-compose up -d

This will start:

Webhook Configuration

Configure Jira webhook to point to:

http://your-vm-ip:8000/webhook/jira

Webhook should trigger on:

  • Issue created
  • Issue updated

How It Works

  1. Ticket Detection: System receives webhook when ticket with "nutest_cortex" label is created/updated
  2. Ticket Parsing: Extracts test logs, error messages, and test file paths
  3. AI Fix Generation: Uses Cursor Premium to analyze failure and generate fix
  4. Fix Application: Clones repo, applies fix, generates commit message
  5. CR Creation: Pushes fix to Gerrit and creates code review
  6. Monitoring: Continuously monitors CR for comments and votes
  7. Learning: Stores feedback and learns patterns for future fixes
  8. Iterative Improvement: Responds to comments with improved fixes

Learning System

The system learns from:

  • CR Comments: Extracts actionable feedback
  • Review Votes: Tracks +1, +2, -1 patterns
  • Human Patches: Compares AI fixes vs human fixes when someone else fixes the CR
  • Jira Comments: Extracts feedback from ticket comments
  • CR Outcomes: Tracks which fixes get merged vs abandoned

Learned patterns are stored in SQLite database and used to improve future fixes.

Configuration

Branch Mapping

Edit config/branch_mapping.json to map Jira fixversions to Git branches.

Monitoring Settings

In config/config.yaml:

monitoring:
  poll_interval: 30  # seconds between polling Gerrit
  enable_learning: true
  max_iterative_fixes: 3  # max patch sets per CR

Learning Settings

learning:
  db_path: "data/learning_db.sqlite"
  enable_human_patch_learning: true
  enable_comment_learning: true
  enable_jira_comment_learning: true

Project Structure

nutest_cortex/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ jira_webhook.py      # Webhook listener
β”‚   β”œβ”€β”€ ticket_parser.py     # Parse ticket details
β”‚   β”œβ”€β”€ ai_fixer.py          # AI fix generation
β”‚   β”œβ”€β”€ git_automation.py    # Git operations
β”‚   β”œβ”€β”€ branch_mapper.py     # Branch mapping
β”‚   β”œβ”€β”€ status_reporter.py   # Jira status updates
β”‚   β”œβ”€β”€ gerrit_monitor.py    # CR monitoring
β”‚   β”œβ”€β”€ feedback_learner.py  # Learning system
β”‚   β”œβ”€β”€ fix_summarizer.py    # Commit message generation
β”‚   └── logging_config.py    # Logging setup
β”œβ”€β”€ data/
β”‚   └── learning_db.sqlite    # Learning database
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ branch_mapping.json  # Fixversion mappings
β”‚   └── config.yaml          # Configuration
β”œβ”€β”€ docker/
β”‚   └── docker-compose.yml   # Jira setup
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ main.py                  # Entry point
└── README.md

Troubleshooting

Cursor CLI Not Found

The system auto-detects Cursor CLI. If not found:

  1. Install Cursor CLI on your VM
  2. Set CURSOR_CLI_PATH and CURSOR_AGENT_PATH in .env

Git Authentication Issues

Ensure Gerrit credentials are correct in .env:

  • GERRIT_USERNAME
  • GERRIT_PASSWORD

Webhook Not Receiving Events

  1. Check Jira webhook configuration
  2. Verify webhook URL is accessible from Jira
  3. Check firewall settings
  4. Review logs for errors

Development

Running Tests

# Add test files and run
pytest tests/

Logging

Logs are written to:

  • Console (stdout)
  • logs/nutest_cortex.log (rotating, 10MB max, 5 backups)

Log level can be configured in main.py or via environment variable.

License

[Your License Here]

Contributing

[Contributing Guidelines]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages