Skip to content

Commit 50f5070

Browse files
committed
fix: silently skip duplicate TestFiles.add() instead of raising
Java test discovery adds the same instrumented_behavior_file_path with different fields. The old Pydantic __eq__ treated them as different; the set-based dedup correctly identifies them as the same test file. Since get_test_type_by_instrumented_file_path() returns on first path match anyway, duplicates by path are dead weight. Silent skip (first write wins) is both correct and O(1).
1 parent 0b3fc1e commit 50f5070

2 files changed

Lines changed: 3 additions & 8 deletions

File tree

codeflash/models/models.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,6 @@ def add(self, test_file: TestFile) -> None:
439439
if key not in self._seen_paths:
440440
self._seen_paths.add(key)
441441
self.test_files.append(test_file)
442-
else:
443-
msg = "Test file already exists in the list"
444-
raise ValueError(msg)
445442

446443
def get_by_original_file_path(self, file_path: Path) -> TestFile | None:
447444
normalized = self._normalize_path_for_comparison(file_path)

tests/test_test_files_add.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from pathlib import Path
22

3-
import pytest
4-
53
from codeflash.models.models import TestFile, TestFiles
64
from codeflash.models.test_type import TestType
75

@@ -18,16 +16,16 @@ def test_add_unique_test_file(self) -> None:
1816
assert len(tf.test_files) == 1
1917
assert tf.test_files[0] is test_file
2018

21-
def test_add_duplicate_raises(self) -> None:
19+
def test_add_duplicate_is_noop(self) -> None:
2220
tf = TestFiles(test_files=[])
2321
test_file = TestFile(
2422
instrumented_behavior_file_path=Path("/tmp/test_behavior.py"),
2523
benchmarking_file_path=Path("/tmp/test_perf.py"),
2624
test_type=TestType.GENERATED_REGRESSION,
2725
)
2826
tf.add(test_file)
29-
with pytest.raises(ValueError, match="Test file already exists"):
30-
tf.add(test_file)
27+
tf.add(test_file) # silent skip — first write wins
28+
assert len(tf.test_files) == 1
3129

3230
def test_add_many_files_performance(self) -> None:
3331
tf = TestFiles(test_files=[])

0 commit comments

Comments
 (0)