-
Notifications
You must be signed in to change notification settings - Fork 21
fix: wire Java formatter into detection pipeline #1400
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
Conversation
- 14 new tests in TestConcurrencyPatterns class - synchronized blocks/methods preserved after transformation - volatile field reads, AtomicInteger ops preserved - ConcurrentHashMap, Thread.sleep, wait/notify patterns preserved - ReentrantLock, CountDownLatch patterns preserved - Real-world TokenBucket and CircularBuffer patterns validated - AssertJ assertion on synchronized method call validated - Total: 71 tests (57 existing + 14 new), all passing
…g coverage - Add TestComparatorEdgeCases: float, NaN, Infinity, empty collections, large numbers, null vs empty, booleans - Add TestComparatorErrorHandling: missing DBs, schema mismatch, None return values, error type comparison - Add TestComparatorJavaEdgeCases: EPSILON tolerance, NaN handling, empty tables, Infinity handling - 29 new tests (52 total), all passing Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
… routing - Add TestSqlitePathSelection: file existence checks for Java comparison path - Add TestPassFailFallbackBehavior: pass_fail_only ignores return values, detects failure changes - Add TestDecisionPointDocumentation: canary tests for decision logic code pattern - 12 tests covering SQLite path selection, pass_fail_only behavior, and code pattern stability Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Replace 'not supported for Java' stub with actual formatter detection - Check for java executable via JAVA_HOME and shutil.which - Check for google-java-format JAR in project/.codeflash, ~/.codeflash, and tempdir - Return formatter commands when both java and JAR available - Graceful fallback with descriptive message when not available - Add 7 tests covering all detection paths and non-regression for Python/JS Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Verification ResultsTests✅ All 25 formatter tests passed Code ReviewMain changes:
These timeout-related changes are outside the scope of formatter wiring and should either be:
E2E Verification✅ Formatter detection logic works correctly:
RecommendationThe core formatter wiring functionality is solid and well-tested. Please address the unrelated timeout documentation changes before merging. |
Restore timeout documentation comments in concolic_testing.py and test_runner.py that were unintentionally removed. These comments document the timeout parameter behavior and environment variable overrides. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Update: The unrelated timeout documentation changes have been reverted in commit 5a85fef. The PR now only contains the Java formatter wiring changes. |
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Merge latest changes from base branch including: - Java compilation error detection (PR #1394) - Java formatter detection via google-java-format (PR #1400) - Enhanced test coverage for comparator logic Conflict resolution: - tests/test_languages/test_java/test_comparison_decision.py: Used PR version that enforces strict correctness (no pass_fail_only fallback tests) to align with PR 1401's goal of removing pass_fail_only mode entirely. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Problems fixed
The Java formatter (
JavaFormatterclass incodeflash/languages/java/formatter.py) exists and is fully functional, capable of formatting Java code using google-java-format. However, the project detection pipeline indetector.pyreturned[], "not supported for Java"when asked to detect a formatter for Java projects. This meant optimized Java code was never formatted before being submitted, potentially causing diff noise in PRs and inconsistent code style.Root causes
The
_detect_formatterfunction had a hard-coded early return for Java:This was a placeholder that was never replaced with actual detection logic, even though the
JavaFormatterclass was already implemented with full google-java-format support.Solutions implemented
Added
_detect_java_formatter(project_root)function that:JAVA_HOMEenvironment variable orshutil.which("java")<project_root>/.codeflash/google-java-format-<version>-all-deps.jar~/.codeflash/google-java-format-<version>-all-deps.jar<tempdir>/codeflash/google-java-format-<version>-all-deps.jarjava -jar <path> --replace $file)The version constant is reused from
JavaFormatter.GOOGLE_JAVA_FORMAT_VERSIONto stay in sync.Code changes
codeflash/setup/detector.py:import os, shutil, tempfileat module level_detect_formatterto call_detect_java_formatterfor Java_detect_java_formatterfunction with java and JAR detection logictests/test_languages/test_java/test_formatter.py:TestDetectJavaFormatterclass with 7 tests:Testing
Impact
Java projects will now have their optimized code formatted with google-java-format when the JAR is available. This produces cleaner optimization PRs with consistent code style. When the JAR is not available, behavior is unchanged (no formatting, no errors).