-
Notifications
You must be signed in to change notification settings - Fork 26
fix: silently skip duplicate TestFiles.add() instead of raising #2144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ca8e2b6
perf: use set for O(1) membership check in TestFiles.add()
KRRT7 0b3fc1e
test: add unit tests for TestFiles.add() deduplication
KRRT7 50f5070
fix: silently skip duplicate TestFiles.add() instead of raising
KRRT7 aa98bc1
fix: use native path format and simple subprocess for pytest on Windows
KRRT7 81b0358
fix: surface subprocess errors when pytest XML is missing
KRRT7 4da8e22
Merge branch 'main' into fix/test-files-silent-dedup
KRRT7 7c61881
Merge pull request #2138 from codeflash-ai/fix/windows-junitxml-path
KRRT7 9c9f0de
Merge pull request #2141 from codeflash-ai/fix/subprocess-xml-errors
KRRT7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -429,13 +429,16 @@ class TestFile(BaseModel): | |
|
|
||
| class TestFiles(BaseModel): | ||
| test_files: list[TestFile] | ||
| _seen_paths: set[Path] = PrivateAttr(default_factory=set) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why privateattr @KRRT7 ? |
||
|
|
||
| def model_post_init(self, __context: Any, /) -> None: | ||
| self._seen_paths = {tf.instrumented_behavior_file_path for tf in self.test_files} | ||
|
|
||
| def add(self, test_file: TestFile) -> None: | ||
| if test_file not in self.test_files: | ||
| key = test_file.instrumented_behavior_file_path | ||
| if key not in self._seen_paths: | ||
| self._seen_paths.add(key) | ||
| self.test_files.append(test_file) | ||
| else: | ||
| msg = "Test file already exists in the list" | ||
| raise ValueError(msg) | ||
|
|
||
| def get_by_original_file_path(self, file_path: Path) -> TestFile | None: | ||
| normalized = self._normalize_path_for_comparison(file_path) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from pathlib import Path | ||
|
|
||
| from codeflash.models.models import TestFile, TestFiles | ||
| from codeflash.models.test_type import TestType | ||
|
|
||
|
|
||
| class TestTestFilesAdd: | ||
| def test_add_unique_test_file(self) -> None: | ||
| tf = TestFiles(test_files=[]) | ||
| test_file = TestFile( | ||
| instrumented_behavior_file_path=Path("/tmp/test_behavior.py"), | ||
| benchmarking_file_path=Path("/tmp/test_perf.py"), | ||
| test_type=TestType.GENERATED_REGRESSION, | ||
| ) | ||
| tf.add(test_file) | ||
| assert len(tf.test_files) == 1 | ||
| assert tf.test_files[0] is test_file | ||
|
|
||
| def test_add_duplicate_is_noop(self) -> None: | ||
| tf = TestFiles(test_files=[]) | ||
| test_file = TestFile( | ||
| instrumented_behavior_file_path=Path("/tmp/test_behavior.py"), | ||
| benchmarking_file_path=Path("/tmp/test_perf.py"), | ||
| test_type=TestType.GENERATED_REGRESSION, | ||
| ) | ||
| tf.add(test_file) | ||
| tf.add(test_file) # silent skip — first write wins | ||
| assert len(tf.test_files) == 1 | ||
|
|
||
| def test_add_many_files_performance(self) -> None: | ||
| tf = TestFiles(test_files=[]) | ||
| for i in range(100): | ||
| test_file = TestFile( | ||
| instrumented_behavior_file_path=Path(f"/tmp/test_behavior_{i}.py"), | ||
| benchmarking_file_path=Path(f"/tmp/test_perf_{i}.py"), | ||
| test_type=TestType.GENERATED_REGRESSION, | ||
| ) | ||
| tf.add(test_file) | ||
|
|
||
| assert len(tf.test_files) == 100 | ||
| assert len(tf._seen_paths) == 100 | ||
| # Verify all paths are unique in the set | ||
| expected_paths = {Path(f"/tmp/test_behavior_{i}.py") for i in range(100)} | ||
| assert tf._seen_paths == expected_paths |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will work on windows? @KRRT7