Commit graph

70 commits

Author SHA1 Message Date
dependabot[bot]
ea57fba470
chore(deps): bump better-sqlite3 in /packages/codeflash
Bumps [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) from 12.6.2 to 12.9.0.
- [Release notes](https://github.com/WiseLibs/better-sqlite3/releases)
- [Commits](https://github.com/WiseLibs/better-sqlite3/compare/v12.6.2...v12.9.0)

---
updated-dependencies:
- dependency-name: better-sqlite3
  dependency-version: 12.9.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-23 10:01:59 +00:00
Kevin Turcios
892bff485d feat(js): add JavaScript function tracer with Babel instrumentation
Replaces source-level JavaScript function tracing with Babel AST
transformation via babel-tracer-plugin.js and trace-runner.js. Adds
replay test generation, Python-side tracer runner, and --language
flag to the tracer CLI for explicit JS/TS routing.
2026-04-23 04:33:58 -05:00
Sarthak Agarwal
41f64e9459
Merge pull request #1899 from codeflash-ai/cf-fix-v8-serializer-cross-context
fix: use cross-context type detection in V8 serializer self-test
2026-03-26 23:52:17 +05:30
ali
56403d21aa
refactor: install Python CLI into isolated venv instead of uv tool
Replace `uv tool install` (which installs globally into ~/.local/bin) with
a dedicated venv at an OS-specific cache directory (~/.cache/codeflash/venv
on Linux, ~/Library/Caches/codeflash/venv on macOS, %LOCALAPPDATA%\codeflash\venv
on Windows). The CLI entry point now invokes the binary directly from the venv
instead of via `uv tool run`. Also strips VIRTUAL_ENV/CONDA env vars from child
processes to avoid interference from activated environments.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-26 17:33:56 +02:00
ali
0641930f25
fix: use cross-context type detection in V8 serializer self-test
The V8 serialization self-test used `instanceof Map` which fails in
Jest's sandboxed VM context where the Map class from v8.deserialize
differs from the test environment's Map class. This incorrectly
disabled V8 serialization, falling through to msgpack which often
also isn't resolvable in monorepo setups.

Replaced all `instanceof` checks in the serializer with
`Object.prototype.toString.call()` for cross-VM-context compatibility,
matching the pattern already used in the msgpack codepath.

Trace IDs: 003e1410, fe2ae122, fde51112 (153 affected logs)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-25 18:47:38 +02:00
Kevin Turcios
748094c7e0 Merge remote-tracking branch 'origin/main' into fix-dependabot-vulns 2026-03-10 16:54:29 -06:00
Sarthak Agarwal
aa63155610 update JS package to 0.10.2 2026-03-09 02:32:02 +05:30
Kevin Turcios
d9a329667e fix: resolve jest-runner inside scoped package subdirectories
The recursive search in loop-runner.js wasn't entering package
directories inside scoped namespaces (e.g. @jest/core), so it couldn't
find jest-runner nested at @jest/core/node_modules/jest-runner.
2026-03-07 12:26:52 -06:00
Kevin Turcios
45fb07fad2 fix: upgrade dependencies to resolve Dependabot security alerts
Upgrade Python deps via uv sync --upgrade (werkzeug, filelock for py>=3.10,
and others). Run npm audit fix across JS test fixtures to patch minimatch
and rollup vulnerabilities.

Remaining unfixable:
- filelock <3.20.3 for py<3.10 (patched version requires py>=3.10)
- serialize-javascript in mocha ^10 (fix requires mocha 11 breaking change)
2026-03-07 03:48:38 -05:00
Sarthak Agarwal
bc5e3e878a fix mocha test runner 2026-03-04 03:42:10 +05:30
Sarthak Agarwal
ed2594bfd1 fix: resolve Vitest benchmarking showing wall-clock time instead of per-function timing
Root cause: Vitest performance tests reported "20.0 seconds over 1 loop"
(JUnit XML wall-clock fallback) instead of actual per-function nanosecond
timing. This was a chain of two issues:

1. **stdout interception**: Vitest's default `threads` pool intercepts
   process.stdout.write() and console.log(), preventing timing markers
   from flowing to the parent process. Fixed by adding `--pool=forks`
   to all Vitest commands and config files. The `forks` pool uses child
   processes where stdout flows directly to the parent.

2. **test name detection**: Even after markers flowed through (43,000+
   found in stdout), the parser couldn't match them to JUnit XML
   testcases because all markers had "unknown" as the test name. This
   happened because Vitest doesn't inject `beforeEach` as a global
   (unlike Jest), so capture.js's Jest-style hook to set
   `currentTestName` never fired.

   Fixed by adding Vitest-specific test name detection in capture.js:
   - Primary: `expect.getState().currentTestName` (full describe path)
   - Fallback: `__vitest_worker__.current.fullTestName`
   - Defense-in-depth: parser fallback matches "unknown" markers to
     the first testcase when no name match is found

Result: cheerio's `isHtml` went from "20.0s / 1 loop" to
"902μs / 20,853 loops" with proper speedup analysis.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 14:31:10 +05:30
Sarthak Agarwal
c53740df2e
Merge branch 'main' into fix/jest-junit-and-misc 2026-03-02 22:46:13 +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
Sarthak Agarwal
3a092a28ba [WIP] Docs to JS/TS 2026-02-19 23:41:47 +05:30
ali
7308afebc7
Merge branch 'main' of github.com:codeflash-ai/codeflash 2026-02-17 23:10:28 +02:00
ali
d3074096e8
fix always execute capture perf for external runner 2026-02-17 23:10:01 +02:00
mohammed ahmed
b4ea8b6bd6
Update packages/codeflash/runtime/loop-runner.js
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
2026-02-16 19:26:51 +02:00
ali
d13cdb559b
fallback to directly require the jest-runner module inside the loop runner 2026-02-16 19:11:27 +02:00
ali
2d73cf88bb
typo 2026-02-16 14:55:49 +02:00
mohammed ahmed
56941357c9
Update packages/codeflash/runtime/loop-runner.js
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
2026-02-16 14:35:33 +02:00
ali
2e77f85834
fix: resolve jest-runner from project's node_modules for Jest 30 compatibility
The loop-runner was loading jest-runner from codeflash's node_modules (v29)
instead of the project's (v30), causing "runtime.enterTestCode is not a function"
errors. This fix:

- Adds recursive search to find jest-runner in any node_modules structure
- Works with npm, yarn, and pnpm (including non-hoisted deps)
- Prefers higher versions when multiple are found
- Removes internal looping in capturePerf when using external loop-runner
- Creates fresh TestRunner per batch to avoid Jest 30 state corruption

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-16 14:31:08 +02:00
ali
e9b7154361
Merge branch 'main' of github.com:codeflash-ai/codeflash into fix/js-jest30-loop-runner 2026-02-12 16:39:33 +02:00
ali
536c1d0aad
remove debug statements 2026-02-12 16:15:39 +02:00
ali
175226bd20
fix: correct loop index calculation in JS performance benchmarking
Loop index now represents how many times all test files ran (batch count)
instead of per-invocation index. Also fixes Date.now() usage when random
seed is active and removes JS-specific workaround in number_of_loops.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-12 15:32:16 +02:00
Sarthak Agarwal
0b611c722a Install cli post cloning in npm 2026-02-11 00:10:08 +05:30
Sarthak Agarwal
ce13a6d534
Merge branch 'main' into fix/js-jest30-loop-runner 2026-02-09 21:06:06 +05:30
Sarthak Agarwal
410aca7b83 fix loop count issue among subsequent tests 2026-02-09 20:21:37 +05:30
mohammed ahmed
f800ae3d92
Merge branch 'main' into fix/js-jest30-loop-runner 2026-02-06 17:22:15 +02:00
Sarthak Agarwal
ff7c0f9813 version upgrade to 0.7.1 2026-02-05 22:27:40 +05:30
Sarthak Agarwal
17916ef9fb fix on loop count 2026-02-05 18:07:35 +05:30
mohammedahmed18
017bde1c1f refactor: improve code quality and documentation in loop-runner and capture
Improvements to loop-runner.js:
- Extract isValidJestRunnerPath() helper to reduce code duplication
- Add comprehensive JSDoc comments for Jest version detection
- Improve error messages with more context about detected versions
- Add better documentation for runTests() method
- Add validation for TestRunner class availability in Jest 30

Improvements to capture.js:
- Extract _recordAsyncTiming() helper to reduce duplication
- Add comprehensive JSDoc for _capturePerfAsync() with all parameters
- Improve error handling in async looping (record timing before throwing)
- Enhance shouldStopStability() documentation with algorithm details
- Improve code organization with clearer comments

These changes improve maintainability and debugging without changing behavior.
2026-02-03 21:16:26 +00:00
ali
4157534a26
fix: use getter functions for env var constants in capture.js
After merging main, constants like PERF_STABILITY_CHECK, PERF_MIN_LOOPS,
PERF_LOOP_COUNT were changed to getter functions. Updated all references
in capturePerf and _capturePerfAsync to use the getter function calls.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 22:15:18 +02:00
mohammed ahmed
4c61d08ef9 Merge branch 'main' into fix/js-jest30-loop-runner 2026-02-03 19:18:20 +02:00
ali
04a87cfaec
fix: add Jest 30 support, fix time limit, and fix async function looping
- Add Jest 30 compatibility by detecting version and using TestRunner class
- Resolve jest-runner from project's node_modules instead of codeflash's bundle
- Fix time limit enforcement by using local time tracking instead of shared state
  (Jest runs tests in worker processes, so state isn't shared with runner)
- Integrate stability-based early stopping into capturePerf
- Use plain object instead of Set for stableInvocations to survive Jest module resets
- Fix async function benchmarking: properly loop through iterations using async helper
  (Previously, async functions only got one timing marker due to early return)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 19:04:50 +02:00
Sarthak Agarwal
6384a555df
Merge branch 'main' into fix/jest-xml-path-resolution-monorepo 2026-02-03 20:00:10 +05:30
mohammedahmed18
7f954d1544 refactor: Leverage Python project root detection for jest-runner resolution
Instead of duplicating monorepo detection logic in JavaScript, leverage
the existing Python _find_node_project_root and add _find_monorepo_root
functions. Pass the detected monorepo root via CODEFLASH_MONOREPO_ROOT
environment variable to the loop-runner.

This approach:
- Reuses existing Python project detection logic
- Provides a reliable monorepo root hint to JavaScript
- Maintains fallback directory traversal for edge cases

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-03 14:26:41 +00:00
Sarthak Agarwal
5084ba4b3c update npm package 2026-02-03 19:55:15 +05:30
Sarthak Agarwal
1323df0633 update package to 0.7.0 2026-02-03 19:54:14 +05:30
mohammedahmed18
8223796576 fix: Support Jest runner resolution in monorepos
Added resolveJestRunner() function that walks up the directory tree to
find jest-runner in workspace root node_modules. This fixes the
"jest-runner requires jest-runner to be installed" error when running
in monorepo packages.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-03 12:33:26 +00:00
Sarthak Agarwal
66fadf7ad3 fix: use getter functions for perf env vars to support Vitest module caching
Vitest caches modules and may load capture.js before environment
variables like CODEFLASH_PERF_LOOP_COUNT are set. When these were
read as constants at module load time, they would always return
default values.

This change converts the performance configuration from constants
to getter functions that read environment variables at runtime,
ensuring correct values are used even when the module is cached.

Fixes:
- PERF_LOOP_COUNT always being 1 in Vitest
- PERF_BATCH_SIZE, PERF_MIN_LOOPS, etc. using defaults instead of env values

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 18:02:23 +05:30
Sarthak Agarwal
565b1f59a0 update package to 0.5.0 2026-02-02 23:48:16 +05:30
Sarthak Agarwal
f88b6b7142 vitest perf looping inefficiency 2026-02-02 18:28:04 +05:30
Saurabh Misra
82d9e435ef
Merge branch 'main' into add_vitest_support_to_js 2026-02-01 12:32:09 -08:00
Sarthak Agarwal
aa9b926200
Merge branch 'main' into add_vitest_support_to_js 2026-02-01 03:41:43 +05:30
Kevin Turcios
05711151c2 limit the python version for the postinstall script 2026-01-31 13:53:10 -05:00
Sarthak Agarwal
eb1d27e359 update package to 0.4.0 2026-01-31 20:21:50 +05:30
Sarthak Agarwal
3e7be21e16
Merge branch 'main' into add_vitest_support_to_js 2026-01-31 19:39:03 +05:30
Saurabh Misra
5296dc8321 fix: calculate MAX_BATCHES correctly in Jest loop-runner
Previously, MAX_BATCHES was set to PERF_LOOP_COUNT directly (e.g., 250),
which caused the loop-runner to run 250 batches even though only 25
batches were needed to produce timing data (with BATCH_SIZE=10).

The bug was that timing markers only appeared for the first N batches
(where N = LOOP_COUNT / BATCH_SIZE), and the remaining batches were
wasted overhead.

Fix: Calculate MAX_BATCHES as ceil(LOOP_COUNT / BATCH_SIZE) + 1, capped
at LOOP_COUNT. This ensures only the necessary batches run:
- With LOOP_COUNT=250, BATCH_SIZE=10: MAX_BATCHES = 26 (not 250)

This significantly improves benchmark efficiency by eliminating wasted
Jest passes that don't contribute timing data.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 06:47:01 +00:00
Sarthak Agarwal
4bf664dc39 add vitest runner 2026-01-31 04:29:59 +05:30
Sarthak Agarwal
a29f877df5 publish the 0.3.0 to npm 2026-01-29 23:00:28 +05:30