git-impact-analyzer 0.1.0
A CLI tool to detect which tests are impacted by a git commit using AST parsing.
License: MIT
Requires Python: >=3.8

# Impact Analyzer

Impact Analyzer is a precision CLI tool for AI Engineers and DevOps teams to determine the "blast radius" of code changes.

Unlike simple regex-based tools, Impact Analyzer uses Abstract Syntax Trees (AST) via Tree-sitter to parse code structure. It maps Git diffs directly to the specific test functions they modify, reducing false positives.

## Key Features

- **AST-Powered Precision:** Parses code into syntax trees to identify exactly which test function (for example, lines 10–25) intersects with a git diff change.
- **Multi-Language Support:** Detects and parses Python, TypeScript/JavaScript, Go, and Java.
- **Smart Dependency Tracking:** Flags changes in helper or utility files as dependency modifications.
- **Auto-Cloning:** Accepts local paths or remote Git URLs and clones repos as needed.
- **Modern Tree-sitter:** Uses the standalone `tree-sitter` bindings.

## Installation

### Prerequisites

- Python 3.8+
- Git installed on your system

### Install from source (recommended for development)

```bash
git clone https://github.com/your-username/impact-analyzer.git
cd impact-analyzer
python3 -m venv venv
source venv/bin/activate
pip install -e .
```

The editable install exposes the `impact-analyzer` CLI and installs runtime dependencies such as `GitPython` and `tree-sitter`.

If you need additional Tree-sitter language grammars, either install a maintained package or load/build grammars at runtime using `tree_sitter` APIs.

## Usage

```bash
impact-analyzer --commit <SHA> --repo <PATH_OR_URL>
```

Arguments

| Argument | Required | Description |
|---|---:|---|
| `--commit` | Yes | Full or short SHA of the commit to analyze |
| `--repo` | Yes | Local path or remote git URL (https:// or git@) |

## Examples

Analyze a remote public repository (auto-clones):

```bash
impact-analyzer --commit 75cdcc5 --repo https://github.com/remote-public-repo
```

Analyze a local repository:

```bash
impact-analyzer --commit 45433fd --repo ./my-local-project
```

Analyze a private repository (include PAT in URL):

```bash
impact-analyzer --commit a1b2c3d --repo https://<YOUR_TOKEN>@github.com/your-org/private-repo.git
```

## Sample Output

```
--- Impact Analysis for 75cdcc5 ---

[ADDED] File: tests/tool-execution/session.spec.ts
  + Test: 'safeBash tool execution to get commit SHA'

[MODIFIED] Test: 'Filter sessions list by users' (Lines 45-62) in tests/sessions.spec.ts

[DEPENDENCY] Modified file (potential helper): src/utils/helpers.ts
```

## Architecture

- **Diff Extraction:** Uses `GitPython` to compare the target commit against its parent and extract exact changed line ranges.
- **Language Detection:** Uses file extensions to pick a Tree-sitter parser.
- **AST Querying:** Runs S-expression queries to locate test blocks (example: `(call_expression function: (identifier) @name (#eq? @name "test"))`).
- **Intersection Logic:** Computes whether changed line sets intersect discovered test ranges.

## Contributing

Contributions are welcome. To add support for a new language:

1. Add the language parser dependency to `pyproject.toml`.
2. Update `EXTENSION_MAP` in `src/impact_analyzer/languages.py`.
3. Add the Tree-sitter query in `get_query_for_language`.

## License

This project is licensed under the MIT License.