Skip to content

fix: silently skip duplicate TestFiles.add() instead of raising#2133

Merged
KRRT7 merged 5 commits intocf-fix-concurrency-measurementfrom
fix/test-files-silent-dedup
May 7, 2026
Merged

fix: silently skip duplicate TestFiles.add() instead of raising#2133
KRRT7 merged 5 commits intocf-fix-concurrency-measurementfrom
fix/test-files-silent-dedup

Conversation

@KRRT7
Copy link
Copy Markdown
Collaborator

@KRRT7 KRRT7 commented May 7, 2026

Parent PR

#2132 — perf: targeted performance improvements for E2E pipeline hot path

Summary

Changes TestFiles.add() duplicate handling from raising ValueError to silently skipping (first-write-wins). Fixes Java e2e test failures where test discovery adds the same instrumented_behavior_file_path with different metadata fields.

Problem

The set-based dedup introduced in #2130 correctly identifies duplicate test files by path. However, it raised ValueError on duplicates — which breaks Java test discovery where the same path appears multiple times with varying metadata.

Since get_test_type_by_instrumented_file_path() returns on first path match anyway, duplicates by path are dead weight. Raising is both incorrect (existing callers never expected it) and unnecessary.

Changes

  • codeflash/models/models.py: Remove ValueError raise in add(), silently return when path already in _seen_paths
  • tests/test_test_files_add.py: Update test from test_add_duplicate_raisestest_add_duplicate_is_noop

Key design decisions

  • First-write-wins: The first TestFile added for a given path is kept; subsequent adds with the same path are silently discarded. This matches the existing lookup semantics.
  • No behavioral change for unique paths: Only the duplicate path changes — unique additions work identically.

Test plan

  • test_add_duplicate_is_noop verifies silent skip on duplicate path
  • test_add_unique_test_file passes
  • test_add_many_files_performance passes (100 files, O(1) per add)
  • Java e2e tests pass (was failing before this fix)

@KRRT7 KRRT7 changed the base branch from cf-perf-improvements to main May 7, 2026 04:06
@KRRT7 KRRT7 enabled auto-merge May 7, 2026 04:23
@KRRT7 KRRT7 requested a review from aseembits93 May 7, 2026 08:34
KRRT7 added 5 commits May 7, 2026 11:47
The previous implementation used `if test_file not in self.test_files`
which performs O(n) equality comparison across all TestFile objects.
Replace with a `_seen_paths` set keyed on `instrumented_behavior_file_path`
for O(1) deduplication lookups.
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).
When the test subprocess exits non-zero and produces no JUnit XML,
log the return code and stdout/stderr at WARNING level so the root
cause is visible in CI logs. Previously this was a generic "No test
results found" message that made Windows CI flakes impossible to
diagnose.

Also fixes pre-existing mypy strict errors in parse_xml.py:
- Add return type to _parse_func
- Type CompletedProcess[str] (subprocess uses text=True)
- Parameterize generic types (tuple, re.Match)
- Remove dead .decode() branches (stdout is already str)
@KRRT7 KRRT7 force-pushed the fix/test-files-silent-dedup branch from 6734877 to 9459c5a Compare May 7, 2026 16:47
@KRRT7 KRRT7 requested a review from misrasaurabh1 as a code owner May 7, 2026 16:47
@KRRT7 KRRT7 changed the base branch from main to cf-fix-concurrency-measurement May 7, 2026 16:47
@KRRT7 KRRT7 merged commit 808b76b into cf-fix-concurrency-measurement May 7, 2026
5 of 6 checks passed
@KRRT7 KRRT7 deleted the fix/test-files-silent-dedup branch May 7, 2026 16:47
@KRRT7 KRRT7 restored the fix/test-files-silent-dedup branch May 7, 2026 16:48
@KRRT7
Copy link
Copy Markdown
Collaborator Author

KRRT7 commented May 7, 2026

Superseded by #2144 (same commit, rebased onto the linear stack).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant