Skip to content

Commit 63c475a

Browse files
Codeflash Botclaude
andcommitted
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>
1 parent e329d52 commit 63c475a

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

codeflash/languages/function_optimizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,13 +2794,13 @@ def establish_original_code_baseline(
27942794
if coverage_results and coverage_results.status == CoverageStatus.NOT_FOUND:
27952795
# File was not found in coverage data - likely excluded by test framework config
27962796
logger.warning(
2797-
f"No coverage data found for {self.function_to_optimize.source_file_path}. "
2797+
f"No coverage data found for {self.function_to_optimize.file_path}. "
27982798
f"This file may be excluded from coverage collection by your test framework configuration "
27992799
f"(e.g., coverage.exclude in vitest.config.ts for Vitest, or testMatch/coveragePathIgnorePatterns "
28002800
f"for Jest). Tests ran successfully but coverage cannot be measured."
28012801
)
28022802
return Failure(
2803-
f"Coverage data not found for {self.function_to_optimize.source_file_path}. "
2803+
f"Coverage data not found for {self.function_to_optimize.file_path}. "
28042804
f"The file may be excluded from coverage by your test framework config. "
28052805
f"Check coverage.exclude patterns in vitest.config.ts or jest.config.js."
28062806
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Test for coverage exclusion error message (Bug #5 regression test)."""
2+
3+
from pathlib import Path
4+
5+
from codeflash.models.function_types import FunctionToOptimize
6+
from codeflash.models.models import CodePosition
7+
8+
9+
def test_function_to_optimize_has_file_path_not_source_file_path():
10+
"""Test that FunctionToOptimize has file_path attribute, not source_file_path.
11+
12+
Regression test for Bug #5: Bug #1's fix used wrong attribute name 'source_file_path'
13+
instead of 'file_path', causing AttributeError when constructing coverage error messages.
14+
15+
The bug occurred in function_optimizer.py lines 2797 and 2803:
16+
f"No coverage data found for {self.function_to_optimize.source_file_path}."
17+
18+
This should be:
19+
f"No coverage data found for {self.function_to_optimize.file_path}."
20+
21+
Trace ID: 5c4a75fb-d8eb-4f75-9e57-893f0c44b9c7
22+
"""
23+
# Create a FunctionToOptimize object
24+
func = FunctionToOptimize(
25+
function_name="testFunc",
26+
file_path=Path("/workspace/target/src/test.ts"),
27+
starting_line=1,
28+
ending_line=10,
29+
code_position=CodePosition(line_no=1, col_no=0),
30+
file_path_relative_to_project_root="src/test.ts",
31+
)
32+
33+
# Verify correct attribute exists
34+
assert hasattr(func, "file_path"), "FunctionToOptimize should have 'file_path' attribute"
35+
assert func.file_path == Path("/workspace/target/src/test.ts")
36+
37+
# Verify wrong attribute does NOT exist
38+
assert not hasattr(
39+
func, "source_file_path"
40+
), "FunctionToOptimize should NOT have 'source_file_path' attribute (it's a typo/bug)"
41+
42+
# Verify we can access file_path in string formatting (like the bug location does)
43+
error_message = f"No coverage data found for {func.file_path}."
44+
assert "test.ts" in error_message
45+
# This should NOT raise AttributeError

0 commit comments

Comments
 (0)