Commit graph

21 commits

Author SHA1 Message Date
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
mohammed ahmed
08b9fe8d7f
Merge branch 'main' into fix/vitest-coverage-override 2026-04-04 09:51:41 +02: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
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
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
Codeflash Bot
8f1b9f2e99 Fix: Skip nested functions in JavaScript/TypeScript discovery
Bug: Nested functions were being discovered and attempted to be optimized,
but the extraction logic only captured the nested function body without
parent scope variables, causing validation errors like:
  'Undefined variable(s): base, streamFn, record, writer'

Root cause: The discover_functions method was allowing nested functions
(functions defined inside other functions) to be marked for optimization.
These nested functions depend on closure variables from their parent scope
and cannot be optimized in isolation.

Fix: Added explicit check to skip functions with parent_function set.
Nested functions are now filtered out during discovery phase.

Impact: Resolves 140+ trace failures with undefined variable errors.
Functions like 'wrapStreamFn.wrapped' will no longer be attempted.

Test: Added test_discover_functions.py with 4 test cases:
- test_discovers_top_level_function
- test_skips_nested_functions_in_closures (main bug fix test)
- test_discovers_class_methods (ensure methods still work)
- test_skips_nested_functions_with_multiple_levels

Affects trace IDs including: 02a59310-bb18-47e4-87cb-1e5144ce2d8c
and 140+ others with nested function extraction issues.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-02 11:57:41 +00:00
Mohamed Ashraf
fa9d32f1c4 Merge branch 'main' into omni-java
Resolve 7 merge conflicts from main's modular refactoring + JS improvements:

- aiservice.py: combine multi-language metadata (omni-java) with main's structure
- cmd_init.py: adopt main's modular split (init_config, init_auth, github_workflow) + add Java import
- code_replacer.py: main's clean early-return style + omni-java's non-Python single-block fallback
- version.py, test_support_dispatch.py, test_javascript_test_runner.py: take main's versions
- uv.lock: regenerated

Port Java into main's modular structure:
- Fix init_java.py lazy imports to point to new modules (init_config, init_auth, github_workflow)
- Add Java workflow support to github_workflow.py (detection, template, customization)
- Fix broken Java imports (function_optimizer, line_profiler) after main's module moves

Add safety tests for merge-critical functions:
- test_add_language_metadata.py: 10 tests covering per-language payload correctness
- test_code_replacer_matching.py: 8 tests covering fallback chain

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 00:15:19 +00:00
Sarthak Agarwal
f0e4e5326d max loop count in test support 2026-03-04 16:48:38 +05:30
Kevin Turcios
eceac13fc3 Merge remote-tracking branch 'origin/main' into omni-java
# Conflicts:
#	.claude/rules/architecture.md
#	.claude/rules/code-style.md
#	.github/workflows/claude.yml
#	.github/workflows/duplicate-code-detector.yml
#	codeflash/api/aiservice.py
#	codeflash/cli_cmds/console.py
#	codeflash/cli_cmds/logging_config.py
#	codeflash/code_utils/deduplicate_code.py
#	codeflash/discovery/discover_unit_tests.py
#	codeflash/languages/base.py
#	codeflash/languages/code_replacer.py
#	codeflash/languages/javascript/mocha_runner.py
#	codeflash/languages/javascript/support.py
#	codeflash/languages/python/support.py
#	codeflash/optimization/function_optimizer.py
#	codeflash/verification/parse_test_output.py
#	codeflash/verification/verification_utils.py
#	codeflash/verification/verifier.py
#	packages/codeflash/package-lock.json
#	packages/codeflash/package.json
#	tests/languages/javascript/test_support_dispatch.py
#	tests/test_codeflash_capture.py
#	tests/test_languages/test_javascript_test_runner.py
#	tests/test_multi_file_code_replacement.py
2026-03-04 01:52:32 -05:00
Kevin Turcios
dbc04df9df Update test_support_dispatch.py 2026-03-04 01:32:35 -05:00
Sarthak Agarwal
12294cafb6 fix looping with JS/TS 2026-03-04 10:46:44 +05:30
Kevin Turcios
83c6d5cdd2 fix: import jest patterns from source module instead of re-export
The formatter correctly removed the unused re-exports from
parse_test_output.py. Update the test to import directly from
codeflash.languages.javascript.parse.
2026-02-13 09:55:14 -05:00
Sarthak Agarwal
00a6f4d873 fix unit tests 2026-02-05 19:27:46 +05:30
Sarthak Agarwal
3904126f11 vitest dot notation for junit reporter 2026-02-04 18:25:34 +05:30
Sarthak Agarwal
09e3ba357b xml parsing fix and refactor to support directory 2026-02-04 13:59:19 +05:30
Sarthak Agarwal
b708b6cb26 fix test 2026-01-31 04:37:46 +05:30
Sarthak Agarwal
4bf664dc39 add vitest runner 2026-01-31 04:29:59 +05:30
Sarthak Agarwal
c56002f287 vitest support add to js/ts project 2026-01-31 01:09:52 +05:30