The Autofix plugin leverages LLM tools to fix code violations in your .NET projects running within automated CI/CD pipelines, based on a generated analysis report. dotTEST identifies violations, uses LLM integration to propose fixes for those violations, and verifies each proposed fix to ensure that all issues are fully resolved and no new problems are introduced. Successful fixes result in automatically created commits in the working branch of your project source control repository, enabling manual review and approval before merging.

The dotTEST Autofix Python script is located in <INSTALL_DIR>/integration/aider.

Prerequisites

The following are required to use this functionality:

  • Python 3.10-3.12

    with the following packages: 

    • -pytest8.3.4
    • -python-dotenv1.1.1
    • -setuptools75.8.1
    • -pydantic2.11.4
    • -aider-chat0.86.1

  • A version control system
  • A valid .NET solution file and an analysis report containing violations.

  • Your secret LLM provider API key

This feature depends on LLMs, which may produce inaccurate information

dotTEST Autofix Configuration

Preparing a Virtual Environment

We strongly recommend running the DottestAutoFix.py script inside a Python virtual environment to isolate it from your system-wide Python installation and prevent dependency conflicts.

Follow these steps to set up your virtual environment:

  1. Create a virtual environment:
    python -m venv venv
  2. Enter the virtual environment:
    CALL venv\Scripts\activate.bat
  3. Install the required dependencies:
    python -m pip install --upgrade pip
    pip install -r requirements.txt

Autofix Configuration Options

The DottestAutoFix.py script can be configured using environment variables or command-line arguments. Command-line arguments take precedence over environment variables when both are specified.

Below is the complete reference for all available configuration options:

OptionRequiredCLI ArgumentEnvironment VariableDefault ValueDescription
LLM API KeyYesN/A%PROVIDER%_API_KEY=<KEY>-Your secret LLM provider API key required by Aider. Replace %PROVIDER% with the provider of your choice. Learn more about providers and variables.
Solution FileYes--solution SOLUTIONN/A-Path to the .NET solution file. It must match the solution used for the baseline analysis report.
Baseline ReportYes--report XML_REPORT_PATHREPORT=<XML_REPORT_PATH>-Path to the dotTEST XML report containing violations to be fixed.
Fix LimitNo--fix-limit COUNTFIX_LIMIT=<COUNT>0 (no limit)Maximum number of violation fix attempts per run.
Max AttemptsNo--max-attempts MAX_ATTEMPTSN/A3Maximum retry attempts per violation before stopping.
Model NameNoN/AMODEL_NAME=MODELgpt-4o-miniAI model for fixing violations (e.g., gpt-4, gpt-4o, claude-3-sonnet). Use aider --list-models <fragment> to see the available models.
Weak Model NameNoN/AWEAK_MODEL_NAME=MODEL-Lightweight model for auxiliary tasks, such as commit message generation. When not specified, it defaults to the specified model name (MODEL_NAME).
Tool HomeNo--tool-home DOTTESTCLI_DIRTOOL_HOME=<DOTTESTCLI_DIR>dottestcli directoryPath to the dotTEST installation directory (containing dottestcli.exe).
Lint Command FileNoN/ALINT_COMMAND_FILE=<PATH>lint_commandPath to a custom command file for dottestcli arguments. Only needed if the file is outside the current working directory. See the Lint (dottestcli) Execution Customization section for details.
Verification CommandNo--verification-command COMMANDN/A-Command to verify code integrity after each fix (e.g., "dotnet build"). Success is determined by exit code (0 = success).
No Source ControlNo--allow-no-source-controlN/ADisabledBypass source control warnings. Use with caution - changes will be made without version control.
HelpNo-h or --helpN/AN/ADisplay help information for the DottestAutoFix.py script.

Configuring the Environment

You can use the provided .env.template file as a starting point to create your own .env file with the necessary environment variables.

The .env file will be searched for in the following order:

  1. Current working directory - The directory from which you execute the script
  2. Script directory - The directory containing the CliAutoFix.py file

This allows you to have project-specific environment configurations by placing a .env file in your project directory, while maintaining a default configuration in the script's location.

Customizing the Data Directory

You can customize where fix history and log files are stored by setting the PARASOFT_AUTOFIX_DATA_DIR environment variable. By default, the script creates and uses a .cliAutoFix folder in your current working directory to store fix history and logs. If you set the PARASOFT_AUTOFIX_DATA_DIR environment variable, the script will use the specified directory instead. This can be useful for centralizing history and logs, sharing data between runs, or keeping your project directory clean.

Example:

SET PARASOFT_AUTOFIX_DATA_DIR=C:\my\custom\autofix_data

Lint (dottestcli) Execution Customization

The Autofix script uses dotTEST CLI (dottestcli.exe) to re-analyze code files after applying fixes, ensuring that violations are properly resolved. You can customize the dottestcli execution by providing a custom command template file.

Using the lint_command File:

  1. Copy the lint_command.template file from the Autofix installation directory to your current working directory (where you run the DottestAutoFix script) and rename it to lint_command (remove the .template extension).

  2. Edit the lint_command file to match your project's requirements. The default template contains:

    -config "{config}"
    -solution "{solution}"
    -include "{file_path}"

    You can modify this file to add additional dottestcli arguments such as:

    • -noBuild for suppressing a build in dottestcli
    • -property for setting custom properties
    • -settings for specifying a custom .properties file
    • Any other dottestcli-supported arguments
  3. Use a custom location (optional). By default, the script automatically looks for lint_command in your current working directory. If you want to use a command file from a different location, set the LINT_COMMAND_FILE environment variable:

    SET LINT_COMMAND_FILE=C:\path\to\your\custom_lint_command.txt

Running Autofix

Before running the Autofix script, we recommend creating a dedicated branch for the automated fixes. This allows you to review and test all changes before merging them into your main branch.

  1. Set your API key:
    SET OPENAI_API_KEY=your_secret_open_ai_key
  2. Execute Autofix with the recommended settings:

python DottestAutoFix.py
 --report ".dottest/report/report.xml"
 --max-attempts 3
 --solution BankExample.sln
 --tool-home "C:\Program Files\Parasoft\dotTEST\2025.2"

To ensure accurate results and efficient use of the Autofix plugin, follow these best practices:

Generate a new baseline after each Autofix session: Code changes made during the autofix process can alter file line numbers and structure, making the violation locations in your original report.xml obsolete. Regenerate your baseline report to ensure it accurately reflects your updated codebase.

Fix history tracking: The script creates data files in the .cliAutoFix folder to track fix attempts and outcomes in *.history.yaml files.

Preserve history: To avoid re-attempting the same violations:

  • Preserve the .cliAutoFix folder and its *.history.yaml files between runs.
  • Alternatively, ensure all attempted violations are either fixed or suppressed before the next run.

Reviewing Results

After each successful fix, the Autofix script creates a commit in your repository. Since AI-generated code may contain errors or suboptimal solutions, it is crucial to review all changes carefully.

Follow these best practices when reviewing AI-generated fixes:

  • Read the commit messages - Understand what changes were made and why.
  • Test the changes - Ensure the fix resolves the violation without introducing new issues.
  • Check the code quality - Verify that the fix follows your team's coding standards.
  • Apply incremental fixes - For minor issues in otherwise good fixes, create separate commits with manual corrections.
  • Revert when necessary - If a fix is fundamentally wrong, revert the entire commit.
  • Use a branching strategy - Work on a feature branch and merge after review, or cherry-pick verified commits.

Troubleshooting

If you encounter any issues while running the script, ensure that:

  • All dependencies are correctly installed
  • Environment variables are properly configured
  • All required CLI parameters are properly passed

  • No labels