Commit graph

6509 commits

Author SHA1 Message Date
Kevin Turcios
e721d8da03 test: add Java test suite and update existing tests
Add comprehensive Java test suite (648 unit tests + 11 E2E tests):
- test_languages/test_java/: parser, context, discovery, replacement,
  instrumentation, comparator, line_profiler, run_and_parse, etc.
- test_java_e2e.py: end-to-end pipeline tests
- test_java_assertion_removal.py, test_java_test_discovery.py
- Update existing Python/JS tests for protocol changes
2026-03-02 21:12:12 -05:00
Kevin Turcios
9cd03277af feat: add Java CLI, setup, and pipeline integration
- Add init_java.py for Java project initialization (Maven detection, config)
- Update cli.py and cmd_init.py with Java language option
- Update detector.py for Java/Maven project auto-detection
- Add config_writer.py for Java codeflash.toml generation
- Update create_pr.py, critic.py, PrComment.py for Java support
- Add Java tracer entry point
- Update console.py and logging_config.py
2026-03-02 21:11:40 -05:00
Kevin Turcios
809dc49e30 refactor: update shared infrastructure for multi-language support
- Extend LanguageSupport protocol in base.py with Java-needed methods
  (parse_test_xml, compare_test_results, replace_function_definitions, etc.)
- Add Java to language registry
- Update models.py with Java-related fields
- Refactor function_optimizer.py base class for language-agnostic dispatch
- Add normalizers package, deduplicate_code, coverage_utils modules
- Update verification modules for Java XML test output parsing
- Update Python/JS support and function_optimizer for protocol changes
- Add parse_xml.py for Python XML test result parsing
2026-03-02 21:11:26 -05:00
Kevin Turcios
fe44f29633 feat: add Java language support modules
Complete Java language implementation under codeflash/languages/java/:
- support.py: JavaSupport (LanguageSupport implementation)
- parser.py, parse.py: Java source parsing via tree-sitter
- context.py: code context extraction for optimization
- discovery.py: function discovery in Java sources
- config.py, build_tools.py: Maven/Gradle project detection
- import_resolver.py: Java import analysis
- formatter.py: Java code formatting
- instrumentation.py: test instrumentation for behavioral equivalence
- test_runner.py: JUnit test execution and result parsing
- test_discovery.py: JUnit test file discovery
- comparator.py: test result comparison via SQLite
- line_profiler.py: bytecode-level line profiling
- replacement.py: optimized code replacement in source files
- function_optimizer.py: JavaFunctionOptimizer subclass
- remove_asserts.py: assertion removal transformer
- concurrency_analyzer.py: thread-safety pattern detection
- resources/: CodeflashHelper.java, codeflash-runtime JAR
2026-03-02 20:03:07 -05:00
Kevin Turcios
e7d752e69d chore: add tree-sitter-java dependency and update lockfile 2026-03-02 20:02:52 -05:00
Kevin Turcios
ece1bc8589 ci: add Java CI workflows and optimize workflow template
Add java-e2e-tests.yml, e2e-java-fibonacci-nogit.yaml workflows,
codeflash-optimize-java.yaml template, and update unit-tests.yaml
to include Java test paths.
2026-03-02 20:02:43 -05:00
Kevin Turcios
031708509c docs: add Java support architecture documentation 2026-03-02 20:02:33 -05:00
Kevin Turcios
95bdd38340 feat: add Java sample project and test fixtures
Sample Maven project (code_to_optimize/java/) with Calculator, BubbleSort,
Fibonacci, StringUtils, etc. plus JUnit 5 tests for E2E validation.
Also adds java_maven test fixture for unit tests.
2026-03-02 20:02:27 -05:00
Kevin Turcios
2f88729d3b feat: add codeflash-java-runtime library
Maven project providing the Java-side runtime for codeflash optimizations:
Comparator, Serializer, ResultWriter, Blackhole, BenchmarkContext,
and a bytecode-level line profiler agent (ASM-based).
Includes comprehensive unit tests.
2026-03-02 20:02:19 -05:00
Kevin Turcios
d229125cdf
Merge pull request #1724 from codeflash-ai/fix-duplicate-detector-concurrency
fix: merge duplicate detector into claude workflow and add concurrency
2026-03-02 21:41:37 +00:00
Kevin Turcios
ad4ebdb710 fix: merge duplicate detector into claude workflow and add concurrency
Consolidates duplicate-code-detector.yml into claude.yml as a step in
the pr-review job. Adds concurrency groups with cancel-in-progress to
prevent comment spam from racing workflow runs.
2026-03-02 16:36:35 -05:00
Sarthak Agarwal
d805c6ebb5
Merge pull request #1720 from codeflash-ai/fix/jest-junit-and-misc
Multiple Small fixes on JS/TS codebases
2026-03-02 22:56:09 +05:30
Sarthak Agarwal
c53740df2e
Merge branch 'main' into fix/jest-junit-and-misc 2026-03-02 22:46:13 +05:30
Sarthak Agarwal
d5dba8ce71 add mocha support 2026-03-02 22:44:48 +05:30
Sarthak Agarwal
6330f69a41
Merge pull request #1551 from codeflash-ai/add_docs_to_js
Docs to JS/TS
2026-03-02 22:24:03 +05:30
Sarthak Agarwal
eaf6ad5860
Update FRICTIONLESS_SETUP_PLAN.md 2026-03-02 22:23:15 +05:30
Sarthak Agarwal
dfb951b945
Update JS_PROMPT_PARITY_RECOMMENDATIONS.md 2026-03-02 22:22:51 +05:30
Sarthak Agarwal
be031ce205 docs: update JS/TS docs with package manager instructions, monorepo guide, and troubleshooting
- Fix javascript-installation.mdx: remove references to nonexistent
  codeflash.config.js, use package.json config, fix supported framework
  list (only Jest/Vitest), add Python CLI requirement note
- Add package manager-specific commands (npm/yarn/pnpm/bun) throughout
- Add monorepo setup guide with workspace examples
- Add auto-detection table explaining what codeflash init detects
- Add troubleshooting for common issues (exports, framework detection,
  timeouts, TypeScript, monorepo)
- Add yarn/pnpm CI examples to GitHub Actions page with monorepo tip

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 22:10:47 +05:30
Sarthak Agarwal
0746ae42ea fix: show actionable error when JS/TS function exists but is not exported
When a user targets a function that exists in the file but is not exported,
show a clear message suggesting they add an export statement, instead of
the generic "function not found" error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 22:04:25 +05:30
Sarthak Agarwal
b0afe2ef9c feat: add skip_confirm and skip_api_key params to JS init for non-interactive mode
Allow init_js_project(), should_modify_package_json_config(), and
collect_js_setup_info() to run without interactive prompts when
skip_confirm=True. Uses auto-detected defaults instead of prompting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 22:03:46 +05:30
Sarthak Agarwal
0490b221f2 fix: raise clear error for unsupported JS test frameworks instead of silent fallback
Add NotImplementedError guard in all 3 test dispatchers (behavioral,
benchmarking, line-profile) for frameworks other than jest and vitest.
Previously, mocha and other frameworks silently fell through to Jest,
causing confusing failures. Now users get a clear error message.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 22:03:13 +05:30
Sarthak Agarwal
4bf8cb7412 feat: discover object methods exported via CJS module.exports = variable
Resolve `module.exports = varName` where varName is an object literal
containing methods. For patterns like `const utils = { match() {} };
module.exports = utils;`, the individual methods are now recognized as
exported. This fixes function discovery for CJS libraries like Moleculer.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 22:01:56 +05:30
Sarthak Agarwal
76d994e87c feat: discover const arrow functions exported via named export clauses
Post-process find_functions() to mark functions as exported when they appear
in named export clauses like `export { joinBy }`. This fixes discovery for
TypeScript codebases (e.g., Strapi) that define const arrow functions and
export them via a separate export statement.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 22:00:33 +05:30
Sarthak Agarwal
3c2a2b3694 feat: bundle JUnit XML reporter for Jest, replacing external jest-junit dependency
Ship a zero-dependency jest-reporter.js inside the codeflash runtime package
instead of requiring the external jest-junit npm package. This ensures the
reporter is always available when codeflash is installed, fixing Jest-based
projects (Strapi, Moleculer) that failed because jest-junit wasn't installed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 21:59:41 +05:30
Kevin Turcios
ab1a5355ef
Merge pull request #1718 from codeflash-ai/fix-claude-workflow
fix: rewrite Claude Code PR review prompt
2026-03-02 15:55:55 +00:00
Kevin Turcios
29d0d2cb48 fix: rewrite Claude Code PR review prompt for better instruction following
- Use XML structure instead of markdown for clearer step boundaries
- Resolve stale review threads via GraphQL instead of leaving them
- Positive framing instead of negation for instructions
- Replace aggressive language with calm direct instructions
- Add /simplify skill invocation for code quality pass
- Add verification checkpoint at the end
- Auto-close stale codeflash optimization PRs (age, conflicts, CI failures, deleted functions)
- Remove inline comment MCP tool, add Skill tool
2026-03-02 10:53:35 -05:00
Kevin Turcios
aed71612ba
Merge pull request #1715 from codeflash-ai/prepare-java-support
add Java scaffolding
2026-03-02 12:45:21 +00:00
Kevin Turcios
3ad21016fc refactor: deduplicate format_code and validate_syntax between JS and TS support
Use self.default_file_extension in format_code and a treesitter_language
property in validate_syntax so TypeScriptSupport inherits both methods
from JavaScriptSupport instead of duplicating them.
2026-03-02 07:33:45 -05:00
Kevin Turcios
67f789ce67 refactor: deduplicate language metadata and helper function creation
Extract add_language_metadata() in AiServiceClient to consolidate 3
identical payload setup blocks. Extract helper_from_func() closure in
import_resolver to consolidate duplicate HelperFunction creation.
2026-03-02 07:20:27 -05:00
Kevin Turcios
415ad33bdc fix: add missing protocol methods to PythonSupport
Protocol methods with default bodies on a Protocol class are not
inherited by implementations. Add explicit detect_module_system and
adjust_test_config_for_discovery to PythonSupport.
2026-03-02 07:09:32 -05:00
Kevin Turcios
38444462f3 docs: document LanguageSupport protocol methods in architecture.md 2026-03-02 07:07:47 -05:00
Kevin Turcios
8ca716258f refactor: convert remaining language guards to protocol dispatch and add Java scaffolding
Add JAVA enum value, is_java() helper, registry import guard, and Java
test frameworks (junit5/junit4/testng) as zero-behavior-change scaffolding.

Add 6 new LanguageSupport protocol methods/properties
(default_language_version, valid_test_frameworks,
test_result_serialization_format, load_coverage,
adjust_test_config_for_discovery, detect_module_system,
process_generated_test_strings) and implement them in PythonSupport and
JavaScriptSupport.

Replace 12 is_python()/is_javascript() guards across aiservice.py (5),
parse_test_output.py (4), verifier.py (2), and discover_unit_tests.py (1)
with protocol dispatch, moving ~40 lines of JS instrumentation logic from
verifier.py into JavaScriptSupport.

Also add imported_type_skeletons field to CodeContext and
JAVA_TESTCASE_TIMEOUT constant for upcoming Java support.
2026-03-02 07:04:36 -05:00
Kevin Turcios
2e4127a3b6
Merge pull request #1708 from codeflash-ai/extract-js-optimizer
refactor: extract JavaScript Optimizer subclass
2026-03-02 11:44:11 +00:00
Kevin Turcios
341c622d40 docs: update rules and architecture for new language structure
- Add JS optimizer, normalizer, and support files to architecture tree
- Update key entry points table for per-function optimization and test execution
- Add protocol dispatch preference to language-patterns rules
- Fix stale context path in optimization-patterns
- Add explicit utf-8 encoding rule scoped to new/changed code
2026-03-02 06:10:12 -05:00
Kevin Turcios
04a94f2b03 test: update tests for refactored language support
- Update discover_functions calls to new (source, file_path) signature
- Use language-specific FunctionOptimizer subclasses in tests
- Add explicit utf-8 encoding to read_text()/write_text() for Windows
- Fix pytest fixture in TestTsJestSkipsConversion (was __init__)
- Update nonexistent file tests for source-based discover_functions
- Remove unused imports
2026-03-02 06:09:06 -05:00
Kevin Turcios
3ebaf1066a refactor: extract JavaScriptFunctionOptimizer and eliminate language guards
- Extract JavaScriptFunctionOptimizer subclass with JS-specific overrides
  for code context, candidate comparison, line profiling, and code replacement
- Replace is_python()/is_javascript() guards with LanguageSupport protocol
  dispatch across optimizer, verification, and utility layers
- Move generate_concolic_tests into LanguageSupport (default no-op, Python
  overrides with CrossHair)
- Collapse normalizer infrastructure: delete CodeNormalizer ABC and registry,
  move implementations into language directories
- Unify discover_functions to source-based signature (source, file_path)
- Flatten function discovery indirection, making git-diff discovery work
  for JS/TS
- Extract language-agnostic code replacer to languages/code_replacer.py
- Deduplicate error constants and function grouping logic into shared locations
- Restore pytest_cmd support in PythonSupport test runners
- Add empty-code guard in language-agnostic code replacer
- Fix tmpdir_path cleanup, self.args crash, UnboundLocalError in finally block
2026-03-02 06:08:22 -05:00
Kevin Turcios
8a75fe1377
Merge pull request #1699 from codeflash-ai/extract-python-optimizer
refactor: extract PythonFunctionOptimizer subclass
2026-03-02 08:18:15 +00:00
claude[bot]
4ccbffe4f3 fix: combine conditions in line_profiler_step to avoid returning empty dict for all TestResults
The return statement was outside the inner if-not block, causing all TestResults
(even populated ones) to return an empty dict.

Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com>
2026-03-02 07:36:55 +00:00
claude[bot]
192cf0f8c8 style: fix unused loop variable in function_optimizer.py
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 07:19:31 +00:00
Kevin Turcios
b6af185998 fix: split discovery and instrumentation log messages for E2E harnesses
Log "Discovered N existing unit test files" after counting tests, and
"Instrumented N existing unit test files" after injecting profiling.
Python E2E harness matches "Discovered", JS harness matches "Instrumented".
2026-03-02 02:16:50 -05:00
claude[bot]
6f2939aa02 fix: restore 'Discovered' log message for E2E test compatibility
The refactoring changed the log message from 'Discovered' to 'Instrumented',
breaking the E2E test regex in end_to_end_test_utilities.py:225.

Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com>
2026-03-02 06:27:56 +00:00
claude[bot]
1f914c58e3 docs: update architecture.md with new Python optimizer files
Add languages/python/function_optimizer.py and languages/python/optimizer.py
to the directory tree and Key Entry Points table.

Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 05:44:02 +00:00
Kevin Turcios
6a916ac83f fix: address review feedback on PythonFunctionOptimizer extraction
- Add clarifying comment on shared replace_function_definitions_in_module import
- Remove misleading alias in test_unused_helper_revert.py, use PythonFunctionOptimizer directly
- Align base line_profiler_step return type to dict[str, Any]
- Fix latent bug: handle non-empty TestResults in line_profiler_step
2026-03-01 23:51:43 -05:00
Kevin Turcios
2b40e4bd48
Update codeflash/optimization/optimizer.py
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
2026-03-01 23:36:00 -05:00
Kevin Turcios
a55841b978 fix: use PythonFunctionOptimizer in tests that depend on Python-specific hooks 2026-03-01 23:22:19 -05:00
Kevin Turcios
96c1459ca4 chore: add TODO for get_code_optimization_context extraction, update follow_up.md 2026-03-01 23:22:15 -05:00
Kevin Turcios
a3d81ba95d refactor: remove redundant AST pre-resolution from create_function_optimizer
The factory method was resolving the function AST from original_module_ast
before constructing PythonFunctionOptimizer, duplicating the _resolve_function_ast
hook. Now the hook handles resolution and the factory checks the result post-construction.
2026-03-01 23:10:57 -05:00
Kevin Turcios
a2e3a0a84d refactor: extract line_profiler_step and parse_line_profile_test_results into PythonFunctionOptimizer 2026-03-01 23:02:59 -05:00
Kevin Turcios
c8b8074e48 refactor: extract should_skip_sqlite_cleanup hook into PythonFunctionOptimizer 2026-03-01 22:59:49 -05:00
Kevin Turcios
2457da1932 refactor: extract compare_candidate_results hook into PythonFunctionOptimizer 2026-03-01 22:57:18 -05:00