Commit graph

7892 commits

Author SHA1 Message Date
Sarthak Agarwal
81be416043
Merge pull request #1991 from codeflash-ai/fix/verifier-path-validation
Fix: Handle test paths outside tests_root in verifier.py
2026-04-04 16:31:52 +05:30
Sarthak Agarwal
c0942b162b
Merge pull request #1992 from codeflash-ai/fix/typescript-jest-config-require
Fix Jest runtime config failing to load TypeScript base configs
2026-04-04 16:31:30 +05:30
Sarthak Agarwal
755d0f24fd
Merge pull request #1990 from codeflash-ai/fix/coverage-utils-framework-agnostic-messages
Fix: Make coverage error messages framework-agnostic
2026-04-04 16:31:16 +05:30
claude[bot]
d8c2b94359 style: remove redundant local import re and fix test conventions
- Remove redundant `import re` inside _is_vitest_workspace() since re is already imported at module level
- Convert tests to use pytest tmp_path fixture instead of tempfile.TemporaryDirectory()
- Add missing return type annotations and encoding= parameters
- Remove unused pytest import and docstrings

Co-authored-by: mohammed ahmed <undefined@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-04 07:56:07 +00:00
claude[bot]
ba0d2bc9a3 style: add missing -> None return type annotations to test methods 2026-04-04 07:52:21 +00:00
mohammed ahmed
08b9fe8d7f
Merge branch 'main' into fix/vitest-coverage-override 2026-04-04 09:51:41 +02:00
mohammed ahmed
cd1387ff7a
Merge branch 'main' into fix/verifier-path-validation 2026-04-04 09:49:18 +02:00
Sarthak Agarwal
973ebc2cf1
Merge pull request #1979 from codeflash-ai/fix/colocated-test-path-resolution
fix: handle co-located test directories with traverse_up
2026-04-04 12:04:00 +05:30
Sarthak Agarwal
0f2c50c239
Merge pull request #1982 from codeflash-ai/fix/vitest-mock-path-resolution
Fix vi.mock() path resolution in generated vitest tests
2026-04-04 12:03:45 +05:30
Sarthak Agarwal
c63defa2b2
Merge pull request #1984 from codeflash-ai/fix/js-project-root-per-function
Fix: Recalculate js_project_root per function in monorepos
2026-04-04 12:03:29 +05:30
Sarthak Agarwal
73d7a77e05
Merge pull request #1986 from codeflash-ai/fix/vitest-setupfiles-path-resolution
Fix Vitest setupFiles path resolution and workspace detection
2026-04-04 12:03:06 +05:30
mohammed ahmed
8d1c5e8108 Fix Jest runtime config failing to load TypeScript base configs
**Problem**: When a project uses `jest.config.ts` (TypeScript config), the
generated runtime config tries to `require('./jest.config.ts')`, which fails
because Node.js CommonJS cannot parse TypeScript syntax without compilation.

**Error**: `SyntaxError: Missing initializer in const declaration` at the
TypeScript type annotation (e.g., `const config: Config = ...`).

**Impact**: Affected 18 out of 38 optimization runs (~47%) in initial testing.
All TypeScript projects using `jest.config.ts` were unable to run tests.

**Root Cause**: Line 386 in test_runner.py used `base_config_path.name`
directly without checking the extension. The generated runtime config is
always a `.js` file, so it cannot use `require()` on `.ts` files.

**Solution**: Check if `base_config_path` is a TypeScript file (.ts). If so,
create a standalone runtime config without trying to extend it via require().
Jest will still discover and use the original TypeScript config naturally.

**Testing**:
- Added comprehensive test in test_jest_typescript_config_bug.py
- Test creates a realistic TypeScript Jest config and verifies the generated
  runtime config loads without syntax errors
- Existing 34 JavaScript test runner tests still pass
- No linting/type errors from `uv run prek`

**Trace IDs affected**: 0fd176bf-5c7f-4f41-8396-77c46be86412 and 17 others

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-04 05:12:00 +00:00
mohammed ahmed
218f3b5014 Fix test path validation error for JS/TS tests outside tests_root
When JavaScript/TypeScript support generates test files in __tests__
subdirectories adjacent to source files (e.g., src/foo/__tests__/codeflash-generated/),
these test files are not within the configured tests_project_rootdir.

Previously, verifier.py:37 called module_name_from_file_path() without
handling the ValueError that occurs when the test path is outside tests_root,
causing optimization runs to crash.

This fix adds try-except handling with a fallback to using just the filename,
matching the pattern already used in javascript/parse.py:330-333.

Fixes trace ID: 84f5467f-8acf-427f-b468-02cb3342097e

Changes:
- codeflash/verification/verifier.py:37-48: Added try-except for path computation
- tests/verification/test_verifier_path_handling.py: Added unit tests

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-04 02:39:52 +00:00
mohammed ahmed
933a2602c3 Fix: Make coverage error messages framework-agnostic
Error messages in coverage_utils.py hardcoded "Jest" even when the
test framework was Vitest. This caused confusion in logs when Vitest
tests failed (e.g., "Jest coverage file not found" when using Vitest).

The JestCoverageUtils class is used for both Jest and Vitest since
they share the same Istanbul/v8 coverage format. Error messages
should be framework-agnostic.

Changes:
- "Jest coverage file not found" → "JavaScript coverage file not found"
- "Failed to parse Jest coverage file" → "Failed to parse JavaScript coverage file"
- "No coverage data found for X in Jest coverage" → "No coverage data found for X in JavaScript coverage"
- "Function X not found in Jest fnMap" → "Function X not found in JavaScript fnMap"

Affected trace IDs: 37e5a406, 735555fa, 940dfe80, c1e1de0e, dbec6c33, de96b1ab, fcf08c6b (7 logs from Apr 4 00:50 batch)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-04 00:55:03 +00:00
claude[bot]
143241310a style: fix quote style in vitest_runner.py
Co-authored-by: mohammed ahmed <undefined@users.noreply.github.com>
2026-04-03 21:42:48 +00:00
mohammed ahmed
bf15f44f44 Fix Vitest coverage collection by overriding coverage.reporter
## Problem
When Codeflash runs Vitest tests, coverage files are not collected even
though tests run successfully. This affects 14 out of ~20 optimization
runs, resulting in 0% coverage reported.

Root cause: The generated `codeflash.vitest.config.mjs` only overrides
`include`, `pool`, and `setupFiles`, but does NOT override coverage
settings. When the project's vitest.config.ts has custom coverage
settings (e.g., `reporter: ["text", "lcov"]`), Vitest's `mergeConfig()`
doesn't properly handle the nested coverage object merge with command-line
flags like `--coverage.reporter=json`, resulting in coverage files not
being written to the expected location.

## Solution
Explicitly override `coverage.reporter` to `['json']` in the generated
codeflash.vitest.config.mjs file. This ensures consistent behavior
regardless of Vitest version or project configuration.

## Testing
Added comprehensive unit tests in test_vitest_coverage_config.py that:
1. Verify coverage overrides are present in generated config
2. Test with and without existing project coverage settings
3. Confirm generated config includes expected coverage.reporter

All tests pass ✓

## References
- Trace IDs affected: 11f707d6, 69b271f5, and 12 others
- Related to iteration 2 investigation in fix_history.log

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-03 21:39:45 +00:00
claude[bot]
9d22f43216 style: fix linting issues in vitest setupFiles PR
- Move `import re` to module-level (was inside function body)
- Add encoding="utf-8" to read_text() call
- Fix tests: use tmp_path fixture, add -> None return types, add encoding args

Co-authored-by: mohammed ahmed <undefined@users.noreply.github.com>
2026-04-03 20:11:05 +00:00
mohammed ahmed
0116a1f9e6 Fix Vitest setupFiles path resolution and workspace detection
**Problem:**

1. Vitest tests were failing with 'Cannot find module .../test/setup.ts'
   when testing functions in nested directories (e.g., extensions/discord/).

2. Root cause had two parts:
   - _is_vitest_workspace() was doing substring search for 'workspace',
     matching it even in comments, causing false positives
   - Custom vitest config wasn't overriding setupFiles, leaving relative
     paths from original config that resolved incorrectly

**Solution:**

1. Improved workspace detection (vitest_runner.py:172-191):
   - Use regex to match actual workspace config patterns
   - Match defineWorkspace( function calls
   - Match workspace: [ property assignments
   - Ignore 'workspace' in comments

2. Override setupFiles in custom config (vitest_runner.py:235-242):
   - Set setupFiles: [] to disable project setup files
   - Prevents relative path resolution issues
   - Safe since Codeflash tests are self-contained

**Testing:**

Added test_vitest_setupfiles_fix.py with 2 test cases:
- Verifies setupFiles is overridden in generated config
- Verifies configs without setupFiles still work

**Trace ID:** 161e21be-9306-4a4d-a9dc-978f65a1af7a

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-03 20:06:27 +00:00
Kevin Turcios
8d51e2d310
Merge pull request #1985 from codeflash-ai/feat/compare-inject-flag
feat: add --inject flag to codeflash compare
2026-04-03 11:35:24 -05:00
Kevin Turcios
a5a475d0b4 address review: fix _shutil alias, warn on --inject with --script
- Replace `import shutil as _shutil` with plain `import shutil` to
  match the existing style in the same function
- Warn when --inject is used with --script mode (unsupported combo)
  instead of silently dropping the flag
2026-04-03 11:21:05 -05:00
Kevin Turcios
3444babf58 add --inject flag to codeflash compare
When benchmarking already-merged optimizations, the benchmark file
often doesn't exist at either the base or head ref. The --inject flag
copies specified files/directories from the working tree into both
worktrees before benchmark discovery and execution, eliminating the
need to cherry-pick benchmark commits onto temporary branches.

Usage:
  codeflash compare <base> <head> --inject tests/benchmarks/test_bench.py
2026-04-03 11:15:18 -05:00
HeshamHM28
f352f9929f feat: update comparison logic to throw exceptions for KryoPlaceholder instances 2026-04-03 17:06:04 +02:00
HeshamHM28
3bc4941c01 feat: optimize comparison handling for KryoPlaceholder and enhance void method state tests 2026-04-03 16:45:41 +02:00
claude[bot]
e7596b5bef style: fix naming, imports, and test conventions in js_project_root fix
- Rename `_get_js_project_root` → `get_js_project_root` (no leading underscores per convention)
- Remove redundant `from pathlib import Path` import inside method (already imported at top)
- Remove unnecessary docstring from new method
- Rewrite tests to use `tmp_path` fixture instead of `tempfile.TemporaryDirectory()`
- Add `.resolve()` calls and `encoding="utf-8"` per project conventions
- Simplify second test file to focus on the actual caching behavior

Co-authored-by: mohammed ahmed <undefined@users.noreply.github.com>
2026-04-03 14:36:12 +00:00
mohammed ahmed
46c49910cd Fix: Recalculate js_project_root per function in monorepos
**Issue:**
When optimizing multiple functions in a monorepo with nested package.json
files (e.g., extensions/discord/package.json), the js_project_root was set
once for the first function and reused for all subsequent functions. This
caused vitest to look for setupFiles in the wrong directory.

**Root Cause:**
test_cfg.js_project_root was set during initial setup and never recalculated.
When function #1 was in extensions/discord/, all subsequent functions in
src/ inherited this wrong project root.

**Fix:**
- Added _get_js_project_root() method to FunctionOptimizer
- Calculate js_project_root fresh for each function using find_node_project_root()
- Updated all test execution paths (behavior, performance, line_profile)

**Impact:**
- Vitest now runs from the correct working directory for each function
- setupFiles can be resolved correctly
- Functions in different monorepo packages can be optimized correctly

Fixes trace IDs: 12d26b00-cbae-49a8-a3cd-c36024ee06ec, 1cde1c65-ef42-4072-afbc-165b0c235688, and 18 others

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-03 14:30:24 +00:00
mohammed ahmed
cdb361b5a3 Fix vi.mock() path resolution in generated vitest tests
Extended fix_jest_mock_paths() to handle vitest mock calls (vi.mock()) in
addition to jest.mock(). Previously, only jest.mock() paths were corrected,
causing vitest tests to fail with "Cannot find module" errors.

Problem:
- Source at src/agents/workspace.ts imports ../routing/session-key
- Generated test at test/test_workspace.test.ts used vi.mock('../routing/session-key')
- This resolves to /routing/session-key (wrong - goes up from test/, not found)
- Should be vi.mock('../src/routing/session-key') (correct path from test/)

Solution:
- Updated regex pattern to match both jest.mock() and vi.mock()
- Function now fixes relative paths for both test frameworks
- Added unit tests to verify both jest and vitest paths are corrected

Trace ID: 265059d4-f518-44da-8367-d90ca424092c

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-03 13:44:27 +00:00
ali
eef9ff9edc
Merge branch 'main' of github.com:codeflash-ai/codeflash into fix/colocated-test-path-resolution 2026-04-03 15:34:29 +02:00
Sarthak Agarwal
a756701bb2
Merge pull request #1974 from codeflash-ai/fix/false-positive-test-discovery
Fix false positive test discovery from substring matching
2026-04-03 18:26:19 +05:30
HeshamHM28
f42b58bb98 feat: implement bubble sort optimization and corresponding tests in Java 2026-04-03 14:55:09 +02:00
Kevin Turcios
accb245486
Merge pull request #1941 from codeflash-ai/cf-compare-copy-benchmarks
feat: enhance codeflash compare with memory profiling, script mode, and auto-calibration
2026-04-03 07:13:00 -05:00
ali
b77896d17f
fix: handle class methods, aliased imports, and namespace access in JS test discovery
The index-only approach missed tests for class methods (imported by class name),
aliased imports (only alias was tracked), and namespace imports (e.g. math.calculate).
Adds class_name→methods index, tracks both original+alias names, and extracts
namespace member access via regex.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 13:54:46 +02:00
ali
d8e758800f
Merge branch 'main' of github.com:codeflash-ai/codeflash into fix/false-positive-test-discovery 2026-04-03 13:32:34 +02:00
Sarthak Agarwal
30ea7015cc
Merge pull request #1977 from codeflash-ai/fix/js-discover-tests-performance
perf(js): optimize discover_tests from O(N×M) to O(N+M)
2026-04-03 16:56:28 +05:30
Sarthak Agarwal
61a539f3b5
Merge pull request #1978 from codeflash-ai/fix/jest-testmatch-testregex-conflict
fix(js): resolve Jest testMatch/testRegex configuration conflict
2026-04-03 16:48:56 +05:30
Sarthak Agarwal
3b7c61e9dd
Merge pull request #1971 from codeflash-ai/fix/vitest-coverage-excluded-files
fix: Improve error messaging for files excluded from Vitest coverage
2026-04-03 16:47:09 +05:30
Codeflash Bot
c57c39ae09 fix: handle co-located test directories with traverse_up
This fixes a ValueError that occurs when generated tests are placed in
co-located __tests__ directories outside the configured tests_root.

Root cause:
The CLI's _find_codeflash_test_dir() method generates tests in co-located
__tests__ directories (e.g., src/gateway/server/__tests__/) when they exist,
but verifier.py tried to compute a module path relative to the configured
tests_root (e.g., /workspace/target/test), causing:

ValueError: '/workspace/target/src/gateway/server/__tests__/codeflash-generated/test_xxx.test.ts'
is not in the subpath of '/workspace/target/test'

Fix:
- Added traverse_up=True to module_name_from_file_path() call in verifier.py
- This allows the function to find a common ancestor directory and compute
  the relative path from there, handling tests outside tests_root

Testing:
- Added comprehensive unit tests in test_module_name_from_file_path.py
- All existing tests pass 
- Linting passes 

Impact:
- Resolves crashes when optimizing functions with co-located test directories
- Enables proper handling of monorepo and __tests__ directory structures

Trace IDs affected: 7b97ddba-6ecd-42fd-b572-d40658746836

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-03 07:23:10 +00:00
claude[bot]
ab728f7452
Merge pull request #1975 from codeflash-ai/codeflash/optimize-pr1941-2026-04-02T18.50.56
️ Speed up function `validate_and_format_benchmark_table` by 45% in PR #1941 (`cf-compare-copy-benchmarks`)
2026-04-03 02:22:43 +00:00
ali
d464ad60c5
Merge branch 'main' of github.com:codeflash-ai/codeflash into fix/js-discover-tests-performance 2026-04-03 04:19:39 +02:00
ali
8e443e8f83
Merge branch 'main' of github.com:codeflash-ai/codeflash into fix/false-positive-test-discovery 2026-04-03 04:17:44 +02:00
ali
7777b24cc7
Merge branch 'main' of github.com:codeflash-ai/codeflash into fix/vitest-coverage-excluded-files 2026-04-03 03:05:36 +02:00
Codeflash Bot
b9d8efa0d1 fix(js): resolve Jest testMatch/testRegex configuration conflict
Fix Jest validation error that prevented all TypeScript/JavaScript optimizations
in projects using bundler moduleResolution.

## Problem

When optimizing JS/TS projects with bundler moduleResolution, Jest would fail with:

This blocked ALL optimizations for these projects since no tests could run.

## Root Cause

Two-stage Jest config generation caused conflicting options:

1. \_create_codeflash_jest_config() creates base config with `testRegex` (line 321)
2. \_create_runtime_jest_config() extends base config:
   ```javascript
   module.exports = {
     ...baseConfig,  // Spreads testRegex from base
     testMatch: [...],  // Adds testMatch - CONFLICT!
   }
   ```
3. Jest sees both options and rejects the configuration

## Solution

Explicitly clear `testRegex` when setting `testMatch` in runtime config:
```javascript
testMatch: ['**/*.test.ts', ...],
testRegex: undefined,  // Clear inherited testRegex
```

Jest config precedence allows explicit `undefined` to override inherited values.

## Testing

Before:
```
 Jest failed with returncode=1.
   Validation Error: Configuration options testMatch and testRegex cannot be used together.
```

After:
```
 Jest runs without configuration errors
 Config validation passes
```

Tested on n8n packages/workflow which uses bundler moduleResolution.

## Impact

- Fixes all JS/TS projects that use:
  - TypeScript with bundler moduleResolution (common in modern repos)
  - Projects where Codeflash detects the need for ESM compatibility config
- Allows optimization to proceed past configuration stage

## Files Changed

- `codeflash/languages/javascript/test_runner.py` - _create_runtime_jest_config()

Fixes issue where TypeScript projects with bundler moduleResolution
would immediately fail Jest validation, preventing any optimizations.
2026-04-02 20:02:30 +00:00
claude[bot]
867c3df583 style: replace unicode multiplication sign in comment with ASCII x
Co-authored-by: mohammed ahmed <undefined@users.noreply.github.com>
2026-04-02 19:59:21 +00:00
Codeflash Bot
0d0f722af4 perf(js): optimize discover_tests from O(N×M) to O(N+M)
Fix test discovery performance bottleneck that caused indefinite hangs on large codebases.

## Problem
The discover_tests() method had O(N×M) complexity where N is the number of test files
and M is the number of source functions. For large repos (e.g., n8n with 12,138 functions
and 5,502 test files), this created ~66 million iterations and caused the process to hang
indefinitely at the test discovery stage.

## Root Cause
Lines 258-265 iterated over ALL source functions for EVERY test file:
```python
for test_file in test_files:  # N iterations
    for func in source_functions:  # M iterations per test file
        if func.function_name in imported_names or func.function_name in source:
            # map test to function
```

Additionally, the `func.function_name in source` check performed expensive string
containment searches on entire test files for every function, making it even slower.

## Solution
Rewrote algorithm to build a reverse index first, reducing complexity to O(N+M):
1. Build function_name → qualified_name dict once (O(M))
2. For each test file, only check imported names against the index (O(N))

This reduces iterations from ~66 million to ~17,640 for large repos.

## Performance Impact
Tested on n8n repository (12,138 functions, 5,502 test files):
- **Before**: Hung indefinitely (killed after 90+ seconds, never completed)
- **After**: 45.2 seconds total
- **Improvement**: 3,700x complexity reduction

Also removed the fallback `func.function_name in source` check as it was:
- Extremely expensive (substring search in entire file)
- Prone to false positives (matches in comments/strings)
- Unnecessary (functions must be imported to be used)

## Testing
- Verified on n8n repo: discovers 149,378 tests in 45s (previously hung)
- Verified on smaller repos: still works correctly with negligible overhead

Fixes performance issue where Codeflash would appear to hang after function discovery
when run with --all on large JavaScript/TypeScript monorepos.
2026-04-02 19:56:27 +00:00
Sarthak Agarwal
b0c4e1f10e
Merge pull request #1976 from codeflash-ai/fix/nested-functions-parity-test
fix: update nested functions parity test
2026-04-03 01:11:35 +05:30
ali
834adc5a43
fix: update nested functions parity test to match new JS discovery behavior
PR #1968 changed JS to skip nested functions like Python, but the parity
test still expected JS to discover both outer and inner.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-02 21:02:23 +02:00
claude[bot]
cfcbae5854 style: remove duplicate comments introduced by optimization 2026-04-02 18:53:03 +00:00
Codeflash Bot
63c475af0e Fix AttributeError: use file_path not source_file_path
Bug #5 fix: The coverage exclusion error messages used
self.function_to_optimize.source_file_path but FunctionToOptimize
only has file_path attribute, not source_file_path. This caused
AttributeError when files were excluded from coverage.

Trace ID: 5c4a75fb-d8eb-4f75-9e57-893f0c44b9c7

Changes:
- Fixed lines 2797, 2803: source_file_path -> file_path
- Added regression test to verify correct attribute used

Testing:
- New test passes
- Linting passes

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-02 18:51:38 +00:00
codeflash-ai[bot]
4e07c98f69
Optimize validate_and_format_benchmark_table
The hot path shows `logger.debug` consuming 18.3% of original runtime despite appearing infrequently (141 hits), because formatting the f-string occurs unconditionally even when debug logging is disabled. Wrapping it with `logger.isEnabledFor(logging.DEBUG)` defers string construction until confirmed necessary, eliminating wasteful formatting. Replacing `lambda x: x[3]` with `operator.itemgetter(3)` in the sort key reduces per-comparison overhead from a Python function call to a C-level attribute access, and hoisting the division constant `1_000_000.0` outside the loop avoids repeated float literal construction. Line profiler confirms the sort line dropped from 568 µs to 197 µs (65% faster) and the debug call from 1102 µs to 124 µs (89% faster), yielding a 45% overall speedup with no correctness or metric trade-offs.
2026-04-02 18:51:00 +00:00
Codeflash Bot
29e42ae9cc Fix false positive test discovery from substring matching
Issue: Test discovery incorrectly matched test files with source functions
when the function name appeared anywhere in the test file, including in
mocks, comments, or unrelated code. This caused 'Failed to instrument test
file' errors.

Root cause: In javascript/support.py line 259, naive substring matching
(func.function_name in source) matched function names even when they were
only mentioned in mocks like:
  vi.mock('./file.js', () => ({ funcName: ... }))

Example: Function parseRestartRequestParams from restart-request.ts was
wrongly matched with update.test.ts because the test file mocked it.

Fix: Removed substring matching, now only matches explicitly imported
functions. This is more reliable and avoids false positives.

Trace ID: 0b575a96-62a8-4910-b163-1ad10e60ba79

Changes:
- Removed naive substring check in discover_tests()
- Only match functions that are explicitly imported
- Added regression tests (2 test cases)

Testing:
- All 70 JavaScript tests pass
- New tests verify fix works correctly
- Linting/type checks pass (uv run prek)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-02 18:46:48 +00:00
Codeflash Bot
e329d52c34 fix: Improve error messaging for files excluded from Vitest coverage
## Problem
When a file is excluded from coverage by vitest.config.ts (e.g., via
`coverage.exclude: ["src/agents/**"]`), Codeflash reports misleading
"Test coverage is 0.0%" messages even though tests run successfully.

This happens because:
- Vitest doesn't include excluded files in coverage-final.json
- Codeflash detects this (status = NOT_FOUND) but shows generic 0% message
- Users don't know the file is excluded from coverage collection

## Solution
Detect when coverage status is NOT_FOUND and provide a clear, actionable
error message explaining:
1. No coverage data was found for the file
2. It may be excluded by test framework configuration
3. Where to check (coverage.exclude in vitest.config.ts, etc.)

## Changes
- function_optimizer.py: Check CoverageStatus.NOT_FOUND before reporting 0%
- Added clear warning log and user-facing error message
- New test file: test_vitest_coverage_exclusions.py

## Testing
- All existing JavaScript tests pass
- New tests verify NOT_FOUND status is returned correctly
- Manual verification with openclaw logs (trace: 2a84fe6b-9871-4916-96da-bdd79bca508a)

Fixes #BUG-1 (from autoresearch:debug workflow)
Trace IDs affected: All 10 log files showing 0% coverage in /workspace/logs

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-02 17:44:46 +00:00