From b8785f6b3a4d0af6c9766466609a9e0bf7b3e66a Mon Sep 17 00:00:00 2001 From: HeshamHM28 Date: Wed, 10 Dec 2025 21:04:45 +0200 Subject: [PATCH] add passed unit test --- codeflash/github/PrComment.py | 5 +++-- codeflash/models/models.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/codeflash/github/PrComment.py b/codeflash/github/PrComment.py index fe0ff095e..6fba28544 100644 --- a/codeflash/github/PrComment.py +++ b/codeflash/github/PrComment.py @@ -24,14 +24,14 @@ class PrComment: original_async_throughput: Optional[int] = None best_async_throughput: Optional[int] = None - def to_json(self) -> dict[str, Union[str, int, dict[str, dict[str, int]], list[BenchmarkDetail], None]]: + def to_json(self) -> dict[str, Union[str, int, dict[str, dict[str, int]], list[BenchmarkDetail], list[str], None]]: report_table = { test_type.to_name(): result for test_type, result in self.winning_behavior_test_results.get_test_pass_fail_report_by_type().items() if test_type.to_name() } - result: dict[str, Union[str, int, dict[str, dict[str, int]], list[BenchmarkDetail], None]] = { + result: dict[str, Union[str, int, dict[str, dict[str, int]], list[BenchmarkDetail], list[str], None]] = { "optimization_explanation": self.optimization_explanation, "best_runtime": humanize_runtime(self.best_runtime), "original_runtime": humanize_runtime(self.original_runtime), @@ -41,6 +41,7 @@ def to_json(self) -> dict[str, Union[str, int, dict[str, dict[str, int]], list[B "speedup_pct": self.speedup_pct, "loop_count": self.winning_benchmarking_test_results.number_of_loops(), "report_table": report_table, + "passed_existing_tests": self.winning_behavior_test_results.get_passed_existing_test_names(), "benchmark_details": self.benchmark_details if self.benchmark_details else None, } diff --git a/codeflash/models/models.py b/codeflash/models/models.py index 0ea380059..538a16150 100644 --- a/codeflash/models/models.py +++ b/codeflash/models/models.py @@ -686,6 +686,24 @@ def get_test_pass_fail_report_by_type(self) -> dict[TestType, dict[str, int]]: report[test_result.test_type]["failed"] += 1 return report + def get_passed_existing_test_names(self) -> list[str]: + """Get a list of passed existing unit test names. + + Only considers tests from the first loop (loop_index == 1) to avoid duplicates. + Returns test names in the format: module_path::ClassName.test_name or module_path::test_name + """ + passed_tests: list[str] = [] + for test_result in self.test_results: + if ( + test_result.loop_index == 1 + and test_result.did_pass + and test_result.test_type == TestType.EXISTING_UNIT_TEST + ): + class_prefix = f"{test_result.id.test_class_name}." if test_result.id.test_class_name else "" + test_name = f"{test_result.id.test_module_path}::{class_prefix}{test_result.id.test_function_name}" + passed_tests.append(test_name) + return passed_tests + @staticmethod def report_to_string(report: dict[TestType, dict[str, int]]) -> str: return " ".join(