Conversation
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.
⚡️ 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.
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.
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.
Current behavior:
codeflash trace→ automatically runs optimization after tracingcodeflash trace --trace-only→ only traces, no optimization
This is acceptable if documented clearly.
| from codeflash.languages.javascript.tracer import JavaScriptTracer | ||
|
|
||
|
|
||
| def node_available() -> bool: |
There was a problem hiding this comment.
💡 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.
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)
PR Review Summary✅ Prek ChecksAll prek checks (ruff check, ruff format) passed successfully. No linting or formatting issues detected.
|
| File | Statements | Missed | Coverage |
|---|---|---|---|
codeflash/languages/javascript/support.py |
916 | 240 | 74% |
codeflash/languages/javascript/tracer.py |
119 | 17 | 86% ✅ |
codeflash/languages/javascript/tracer_runner.py |
161 | 106 | 34% |
| TOTAL | 1,196 | 363 | 70% |
Notes:
- ✅
tracer.pyhas excellent coverage (86%) ⚠️ tracer_runner.pyhas low coverage (34%) - needs more test cases for error paths and edge casessupport.pyhas acceptable coverage (74%) but could be improved- Note:
codeflash/languages/javascript/parse.pywas deleted (consolidated intoparse_test_output.py)
Test Results:
- 2,210 tests passed
- 8 tests failed (unrelated to this PR - in
test_tracer.py, appear to be pre-existing issues with Python tracer) - 42 tests skipped
- Added 21 new JavaScript tracer tests in
test_javascript_tracer.py
🔍 Code Review - Existing Issues Still Present
After reviewing the latest commits, the following issues from the previous review are still not addressed:
-
tracer_runner.py:183 -
⚠️ capture_output=Falsemakes debugging failures difficult- When tracer fails, no stdout/stderr is captured for diagnostics
- Recommended: Use
capture_output=True, text=Trueand log output on error
-
replay_test.py:296 -
⚠️ Silent exception handling without logging- Catching all exceptions without logging makes debugging impossible
- Recommended: Add
logger.exception()to log the actual error
-
tracer.py:353 - ℹ️ Auto-triggers optimization without explicit consent
- This is acceptable behavior but should be clearly documented in CLI help
- Current behavior:
codeflash trace→ auto-optimization;codeflash trace --trace-only→ trace only
-
test_javascript_tracer.py:28 - 💡 Consider adding helper for npm dependency setup
- E2E tests check for Node.js but don't verify
node_modules/codeflashexists - Recommended: Add fixture with setup instructions if dependencies missing
- E2E tests check for Node.js but don't verify
📝 Recommendations
- Priority: Fix
tracer_runner.pycapture_output issue - This affects debuggability significantly - Priority: Add logging to exception handlers - Essential for production debugging
- Improve test coverage for
tracer_runner.py- Currently at 34%, should target ≥70% - Document auto-optimization behavior - Make it clear in
--helpoutput what happens after tracing - Address mypy type errors - Schedule a follow-up PR to fix type annotations
✅ Overall Assessment
This is a solid PR that adds JavaScript tracing functionality with good test coverage overall. The main concerns are:
- Low coverage in
tracer_runner.py(34%) - Existing review comments not addressed (capture_output, exception logging)
- Type annotation issues (can be addressed in follow-up)
The PR is functionally ready but would benefit from addressing the debuggability concerns before merging.
Last updated: 2026-02-04
⚡️ Codeflash found optimizations for this PR📄 67% (0.67x) speedup for
|
- 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>
Summary
--languageflag and auto-detectionChanges
Test plan
test_javascript_tracer.pyjs-tests.ymlGitHub Actions workflow