Codium-ai / cover-agent

QodoAI Cover-Agent: An AI-Powered Tool for Automated Test Generation and Code Coverage Enhancement! ๐Ÿ’ป๐Ÿค–๐Ÿงช๐Ÿž
https://qodo.ai/
GNU Affero General Public License v3.0
4.37k stars 327 forks source link

Adding diff-cover and coverage based on branch #167

Closed blazar00 closed 1 month ago

blazar00 commented 1 month ago

PR Type

enhancement, tests


Description


Changes walkthrough ๐Ÿ“

Relevant files
Enhancement
CoverAgent.py
Add diff coverage support and logging enhancements             

cover_agent/CoverAgent.py
  • Added support for diff coverage in the coverage agent.
  • Implemented logic to handle diff coverage in the coverage run process.
  • Enhanced logging for diff coverage results.
  • +15/-3   
    CoverageProcessor.py
    Implement diff coverage report parsing                                     

    cover_agent/CoverageProcessor.py
  • Added method to parse diff coverage report.
  • Extracted total, missing lines, and coverage percentage from report.
  • +17/-0   
    PromptBuilder.py
    Add diff coverage flag to PromptBuilder                                   

    cover_agent/PromptBuilder.py - Introduced diff coverage flag in prompt builder.
    +1/-0     
    UnitTestGenerator.py
    Integrate diff coverage in UnitTestGenerator                         

    cover_agent/UnitTestGenerator.py
  • Added diff coverage functionality to unit test generator.
  • Implemented method to run diff coverage.
  • Enhanced logging for diff coverage results.
  • +46/-1   
    main.py
    Add CLI options for diff coverage                                               

    cover_agent/main.py - Added command-line arguments for diff coverage.
    +12/-0   
    app.py
    Add endpoint for current time in FastAPI app                         

    templated_tests/python_fastapi/app.py - Added a new endpoint to return current time in ISO format.
    +8/-0     
    Dependencies
    pyproject.toml
    Add diff-cover dependency                                                               

    pyproject.toml - Added `diff-cover` as a dependency.
    +1/-0     

    ๐Ÿ’ก PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    codiumai-pr-agent-pro[bot] commented 1 month ago

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Reviewer Guide ๐Ÿ”

    Here are some key observations to aid the review process:

    โฑ๏ธ Estimated effort to review: 3 ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ตโšชโšช
    ๐Ÿงช No relevant tests
    ๐Ÿ”’ No security concerns identified
    โšก Key issues to review

    Possible Bug
    Typo in variable name 'comparasion_branch' instead of 'comparison_branch' Possible Bug
    Typo in variable name 'comparasion_branch' instead of 'comparison_branch' Code Smell
    Unused variable 'time_of_test_command' in run_diff_coverage method Possible Bug
    Missing import for datetime module in the new get_time endpoint
    codiumai-pr-agent-pro[bot] commented 1 month ago

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions โœจ

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Improve variable naming for clarity and correctness ___ **Consider using a more descriptive variable name instead of comparasion_branch. The
    correct spelling is "comparison", and a more descriptive name could be base_branch
    or target_branch.** [cover_agent/CoverAgent.py [43]](https://github.com/Codium-ai/cover-agent/pull/167/files#diff-dac868643df79ec6dfcf446359468a88ba6a6617bb8ffa0139757f0fbf5195b1R43-R43) ```diff -comparasion_branch=args.branch, +base_branch=args.branch, ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: The suggestion corrects a spelling mistake and improves the variable name for clarity, which enhances code readability and maintainability.
    8
    Use a constant for the default branch name instead of hardcoding it ___ **Consider using a constant or configuration variable for the default branch name
    ("main") instead of hardcoding it in the method signature. This would make it easier
    to change the default branch name across the entire application if needed.** [cover_agent/UnitTestGenerator.py [34]](https://github.com/Codium-ai/cover-agent/pull/167/files#diff-19760582d9ede3a799fdbb541ad357b4822682e837bca8365196fba50daf57e3R34-R34) ```diff -comparasion_branch: str = "main", +comparasion_branch: str = DEFAULT_BRANCH, ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: Using a constant for the default branch name improves flexibility and maintainability, allowing for easier updates across the codebase if the default branch changes.
    7
    Enhancement
    Extract coverage check logic into separate methods for improved readability and maintainability ___ **Consider extracting the coverage check logic into a separate method to improve
    readability and maintainability. This would also make it easier to add more coverage
    types in the future if needed.** [cover_agent/CoverAgent.py [152-157]](https://github.com/Codium-ai/cover-agent/pull/167/files#diff-dac868643df79ec6dfcf446359468a88ba6a6617bb8ffa0139757f0fbf5195b1R152-R157) ```diff -if self.test_gen.current_coverage < (self.test_gen.desired_coverage / 100) and self.args.diff_coverage: - # Run the coverage tool again if the desired coverage hasn't been reached - self.test_gen.run_diff_coverage() -elif self.test_gen.current_coverage < (self.test_gen.desired_coverage / 100): - # Run the coverage tool again if the desired coverage hasn't been reached - self.test_gen.run_coverage() +if self._should_run_coverage(): + self._run_appropriate_coverage() +def _should_run_coverage(self): + return self.test_gen.current_coverage < (self.test_gen.desired_coverage / 100) + +def _run_appropriate_coverage(self): + if self.args.diff_coverage: + self.test_gen.run_diff_coverage() + else: + self.test_gen.run_coverage() + ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: Extracting the coverage check logic into separate methods improves code readability and maintainability, making it easier to manage and extend in the future.
    7
    Make regular expression pattern matching case-insensitive for improved robustness ___ **Consider using the re.IGNORECASE flag in the regular expressions to make the pattern
    matching case-insensitive. This can help prevent potential issues if the report
    format changes slightly.** [cover_agent/CoverageProcessor.py [240-248]](https://github.com/Codium-ai/cover-agent/pull/167/files#diff-610c623a5c322b67c9a12fa75021723cc335d4dc3ce4676eb8576a20f3ffd93eR240-R248) ```diff -total_lines_match = re.search(r'Total:\s+(\d+)\s+lines', report_text) +total_lines_match = re.search(r'Total:\s+(\d+)\s+lines', report_text, re.IGNORECASE) total_lines = int(total_lines_match.group(1)) if total_lines_match else 0 # Extract missing lines -missing_lines_match = re.search(r'Missing:\s+(\d+)\s+lines', report_text) +missing_lines_match = re.search(r'Missing:\s+(\d+)\s+lines', report_text, re.IGNORECASE) missing_lines = int(missing_lines_match.group(1)) if missing_lines_match else 0 -coverage_match = re.search(r'Coverage:\s+(\d+)%', report_text) +coverage_match = re.search(r'Coverage:\s+(\d+)%', report_text, re.IGNORECASE) coverage_percentage = float(coverage_match.group(1)) / 100 if coverage_match else 0.0 ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 6 Why: Using the `re.IGNORECASE` flag makes the code more robust against potential changes in the report format, although the current format may not require it.
    6
    Organization
    best practice
    Use default iterators and operators when calling methods ___ **Consider using default iterators and operators for the coverage_processor object
    when calling parse_diff_coverage_report. This aligns with the company's best
    practices and can potentially simplify the code.** [cover_agent/UnitTestGenerator.py [253-255]](https://github.com/Codium-ai/cover-agent/pull/167/files#diff-19760582d9ede3a799fdbb541ad357b4822682e837bca8365196fba50daf57e3R253-R255) ```diff -lines_processed, lines_missed, diff_coverage_percentage = coverage_processor.parse_diff_coverage_report( - report_text=stdout -) +lines_processed, lines_missed, diff_coverage_percentage = coverage_processor.parse_diff_coverage_report(stdout) ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 3 Why: The suggestion aligns with company best practices, but the impact on code functionality is minimal since the original code is already clear and correct.
    3

    ๐Ÿ’ก Need additional feedback ? start a PR chat