Skip to content

fix: add Java patterns to instrumented test file cleanup#1338

Merged
mashraf-222 merged 2 commits intoomni-javafrom
fix/java-instrumented-test-cleanup
Feb 4, 2026
Merged

fix: add Java patterns to instrumented test file cleanup#1338
mashraf-222 merged 2 commits intoomni-javafrom
fix/java-instrumented-test-cleanup

Conversation

@mashraf-222
Copy link
Contributor

Problem

Java optimizations were failing when run sequentially because instrumented test files from previous optimizations were not being cleaned up.

Error:

WARNING: Test type not found for 'FibonacciSearchTest__perfonlyinstrumented.java'
WARNING: Couldn't run any tests for original function knapSack. Skipping optimization.
Result: ❌ No optimizations found

This made it impossible to run multiple Java optimizations without manually deleting instrumented files between runs.

Root Cause

The find_leftover_instrumented_test_files() method in optimizer.py has regex patterns to detect and clean up instrumented test files, but it only included patterns for:

  • Python: test_.*__perfinstrumented.py
  • JavaScript: *__perfinstrumented.test.js

Java patterns were missing:

  • *Test__perfinstrumented.java
  • *Test__perfonlyinstrumented.java

Solution

Added Java patterns to the cleanup regex:

# Java patterns
r".*Test__perfinstrumented\.java|.*Test__perfonlyinstrumented\.java"

Now the cleanup method (called at line 482 before each optimization) will properly detect and remove Java instrumented test files.

Changes

optimizer.py (line 624-649):

  • Added Java patterns to docstring
  • Added Java regex patterns to the compiled pattern
  • Added pipe | separator before Java patterns

test_cleanup_instrumented_files.py (new file):

  • 4 comprehensive test cases covering Java, Python, JavaScript, and mixed scenarios
  • Verifies instrumented files ARE detected
  • Verifies normal test files are NOT detected
  • All tests pass ✓

Testing

✅ Unit tests:

$ pytest tests/test_cleanup_instrumented_files.py -v
test_find_leftover_instrumented_test_files_java PASSED
test_find_leftover_instrumented_test_files_python PASSED  
test_find_leftover_instrumented_test_files_javascript PASSED
test_find_leftover_instrumented_test_files_mixed PASSED
4 passed in 0.05s

✅ Regex validation:

  • FibonacciSearchTest__perfonlyinstrumented.java ✓ MATCH
  • BruteForceKnapsackTest__perfinstrumented.java ✓ MATCH
  • FibonacciSearchTest.java ✗ NO MATCH (correct)

Impact

  • ✅ Java optimizations can now run sequentially without manual cleanup
  • ✅ Prevents test discovery failures from stale instrumented files
  • ✅ Consistent behavior across Python, JavaScript, and Java
  • ✅ No breaking changes - only adds missing patterns

This fixes a critical bug blocking Java E2E optimizations.

mashraf-222 and others added 2 commits February 3, 2026 23:42
Java instrumented test files (*Test__perfinstrumented.java and
*Test__perfonlyinstrumented.java) were not being cleaned up after
optimization, causing subsequent optimizations to fail.

The find_leftover_instrumented_test_files() method had regex patterns
for Python and JavaScript but was missing Java patterns.

Changes:
- Add Java patterns to cleanup regex in optimizer.py
- Add comprehensive test coverage for Java, Python, JS, and mixed scenarios
- All 4 new tests pass

Testing: Verified regex matches Java instrumented files correctly and
cleanup prevents stale files from blocking optimizations.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Some instrumented test files have numeric suffixes like _2, _3:
- FibonacciSeriesTest__perfinstrumented_2.java
- KnapsackTest__perfonlyinstrumented_3.java

Updated regex to match optional numeric suffix: (?:_\d+)?
Updated test to verify files with suffixes are detected.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@mashraf-222 mashraf-222 merged commit 65318e2 into omni-java Feb 4, 2026
18 of 29 checks passed
@mashraf-222 mashraf-222 deleted the fix/java-instrumented-test-cleanup branch February 4, 2026 00:13
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.

2 participants