Skip to content

Commit 1f6e840

Browse files
authored
Develop (#1)
* feat: allow for flexible mutation to mutate on entire codebase * feat: allow mutation on diff * chore: apply black, lint * fix: prompt enhancement * update docs * refactor: add more logging and assertions
1 parent 4100147 commit 1f6e840

40 files changed

+597
-5315
lines changed

README.md

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ MutaHunter leverages LLM models to inject context-aware faults into your codebas
3434

3535
Examples:
3636

37-
- [React Example](/examples/vite-react-testing-ts/)
3837
- [Go Example](/examples/go_webservice/)
3938
- [Java Example](/examples/java_maven/)
4039
- [JavaScript Example](/examples/js_vanilla/)
@@ -46,11 +45,11 @@ Feel free to add more examples! ✨
4645

4746
1. **AI-Driven Mutation Testing:** Mutahunter leverages advanced LLM models to inject context-aware faults into your codebase rather than blindly mutating the code. This allows the mutants to closely resemble real bugs.
4847
2. **Language Agnostic:** Mutahunter supports various programming languages and can be extended to work with any language that provides a coverage report in **Cobertura** XML format, **Jacoco** XML format, and **lcov** format.
49-
3. **Enhanced Mutation Coverage Report (experimental):** Mutahunter provides detailed mutation coverage reports, highlighting the effectiveness of your test suite and identifying potential weaknesses.
48+
3. **Diff-Based Mutation Testing:** Mutahunter can run mutation testing specifically on modified files and lines based on the latest commit or pull request changes. This feature optimizes the mutation testing process by focusing on recent changes.
49+
4. **Enhanced Mutation Coverage Report (WIP):** Mutahunter provides detailed mutation coverage reports, highlighting the effectiveness of your test suite and identifying potential weaknesses.
5050

5151
**Afraid of sending code to OpenAI or Anthropic? No problem, we support self-hosted versions as well.** 🔒
5252

53-
5453
## Installation and Usage
5554

5655
### Requirements
@@ -75,12 +74,19 @@ pip install git+https://github.com/codeintegrity-ai/mutahunter.git
7574

7675
### How to Execute Mutahunter
7776

78-
To use Mutahunter, you first need a **Cobertura XML**, **Jacoco XML**, or **lcov** code coverage report of a specific test file. Currently, mutation testing works per test file level, not the entire test suite. Therefore, you need to get the coverage report per test file.
77+
To use Mutahunter, you first need a **Cobertura XML**, **Jacoco XML**, or **lcov** code coverage report. **Make sure your test command correlates with the coverage report.**
7978

8079
Example command to run Mutahunter on a Python FastAPI [application](/examples/python_fastapi/):
8180

8281
```bash
83-
mutahunter run --test-command "pytest test_app.py" --test-file-path "test_app.py" --code-coverage-report-path "coverage.xml" --only-mutate-file-paths "app.py"
82+
mutahunter run --test-command "pytest test_app.py" --code-coverage-report-path "coverage.xml" --only-mutate-file-paths "app.py"
83+
# --only-mutate-file-paths makes it faster by focusing on specific files
84+
```
85+
86+
To run mutation testing specifically on modified files and lines based on the latest commit:
87+
88+
```bash
89+
mutahunter run --test-command "pytest test_app.py" --code-coverage-report-path "coverage.xml" --modified-files-only
8490
```
8591

8692
The mutahunter run command has the following options:
@@ -108,11 +114,6 @@ Options:
108114
Required: Yes
109115
Example: `--coverage-type cobertura`
110116
111-
--test-file-path <PATH>
112-
Description: Path to the test file to run the tests on.
113-
Required: Yes
114-
Example: `--test-file-path /path/to/test_file.py`
115-
116117
--exclude-files <FILES>
117118
Description: Files to exclude from analysis.
118119
Required: No
@@ -122,11 +123,10 @@ Options:
122123
Description: Specifies which files to mutate. This is useful when you want to focus on specific files and it makes the mutations faster!
123124
Required: No
124125
Example: `--only-mutate-file-paths file1.py file2.py`
125-
126-
--generate-report (experimental)
127-
Description: Generate a detailed report on identified weaknesses in the test suite and potential bugs not caught by the test suite.
126+
127+
--modified-files-only
128+
Description: Runs mutation testing only on modified files and lines based on the latest commit.
128129
Required: No
129-
Example: `--generate-report`
130130
```
131131

132132
#### Mutation Testing Report
@@ -148,29 +148,13 @@ An example survived mutant information would be like so:
148148
"mutant_path": "/Users/taikorind/Documents/personal/codeintegrity/mutahunter/logs/_latest/mutants/4_analyzer.py",
149149
"status": "SURVIVED",
150150
"error_msg": "",
151-
"test_file_path": "tests/test_analyzer.py",
152151
"diff": "for line in range(start_line, end_line + 1):
153152
- function_executed_lines.append(line - start_line + 1)
154153
+ function_executed_lines.append(line - start_line) # Mutation: Change the calculation of executed lines to start from 0 instead of 1.\n"
155154
},
156155
]
157156
```
158157

159-
Detailed report on identified weaknesses in the test suite and potential bugs not caught by the test suite:
160-
161-
Example report (**experimental*):
162-
163-
```markdown
164-
### Identified Weaknesses in the Test Suite
165-
1. **Callback Handling in `callback`**:
166-
- **Weakness**: The test suite does not test the `callback` function for different node types, including the newly added `class_definition`.
167-
- **Improvement**: Add tests to verify that the `callback` function correctly identifies and handles `class_definition` nodes, in addition to other node types.
168-
169-
### Potential Bugs Not Caught by the Test Suite
170-
1. **Callback Handling**:
171-
- **Bug**: The `callback` function might incorrectly handle or miss `class_definition` nodes, leading to incomplete or incorrect function block identification.
172-
```
173-
174158
## Roadmap
175159

176160
### Mutation Testing Capabilities

examples/go_webservice/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ gocov convert coverage.out | gocov-xml > coverage.xml
1717
## Running Mutahunter to analyze the tests
1818

1919
```bash
20-
mutahunter run --test-command "go test" --test-file-path "app_test.go" --code-coverage-report-path "coverage.xml" --only-mutate-file-paths "app.go"
20+
mutahunter run --test-command "go test" --code-coverage-report-path "coverage.xml" --only-mutate-file-paths "app.go" --model "claude-3-5-sonnet-20240620"
2121
```

examples/java_maven/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
## Generate test coverage report
44

55
```bash
6-
mvn test -DtestSourceDirectory=src/test/java/CalculatorTest.java
6+
mvn test
77
```
88

99
## Running Mutahunter to analyze the tests
1010

1111
Coverage report was already generated. Now, we will run Mutahunter to analyze the tests.
1212

1313
```bash
14-
mutahunter run --test-command "mvn test -DtestSourceDirectory=src/test/java/CalculatorTest.java -q" --test-file-path "src/test/java/CalculatorTest.java" --code-coverage-report-path "target/site/jacoco/jacoco.xml" --only-mutate-file-paths "src/main/java/com/example/Calculator.java" --coverage-type jacoco
14+
mutahunter run --test-command "mvn test" --code-coverage-report-path "target/site/jacoco/jacoco.xml" --coverage-type jacoco --model "claude-3-5-sonnet-20240620"
1515
```

examples/java_maven/src/main/java/com/example/Main.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/js_vanilla/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ npm run test:coverage
1212
## Running Mutahunter to analyze the tests
1313

1414
```bash
15-
mutahunter run --test-command "npm run test" --test-file-path "ui.test.js" --code-coverage-report-path "coverage/coverage.xml" --only-mutate-file-paths "ui.js"
15+
mutahunter run --test-command "npm run test" --code-coverage-report-path "coverage/coverage.xml" --only-mutate-file-paths "ui.js"
1616
```

examples/python_fastapi/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ This example is from CodiumAI’s cover-agent [repository](https://github.com/Co
66

77
```bash
88
pip install -r requirements.txt
9-
pytest --cov=app --cov-report=xml --cov-report=term
9+
pytest --cov=. --cov-report=xml --cov-report=term
1010
```
1111

1212
## Running Mutahunter to analyze the tests
1313

1414
```bash
15-
mutahunter run --test-command "pytest test_app.py" --test-file-path "test_app.py" --code-coverage-report-path "coverage.xml" --only-mutate-file-paths "app.py"
15+
mutahunter run --test-command "pytest" --code-coverage-report-path "coverage.xml" --only-mutate-file-paths "app.py"
1616
```

examples/python_fastapi/__init__.py

Whitespace-only changes.

examples/python_fastapi/tests/__init__.py

Whitespace-only changes.

examples/python_fastapi/test_app.py renamed to examples/python_fastapi/tests/test_app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import pytest
2-
from app import app
32
from fastapi.testclient import TestClient
43

4+
from ..app import app
5+
56
client = TestClient(app)
67

78

examples/vite-react-testing-ts/.gitignore

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)