Skip to content

Commit c62d4c5

Browse files
committed
feat: improve prompt
1 parent f99b489 commit c62d4c5

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

src/mutahunter/core/llm_mutation_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def generate_mutant(self, repo_map_result):
5454
covered_lines=self.executed_lines,
5555
example_output=self.prompt.example_output,
5656
function_block=function_block_with_line_num,
57-
maximum_num_of_mutants_per_function_block=3,
57+
maximum_num_of_mutants_per_function_block=2,
5858
)
5959
prompt = {
6060
"system": system_template,

src/mutahunter/core/prompts/system.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
11
SYSTEM_PROMPT = """
2-
You are an AI Agent part of the Software Quality Assurance Team. Your task is to mutate the {{language}} code provided to you. You will be provided with the Abstract Syntax Tree (AST) of the source code for contextual understanding. This AST will help you understand the entire source code. Make sure to read the AST before proceeding with the mutation.
2+
You are an AI Agent part of the Software Quality Assurance Team. Your task is to mutate the {{language}} code provided to you. You will be provided with the Abstract Syntax Tree (AST) of the source code for contextual understanding. This AST will help you understand the entire source code. Make sure to read the AST before proceeding with the mutation.
3+
4+
## Mutation Focus Guidelines
5+
1. Modify Core Logic:
6+
- Conditional Statements: Introduce incorrect conditions (e.g., `if (a < b)` changed to `if (a <= b)`).
7+
- Loop Logic: Alter loop conditions to cause infinite loops or early termination.
8+
- Calculations: Introduce off-by-one errors or incorrect mathematical operations.
9+
10+
2. Alter Outputs:
11+
- Return Values: Change the expected return type (e.g., returning `null` instead of an object).
12+
- Response Formats: Modify response structure (e.g., missing keys in a JSON response).
13+
- Data Corruption: Return corrupted or incomplete data.
14+
15+
3. Change Method Calls:
16+
- Parameter Tampering: Pass incorrect or malicious parameters.
17+
- Function Replacement: Replace critical functions with no-op or harmful ones.
18+
- Dependency Removal: Omit critical method calls that maintain state or security.
19+
20+
4. Simulate Failures:
21+
- Exception Injection: Introduce runtime exceptions (e.g., `NullPointerException`, `IndexOutOfBoundsException`).
22+
- Resource Failures: Simulate failures in external resources (e.g., database disconnection, file not found).
23+
24+
5. Modify Data Handling:
25+
- Parsing Errors: Introduce parsing errors for data inputs (e.g., incorrect date formats).
26+
- Validation Bypass: Disable or weaken data validation checks.
27+
- State Alteration: Incorrectly alter object states, leading to inconsistent data.
28+
29+
6. Introduce Boundary Conditions:
30+
- Array Indices: Use out-of-bounds indices.
31+
- Parameter Extremes: Use extreme values for parameters (e.g., maximum integers, very large strings).
32+
- Memory Limits: Introduce large inputs to test memory handling.
33+
34+
7. Timing and Concurrency:
35+
- Race Conditions: Alter synchronization to create race conditions.
36+
- Deadlocks: Introduce scenarios that can lead to deadlocks.
37+
- Timeouts: Simulate timeouts in critical operations.
38+
39+
8. Remove Code Blocks:
40+
- Security Checks: Remove or bypass security checks (e.g., authentication, authorization).
41+
- Error Handling: Remove error handling blocks, causing unhandled exceptions.
42+
- Data Integrity Checks: Remove checks that ensure data consistency.
43+
44+
9. Replicate Known CVE Bugs:
45+
- Buffer Overflow: Introduce buffer overflows by manipulating array sizes.
46+
- SQL Injection: Allow unsanitized input to be passed to SQL queries.
47+
- Cross-Site Scripting (XSS): Introduce vulnerabilities that allow JavaScript injection in web responses.
48+
- Cross-Site Request Forgery (CSRF): Bypass anti-CSRF measures.
49+
- Path Traversal: Modify file access logic to allow path traversal attacks.
50+
- Insecure Deserialization: Introduce vulnerabilities in deserialization logic.
51+
- Privilege Escalation: Modify role-based access controls to allow unauthorized actions.
352
"""

src/mutahunter/core/prompts/user.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Mutants(BaseModel):
2525
{{function_block}}
2626
```
2727
28-
Generate 1~{{maximum_num_of_mutants_per_function_block}} mutants for the function block provided to you. Ensure that the mutants are semantically different from the original code. Focus on critical areas such as error handling, boundary conditions, and logical branches.
28+
Generate 1~{{maximum_num_of_mutants_per_function_block}} mutants for the function block provided to you. Ensure that the mutants are semantically different from the original code. Refer to the mutation guidelines provided in the system prompt for mutation focus areas. Each mutant should be a single mutation applied to the original code. Provide the mutated line along with a comment describing the mutation. Ensure that the mutated line is syntactically correct and does not introduce compilation errors.
2929
"""
3030

3131

@@ -46,7 +46,6 @@ class Mutants(BaseModel):
4646
- Improvement Recommendations: Suggestions for new or improved test cases to effectively target and eliminate the surviving mutants.
4747
4848
## Example Output:
49-
======
5049
### Vulnerable Code Areas
5150
**File:** `src/main/java/com/example/BankAccount.java`
5251
**Location:** Line 45

0 commit comments

Comments
 (0)