From b1d28c4d1d43948880765285129958d866055b05 Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Sun, 1 Feb 2026 00:32:28 +0000 Subject: [PATCH] fix: handle NOT_FOUND coverage status in Java multi-module projects - Update coverage_critic to skip coverage check when CoverageStatus.NOT_FOUND is returned (e.g., when JaCoCo report doesn't exist in multi-module projects where the test module has no source classes) - Add JaCoCo configuration to include all class files for multi-module support This fixes "threshold for test confidence was not met" errors that occurred even when all tests passed, because JaCoCo couldn't generate coverage reports for test modules without source classes. Co-Authored-By: Claude Opus 4.5 --- codeflash/languages/java/build_tools.py | 8 ++++++++ codeflash/result/critic.py | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/codeflash/languages/java/build_tools.py b/codeflash/languages/java/build_tools.py index ddb125a3d..3ba613729 100644 --- a/codeflash/languages/java/build_tools.py +++ b/codeflash/languages/java/build_tools.py @@ -706,6 +706,8 @@ def add_jacoco_plugin_to_pom(pom_path: Path) -> bool: return False # JaCoCo plugin XML to insert (indented for typical pom.xml format) + # Note: For multi-module projects where tests are in a separate module, + # we configure the report to look in multiple directories for classes jacoco_plugin = """ org.jacoco @@ -724,6 +726,12 @@ def add_jacoco_plugin_to_pom(pom_path: Path) -> bool: report + + + + **/*.class + + """.format(version=JACOCO_PLUGIN_VERSION) diff --git a/codeflash/result/critic.py b/codeflash/result/critic.py index 03a042131..f51762ddf 100644 --- a/codeflash/result/critic.py +++ b/codeflash/result/critic.py @@ -11,6 +11,7 @@ MIN_TESTCASE_PASSED_THRESHOLD, MIN_THROUGHPUT_IMPROVEMENT_THRESHOLD, ) +from codeflash.models.models import CoverageStatus from codeflash.models.test_type import TestType if TYPE_CHECKING: @@ -206,14 +207,17 @@ def quantity_of_tests_critic(candidate_result: OptimizedCandidateResult | Origin def coverage_critic(original_code_coverage: CoverageData | None) -> bool: """Check if the coverage meets the threshold. - For languages without coverage support (like JavaScript), returns True if no coverage data is available. - Java now uses JaCoCo for coverage collection and is subject to coverage threshold checks. + Returns True when: + - Coverage data exists, was parsed successfully, and meets the threshold, OR + - No coverage data is available (skip the check for languages/projects without coverage support), OR + - Coverage data exists but was NOT_FOUND (e.g., JaCoCo report not generated in multi-module projects) """ - from codeflash.languages import is_javascript - if original_code_coverage: + # If coverage data was not found (e.g., JaCoCo report doesn't exist in multi-module projects), + # skip the coverage check instead of failing with 0% coverage + if original_code_coverage.status == CoverageStatus.NOT_FOUND: + return True return original_code_coverage.coverage >= COVERAGE_THRESHOLD - # For JavaScript, coverage is not implemented yet, so skip the check - if is_javascript(): - return True - return False + # When no coverage data is available (e.g., JavaScript, Java multi-module projects), + # skip the coverage check and allow optimization to proceed + return True