Commit graph

7761 commits

Author SHA1 Message Date
HeshamHM28
ee70689573 Merge remote-tracking branch 'origin/main' into fix/gradle-classpath-missing-jars 2026-04-09 08:16:49 +00:00
Kevin Turcios
9e6923916c
Merge pull request #2027 from codeflash-ai/fix/dependabot-exclude-fixtures
ci: exclude test fixtures from Dependabot
2026-04-09 02:51:20 -05:00
Kevin Turcios
50224baee9 ci: add dependabot.yml to exclude test fixture directories
Dependabot was auto-discovering all package.json and pyproject.toml
files including 12 in code_to_optimize/ (test fixtures). These PRs
always fail because E2E tests need secrets unavailable on Dependabot
PRs — 70% of Dependabot runs were failing on vite updates to fixtures.

Explicit config monitors only the real dependency files:
- / (root pyproject.toml)
- /packages/codeflash (npm package)
- GitHub Actions versions
2026-04-09 02:50:03 -05:00
Kevin Turcios
bd051ffb42
Merge pull request #2026 from codeflash-ai/fix/pin-claude-code-action-v1.0.89
ci: pin claude-code-action to v1.0.89 (fix Bedrock auth)
2026-04-09 02:17:16 -05:00
Kevin Turcios
77be8b1949
Merge pull request #2025 from codeflash-ai/fix/e2e-path-triggers
ci: replace wildcard path triggers on E2E tests
2026-04-09 02:17:01 -05:00
Kevin Turcios
3dc21bdec3 ci: pin claude-code-action to v1.0.89 to fix Bedrock auth
v1.0.90 broke Bedrock OIDC auth — all Claude Code runs have been
failing with 403 since Apr 8.

Root cause: anthropics/claude-code-action#1196
Pinning to v1.0.89 (last working version) until upstream fix lands.
2026-04-09 02:12:14 -05:00
Kevin Turcios
d344324325 ci: replace wildcard path triggers with targeted filters on E2E tests
All 12 E2E workflows used `paths: ['**']` which triggered on every file
change — docs, configs, experiments, etc. This caused ~140-200 min of
compute per push event (18+ parallel workflows).

Now E2E tests only trigger when relevant source code changes:
- Python E2E: codeflash/**, tests/**, pyproject.toml, uv.lock, workflow files
- JS E2E: same + packages/**
- Java E2E: already had proper path filters (no change needed)

Estimated savings: ~$150-200/mo in CI compute.
2026-04-09 02:06:28 -05:00
mashraf-222
1f698374e5
Merge pull request #2019 from codeflash-ai/cf-1090-java-documentation-gaps
docs: fix Java documentation gaps across 5 pages
2026-04-09 01:09:10 +02:00
Aseem Saxena
4392694ab5
Merge pull request #2021 from codeflash-ai/feat/track-subagent-mode-posthog
feat: track subagent mode in PostHog
2026-04-08 14:06:27 -07:00
Mohamed Ashraf
5f2a1c84de feat: track subagent mode globally in all PostHog events
Move subagent tracking from a single event property to the ph() function
so every PostHog event is automatically tagged with subagent: true/false.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 20:33:52 +00:00
Aseem Saxena
a958f3182b
Merge pull request #1856 from codeflash-ai/fix/structured-error-output-subagent-mode
fix: output structured XML errors in subagent mode
2026-04-08 12:48:18 -07:00
aseembits93
4a50528c49 feat: track subagent mode in cli-optimize-run-start PostHog event
Adds `subagent: bool` property to the existing run-start event so PostHog
can segment and compare agent-driven vs human CLI optimization runs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-08 12:29:49 -07:00
Mohamed Ashraf
71fc73eec3 Merge remote-tracking branch 'origin/main' into cf-1090-java-documentation-gaps 2026-04-08 17:07:40 +00:00
mashraf-222
33c8cc19e4
Merge pull request #1946 from codeflash-ai/cf-1080-spotless-skip
fix: add Spotless skip flags to Maven and Gradle validation
2026-04-08 18:40:52 +02:00
Mohamed Ashraf
81e665dde4 docs: fix Java documentation gaps across 5 pages
Add Java to supported languages in how-codeflash-works, add auth and
GitHub App steps to java-installation, add Java tab to codeflash-all
tip, reorder trace-and-optimize Java examples, and clarify Java class
method syntax in one-function.

Closes CF-1090

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 16:28:19 +00:00
Mohamed Ashraf
8961b14d6f fix: update test assertion to match POSIX-normalized paths in Jest config
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 12:12:26 +00:00
Mohamed Ashraf
4c70a21294 fix: resolve Windows CI failures from path separator mismatches
Normalize paths to forward slashes in JS/TS code generation and coverage
parsing — backslashes are escape chars in JavaScript strings and cause
silent corruption on Windows. Also relax timing test thresholds for CI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 00:15:40 +00:00
Mohamed Ashraf
e30bdd6748 Merge remote-tracking branch 'origin/main' into cf-1080-spotless-skip 2026-04-06 16:18:05 +00:00
Sarthak Agarwal
94e1b02597
Merge pull request #1967 from codeflash-ai/docs/update-java-documentation
docs: update Java documentation to match actual implementation
2026-04-06 18:39:07 +05:30
Sarthak Agarwal
21249265cf
Merge pull request #1988 from codeflash-ai/fix/vitest-coverage-override
Fix Vitest coverage collection by overriding coverage.reporter
2026-04-04 16:32:04 +05:30
Sarthak Agarwal
81be416043
Merge pull request #1991 from codeflash-ai/fix/verifier-path-validation
Fix: Handle test paths outside tests_root in verifier.py
2026-04-04 16:31:52 +05:30
Sarthak Agarwal
c0942b162b
Merge pull request #1992 from codeflash-ai/fix/typescript-jest-config-require
Fix Jest runtime config failing to load TypeScript base configs
2026-04-04 16:31:30 +05:30
Sarthak Agarwal
755d0f24fd
Merge pull request #1990 from codeflash-ai/fix/coverage-utils-framework-agnostic-messages
Fix: Make coverage error messages framework-agnostic
2026-04-04 16:31:16 +05:30
claude[bot]
d8c2b94359 style: remove redundant local import re and fix test conventions
- Remove redundant `import re` inside _is_vitest_workspace() since re is already imported at module level
- Convert tests to use pytest tmp_path fixture instead of tempfile.TemporaryDirectory()
- Add missing return type annotations and encoding= parameters
- Remove unused pytest import and docstrings

Co-authored-by: mohammed ahmed <undefined@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-04 07:56:07 +00:00
claude[bot]
ba0d2bc9a3 style: add missing -> None return type annotations to test methods 2026-04-04 07:52:21 +00:00
mohammed ahmed
08b9fe8d7f
Merge branch 'main' into fix/vitest-coverage-override 2026-04-04 09:51:41 +02:00
mohammed ahmed
cd1387ff7a
Merge branch 'main' into fix/verifier-path-validation 2026-04-04 09:49:18 +02:00
Sarthak Agarwal
973ebc2cf1
Merge pull request #1979 from codeflash-ai/fix/colocated-test-path-resolution
fix: handle co-located test directories with traverse_up
2026-04-04 12:04:00 +05:30
Sarthak Agarwal
0f2c50c239
Merge pull request #1982 from codeflash-ai/fix/vitest-mock-path-resolution
Fix vi.mock() path resolution in generated vitest tests
2026-04-04 12:03:45 +05:30
Sarthak Agarwal
c63defa2b2
Merge pull request #1984 from codeflash-ai/fix/js-project-root-per-function
Fix: Recalculate js_project_root per function in monorepos
2026-04-04 12:03:29 +05:30
Sarthak Agarwal
73d7a77e05
Merge pull request #1986 from codeflash-ai/fix/vitest-setupfiles-path-resolution
Fix Vitest setupFiles path resolution and workspace detection
2026-04-04 12:03:06 +05:30
mohammed ahmed
8d1c5e8108 Fix Jest runtime config failing to load TypeScript base configs
**Problem**: When a project uses `jest.config.ts` (TypeScript config), the
generated runtime config tries to `require('./jest.config.ts')`, which fails
because Node.js CommonJS cannot parse TypeScript syntax without compilation.

**Error**: `SyntaxError: Missing initializer in const declaration` at the
TypeScript type annotation (e.g., `const config: Config = ...`).

**Impact**: Affected 18 out of 38 optimization runs (~47%) in initial testing.
All TypeScript projects using `jest.config.ts` were unable to run tests.

**Root Cause**: Line 386 in test_runner.py used `base_config_path.name`
directly without checking the extension. The generated runtime config is
always a `.js` file, so it cannot use `require()` on `.ts` files.

**Solution**: Check if `base_config_path` is a TypeScript file (.ts). If so,
create a standalone runtime config without trying to extend it via require().
Jest will still discover and use the original TypeScript config naturally.

**Testing**:
- Added comprehensive test in test_jest_typescript_config_bug.py
- Test creates a realistic TypeScript Jest config and verifies the generated
  runtime config loads without syntax errors
- Existing 34 JavaScript test runner tests still pass
- No linting/type errors from `uv run prek`

**Trace IDs affected**: 0fd176bf-5c7f-4f41-8396-77c46be86412 and 17 others

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-04 05:12:00 +00:00
mohammed ahmed
218f3b5014 Fix test path validation error for JS/TS tests outside tests_root
When JavaScript/TypeScript support generates test files in __tests__
subdirectories adjacent to source files (e.g., src/foo/__tests__/codeflash-generated/),
these test files are not within the configured tests_project_rootdir.

Previously, verifier.py:37 called module_name_from_file_path() without
handling the ValueError that occurs when the test path is outside tests_root,
causing optimization runs to crash.

This fix adds try-except handling with a fallback to using just the filename,
matching the pattern already used in javascript/parse.py:330-333.

Fixes trace ID: 84f5467f-8acf-427f-b468-02cb3342097e

Changes:
- codeflash/verification/verifier.py:37-48: Added try-except for path computation
- tests/verification/test_verifier_path_handling.py: Added unit tests

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-04 02:39:52 +00:00
mohammed ahmed
933a2602c3 Fix: Make coverage error messages framework-agnostic
Error messages in coverage_utils.py hardcoded "Jest" even when the
test framework was Vitest. This caused confusion in logs when Vitest
tests failed (e.g., "Jest coverage file not found" when using Vitest).

The JestCoverageUtils class is used for both Jest and Vitest since
they share the same Istanbul/v8 coverage format. Error messages
should be framework-agnostic.

Changes:
- "Jest coverage file not found" → "JavaScript coverage file not found"
- "Failed to parse Jest coverage file" → "Failed to parse JavaScript coverage file"
- "No coverage data found for X in Jest coverage" → "No coverage data found for X in JavaScript coverage"
- "Function X not found in Jest fnMap" → "Function X not found in JavaScript fnMap"

Affected trace IDs: 37e5a406, 735555fa, 940dfe80, c1e1de0e, dbec6c33, de96b1ab, fcf08c6b (7 logs from Apr 4 00:50 batch)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-04 00:55:03 +00:00
claude[bot]
143241310a style: fix quote style in vitest_runner.py
Co-authored-by: mohammed ahmed <undefined@users.noreply.github.com>
2026-04-03 21:42:48 +00:00
mohammed ahmed
bf15f44f44 Fix Vitest coverage collection by overriding coverage.reporter
## Problem
When Codeflash runs Vitest tests, coverage files are not collected even
though tests run successfully. This affects 14 out of ~20 optimization
runs, resulting in 0% coverage reported.

Root cause: The generated `codeflash.vitest.config.mjs` only overrides
`include`, `pool`, and `setupFiles`, but does NOT override coverage
settings. When the project's vitest.config.ts has custom coverage
settings (e.g., `reporter: ["text", "lcov"]`), Vitest's `mergeConfig()`
doesn't properly handle the nested coverage object merge with command-line
flags like `--coverage.reporter=json`, resulting in coverage files not
being written to the expected location.

## Solution
Explicitly override `coverage.reporter` to `['json']` in the generated
codeflash.vitest.config.mjs file. This ensures consistent behavior
regardless of Vitest version or project configuration.

## Testing
Added comprehensive unit tests in test_vitest_coverage_config.py that:
1. Verify coverage overrides are present in generated config
2. Test with and without existing project coverage settings
3. Confirm generated config includes expected coverage.reporter

All tests pass ✓

## References
- Trace IDs affected: 11f707d6, 69b271f5, and 12 others
- Related to iteration 2 investigation in fix_history.log

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-03 21:39:45 +00:00
claude[bot]
9d22f43216 style: fix linting issues in vitest setupFiles PR
- Move `import re` to module-level (was inside function body)
- Add encoding="utf-8" to read_text() call
- Fix tests: use tmp_path fixture, add -> None return types, add encoding args

Co-authored-by: mohammed ahmed <undefined@users.noreply.github.com>
2026-04-03 20:11:05 +00:00
mohammed ahmed
0116a1f9e6 Fix Vitest setupFiles path resolution and workspace detection
**Problem:**

1. Vitest tests were failing with 'Cannot find module .../test/setup.ts'
   when testing functions in nested directories (e.g., extensions/discord/).

2. Root cause had two parts:
   - _is_vitest_workspace() was doing substring search for 'workspace',
     matching it even in comments, causing false positives
   - Custom vitest config wasn't overriding setupFiles, leaving relative
     paths from original config that resolved incorrectly

**Solution:**

1. Improved workspace detection (vitest_runner.py:172-191):
   - Use regex to match actual workspace config patterns
   - Match defineWorkspace( function calls
   - Match workspace: [ property assignments
   - Ignore 'workspace' in comments

2. Override setupFiles in custom config (vitest_runner.py:235-242):
   - Set setupFiles: [] to disable project setup files
   - Prevents relative path resolution issues
   - Safe since Codeflash tests are self-contained

**Testing:**

Added test_vitest_setupfiles_fix.py with 2 test cases:
- Verifies setupFiles is overridden in generated config
- Verifies configs without setupFiles still work

**Trace ID:** 161e21be-9306-4a4d-a9dc-978f65a1af7a

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-03 20:06:27 +00:00
Kevin Turcios
8d51e2d310
Merge pull request #1985 from codeflash-ai/feat/compare-inject-flag
feat: add --inject flag to codeflash compare
2026-04-03 11:35:24 -05:00
Kevin Turcios
a5a475d0b4 address review: fix _shutil alias, warn on --inject with --script
- Replace `import shutil as _shutil` with plain `import shutil` to
  match the existing style in the same function
- Warn when --inject is used with --script mode (unsupported combo)
  instead of silently dropping the flag
2026-04-03 11:21:05 -05:00
Kevin Turcios
3444babf58 add --inject flag to codeflash compare
When benchmarking already-merged optimizations, the benchmark file
often doesn't exist at either the base or head ref. The --inject flag
copies specified files/directories from the working tree into both
worktrees before benchmark discovery and execution, eliminating the
need to cherry-pick benchmark commits onto temporary branches.

Usage:
  codeflash compare <base> <head> --inject tests/benchmarks/test_bench.py
2026-04-03 11:15:18 -05:00
claude[bot]
e7596b5bef style: fix naming, imports, and test conventions in js_project_root fix
- Rename `_get_js_project_root` → `get_js_project_root` (no leading underscores per convention)
- Remove redundant `from pathlib import Path` import inside method (already imported at top)
- Remove unnecessary docstring from new method
- Rewrite tests to use `tmp_path` fixture instead of `tempfile.TemporaryDirectory()`
- Add `.resolve()` calls and `encoding="utf-8"` per project conventions
- Simplify second test file to focus on the actual caching behavior

Co-authored-by: mohammed ahmed <undefined@users.noreply.github.com>
2026-04-03 14:36:12 +00:00
mohammed ahmed
46c49910cd Fix: Recalculate js_project_root per function in monorepos
**Issue:**
When optimizing multiple functions in a monorepo with nested package.json
files (e.g., extensions/discord/package.json), the js_project_root was set
once for the first function and reused for all subsequent functions. This
caused vitest to look for setupFiles in the wrong directory.

**Root Cause:**
test_cfg.js_project_root was set during initial setup and never recalculated.
When function #1 was in extensions/discord/, all subsequent functions in
src/ inherited this wrong project root.

**Fix:**
- Added _get_js_project_root() method to FunctionOptimizer
- Calculate js_project_root fresh for each function using find_node_project_root()
- Updated all test execution paths (behavior, performance, line_profile)

**Impact:**
- Vitest now runs from the correct working directory for each function
- setupFiles can be resolved correctly
- Functions in different monorepo packages can be optimized correctly

Fixes trace IDs: 12d26b00-cbae-49a8-a3cd-c36024ee06ec, 1cde1c65-ef42-4072-afbc-165b0c235688, and 18 others

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-03 14:30:24 +00:00
claude[bot]
3a54a740f9 style: rename _BUILD_FILES to build_files to fix ruff N806
Co-authored-by: Hesham Mohamed <undefined@users.noreply.github.com>
2026-04-03 13:44:41 +00:00
mohammed ahmed
cdb361b5a3 Fix vi.mock() path resolution in generated vitest tests
Extended fix_jest_mock_paths() to handle vitest mock calls (vi.mock()) in
addition to jest.mock(). Previously, only jest.mock() paths were corrected,
causing vitest tests to fail with "Cannot find module" errors.

Problem:
- Source at src/agents/workspace.ts imports ../routing/session-key
- Generated test at test/test_workspace.test.ts used vi.mock('../routing/session-key')
- This resolves to /routing/session-key (wrong - goes up from test/, not found)
- Should be vi.mock('../src/routing/session-key') (correct path from test/)

Solution:
- Updated regex pattern to match both jest.mock() and vi.mock()
- Function now fixes relative paths for both test frameworks
- Added unit tests to verify both jest and vitest paths are corrected

Trace ID: 265059d4-f518-44da-8367-d90ca424092c

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-03 13:44:27 +00:00
HeshamHM28
9ac3d14f23 fix: harden settings.gradle module detection and use exact test assertions
- Replace fragile multi-regex settings.gradle parser with a single broad
  pattern that extracts all quoted module identifiers, handling any DSL style
- Add _scan_filesystem_for_modules() as fallback when settings parsing fails
- Fix all test assertions to use full string equality (== []) not substring (in)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 13:41:57 +00:00
ali
eef9ff9edc
Merge branch 'main' of github.com:codeflash-ai/codeflash into fix/colocated-test-path-resolution 2026-04-03 15:34:29 +02:00
HeshamHM28
dd107d5cf9 fix: resolve missing project JARs in Gradle multi-module classpath
Gradle's testRuntimeClasspath resolves project dependencies to JAR files
(build/libs/*.jar), but testClasses only compiles classes without building
JARs. This caused all tests to fail in multi-module projects like OpenRewrite
where 11 critical dependency JARs were missing from the classpath.

Changes:
- Add _resolve_project_classpath() to detect missing project JARs and replace
  them with build/classes/*/main + build/resources/main directories
- Add _compile_dependency_modules() to compile testRuntimeOnly project deps
  (e.g. rewrite-java-21) that testClasses skips
- Fix _extract_modules_from_settings_gradle() to parse multi-line include(),
  Kotlin listOf() variable declarations, and Groovy-style includes
- Remove old partial multi-module classpath supplement (superseded)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 13:29:16 +00:00
Sarthak Agarwal
a756701bb2
Merge pull request #1974 from codeflash-ai/fix/false-positive-test-discovery
Fix false positive test discovery from substring matching
2026-04-03 18:26:19 +05:30
Kevin Turcios
accb245486
Merge pull request #1941 from codeflash-ai/cf-compare-copy-benchmarks
feat: enhance codeflash compare with memory profiling, script mode, and auto-calibration
2026-04-03 07:13:00 -05:00