Fix: Disable Vitest coverage thresholds for Codeflash-generated tests#1969
Fix: Disable Vitest coverage thresholds for Codeflash-generated tests#1969
Conversation
…onments
- Add -w flag for pnpm workspace roots to avoid ERR_PNPM_ADDING_TO_ROOT
- Use local package path (/opt/codeflash/packages/codeflash) in dev mode
- Improve error logging to show actual stderr at ERROR level instead of WARNING
- Add unit tests for workspace detection and local package usage
Fixes 9/13 optimization failures caused by 'Cannot find package codeflash'
Trace IDs affected: 08d594a2, 1722cff7, 23480bf7, 3074f19b, 6043236e,
b883f1bd, d01b03ce, e56507a4, f8f54e06
**Problem:** When running Codeflash-generated tests with coverage enabled, Vitest would fail with returncode=1 due to project-level coverage thresholds not being met. Generated tests typically cover only a single function (~1-2% of codebase), which fails projects with thresholds like 70% lines/functions configured in their vitest.config.ts. **Root Cause:** In vitest_runner.py line 450, Codeflash was adding --coverage flag without disabling the project's global coverage thresholds. This caused false failures even when all tests passed successfully. **Solution:** Added coverage threshold override flags when coverage is enabled: - --coverage.thresholds.lines=0 - --coverage.thresholds.functions=0 - --coverage.thresholds.statements=0 - --coverage.thresholds.branches=0 These flags disable project-level thresholds, allowing coverage collection without failing the test run. Coverage data is still collected for analysis, but thresholds no longer cause false failures. **Testing:** - Added comprehensive unit tests in test_vitest_coverage_thresholds.py - All 40 existing vitest-related tests pass - Verified with uv run prek (linter + type checker) **Related Issues:** Trace IDs affected: 05a626f3, 932e7799, a145328d, aa9bb63f, d669202e, e6de097a Fixes 6 out of 10 optimization failures in openclaw project.
|
Claude finished @mohammedahmed18's task in 2m 22s —— View job PR Review Summary
Prek Checks
Code ReviewThe fix is correct. Setting Vitest coverage thresholds to 0 via CLI flags is the right approach to prevent false failures from project-level thresholds. The 4 metrics covered (lines, functions, statements, branches) are the standard Vitest threshold types. One issue: tests were reverted. The PR description states "Added comprehensive unit tests in The existing Minor: No concern about Vitest version compatibility — the Duplicate DetectionNo duplicates detected. The threshold override logic is unique to Optimization PRsPR #1954 ( Last updated: 2026-04-02 |
| logger.debug(f"Coverage will be written to: {coverage_dir}") | ||
|
|
||
| vitest_cmd.extend(["--coverage", "--coverage.reporter=json", f"--coverage.reportsDirectory={coverage_dir}"]) | ||
| vitest_cmd.extend( |
There was a problem hiding this comment.
Why we are disabling coverage here?
There was a problem hiding this comment.
not disabling but removing the thresholds only
The merge-base changed after approval.
Problem
When running Codeflash-generated tests with coverage enabled, Vitest would fail with returncode=1 due to project-level coverage thresholds not being met.
Generated tests typically cover only a single function (~1-2% of codebase), which fails projects with thresholds like 70% lines/functions configured in their vitest.config.ts.
Root Cause
In
vitest_runner.pyline 450, Codeflash was adding--coverageflag without disabling the project's global coverage thresholds. This caused false failures even when all tests passed successfully.Example error from logs:
Solution
Added coverage threshold override flags when coverage is enabled:
--coverage.thresholds.lines=0--coverage.thresholds.functions=0--coverage.thresholds.statements=0--coverage.thresholds.branches=0These flags disable project-level thresholds, allowing coverage collection without failing the test run. Coverage data is still collected for analysis, but thresholds no longer cause false failures.
Testing
test_vitest_coverage_thresholds.pyuv run prek(linter + type checker)Impact
Fixes 6 out of 10 optimization failures in the openclaw test project.
Affected Trace IDs:
Files Changed
codeflash/languages/javascript/vitest_runner.py: Added threshold override flagstests/languages/javascript/test_vitest_coverage_thresholds.py: New comprehensive test suite