diff --git a/codeflash/languages/function_optimizer.py b/codeflash/languages/function_optimizer.py index 378b1a15f..b348a6e46 100644 --- a/codeflash/languages/function_optimizer.py +++ b/codeflash/languages/function_optimizer.py @@ -2794,13 +2794,13 @@ class FunctionOptimizer: if coverage_results and coverage_results.status == CoverageStatus.NOT_FOUND: # File was not found in coverage data - likely excluded by test framework config logger.warning( - f"No coverage data found for {self.function_to_optimize.source_file_path}. " + f"No coverage data found for {self.function_to_optimize.file_path}. " f"This file may be excluded from coverage collection by your test framework configuration " f"(e.g., coverage.exclude in vitest.config.ts for Vitest, or testMatch/coveragePathIgnorePatterns " f"for Jest). Tests ran successfully but coverage cannot be measured." ) return Failure( - f"Coverage data not found for {self.function_to_optimize.source_file_path}. " + f"Coverage data not found for {self.function_to_optimize.file_path}. " f"The file may be excluded from coverage by your test framework config. " f"Check coverage.exclude patterns in vitest.config.ts or jest.config.js." ) diff --git a/tests/languages/test_coverage_exclusion_message.py b/tests/languages/test_coverage_exclusion_message.py new file mode 100644 index 000000000..c196c6bc5 --- /dev/null +++ b/tests/languages/test_coverage_exclusion_message.py @@ -0,0 +1,45 @@ +"""Test for coverage exclusion error message (Bug #5 regression test).""" + +from pathlib import Path + +from codeflash.models.function_types import FunctionToOptimize +from codeflash.models.models import CodePosition + + +def test_function_to_optimize_has_file_path_not_source_file_path(): + """Test that FunctionToOptimize has file_path attribute, not source_file_path. + + Regression test for Bug #5: Bug #1's fix used wrong attribute name 'source_file_path' + instead of 'file_path', causing AttributeError when constructing coverage error messages. + + The bug occurred in function_optimizer.py lines 2797 and 2803: + f"No coverage data found for {self.function_to_optimize.source_file_path}." + + This should be: + f"No coverage data found for {self.function_to_optimize.file_path}." + + Trace ID: 5c4a75fb-d8eb-4f75-9e57-893f0c44b9c7 + """ + # Create a FunctionToOptimize object + func = FunctionToOptimize( + function_name="testFunc", + file_path=Path("/workspace/target/src/test.ts"), + starting_line=1, + ending_line=10, + code_position=CodePosition(line_no=1, col_no=0), + file_path_relative_to_project_root="src/test.ts", + ) + + # Verify correct attribute exists + assert hasattr(func, "file_path"), "FunctionToOptimize should have 'file_path' attribute" + assert func.file_path == Path("/workspace/target/src/test.ts") + + # Verify wrong attribute does NOT exist + assert not hasattr( + func, "source_file_path" + ), "FunctionToOptimize should NOT have 'source_file_path' attribute (it's a typo/bug)" + + # Verify we can access file_path in string formatting (like the bug location does) + error_message = f"No coverage data found for {func.file_path}." + assert "test.ts" in error_message + # This should NOT raise AttributeError