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
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.
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.
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>
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>
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>
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>
- 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>
**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>
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>
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>
## 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>
**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>
- 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
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
- 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>
**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>
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>
- 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>
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>