-
Notifications
You must be signed in to change notification settings - Fork 21
feat(js): add JavaScript function tracer with Babel instrumentation #1377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
⚡️ Codeflash found optimizations for this PR📄 18% (0.18x) speedup for
|
| logger.info("Running JavaScript tracer: %s", " ".join(cmd)) | ||
|
|
||
| try: | ||
| process = subprocess.run(cmd, cwd=project_root, env=env, capture_output=False, check=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
capture_output=False, which makes debugging failures very difficult. When the tracer fails (non-zero exit code), there's no stdout/stderr available to diagnose the issue.
Suggested fix:
process = subprocess.run(cmd, cwd=project_root, env=env, capture_output=True, text=True, check=False)
if process.returncode != 0:
result["error"] = f"Tracing failed with exit code {process.returncode}\nStdout: {process.stdout}\nStderr: {process.stderr}"| conn.close() | ||
| return functions | ||
|
|
||
| except Exception: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested fix:
except Exception as e:
logger.exception(f"Failed to get traced functions from {trace_file}: {e}")
return []| sys.exit(1) | ||
|
|
||
| console.print(f"[green]Trace saved to: {result['trace_file']}[/green]") | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Acknowledged: The JavaScript tracer automatically triggers optimization without explicit user consent when not in trace-only mode. This is acceptable as it matches the intended workflow and is documented through the CLI flags.
| from codeflash.languages.javascript.tracer import JavaScriptTracer | ||
|
|
||
|
|
||
| def node_available() -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Consider adding helper: The E2E tests check for Node.js availability, but there's no helper to install npm dependencies. Consider adding a fixture that checks if node_modules/codeflash exists and provides setup instructions if missing.
PR Review Summary✅ Prek ChecksAll prek checks (ruff format, ruff check) passed successfully. No auto-fixable issues found.
|
| File | Coverage (PR) | Coverage (Main) | Change | Status |
|---|---|---|---|---|
| replay_test.py (NEW) | 64% | N/A | +64% | |
| tracer_runner.py (NEW) | 34% | N/A | +34% | 🔴 Below 75% |
| tracer.py | 86% | N/A | +86% | ✅ Good |
| support.py | 74% | 74% | 0% | ✅ Maintained |
| parse_test_output.py | 42% | 59% | -17% |
Overall Coverage:
- Main branch: 79.4%
- PR branch: Unable to calculate due to deleted file in coverage data
- Test results: 8 failing tests (same failures exist on main branch - not introduced by this PR)
Concerns:
- 🔴 tracer_runner.py: Only 34% coverage - critical new functionality is undertested
⚠️ replay_test.py: 64% coverage - below recommended 75% threshold⚠️ parse_test_output.py: Coverage decreased from 59% to 42%
Recommendation: Add more unit tests for tracer_runner.py and replay_test.py to improve coverage above 75% threshold.
Last updated: 2026-02-05 17:51 UTC
Review by Claude Code Bot
⚡️ Codeflash found optimizations for this PR📄 67% (0.67x) speedup for
|
Add Babel-based function tracing for JavaScript/TypeScript: - tracer.js: Core tracer with SQLite storage and nanosecond timing - babel-tracer-plugin.js: AST transformation to wrap functions - trace-runner.js: Entry point for running traced code - replay.js: Utilities for replay test generation - Update package.json with exports and dependencies
Add Python modules for JavaScript tracing orchestration: - replay_test.py: Generate Jest/Vitest replay tests from traces - tracer_runner.py: Run trace-runner.js and detect test frameworks - tracer.py: Refactored to use Babel-only approach, removed legacy source transformation code
Move Jest/Vitest JUnit XML parsing from separate module into the main parse_test_output.py file to reduce module fragmentation. Remove duplicate tests that were testing the now-deleted module.
Add language detection and routing to JavaScript tracer in the main tracer CLI. Supports --language flag and auto-detection from file extensions in project.
Add comprehensive test coverage for JavaScript tracing: - Unit tests for trace parsing (function_calls and legacy schemas) - Unit tests for replay test generation (Jest and Vitest) - E2E test for full tracing pipeline with npm dependencies - Framework detection tests (Jest, Vitest, package.json)
- Add explicit type annotations for json.load return values - Annotate result dict with dict[str, Any] - Add type hints for config parameters - Fix pytest_split unpacking to satisfy type checker - Add null check for outfile before passing to run_javascript_tracer_main Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
| } | ||
|
|
||
| console.log('[codeflash] Running Vitest with tracing...'); | ||
| console.log('[codeflash] Note: ESM tracing requires additional setup. See documentation.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are we implementing this as its quite common to have vitest with esm in current times.
| const config = parseArgs(args); | ||
|
|
||
| // Register Babel with tracer plugin | ||
| registerBabel(config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to understand how this will work when the transformation of codebases in vitest/webpack or esbuild happens before registering babel.
We might need more examples/tests with vitest and esm compatibility.
Summary
--languageflag and auto-detectionChanges
Test plan
test_javascript_tracer.pyjs-tests.ymlGitHub Actions workflow