diff --git a/codeflash/models/models.py b/codeflash/models/models.py index d850e3827..36c9869eb 100644 --- a/codeflash/models/models.py +++ b/codeflash/models/models.py @@ -372,23 +372,58 @@ def add(self, test_file: TestFile) -> None: raise ValueError(msg) def get_by_original_file_path(self, file_path: Path) -> TestFile | None: - return next((test_file for test_file in self.test_files if test_file.original_file_path == file_path), None) + normalized = self._normalize_path_for_comparison(file_path) + return next( + ( + test_file + for test_file in self.test_files + if test_file.original_file_path is not None + and normalized == self._normalize_path_for_comparison(test_file.original_file_path) + ), + None, + ) def get_test_type_by_instrumented_file_path(self, file_path: Path) -> TestType | None: + normalized = self._normalize_path_for_comparison(file_path) return next( ( test_file.test_type for test_file in self.test_files - if (file_path in (test_file.instrumented_behavior_file_path, test_file.benchmarking_file_path)) + if normalized == self._normalize_path_for_comparison(test_file.instrumented_behavior_file_path) + or ( + test_file.benchmarking_file_path is not None + and normalized == self._normalize_path_for_comparison(test_file.benchmarking_file_path) + ) ), None, ) def get_test_type_by_original_file_path(self, file_path: Path) -> TestType | None: + normalized = self._normalize_path_for_comparison(file_path) return next( - (test_file.test_type for test_file in self.test_files if test_file.original_file_path == file_path), None + ( + test_file.test_type + for test_file in self.test_files + if test_file.original_file_path is not None + and normalized == self._normalize_path_for_comparison(test_file.original_file_path) + ), + None, ) + @staticmethod + def _normalize_path_for_comparison(path: Path) -> str: + """Normalize a path for cross-platform comparison. + + Resolves the path to an absolute path and handles Windows case-insensitivity. + """ + try: + resolved = str(path.resolve()) + except (OSError, RuntimeError): + # If resolve fails (e.g., file doesn't exist), use absolute path + resolved = str(path.absolute()) + # Only lowercase on Windows where filesystem is case-insensitive + return resolved.lower() if sys.platform == "win32" else resolved + def __iter__(self) -> Iterator[TestFile]: return iter(self.test_files) diff --git a/codeflash/verification/parse_test_output.py b/codeflash/verification/parse_test_output.py index d6b529d6d..2cb112221 100644 --- a/codeflash/verification/parse_test_output.py +++ b/codeflash/verification/parse_test_output.py @@ -316,7 +316,14 @@ def parse_test_xml( logger.warning(f"Could not find the test for file name - {test_file_path} ") continue test_type = test_files.get_test_type_by_instrumented_file_path(test_file_path) - assert test_type is not None, f"Test type not found for {test_file_path}" + if test_type is None: + # Log registered paths for debugging + registered_paths = [str(tf.instrumented_behavior_file_path) for tf in test_files.test_files] + logger.warning( + f"Test type not found for '{test_file_path}'. " + f"Registered test files: {registered_paths}. Skipping test case." + ) + continue test_module_path = module_name_from_file_path(test_file_path, test_config.tests_project_rootdir) result = testcase.is_passed # TODO: See for the cases of ERROR and SKIPPED test_class = None