Testing Configurations Locally
Relevant source files
The following files were used as context for generating this wiki page:
Local testing ensures that PR-Agent settings and the autonomous fixer script function correctly before deployment to the GitHub environment. This process involves validating the .pr_agent.toml configuration and executing the autofix.py script to simulate code repairs and validation checks.
The project uses a central configuration model where settings from JWEB0689/pr-agent-settings are inherited by all repositories in the organization. Local testing allows you to verify how these global settings interact with repository-specific overrides and how the autonomous fixer handles different project layouts.
Sources: README.md:1-12, scripts/autofix.py:1-25
Autonomous Fixer Execution
The autofix.py script provides the primary mechanism for testing code repairs locally. It operates in two distinct modes: review-fix and ci-fix. When you run the script, it first attempts to resolve findings left by the AI reviewer. If no findings exist, it falls back to repairing CI build or test failures by running local test commands.
Execution Modes
| Mode | Trigger Condition | Action Taken |
|---|---|---|
| review-fix | PR-Agent review comments exist on the PR. | Fetches comments, sends file context to Gemini, and applies suggested fixes. |
| ci-fix | No review findings found. | Runs the local test runner; if it fails, sends errors and context to Gemini for repair. |
Sources: scripts/autofix.py:14-25, scripts/autofix.py:461-482
Logic Flow for Local Validation
The following diagram illustrates how the autofix.py script decides which repair path to take and how it validates changes locally.
The script uses subprocess.run to execute shell commands and urllib.request to interact with the Gemini and GitHub APIs.
Sources: scripts/autofix.py:47-60, scripts/autofix.py:461-482
Test Runner Detection
To test configurations locally, the script must identify the appropriate test runner for the repository. The detect_test_runner function inspects the project structure to determine the command and working directory.
| File Detected | Project Type | Command Executed |
|---|---|---|
v2/Cargo.toml | Rust (v2 subdir) | cargo check --workspace --no-default-features |
Cargo.toml | Rust (Root) | cargo check --workspace |
package.json | Node.js | npm test or npm run build |
pyproject.toml | Python | pytest -q |
go.mod | Go | go test ./... |
Sources: scripts/autofix.py:84-111
Environment Configuration
Before running the script locally, you must export specific environment variables. These variables simulate the GitHub Actions environment and provide the necessary credentials for API access.
export GEMINI_API_KEY="your_google_ai_key"
export REPO="owner/repo"
export PR_NUMBER="123"
export GH_TOKEN="your_github_pat"
The script defaults the GEMINI_MODEL to gemini-3.8-flash if not specified. It also uses origin/main as the default base reference for calculating git diffs.
Sources: scripts/autofix.py:31-41, scripts/autofix.py:448-458
Context Preparation
The script gathers context by reading modified files and extracting relevant paths from error logs. It limits context to a maximum of 12 files or 80,000 bytes per file to prevent exceeding LLM context windows.
- Modified Files: Identifies changes using
git diff --name-only. - Error Parsing: Extracts file paths and line numbers from compiler or runtime error strings using regex patterns.
- File Reading: Reads full contents of identified files into a JSON structure for the Gemini prompt.
Sources: scripts/autofix.py:63-81, scripts/autofix.py:121-135, scripts/autofix.py:382-392
Summary
Testing configurations locally allows developers to verify the autonomous repair logic and PR-Agent settings without triggering remote workflows. By utilizing the autofix.py script, you can simulate how the system detects project types, runs validation commands, and interacts with the Gemini API to resolve issues. Successful local execution results in a git commit and push, while failures trigger an automatic rollback to maintain repository integrity.
Sources: scripts/autofix.py:273-305, README.md:14-23