Commit graph

6524 commits

Author SHA1 Message Date
Sarthak Agarwal
6b644faf25 update docs and sidebar index 2026-03-05 01:59:56 +05:30
Sarthak Agarwal
f0e4e5326d max loop count in test support 2026-03-04 16:48:38 +05:30
Sarthak Agarwal
f0bf7dcdcb reduce time 2026-03-04 11:09:39 +05:30
Sarthak Agarwal
2e1ef202d1 Merge branch 'main' into fix/js-vitest-benchmarking-and-mocha-cjs 2026-03-04 10:47:13 +05:30
Sarthak Agarwal
12294cafb6 fix looping with JS/TS 2026-03-04 10:46:44 +05:30
Kevin Turcios
d46908faa2
Merge pull request #1752 from codeflash-ai/chore/pre-push-prek-rule
chore: add pre-push prek rule and fix pr-review close permission
2026-03-04 03:10:30 +00:00
Kevin Turcios
8f50f31251 fix: add gh pr close permission to pr-review workflow
The merge_optimization_prs step needs to close stale PRs but
gh pr close was missing from the allowed tools list.
2026-03-03 21:04:14 -05:00
Kevin Turcios
c2fe5261a3 chore: add pre-push prek rule to match CI behavior 2026-03-03 21:02:44 -05:00
Kevin Turcios
3e072a7ad0
Merge pull request #1750 from codeflash-ai/refactor/language-version-protocol
chore: remove simplify step from Claude PR review and add prek rule
2026-03-04 01:14:37 +00:00
Kevin Turcios
dee1175acd chore: remove simplify step from Claude PR review and add prek rule
Drop the /simplify step that caused unprompted refactors and scope
creep in PR reviews. Also add prek pre-commit rule to project config
so the PR bot and all contributors see it.
2026-03-03 20:02:22 -05:00
Kevin Turcios
c611617db7 update base 2026-03-03 19:57:47 -05:00
Sarthak Agarwal
94504ccd30
Merge pull request #1742 from codeflash-ai/fix/js-vitest-benchmarking-and-mocha-cjs
Mocha test runner fix
2026-03-04 04:18:59 +05:30
Sarthak Agarwal
43a6ce1c8d Merge branch 'main' into fix/js-vitest-benchmarking-and-mocha-cjs 2026-03-04 03:43:15 +05:30
Sarthak Agarwal
bc5e3e878a fix mocha test runner 2026-03-04 03:42:10 +05:30
Sarthak Agarwal
52210f6f2a
Merge pull request #1737 from codeflash-ai/fix/js-vitest-benchmarking-and-mocha-cjs
fix/js vitest benchmarking and mocha cjs
2026-03-04 00:18:05 +05:30
Sarthak Agarwal
4766daac7e fix: regenerate stale vitest config and add .js extension for ESM imports
Two fixes discovered during end-to-end testing:

1. _ensure_codeflash_vitest_config() reused existing configs that lacked
   pool: 'forks', causing benchmarking to fall back to wall-clock timing
   on re-runs. Now checks for the required setting and regenerates if
   missing.

2. ESM projects require explicit .js file extensions in import specifiers
   (e.g., `import foo from './lib/foo.js'`). The verifier stripped the
   extension but never added .js back for ESM, causing
   ERR_MODULE_NOT_FOUND in Mocha ESM projects like axios.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 16:57:34 +05:30
Sarthak Agarwal
e8a4f96c0b fix: strip CJS require('vitest') and require('@jest/globals') in Mocha tests
The AI backend generates vitest/jest-style imports for Mocha projects.
Our sanitize_mocha_imports() stripped ESM `import { ... } from 'vitest'`,
but process_generated_test_strings() runs BEFORE postprocessing and calls
ensure_module_system_compatibility() which converts these to CJS requires.
Result: `const { ... } = require('vitest')` survived sanitization.

Added regexes for the CJS variants of vitest and @jest/globals requires.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 16:01:55 +05:30
Sarthak Agarwal
ed2594bfd1 fix: resolve Vitest benchmarking showing wall-clock time instead of per-function timing
Root cause: Vitest performance tests reported "20.0 seconds over 1 loop"
(JUnit XML wall-clock fallback) instead of actual per-function nanosecond
timing. This was a chain of two issues:

1. **stdout interception**: Vitest's default `threads` pool intercepts
   process.stdout.write() and console.log(), preventing timing markers
   from flowing to the parent process. Fixed by adding `--pool=forks`
   to all Vitest commands and config files. The `forks` pool uses child
   processes where stdout flows directly to the parent.

2. **test name detection**: Even after markers flowed through (43,000+
   found in stdout), the parser couldn't match them to JUnit XML
   testcases because all markers had "unknown" as the test name. This
   happened because Vitest doesn't inject `beforeEach` as a global
   (unlike Jest), so capture.js's Jest-style hook to set
   `currentTestName` never fired.

   Fixed by adding Vitest-specific test name detection in capture.js:
   - Primary: `expect.getState().currentTestName` (full describe path)
   - Fallback: `__vitest_worker__.current.fullTestName`
   - Defense-in-depth: parser fallback matches "unknown" markers to
     the first testcase when no name match is found

Result: cheerio's `isHtml` went from "20.0s / 1 loop" to
"902μs / 20,853 loops" with proper speedup analysis.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 14:31:10 +05:30
Sarthak Agarwal
a78b4cc299 fix: support Mocha CJS projects and sanitize incorrect framework imports
Three related fixes for Mocha test generation in CommonJS projects:

1. inject_test_globals() now accepts module_system param — emits
   `require('node:assert/strict')` for CJS instead of ESM import syntax
2. ensure_module_system_compatibility() now converts ESM→CJS even when
   the source has mixed imports (was skipping when both ESM and CJS were
   detected, leaving the ESM import from inject_test_globals unconverted)
3. New sanitize_mocha_imports() strips vitest/jest/@jest/globals imports
   that the AI sometimes generates for Mocha projects — Mocha provides
   describe/it/before*/after* as globals

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 14:30:22 +05:30
Sarthak Agarwal
f53272c03b fix: use pattern matching for collocated tests in monorepos
When testsRoot overlaps moduleRoot (common in JS/TS monorepos like Ghost
where both point to "src"), the directory-based filter incorrectly
excluded ALL source files. Switch to filename/directory pattern matching
(*.test.*, *.spec.*, __tests__/) when roots overlap, preserving the
existing directory-based filter for standard layouts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 14:29:05 +05:30
Kevin Turcios
206020b1af
Merge pull request #1735 from codeflash-ai/chore/limit-claude-workflow-triggers
chore: limit claude workflow triggers to reduce spam
2026-03-03 03:04:06 +00:00
Kevin Turcios
12b18de2d1 chore: limit claude workflow triggers to reduce spam
- Add paths-ignore to skip reviews for docs, config, CI, and non-production files
- Use github.event.sender.login instead of github.actor for reliable bot detection
- Add triage step to early-exit on trivial PRs
2026-03-02 22:01:11 -05:00
Kevin Turcios
ed8991ad82
Merge pull request #1734 from codeflash-ai/chore/claude-workflow-use-sonnet
chore: switch claude workflow model from opus to sonnet 4.6
2026-03-03 02:39:17 +00:00
aseembits93
7ee1e7bd2f chore: switch claude workflow model from opus to sonnet 4.6
Use claude-sonnet-4-6 instead of claude-opus-4-6 for CI cost/speed savings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 08:08:28 +05:30
Kevin Turcios
d229125cdf
Merge pull request #1724 from codeflash-ai/fix-duplicate-detector-concurrency
fix: merge duplicate detector into claude workflow and add concurrency
2026-03-02 21:41:37 +00:00
Kevin Turcios
ad4ebdb710 fix: merge duplicate detector into claude workflow and add concurrency
Consolidates duplicate-code-detector.yml into claude.yml as a step in
the pr-review job. Adds concurrency groups with cancel-in-progress to
prevent comment spam from racing workflow runs.
2026-03-02 16:36:35 -05:00
Sarthak Agarwal
d805c6ebb5
Merge pull request #1720 from codeflash-ai/fix/jest-junit-and-misc
Multiple Small fixes on JS/TS codebases
2026-03-02 22:56:09 +05:30
Sarthak Agarwal
c53740df2e
Merge branch 'main' into fix/jest-junit-and-misc 2026-03-02 22:46:13 +05:30
Sarthak Agarwal
d5dba8ce71 add mocha support 2026-03-02 22:44:48 +05:30
Sarthak Agarwal
6330f69a41
Merge pull request #1551 from codeflash-ai/add_docs_to_js
Docs to JS/TS
2026-03-02 22:24:03 +05:30
Sarthak Agarwal
eaf6ad5860
Update FRICTIONLESS_SETUP_PLAN.md 2026-03-02 22:23:15 +05:30
Sarthak Agarwal
dfb951b945
Update JS_PROMPT_PARITY_RECOMMENDATIONS.md 2026-03-02 22:22:51 +05:30
Sarthak Agarwal
be031ce205 docs: update JS/TS docs with package manager instructions, monorepo guide, and troubleshooting
- Fix javascript-installation.mdx: remove references to nonexistent
  codeflash.config.js, use package.json config, fix supported framework
  list (only Jest/Vitest), add Python CLI requirement note
- Add package manager-specific commands (npm/yarn/pnpm/bun) throughout
- Add monorepo setup guide with workspace examples
- Add auto-detection table explaining what codeflash init detects
- Add troubleshooting for common issues (exports, framework detection,
  timeouts, TypeScript, monorepo)
- Add yarn/pnpm CI examples to GitHub Actions page with monorepo tip

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 22:10:47 +05:30
Sarthak Agarwal
0746ae42ea fix: show actionable error when JS/TS function exists but is not exported
When a user targets a function that exists in the file but is not exported,
show a clear message suggesting they add an export statement, instead of
the generic "function not found" error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 22:04:25 +05:30
Sarthak Agarwal
b0afe2ef9c feat: add skip_confirm and skip_api_key params to JS init for non-interactive mode
Allow init_js_project(), should_modify_package_json_config(), and
collect_js_setup_info() to run without interactive prompts when
skip_confirm=True. Uses auto-detected defaults instead of prompting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 22:03:46 +05:30
Sarthak Agarwal
0490b221f2 fix: raise clear error for unsupported JS test frameworks instead of silent fallback
Add NotImplementedError guard in all 3 test dispatchers (behavioral,
benchmarking, line-profile) for frameworks other than jest and vitest.
Previously, mocha and other frameworks silently fell through to Jest,
causing confusing failures. Now users get a clear error message.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 22:03:13 +05:30
Sarthak Agarwal
4bf8cb7412 feat: discover object methods exported via CJS module.exports = variable
Resolve `module.exports = varName` where varName is an object literal
containing methods. For patterns like `const utils = { match() {} };
module.exports = utils;`, the individual methods are now recognized as
exported. This fixes function discovery for CJS libraries like Moleculer.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 22:01:56 +05:30
Sarthak Agarwal
76d994e87c feat: discover const arrow functions exported via named export clauses
Post-process find_functions() to mark functions as exported when they appear
in named export clauses like `export { joinBy }`. This fixes discovery for
TypeScript codebases (e.g., Strapi) that define const arrow functions and
export them via a separate export statement.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 22:00:33 +05:30
Sarthak Agarwal
3c2a2b3694 feat: bundle JUnit XML reporter for Jest, replacing external jest-junit dependency
Ship a zero-dependency jest-reporter.js inside the codeflash runtime package
instead of requiring the external jest-junit npm package. This ensures the
reporter is always available when codeflash is installed, fixing Jest-based
projects (Strapi, Moleculer) that failed because jest-junit wasn't installed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 21:59:41 +05:30
Kevin Turcios
ab1a5355ef
Merge pull request #1718 from codeflash-ai/fix-claude-workflow
fix: rewrite Claude Code PR review prompt
2026-03-02 15:55:55 +00:00
Kevin Turcios
29d0d2cb48 fix: rewrite Claude Code PR review prompt for better instruction following
- Use XML structure instead of markdown for clearer step boundaries
- Resolve stale review threads via GraphQL instead of leaving them
- Positive framing instead of negation for instructions
- Replace aggressive language with calm direct instructions
- Add /simplify skill invocation for code quality pass
- Add verification checkpoint at the end
- Auto-close stale codeflash optimization PRs (age, conflicts, CI failures, deleted functions)
- Remove inline comment MCP tool, add Skill tool
2026-03-02 10:53:35 -05:00
Kevin Turcios
aed71612ba
Merge pull request #1715 from codeflash-ai/prepare-java-support
add Java scaffolding
2026-03-02 12:45:21 +00:00
Kevin Turcios
3ad21016fc refactor: deduplicate format_code and validate_syntax between JS and TS support
Use self.default_file_extension in format_code and a treesitter_language
property in validate_syntax so TypeScriptSupport inherits both methods
from JavaScriptSupport instead of duplicating them.
2026-03-02 07:33:45 -05:00
Kevin Turcios
67f789ce67 refactor: deduplicate language metadata and helper function creation
Extract add_language_metadata() in AiServiceClient to consolidate 3
identical payload setup blocks. Extract helper_from_func() closure in
import_resolver to consolidate duplicate HelperFunction creation.
2026-03-02 07:20:27 -05:00
Kevin Turcios
415ad33bdc fix: add missing protocol methods to PythonSupport
Protocol methods with default bodies on a Protocol class are not
inherited by implementations. Add explicit detect_module_system and
adjust_test_config_for_discovery to PythonSupport.
2026-03-02 07:09:32 -05:00
Kevin Turcios
38444462f3 docs: document LanguageSupport protocol methods in architecture.md 2026-03-02 07:07:47 -05:00
Kevin Turcios
8ca716258f refactor: convert remaining language guards to protocol dispatch and add Java scaffolding
Add JAVA enum value, is_java() helper, registry import guard, and Java
test frameworks (junit5/junit4/testng) as zero-behavior-change scaffolding.

Add 6 new LanguageSupport protocol methods/properties
(default_language_version, valid_test_frameworks,
test_result_serialization_format, load_coverage,
adjust_test_config_for_discovery, detect_module_system,
process_generated_test_strings) and implement them in PythonSupport and
JavaScriptSupport.

Replace 12 is_python()/is_javascript() guards across aiservice.py (5),
parse_test_output.py (4), verifier.py (2), and discover_unit_tests.py (1)
with protocol dispatch, moving ~40 lines of JS instrumentation logic from
verifier.py into JavaScriptSupport.

Also add imported_type_skeletons field to CodeContext and
JAVA_TESTCASE_TIMEOUT constant for upcoming Java support.
2026-03-02 07:04:36 -05:00
Kevin Turcios
2e4127a3b6
Merge pull request #1708 from codeflash-ai/extract-js-optimizer
refactor: extract JavaScript Optimizer subclass
2026-03-02 11:44:11 +00:00
Kevin Turcios
341c622d40 docs: update rules and architecture for new language structure
- Add JS optimizer, normalizer, and support files to architecture tree
- Update key entry points table for per-function optimization and test execution
- Add protocol dispatch preference to language-patterns rules
- Fix stale context path in optimization-patterns
- Add explicit utf-8 encoding rule scoped to new/changed code
2026-03-02 06:10:12 -05:00
Kevin Turcios
04a94f2b03 test: update tests for refactored language support
- Update discover_functions calls to new (source, file_path) signature
- Use language-specific FunctionOptimizer subclasses in tests
- Add explicit utf-8 encoding to read_text()/write_text() for Windows
- Fix pytest fixture in TestTsJestSkipsConversion (was __init__)
- Update nonexistent file tests for source-based discover_functions
- Remove unused imports
2026-03-02 06:09:06 -05:00