Skip to content

PETROL-BOY/prompt-qa-validator

Repository files navigation

Prompt-QA-Validator

Automatically generate comprehensive, production-ready Jest test cases for your JavaScript functions using AI.

🚀 Features

  • Automated Test Generation: Analyzes JavaScript functions and creates ready-to-run Jest test suites.
  • Deep Edge Case Analysis: Identifies subtle bugs, security issues, and boundary conditions.
  • Flexible AI Backend: Supports OpenAI, Open Source Models (via compatible APIs), and Ollama.
  • Integrated Workflow: Parses code, generates tests, writes files, and runs them in one go.
  • Coverage Reports: Generated tests are configured to collect code coverage automatically.

🛠️ Installation

  1. Clone the repository

    git clone <repository-url>
    cd prompt-qa-validator
  2. Install dependencies

    npm install
  3. Configure Environment Duplicate .env.example to .env:

    cp .env.example .env
    # or on Windows
    copy .env.example .env

    Configure your LLM provider in .env:

    For OpenAI or Open Source Models (Compatible API):

    # For OpenAI
    OPENAI_API_KEY=sk-your-key
    OPENAI_MODEL=gpt-4
    
    # OR for Open Source Models (LocalAI, vLLM, LM Studio)
    # Point to your local server's API endpoint
    OPENAI_BASE_URL=http://localhost:1234/v1
    OPENAI_API_KEY=dummy-key
    OPENAI_MODEL=mistral-instruct  # or your OSS model name

    For Native Ollama:

    # Special handling for Ollama native API (detects /api suffix)
    OPENAI_BASE_URL=http://localhost:11434/api
    OPENAI_MODEL=llama3
    OPENAI_API_KEY=dummy

📖 Usage

Run with Example

Generate tests for the included sample functions:

npm run example
# OR
node src/index.js examples/sample-functions.js

Run on Your Code

Pass any JavaScript file path to the CLI:

node src/index.js ./path/to/your-file.js

Run Generated Tests

To run the generated tests separately:

npm test

🏗️ How It Works

  1. Parse: The tool reads your .js file and extracts function signatures and bodies.
  2. Analyze: An AI agent acts as a Code Analyzer to understand the purpose and constraints of each function.
  3. Generate: A separate "QA Engineer" agent writes comprehensive Jest test cases, covering happy paths, error cases, and edge cases.
  4. Execute: The tool writes the tests to generated-tests/ and immediately attempts to run them using Jest.

📂 Project Structure

prompt-qa-validator/
├── src/
│   ├── index.js             # Entry point
│   └── lib/
│       ├── testGenerator.js # Main orchestration logic
│       ├── llmClient.js     # Handles OpenAI/Ollama communication
│       ├── fileParser.js    # Extracts functions from code
│       └── prompts.js       # System and User prompts
├── examples/                # Sample code to test
├── generated-tests/         # Output directory for generated tests
└── jest.config.js           # Jest configuration

📝 License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors