mirror of
https://github.com/codeflash-ai/codeflash.git
synced 2026-05-04 18:25:17 +00:00
Fix AttributeError: use file_path not source_file_path
Bug #5 fix: The coverage exclusion error messages used self.function_to_optimize.source_file_path but FunctionToOptimize only has file_path attribute, not source_file_path. This caused AttributeError when files were excluded from coverage. Trace ID: 5c4a75fb-d8eb-4f75-9e57-893f0c44b9c7 Changes: - Fixed lines 2797, 2803: source_file_path -> file_path - Added regression test to verify correct attribute used Testing: - New test passes - Linting passes Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
e329d52c34
commit
63c475af0e
2 changed files with 47 additions and 2 deletions
|
|
@ -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."
|
||||
)
|
||||
|
|
|
|||
45
tests/languages/test_coverage_exclusion_message.py
Normal file
45
tests/languages/test_coverage_exclusion_message.py
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue