fix: prevent Maven running all tests + fix TestFile type annotation#1345
fix: prevent Maven running all tests + fix TestFile type annotation#1345mashraf-222 merged 4 commits intoomni-javafrom
Conversation
Added comprehensive debug logging to _build_test_filter() and _run_maven_tests() to understand why Maven runs all tests instead of specific tests. Logs will show: - Test filter value and whether it's empty - Number of test files being processed - Paths that fail to convert to class names - Warning when filter is empty Part of Bug #3 investigation.
⚡️ Codeflash found optimizations for this PR📄 34% (0.34x) speedup for
|
Applying Bug #2 fix to this branch for testing. Java needs tests_project_rootdir set to actual test directory (src/test/java) instead of project root for test file resolution.
Bug #3: Maven Runs All Tests Instead of Specific Tests - Added validation in _run_maven_tests() to raise ValueError when test filter is empty - Added detailed error logging in _build_test_filter() to track why tests are skipped - Added warnings when TestFile objects have None paths - Prevents silent failure where Maven runs ALL tests instead of target tests Bug #4: Incorrect Type Annotation in TestFile Model - Fixed benchmarking_file_path: Path = None -> Optional[Path] = None - Original annotation caused Pydantic validation errors when path was None - This was preventing proper testing and validation of None paths Changes: - codeflash/languages/java/test_runner.py: Added validation and logging - codeflash/models/models.py: Fixed type annotation - codeflash/discovery/discover_unit_tests.py: Added Bug #2 fix (tests_project_rootdir) - tests/test_java_test_filter_validation.py: 4 comprehensive test cases Tests: - test_build_test_filter_with_none_benchmarking_paths: Verifies None paths handled correctly - test_build_test_filter_with_valid_paths: Verifies valid paths work - test_run_maven_tests_raises_on_empty_filter: Verifies validation catches empty filter - test_run_maven_tests_succeeds_with_valid_filter: Verifies normal case works All 4 tests passing ✓ Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
df00344 to
aa718c8
Compare
E2E Test ResultsGoal: Prevent Maven from running all tests when filter is empty + Fix TestFile type annotation. Result: ✅ PASS What was testedVerified both issues are fixed through comprehensive unit testing:
Test commands# Checkout PR branch
cd /home/ubuntu/code/codeflash
git checkout debug/java-test-filter
# Run unit tests
pytest tests/test_java_test_filter_validation.py -vEvidenceAll 4 unit tests pass: Issue 1 - Empty filter validation: Code change verified in if test_filter:
validated_filter = _validate_test_filter(test_filter)
cmd.append(f"-Dtest={validated_filter}")
logger.debug(f"Added -Dtest={validated_filter} to Maven command")
else:
# CRITICAL: Empty test filter means Maven will run ALL tests
error_msg = (
f"Test filter is EMPTY for mode={mode}! "
f"Maven will run ALL tests instead of the specified tests. "
)
logger.error(error_msg)
raise ValueError(error_msg) # NEW: Prevents silent failureTest verification:
Issue 2 - Type annotation fix: Code change verified in class TestFile(BaseModel):
instrumented_behavior_file_path: Path
- benchmarking_file_path: Path = None # INVALID in Pydantic
+ benchmarking_file_path: Optional[Path] = None # FIXED
original_file_path: Optional[Path] = NoneTest verification:
Additional improvementsThe PR also adds comprehensive debug logging to track:
This will help diagnose future test execution issues. Impact
Both issues are verified fixed through passing unit tests. The empty filter validation is a circuit breaker that prevents silent failures. Tested with Claude Code |
Maven Test Execution Fixes
Problems Fixed
This PR addresses two related issues that were causing Java E2E optimizations to fail:
Issue 1: Maven runs ALL tests instead of specific tests
Issue 2: Incorrect type annotation in TestFile model
benchmarking_file_path: Path = Noneshould beOptional[Path] = NoneRoot Causes
Issue 1: Empty test filter
_build_test_filter()returns empty string when all tests have None paths or fail conversion-Dtest=parameter added to Maven commandIssue 2: Invalid type annotation
Path = Noneis invalid in PydanticOptional[Path] = Noneto allow None valuesSolutions Implemented
Issue 1 Fix:
_run_maven_tests()to raiseValueErrorif filter is empty_build_test_filter()to track skipped testsIssue 2 Fix:
benchmarking_file_path: Path = NonetoOptional[Path] = NoneCode Changes
codeflash/languages/java/test_runner.py (Issue 1):
codeflash/models/models.py (Issue 2):
benchmarking_file_pathcodeflash/discovery/discover_unit_tests.py:
tests_project_rootdirfor Javatests/test_java_test_filter_validation.py:
Testing
Impact
Notes
🤖 Generated with Claude Sonnet 4.5