diff --git a/src/seer/automation/codegen/prompts.py b/src/seer/automation/codegen/prompts.py index 3a53af2c3..bf78d7285 100644 --- a/src/seer/automation/codegen/prompts.py +++ b/src/seer/automation/codegen/prompts.py @@ -18,7 +18,7 @@ def format_system_msg(): ) @staticmethod - def format_plan_step_msg(diff_str: str): + def format_plan_step_msg(diff_str: str, has_coverage_info: bool | str = False, has_test_result_info: bool | str = False): return textwrap.dedent( """\ You are given the below code changes as a diff: @@ -44,15 +44,78 @@ def format_plan_step_msg(diff_str: str): ) @staticmethod - def format_additional_code_coverage_info(coverage_info: dict): + def format_additional_code_coverage_info(coverage_info_str: str): return textwrap.dedent( """\ - You are given the following code coverage information as a json object: - {coverage_info} - TODO: Using the info...create the best unit tests + You are given the following code coverage information for the current diff as a json object: + {coverage_info_str} + + # Additional Instructions for Using Code Coverage Information: + + 1. Analyze the provided code coverage data carefully. Pay attention to: + - Lines that are marked as 'miss' or 'partial' + - The overall coverage percentage for each file + - Any significant differences between 'base_totals' and 'head_totals' + + 2. Prioritize creating tests for: + - Uncovered lines (marked as 'miss') + - Partially covered lines (marked as 'partial') + - Files with lower overall coverage percentages + - New or modified code that has resulted in coverage decreases + + 3. For each file in the diff: + - Compare the 'base_totals' and 'head_totals' to identify changes in coverage + - Focus on increasing both line and branch coverage + - Pay special attention to changes in complexity and ensure they are adequately tested + + 4. When designing tests: + - Aim to increase the 'hits' count while decreasing 'misses' and 'partials' + - Consider edge cases and boundary conditions, especially for partially covered lines + - Ensure that any increase in 'complexity_total' is matched with appropriate test coverage + + Remember, the goal is not just to increase the coverage numbers, but to ensure that the new tests meaningfully verify the behavior of the code, especially focusing on the changes and additions in the current diff. + + Integrate this information with the diff analysis to provide a comprehensive and targeted testing strategy. + """ + ).format( + coverage_info_str=coverage_info_str, + ) + + @staticmethod + def format_additional_test_results_info(test_result_data: str): + return textwrap.dedent( + """\ + You are provided with the following test result data for existing tests for the diff: + {test_result_data} + + # Instructions for Analyzing Test Result Data: + + 1. Review the test result data for each existing test, focusing on: + - Failure messages + - Test duration + - Failure rates + + 2. For tests with failures: + - Analyze the failure messages to identify issues introduced or exposed by this commit + - Consider creating additional tests to isolate and address these failures + - Suggest improvements or refactoring for the existing tests if the failures seem to be related to the changes in this commit + + 3. For tests with unusually long durations: + - Evaluate if the commit has introduced performance issues + - Consider adding performance-related tests if long durations are unexpected and related to the changes + + 4. Use the 'name' field of each test to understand its purpose and coverage area: + - Identify gaps in test coverage based on the names and purposes of existing tests, especially in relation to the changes in this commit + - Suggest new tests that complement the existing test suite and specifically address the changes in this commit + + 5. Pay special attention to the 'failure_rate' for each test: + - For tests with high failure rates, investigate if the failures are directly related to the changes in this commit + - For tests that previously passed but now fail, focus on understanding what in the commit might have caused this change + + Use this information to enhance your test creation strategy, ensuring that new tests reinforce areas of failure, and improve overall test suite effectiveness in the context of the changes introduced. """ ).format( - coverage_info=coverage_info, + test_result_data=test_result_data, ) @staticmethod