-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9dfa1a
commit 2293ea9
Showing
5 changed files
with
181 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Tuple | ||
|
||
class AgentCompletionABC(ABC): | ||
"""Abstract base class for AI-driven prompt handling.""" | ||
|
||
@abstractmethod | ||
def generate_tests( | ||
self, failed_tests: str, language: str, test_framework: str, coverage_report: str | ||
) -> Tuple[str, int, int, str]: | ||
""" | ||
Generates additional unit tests to improve test coverage. | ||
Returns: | ||
Tuple[str, int, int, str]: AI-generated test cases, input token count, output token count, and generated prompt. | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def analyze_test_failure(self, stderr: str, stdout: str, processed_test_file: str) -> Tuple[str, int, int, str]: | ||
""" | ||
Analyzes a test failure and returns insights. | ||
Returns: | ||
Tuple[str, int, int, str]: AI-generated analysis, input token count, output token count, and generated prompt. | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def analyze_test_insert_line(self, test_file: str) -> Tuple[str, int, int, str]: | ||
""" | ||
Determines where to insert new test cases. | ||
Returns: | ||
Tuple[str, int, int, str]: Suggested insertion point, input token count, output token count, and generated prompt. | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def analyze_test_against_context(self, test_code: str, context: str) -> Tuple[str, int, int, str]: | ||
""" | ||
Validates whether a test is appropriate for its corresponding source code. | ||
Returns: | ||
Tuple[str, int, int, str]: AI validation result, input token count, output token count, and generated prompt. | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def analyze_suite_test_headers_indentation(self, test_file: str) -> Tuple[str, int, int, str]: | ||
""" | ||
Determines the indentation style used in test suite headers. | ||
Returns: | ||
Tuple[str, int, int, str]: Suggested indentation style, input token count, output token count, and generated prompt. | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from cover_agent.AgentCompletionABC import AgentCompletionABC | ||
from cover_agent.PromptBuilder import PromptBuilder | ||
from cover_agent.AICaller import AICaller | ||
|
||
class DefaultAgentCompletion(AgentCompletionABC): | ||
"""Default implementation using PromptBuilder and AICaller.""" | ||
|
||
def __init__(self, builder: PromptBuilder, caller: AICaller): | ||
self.builder = builder | ||
self.caller = caller | ||
|
||
def generate_tests(self, failed_tests, language, test_framework, coverage_report): | ||
"""Generates additional unit tests to improve test coverage.""" | ||
prompt = self.builder.build_prompt_custom( | ||
file="test_generation_prompt", | ||
failed_tests_section=failed_tests, | ||
language=language, | ||
testing_framework=test_framework, | ||
code_coverage_report=coverage_report, | ||
) | ||
response, prompt_tokens, completion_tokens = self.caller.call_model(prompt) | ||
return response, prompt_tokens, completion_tokens, prompt | ||
|
||
def analyze_test_failure(self, stderr, stdout, processed_test_file): | ||
"""Analyzes the output of a failed test to determine the cause of failure.""" | ||
prompt = self.builder.build_prompt_custom( | ||
file="analyze_test_run_failure", | ||
stderr=stderr, | ||
stdout=stdout, | ||
processed_test_file=processed_test_file, | ||
) | ||
response, prompt_tokens, completion_tokens = self.caller.call_model(prompt) | ||
return response, prompt_tokens, completion_tokens, prompt | ||
|
||
def analyze_test_insert_line(self, test_file): | ||
"""Determines where to insert new test cases.""" | ||
prompt = self.builder.build_prompt_custom( | ||
file="analyze_suite_test_insert_line", | ||
test_file=test_file, | ||
) | ||
response, prompt_tokens, completion_tokens = self.caller.call_model(prompt) | ||
return response, prompt_tokens, completion_tokens, prompt | ||
|
||
def analyze_test_against_context(self, test_code, context): | ||
"""Validates whether a generated test is appropriate for its corresponding source code.""" | ||
prompt = self.builder.build_prompt_custom( | ||
file="analyze_test_against_context", | ||
test_code=test_code, | ||
context=context, | ||
) | ||
response, prompt_tokens, completion_tokens = self.caller.call_model(prompt) | ||
return response, prompt_tokens, completion_tokens, prompt | ||
|
||
def analyze_suite_test_headers_indentation(self, test_file): | ||
"""Determines the indentation style used in test suite headers.""" | ||
prompt = self.builder.build_prompt_custom( | ||
file="analyze_suite_test_headers_indentation", | ||
test_file=test_file, | ||
) | ||
response, prompt_tokens, completion_tokens = self.caller.call_model(prompt) | ||
return response, prompt_tokens, completion_tokens, prompt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters