Commit graph

14 commits

Author SHA1 Message Date
Mohamed Ashraf
f1521d7a2d fix: resolve pre-existing mypy errors on files touched by this PR
The prek mypy hook runs on changed files and bypasses the pyproject.toml
tests/ exclude, surfacing pre-existing errors in both context.py and
test_context.py that block CI for this PR. Fixes applied:

- Import Language from language_enum instead of base (base re-exports are
  not explicit; strict mypy flags attr-defined)
- Annotate _extract_class_declaration, _import_to_statement,
  get_java_imported_type_skeletons, and resolved_imports
- Guard None start/end_line in _extract_function_source_by_lines and
  find_helper_functions; guard None file_path in the import skeleton loop
- Drop unreachable `if not node: continue` in _extract_public_method_signatures
  (JavaMethodNode.node is non-nullable)
- Add -> None to every test method and fix an `int | None` comparison in
  test_context.py

All 880 Java tests pass after the change.
2026-04-28 15:40:02 +00:00
Mohamed Ashraf
1cfcc3aee7 fix: cap wildcard import expansion to avoid token explosion and 5-minute stalls
Wildcard imports like `import org.jooq.*` expand to 870+ types, causing
5 minutes of disk I/O per function before the token budget check kicks in.
89% of jOOQ functions were skipped due to this.

When a wildcard expands to >50 types, filter to only types referenced in
the target method's code. This turns a 5-minute failure into a <1 second
resolution with only the relevant types included.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-01 16:21:39 +00:00
Kevin Turcios
eceac13fc3 Merge remote-tracking branch 'origin/main' into omni-java
# Conflicts:
#	.claude/rules/architecture.md
#	.claude/rules/code-style.md
#	.github/workflows/claude.yml
#	.github/workflows/duplicate-code-detector.yml
#	codeflash/api/aiservice.py
#	codeflash/cli_cmds/console.py
#	codeflash/cli_cmds/logging_config.py
#	codeflash/code_utils/deduplicate_code.py
#	codeflash/discovery/discover_unit_tests.py
#	codeflash/languages/base.py
#	codeflash/languages/code_replacer.py
#	codeflash/languages/javascript/mocha_runner.py
#	codeflash/languages/javascript/support.py
#	codeflash/languages/python/support.py
#	codeflash/optimization/function_optimizer.py
#	codeflash/verification/parse_test_output.py
#	codeflash/verification/verification_utils.py
#	codeflash/verification/verifier.py
#	packages/codeflash/package-lock.json
#	packages/codeflash/package.json
#	tests/languages/javascript/test_support_dispatch.py
#	tests/test_codeflash_capture.py
#	tests/test_languages/test_javascript_test_runner.py
#	tests/test_multi_file_code_replacement.py
2026-03-04 01:52:32 -05:00
misrasaurabh1
aae13a8e69 feat: skip inner-class methods in Java discovery; revert replacement-level inner-class workarounds
- parser.py: add `is_class_nested` flag to `JavaMethodNode`; track
  `class_depth` in `_walk_tree_for_methods` (incremented each time a
  type declaration is entered) and set `is_class_nested = True` when
  depth ≥ 2 (method lives inside a nested/inner class)

- discovery.py: add early-exit in `_should_include_method` when
  `method.is_class_nested` is True — inner-class methods cannot be
  reliably instrumented or tested in isolation, so we skip them up-front
  rather than wasting LLM tokens on candidates that will always be
  rejected later

- replacement.py: revert Bug-4 replacement-level workarounds that are
  now obsolete:
  * remove `target_class_name` parameter from `_parse_optimization_source`
  * restore simple first-match `break` in target-method selection
  * remove class_name filter that blocked helpers from "other" classes

- tests: update `TestNestedClasses`, `TestExtractCodeContextWithInnerClasses`
  to reflect the new no-inner-class-discovery contract; remove
  `TestInnerClassHelperFilter` (superseded by discovery filter);
  add `TestInnerClassMethodFilter` in test_discovery.py with four
  scenarios covering static nested, non-static inner, outer-only, and
  deeply-nested classes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 00:47:01 +00:00
Mohamed Ashraf
0e753e199a fix: improve Java type context sent to AI for test generation
- Increase imported type skeleton token budget from 2000 to 4000
- Add constructor signature summary headers to skeleton output
- Expand wildcard imports (e.g., import com.foo.*) into individual types
  instead of silently skipping them
- Prioritize skeleton processing for types referenced in the target method
  so parameter types are guaranteed context before less-critical types
- Fix invalid [no-arg] annotation in constructor summaries

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 16:55:37 +00:00
mashraf-222
0b8284f519
Merge pull request #1514 from codeflash-ai/fix/java-e2e-critical-bugs
fix: resolve 4 critical Java E2E pipeline bugs
2026-02-18 12:05:48 +02:00
Mohamed Ashraf
ed767da78c test: add Bug 4 early exit tests and strengthen Bug 3 edge case coverage
Bug 4 (candidate_early_exit.py - 6 tests):
- All tests failed → 0 total passed (guard triggers)
- Some tests passed → nonzero (guard does not trigger)
- Empty results → 0 passed (guard triggers)
- Only non-loop1 results → ignored by report (guard triggers)
- Mixed test types all failing → 0 across all types
- Single passing among many failures → prevents early exit

Bug 3 edge cases (context.py - 8 tests):
- Wildcard imports are skipped (class_name=None)
- Import to nonexistent class returns None skeleton
- Skeleton output is well-formed Java (has braces)
- Protected and package-private methods excluded
- Overloaded public methods all extracted
- Generic method signatures extracted correctly
- Round-trip: _extract_type_skeleton → _format_skeleton_for_context
- Round-trip with real MathHelper fixture file

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 10:01:44 +00:00
Mohamed Ashraf
d236d5dd33 test: add tests for imported type skeleton extraction
Add 13 tests covering:
- get_java_imported_type_skeletons(): internal import resolution,
  method signature extraction, external import filtering, deduplication,
  empty input handling, and token budget enforcement
- _extract_public_method_signatures(): public method extraction,
  constructor exclusion, empty class handling, class name filtering
- _format_skeleton_for_context(): basic class formatting, enum
  constants, empty class edge case

Also resolve merge conflict from PR #1515 optimization (bytes-based
single-pass method signature extraction).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 09:54:56 +00:00
HeshamHM28
c4da93c41b fix windows tests 2026-02-18 05:13:46 +02:00
Mohamed Ashraf
09374c1a72 fix: use tree-sitter name-based lookup for Java function extraction
In --all mode, stale line numbers in FunctionToOptimize caused
InvalidJavaSyntaxError when a prior optimization modified the same file.
Now extract_function_source re-parses with tree-sitter to find methods
by name, matching how Python (jedi) and Java replacement already work.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 19:39:16 +00:00
misrasaurabh1
520a1ff08e fix: resolve merge conflict and standardize Java to use FunctionToOptimize
- Resolve merge conflict in code_replacer.py with Java-specific handling
- Update all Java modules to use FunctionToOptimize instead of FunctionInfo
- Add Language.JAVA to language_enum.py
- Update attribute names: name→function_name, start_line→starting_line, etc.
- Update all Java tests to use correct attribute names

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 19:08:09 -08:00
misrasaurabh1
c35ce69eef fix code context extraction bugs 2026-01-30 16:05:44 -08:00
misrasaurabh1
045b4dd6aa make tests do full string equality check 2026-01-30 11:34:15 -08:00
misrasaurabh1
29f266ee63 wip java support 2026-01-30 00:37:24 -08:00