Skip to content

Commit 23238ec

Browse files
authored
Merge pull request #1086 from codeflash-ai/fix-path-resolution/no-gen-tests
FIX: --no-gen-tests Flag Causes Path Resolution Error with Module-Root
2 parents f397f4f + c9916f7 commit 23238ec

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

codeflash/models/models.py

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from collections import Counter, defaultdict
4+
from functools import lru_cache
45
from typing import TYPE_CHECKING
56

67
import libcst as cst
@@ -372,22 +373,51 @@ def add(self, test_file: TestFile) -> None:
372373
raise ValueError(msg)
373374

374375
def get_by_original_file_path(self, file_path: Path) -> TestFile | None:
375-
return next((test_file for test_file in self.test_files if test_file.original_file_path == file_path), None)
376+
normalized = self._normalize_path_for_comparison(file_path)
377+
for test_file in self.test_files:
378+
if test_file.original_file_path is None:
379+
continue
380+
normalized_test_path = self._normalize_path_for_comparison(test_file.original_file_path)
381+
if normalized == normalized_test_path:
382+
return test_file
383+
return None
376384

377385
def get_test_type_by_instrumented_file_path(self, file_path: Path) -> TestType | None:
378-
return next(
379-
(
380-
test_file.test_type
381-
for test_file in self.test_files
382-
if (file_path in (test_file.instrumented_behavior_file_path, test_file.benchmarking_file_path))
383-
),
384-
None,
385-
)
386+
normalized = self._normalize_path_for_comparison(file_path)
387+
for test_file in self.test_files:
388+
normalized_behavior_path = self._normalize_path_for_comparison(test_file.instrumented_behavior_file_path)
389+
if normalized == normalized_behavior_path:
390+
return test_file.test_type
391+
if test_file.benchmarking_file_path is not None:
392+
normalized_benchmark_path = self._normalize_path_for_comparison(test_file.benchmarking_file_path)
393+
if normalized == normalized_benchmark_path:
394+
return test_file.test_type
395+
return None
386396

387397
def get_test_type_by_original_file_path(self, file_path: Path) -> TestType | None:
388-
return next(
389-
(test_file.test_type for test_file in self.test_files if test_file.original_file_path == file_path), None
390-
)
398+
normalized = self._normalize_path_for_comparison(file_path)
399+
for test_file in self.test_files:
400+
if test_file.original_file_path is None:
401+
continue
402+
normalized_test_path = self._normalize_path_for_comparison(test_file.original_file_path)
403+
if normalized == normalized_test_path:
404+
return test_file.test_type
405+
return None
406+
407+
@staticmethod
408+
@lru_cache(maxsize=4096)
409+
def _normalize_path_for_comparison(path: Path) -> str:
410+
"""Normalize a path for cross-platform comparison.
411+
412+
Resolves the path to an absolute path and handles Windows case-insensitivity.
413+
"""
414+
try:
415+
resolved = str(path.resolve())
416+
except (OSError, RuntimeError):
417+
# If resolve fails (e.g., file doesn't exist), use absolute path
418+
resolved = str(path.absolute())
419+
# Only lowercase on Windows where filesystem is case-insensitive
420+
return resolved.lower() if sys.platform == "win32" else resolved
391421

392422
def __iter__(self) -> Iterator[TestFile]:
393423
return iter(self.test_files)

codeflash/verification/parse_test_output.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,14 @@ def parse_test_xml(
316316
logger.warning(f"Could not find the test for file name - {test_file_path} ")
317317
continue
318318
test_type = test_files.get_test_type_by_instrumented_file_path(test_file_path)
319-
assert test_type is not None, f"Test type not found for {test_file_path}"
319+
if test_type is None:
320+
# Log registered paths for debugging
321+
registered_paths = [str(tf.instrumented_behavior_file_path) for tf in test_files.test_files]
322+
logger.warning(
323+
f"Test type not found for '{test_file_path}'. "
324+
f"Registered test files: {registered_paths}. Skipping test case."
325+
)
326+
continue
320327
test_module_path = module_name_from_file_path(test_file_path, test_config.tests_project_rootdir)
321328
result = testcase.is_passed # TODO: See for the cases of ERROR and SKIPPED
322329
test_class = None

0 commit comments

Comments
 (0)