Skip to content

Conversation

@Saga4
Copy link
Contributor

@Saga4 Saga4 commented Feb 4, 2026

  1. function_optimizer.py - Language-specific coverage check

Before: Coverage required for ALL languages (blocked JavaScript)

if not coverage_critic(...) or not quantity_of_tests_critic(...):
return Failure("The threshold for test confidence was not met.")

After: Coverage only required for Python

if not quantity_of_tests_critic(...):
return Failure("...insufficient tests.")
if is_python() and not coverage_critic(...):
return Failure("...insufficient coverage.")

  1. vitest_runner.py - Monorepo support
  • Prioritize vitest config files over package.json when finding project root
  • Added --root flag to vitest commands for correct config resolution
  1. parse.py - Test file resolution
  • Added benchmarking_file_path to lookup dictionaries for perf-only test resolution
  1. edit_generated_tests.py - Test globals injection
  • Pass test_framework to inject_test_globals for framework-specific handling
  1. module_system.py - Module system detection
  • Earlier fix for ESM/CJS detection

The key improvement is that coverage is still enforced for Python (good practice), but skipped for JavaScript/TypeScript where we don't have coverage infrastructure yet.

@Saga4 Saga4 changed the title fix/test_globals Multiple fixes around vitest Feb 4, 2026
@claude
Copy link

claude bot commented Feb 4, 2026

PR Review Summary

✅ Prek Checks

Fixed linting issues:

  • Merged comparison operators in verification_utils.py (PLR1714)
  • Auto-formatted 2 files for code style consistency
  • Committed and pushed fixes in commit 94922ed9

🔍 Code Review

Found 4 critical issues requiring attention:

1. ⚠️ Module Conversion Logic Too Broad

File: codeflash/languages/javascript/module_system.py:421

The condition was changed from checking is_commonjs and not is_esm to just has_require. This means ANY code with a require statement will be converted to ESM, even if it already has proper ESM imports. The original logic correctly avoided converting mixed-module code.

Impact: Could break valid mixed-module systems where both imports and requires coexist.

2. ⚠️ Silent Config File Creation

File: codeflash/languages/javascript/vitest_runner.py:171-240

The _ensure_codeflash_vitest_config function creates a codeflash.vitest.config.js file in the user's project without explicit approval. While this is done to handle restrictive include patterns, it:

  • Creates files in user projects silently
  • May cause config conflicts
  • Writes autogenerated JavaScript that gets imported

Mitigation: The function does check for workspace configs and skips creation in that case, and only creates if no existing config exists.

3. ℹ️ API Change (Non-Breaking)

File: packages/codeflash/runtime/index.js:81-86

Constants PERF_BATCH_SIZE and PERF_LOOP_COUNT were changed to getter functions. Verified that:

  • All usages in loop-runner.js use local constants, not imports
  • No breaking changes detected
  • This change improves dynamic env var reading

4. 📝 Test Logic Change

File: tests/test_languages/test_js_code_replacer.py:2463-2487

Test test_mixed_code_converted_to_esm now expects conversion (opposite of previous behavior). This corresponds to the module system logic change above. The test expects require statements to be converted even in mixed code.

📊 Test Coverage

Coverage analysis was attempted but timed out due to long test execution time. Manual verification shows:

  • Existing tests cover the changed JavaScript support modules
  • New vitest-specific code paths have corresponding test files
  • Test files modified: test_javascript_support.py, test_javascript_run_and_parse.py, test_javascript_optimization_flow.py

🔧 Type Checking (mypy)

Found 206 mypy errors across the codebase, but most are pre-existing issues not introduced by this PR:

  • Complex type annotation issues in models.py (missing type parameters, Any returns)
  • Generic type issues in function_optimizer.py (dict, list, Future without parameters)
  • Optional attribute access issues

Note: These type errors existed before this PR and require significant refactoring to resolve properly. Not blocking for this PR.


Last updated: 2026-02-05 (Re-review after commit 94922ed)

@Saga4 Saga4 marked this pull request as draft February 4, 2026 17:25
Saga4 and others added 3 commits February 5, 2026 00:53
logger.debug("Converting CommonJS to ES Module syntax")
# For ESM target: convert any require statements, even if there are also import statements
# This handles generated tests that have ESM imports for test globals but CommonJS for the function
if target_module_system == ModuleSystem.ES_MODULE and has_require:
Copy link

@claude claude bot Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Fixed in latest commit - test has been removed

@Saga4 Saga4 requested a review from mohammedahmed18 February 4, 2026 23:57
@codeflash-ai
Copy link
Contributor

codeflash-ai bot commented Feb 5, 2026

⚡️ Codeflash found optimizations for this PR

📄 31% (0.31x) speedup for BenchmarkDetail.to_dict in codeflash/models/models.py

⏱️ Runtime : 581 microseconds 445 microseconds (best of 233 runs)

A dependent PR with the suggested changes has been created. Please review:

If you approve, it will be merged into this PR (branch add_vitest_reporter_for_output_format).

Static Badge

@Saga4 Saga4 marked this pull request as ready for review February 5, 2026 15:21
@Saga4 Saga4 merged commit d148f87 into main Feb 5, 2026
24 of 27 checks passed
@Saga4 Saga4 deleted the add_vitest_reporter_for_output_format branch February 5, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant