Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test generation improvement #20

Merged
merged 30 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f9cfdb9
feat: get cov for file
jungs1 Aug 8, 2024
faf3abe
refactor: split file utils
jungs1 Aug 8, 2024
2dc6b59
refactor: improve unit test adding logic
jungs1 Aug 8, 2024
9fa897a
feat: java add test block scheme query
jungs1 Aug 9, 2024
b02c086
chore: update examples
jungs1 Aug 9, 2024
f92f386
fix: find src file dynamically
jungs1 Aug 9, 2024
739d4e2
chore: apply black
jungs1 Aug 9, 2024
bb66c94
fix: update coverage test
jungs1 Aug 9, 2024
43f3974
refactor: improve find_source_file method
jungs1 Aug 9, 2024
c5c5473
fix: allow none repomap
jungs1 Aug 9, 2024
992880a
feat: update mutant prompt
jungs1 Aug 9, 2024
e9a9705
feat: generate better report
jungs1 Aug 9, 2024
6c6f30f
refactor: minor refactor and add more validation
jungs1 Aug 9, 2024
29c5bcf
refactor: use jinja2 template for prompting
jungs1 Aug 9, 2024
c293e89
feat: more jinja2 refactoring
jungs1 Aug 9, 2024
2922655
refactor: remove debug print statements and unused code in llm_mutati…
jungs1 Aug 9, 2024
4cdff2e
feat: add prompt templates
jungs1 Aug 9, 2024
7a2a269
feat: update prompt for mutation testing test gen
jungs1 Aug 9, 2024
889731a
fix: line cov calculation
jungs1 Aug 9, 2024
566c5cd
refactor: unittest mutation prompt
jungs1 Aug 10, 2024
a177cf8
refactor: split code merging logic
jungs1 Aug 10, 2024
01cc3c6
refactor: optimize token counting in RepoMap.get_repo_map()
jungs1 Aug 10, 2024
3f907d5
refactor: update test_generator_user.txt to include language and test…
jungs1 Aug 10, 2024
420e5b1
refactor: update test_generator_user.txt to include language and test…
jungs1 Aug 10, 2024
424d1e2
refactor: Separate import and test node retrieval in Analyzer class
jungs1 Aug 10, 2024
59c2bac
refactor: update examples
jungs1 Aug 10, 2024
cb39b5c
refactor: update templates to include nested directories
jungs1 Aug 10, 2024
bea0f20
chore: remove init in templates
jungs1 Aug 10, 2024
54322b4
chore: apply black and linters
jungs1 Aug 10, 2024
9863a40
feat: add more tests
jungs1 Aug 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: generate better report
  • Loading branch information
jungs1 committed Aug 9, 2024
commit e9a9705c66c48e4c9c6a3cd9c3f9acca08228085
4 changes: 2 additions & 2 deletions src/mutahunter/core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from mutahunter.core.llm_mutation_engine import LLMMutationEngine
from mutahunter.core.logger import logger
from mutahunter.core.prompts.mutant_generator import (
SYSTEM_PROMPT_MUTANT_ANALYSUS,
SYSTEM_PROMPT_MUTANT_ANALYSIS,
USER_PROMPT_MUTANT_ANALYSIS,
)
from mutahunter.core.report import MutantReport
Expand Down Expand Up @@ -246,7 +246,7 @@ def run_mutant_analysis(self) -> None:
with open(k, "r", encoding="utf-8") as f:
src_code = f.read()
prompt = {
"system": Template(SYSTEM_PROMPT_MUTANT_ANALYSUS).render(),
"system": Template(SYSTEM_PROMPT_MUTANT_ANALYSIS).render(),
"user": Template(USER_PROMPT_MUTANT_ANALYSIS).render(
source_code=src_code,
surviving_mutants=json.dumps(v, indent=2),
Expand Down
91 changes: 63 additions & 28 deletions src/mutahunter/core/prompts/mutant_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,37 @@ class Mutants(BaseModel):
"""


SYSTEM_PROMPT_MUTANT_ANALYSUS = """
You are an AI Agent part of the Software Quality Assurance Team. Your task is to analyze the mutation testing results generated by the mutation testing tool. The tool has identified surviving mutants that were not detected by the existing test cases. Your goal is to provide a detailed analysis of these surviving mutants to improve the test coverage and code quality.
SYSTEM_PROMPT_MUTANT_ANALYSIS = """
You are a Senior Software Quality Assurance Analyst specializing in mutation testing. Your task is to analyze surviving mutants from recent mutation tests and produce a concise, professional report.

Objective: Evaluate test coverage gaps and code vulnerabilities based on surviving mutants.

Report Structure:
1. Executive Summary
2. Critical Findings
3. Detailed Analysis
a. Vulnerable Code Areas
b. Test Coverage Gaps
4. Recommendations
a. Test Suite Enhancements
b. Code Refactoring Suggestions
5. Risk Assessment
6. Conclusion

Guidelines:
- Maintain a formal, precise tone throughout the report.
- Prioritize findings based on potential impact and likelihood.
- Provide specific, actionable recommendations.
- Use clear, concise language to ensure accessibility for both technical and non-technical stakeholders.
- Include relevant code snippets and data to support your analysis.
- Limit the report to essential information that drives decision-making and action.

Your analysis should enable the development team to efficiently improve code quality and test coverage.
"""
USER_PROMPT_MUTANT_ANALYSIS = """
## Related Source Code:
Analyze the following mutation testing results and produce a concise, professional report:

## Source Code:
```
{{source_code}}
```
Expand All @@ -109,29 +135,38 @@ class Mutants(BaseModel):
```json
{{surviving_mutants}}
```

Based on the mutation testing results only showing the surviving mutants. Please analyze the following aspects:
## Vulnerable Code Areas:
1. Identify critical sections in the code that are most susceptible to undetected mutations.
2. Rank these areas by severity, considering factors such as frequency of occurrence and potential impact on functionality.
3. For each identified area, cite specific surviving mutant(s) as evidence.

## Test Case Gaps:
1. Provide concrete examples from the surviving mutants JSON for each identified gap.

## Improvement Recommendations:
1. Suggest specific new test cases or modifications to existing ones to target each surviving mutant.
2. Prioritize recommendations based on their potential impact and ease of implementation.
2. Where applicable, provide pseudo-code or test case outlines to illustrate the suggested improvements.

## Code Refactoring Suggestions:
1. Based on the surviving mutants, propose any potential code refactoring that could make the code more robust against mutations.
2. Explain how each refactoring suggestion would help in reducing the number of surviving mutants.

## Format Requirements:
1. Present the final output in concise bullet points.
2. Limit the entire analysis to no more than one page.
3. Ensure each point is supported by specific references to the surviving mutants JSON data.
4. Focus on the most critical findings and high-impact recommendations.
5. Output should be in markdown format for easy readability.
Report Structure:
1. Executive Summary (50 words)
Briefly outline key findings and their potential impact on software quality.
2. Critical Findings (100 words)
Highlight the most significant vulnerabilities and test gaps discovered.
3. Detailed Analysis (400 words)
a. Vulnerable Code Areas
- Identify and rank critical sections susceptible to undetected mutations.
- Cite specific surviving mutants as evidence.
b. Test Coverage Gaps
- Provide concrete examples from the surviving mutants for each gap.
4. Recommendations (300 words)
a. Test Suite Enhancements
- Suggest specific new test cases or modifications.
- Prioritize based on impact and implementation ease.
- Include pseudo-code or test case outlines where applicable.
b. Code Refactoring Suggestions
- Propose refactoring to improve mutation resistance.
- Explain how each suggestion reduces surviving mutants.
5. Risk Assessment (100 words)
Evaluate the potential impact of unaddressed vulnerabilities on system integrity and security.
6. Conclusion (50 words)
Summarize key actions needed to improve code quality and test coverage.

Format Requirements:

Use markdown for easy readability.
Limit the report to a maximum of 2 pages (approximately 1000 words).
Use concise bullet points where appropriate.
Support each point with specific references to the surviving mutants data.
Focus on critical findings and high-impact recommendations.
Maintain a professional tone throughout the report.

Ensure the report provides clear, actionable insights for both technical and non-technical stakeholders.
"""