Skip to content

Commit

Permalink
- made continuing the chat when the generated test fails or if it
Browse files Browse the repository at this point in the history
  doesn't improve coverage optional, so it can be up to each Prompter;

- disabled these in gpt-v2-ablated Prompter to facilitate evaluation;
  • Loading branch information
jaltmayerpizzorno committed Aug 29, 2024
1 parent 1d6b359 commit 1ae7a74
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
11 changes: 9 additions & 2 deletions src/coverup/coverup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion src/coverup/logreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"):
Expand Down
32 changes: 17 additions & 15 deletions src/coverup/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""


Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1ae7a74

Please sign in to comment.