diff --git a/src/coverup/coverup.py b/src/coverup/coverup.py index b4ccbac..19a40ec 100644 --- a/src/coverup/coverup.py +++ b/src/coverup/coverup.py @@ -517,7 +517,11 @@ async def improve_coverage(chatter: llm.Chatter, prompter: prompt.Prompter, seg: except subprocess.CalledProcessError as e: state.inc_counter('F') - prompts = prompter.error_prompt(seg, clean_error(str(e.stdout, 'UTF-8', errors='ignore'))) + error = clean_error(str(e.stdout, 'UTF-8', errors='ignore')) + if not (prompts := prompter.error_prompt(seg, error)): + log_write(seg, "Test failed:\n\n" + error) + break + messages.extend(prompts) continue @@ -538,7 +542,10 @@ async def improve_coverage(chatter: llm.Chatter, prompter: prompt.Prompter, seg: if not gained_lines and not gained_branches: state.inc_counter('U') - prompts = prompter.missing_coverage_prompt(seg, seg.missing_lines, seg.missing_branches) + if not (prompts := prompter.missing_coverage_prompt(seg, seg.missing_lines, seg.missing_branches)): + log_write(seg, "Test doesn't improve coverage") + break + messages.extend(prompts) continue diff --git a/src/coverup/logreader.py b/src/coverup/logreader.py index 2a91182..05d07d7 100644 --- a/src/coverup/logreader.py +++ b/src/coverup/logreader.py @@ -3,7 +3,7 @@ from pathlib import Path -TERMINAL_EVENTS=('G', 'M', 'T', '-', '*') +TERMINAL_EVENTS=('G', 'M', 'T', '-', '*', 'f', 'u') def is_same_as_P(content, begin, end): @@ -107,12 +107,16 @@ def what(content: str): return 'C' elif content.startswith("Executing the test yields an error"): return 'F' + elif content.startswith("Test failed"): + return 'f' elif content.startswith("Executing the test along with"): # side effect return 'S' elif content.startswith("```python"): # response return 'R' elif content.startswith("This test still lacks coverage"): return 'U' + elif content.startswith("Test doesn't improve coverage"): + return 'u' elif content.startswith("Saved as"): # success return 'G' elif content.startswith("Missing modules"): diff --git a/src/coverup/prompt.py b/src/coverup/prompt.py index 11d60a1..434aac3 100644 --- a/src/coverup/prompt.py +++ b/src/coverup/prompt.py @@ -27,13 +27,13 @@ def initial_prompt(self, segment: CodeSegment) -> T.List[dict]: @abc.abstractmethod - def error_prompt(self, segment: CodeSegment, error: str) -> T.List[dict]: + def error_prompt(self, segment: CodeSegment, error: str) -> T.List[dict] | None: """Returns prompts(s) in response to an error.""" @abc.abstractmethod def missing_coverage_prompt(self, segment: CodeSegment, - missing_lines: set, missing_branches: set) -> T.List[dict]: + missing_lines: set, missing_branches: set) -> T.List[dict] | None: """Returns prompts(s) in response to the suggested test(s) lacking coverage.""" @@ -218,21 +218,23 @@ def initial_prompt(self, segment: CodeSegment) -> T.List[dict]: """) ] - def error_prompt(self, segment: CodeSegment, error: str) -> T.List[dict]: - return [_message(f"""\ -Executing the test yields an error, shown below. -Modify the test to correct it; respond only with the complete Python code in backticks. - -{error}""") - ] + def error_prompt(self, segment: CodeSegment, error: str) -> T.List[dict] | None: + return None +# return [_message(f"""\ +#Executing the test yields an error, shown below. +#Modify the test to correct it; respond only with the complete Python code in backticks. +# +#{error}""") +# ] def missing_coverage_prompt(self, segment: CodeSegment, - missing_lines: set, missing_branches: set) -> T.List[dict]: - return [_message(f"""\ -The tests still lack coverage. -Modify to correct that; respond only with the complete Python code in backticks. -""") - ] + missing_lines: set, missing_branches: set) -> T.List[dict] | None: + return None +# return [_message(f"""\ +#The tests still lack coverage. +#Modify to correct that; respond only with the complete Python code in backticks. +#""") +# ] class ClaudePrompter(Prompter):