Commit graph

5541 commits

Author SHA1 Message Date
Kevin Turcios
65ff392d20 add tests 2026-01-24 10:14:54 -05:00
Kevin Turcios
69740f0340 refactor: simplify code_context_extractor by extracting helper and removing dead code
- Extract build_testgen_context helper to reduce duplication in testgen
  token limit handling (~50 lines to ~20 lines)
- Remove unused extract_code_string_context_from_files function (~100 lines)
- Import get_section_names from unused_definition_remover instead of duplicating
2026-01-24 09:25:41 -05:00
Kevin Turcios
47b5235978 refactor: remove unused code and simplify return pattern in unused_definition_remover
Remove unused print_definitions debug function and simplify
detect_unused_helper_functions to use try/except/else pattern.
2026-01-24 09:25:36 -05:00
Kevin Turcios
571b2ba694 skip for 3.9 2026-01-24 07:05:27 -05:00
Kevin Turcios
aba3e79648 Merge branch 'skyvern-grace' of https://github.com/codeflash-ai/codeflash into skyvern-grace 2026-01-24 06:52:10 -05:00
Kevin Turcios
1b92d11058 Update mypy.yml 2026-01-24 06:51:43 -05:00
Kevin Turcios
9c9593aec0 refactor: merge duplicate CST pruning functions into single parameterized function
Consolidated prune_cst_for_read_only_code and prune_cst_for_testgen_code into
prune_cst_for_context with include_target_in_output and include_init_dunder flags.
2026-01-24 06:50:50 -05:00
Kevin Turcios
48b5ff379f refactor: merge duplicate CST pruning functions into single parameterized function
Consolidated prune_cst_for_read_only_code and prune_cst_for_testgen_code into
prune_cst_for_context with include_target_in_output and include_init_dunder flags.
2026-01-24 06:47:33 -05:00
Kevin Turcios
7b33e8b7f6 refactor: smarter placement of global assignments based on dependencies
Assignments that don't reference module-level definitions are now placed
right after imports. Only assignments that reference classes/functions
are placed after those definitions to prevent NameError.
2026-01-24 06:29:39 -05:00
Kevin Turcios
257c5f2b8f test: update test expectations for global assignment placement changes
Update test_no_targets_found to expect outer class to be kept when
targeting nested class methods, and add test for nonexistent targets.
Update test_multi_file_replcement01 to expect global assignments at
module end rather than after imports.
2026-01-24 06:19:48 -05:00
Kevin Turcios
50fba096f7 fix: insert global statements after function definitions to prevent NameError
When LLM-generated optimizations include module-level function calls like
`_register(MessageKind.ASK, ...)`, they were being inserted right after
imports, BEFORE the function definition they reference, causing NameError
at module load time.

Changes:
- Add GlobalStatementTransformer to append global statements at module end
- Reorder transformations: functions → assignments → statements
- Remove unused ImportInserter class
- Update test expectations to reflect new placement behavior
2026-01-24 02:09:38 -05:00
Kevin Turcios
abfa640578 fix: insert global assignments after class definitions to prevent NameError
When LLM-generated optimizations include module-level code like
`_REIFIERS = {MessageKind.XXX: ...}`, the global assignment was being
inserted right after imports, BEFORE the class definition it referenced,
causing NameError at module load time.

Changes:
- GlobalAssignmentTransformer now inserts assignments after all
  class/function definitions instead of right after imports
- GlobalStatementCollector now skips AnnAssign (annotated assignments)
  so they are handled by GlobalAssignmentCollector instead
2026-01-24 01:37:15 -05:00
Kevin Turcios
1bb9d147f4
Merge branch 'main' into skyvern-grace 2026-01-24 01:31:02 -05:00
Kevin Turcios
6b3b10e7fa fix: include dependency classes in read-writable optimization context
Classes used as dependencies (enums, dataclasses, types) were being
excluded from the optimization context even when marked as used by
the target function. This caused NameError when the LLM used these
types in generated optimizations.
2026-01-24 01:19:22 -05:00
Kevin Turcios
34de67681e fix: track attribute access base names as dependencies in DependencyCollector
Fix issue where enum/class attribute access like `MessageKind.VALUE` was not
tracking `MessageKind` as a dependency. The original code skipped all Names
inside Attribute nodes within classes, but this incorrectly filtered out
legitimate references.

Now properly distinguishes between:
- `.attr` part (e.g., `x` in `self.x`) - not tracked (attribute names)
- `.value` part (e.g., `MessageKind` in `MessageKind.VALUE`) - tracked
2026-01-24 00:57:48 -05:00
Kevin Turcios
323e52ed99 fix: use PicklePatcher for instance state to handle unpicklable async objects
When instrumenting classes that inherit from Playwright's Page (like
SkyvernPage), the instance state contains async event loop references
including asyncgen_hooks which cannot be pickled. PicklePatcher gracefully
handles these by replacing unpicklable objects with placeholders.
2026-01-23 21:06:44 -05:00
Kevin Turcios
dbc88ad105 feat: extract __init__ from external library base classes for test context
Add get_external_base_class_inits to extract __init__ methods from external
library base classes (e.g., collections.UserDict) when project classes inherit
from them. This helps the LLM understand constructor signatures for mocking.
2026-01-23 20:46:51 -05:00
Kevin Turcios
6009b83f20 fix: handle module-level function definitions in add_global_assignments
Add GlobalFunctionCollector and GlobalFunctionTransformer to collect and
insert module-level function definitions introduced by LLM optimizations.
This fixes NameError when optimized code introduces new helper functions
like @lru_cache decorated functions that are used by the optimized method.
2026-01-23 18:59:00 -05:00
Kevin Turcios
9f929c2151 fix: handle annotated assignments in GlobalAssignmentCollector
GlobalAssignmentCollector only handled cst.Assign but not cst.AnnAssign
(annotated assignments like `X: int = 1`). When the LLM generated
optimizations with annotated module-level variables, these weren't
copied to the target file, causing NameError at runtime.

- Add visit_AnnAssign to GlobalAssignmentCollector
- Add leave_AnnAssign to GlobalAssignmentTransformer
- Update type hints to include cst.AnnAssign
- Add test for annotated assignment handling
2026-01-23 18:46:49 -05:00
Kevin Turcios
412779d7ba fix: handle repr failures for Mock objects in test result comparison
Mock objects from unittest.mock can have corrupted internal state after
pickling, causing __repr__ to raise AttributeError. Added safe_repr
wrapper to gracefully handle these failures during test result comparison.
2026-01-23 17:58:14 -05:00
Kevin Turcios
9cefc0340b fix: handle instance state capture for classes without __dict__
Support classes using __slots__ and C extension types (like Playwright's
Page) that don't have a __dict__ attribute. Previously raised ValueError,
now captures slot values or public non-callable attributes as fallback.
2026-01-23 17:49:02 -05:00
Kevin Turcios
ebf77033ba test: add tests for base class extraction in imported dataclasses
- Update test_get_imported_class_definitions_includes_dataclass_decorators
  to expect both base class and derived class to be extracted
- Add test_get_imported_class_definitions_extracts_multilevel_inheritance
  to verify multi-level inheritance chains are fully extracted
2026-01-23 07:26:03 -05:00
Kevin Turcios
4e310324b4 fix: recursively extract base classes for imported dataclasses
When extracting imported class definitions for testgen context, also
extract base classes from the same module. This ensures the full
inheritance chain is available for understanding constructor signatures.

For example, when LLMConfig inherits from LLMConfigBase, both classes
are now included in the context so the LLM can see all required
positional arguments from parent classes.
2026-01-23 07:25:56 -05:00
Kevin Turcios
722d05345d decorators & annotations 2026-01-23 06:52:45 -05:00
Kevin Turcios
d53e6d23a7
Merge pull request #1149 from codeflash-ai/async-improvements
feat: clarify improvement type in async optimization display
2026-01-23 01:47:48 -05:00
Kevin Turcios
f87b30403a test: validate concurrency acceptance reason in async E2E test
Ensure the async E2E test verifies that optimizations are accepted
for the correct reason (concurrency improvement).
2026-01-23 01:45:03 -05:00
Kevin Turcios
dc563465e0 feat: add acceptance reason validation to E2E tests
Add expected_acceptance_reason field to TestConfig and update the
improvement regex to capture and validate the improvement type.
2026-01-23 01:44:59 -05:00
Kevin Turcios
7126694ea2 feat: display improvement type in performance messages
Show whether improvement is from runtime, throughput, or concurrency
in the display output (e.g., "45% runtime improvement" instead of
just "45% improvement").
2026-01-23 01:44:55 -05:00
Kevin Turcios
2ed55ed3bb
Merge pull request #1142 from codeflash-ai/dependabot/uv/wheel-0.46.2
Bump wheel from 0.45.1 to 0.46.2
2026-01-22 23:19:53 -05:00
Kevin Turcios
b11145c04f
Merge branch 'main' into dependabot/uv/wheel-0.46.2 2026-01-22 23:17:15 -05:00
Aseem Saxena
c7b5db38c3
Merge pull request #1115 from codeflash-ai/comparator-numpy-types
extend comparator support for np.clongdouble
2026-01-22 19:34:27 -08:00
Aseem Saxena
3c5e2af8dd
Merge branch 'main' into comparator-numpy-types 2026-01-22 19:13:05 -08:00
Kevin Turcios
81a5fa5f67
Merge pull request #1023 from codeflash-ai/repair-async-opts
feat: concurrency-aware async benchmarking
2026-01-22 22:06:21 -05:00
Kevin Turcios
22a5a45583
Merge branch 'main' into repair-async-opts 2026-01-22 22:04:33 -05:00
Kevin Turcios
b49b454844
Merge pull request #1114 from codeflash-ai/comparator-numba-types
Extend comparator to numba data types
2026-01-22 22:04:02 -05:00
Kevin Turcios
7cfe5937c2 merge: resolve conflict with main in test_comparator.py
Keep both numba type tests and pytest temp path normalization tests.
2026-01-22 22:02:14 -05:00
Kevin Turcios
9ad22af6f1
Merge pull request #1146 from codeflash-ai/crosshair-limit
reduce invalid crosshair tests noise
2026-01-22 21:33:38 -05:00
Kevin Turcios
3cd0f30c7e patterns 2026-01-22 21:16:03 -05:00
dependabot[bot]
188a5e79dc
Bump wheel from 0.45.1 to 0.46.2
Bumps [wheel](https://github.com/pypa/wheel) from 0.45.1 to 0.46.2.
- [Release notes](https://github.com/pypa/wheel/releases)
- [Changelog](https://github.com/pypa/wheel/blob/main/docs/news.rst)
- [Commits](https://github.com/pypa/wheel/compare/0.45.1...0.46.2)

---
updated-dependencies:
- dependency-name: wheel
  dependency-version: 0.46.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-22 19:33:20 +00:00
aseembits93
84a03d0f2d minor fix 2026-01-22 11:31:12 -08:00
aseembits93
87c15596fe Merge remote-tracking branch 'origin/main' into comparator-numpy-types 2026-01-22 11:06:07 -08:00
Kevin Turcios
70a069bc49
Merge pull request #1112 from codeflash-ai/comparator-temp-paths
extend comparator to pytest temp paths
2026-01-22 06:15:27 -05:00
Kevin Turcios
9a00b0b745
Merge branch 'main' into comparator-temp-paths 2026-01-22 06:04:31 -05:00
Kevin Turcios
3418b61493
Merge pull request #1120 from codeflash-ai/comparator-wrapped-exceptions
Comparator for wrapped exceptions
2026-01-22 06:00:25 -05:00
Aseem Saxena
af976f937e
Merge branch 'main' into comparator-numba-types 2026-01-20 10:58:12 -08:00
Aseem Saxena
332f888624
Merge branch 'main' into comparator-wrapped-exceptions 2026-01-20 10:57:06 -08:00
HeshamHM28
8245bb567c
Merge pull request #1111 from codeflash-ai/feat/line/profiler/vsc
[Feat]  Add a line profiler for VS Code
2026-01-20 09:38:31 -08:00
HeshamHM28
be9c4bed80
Merge branch 'main' into feat/line/profiler/vsc 2026-01-20 09:26:46 -08:00
mashraf-222
98cfe6e4f9
Merge pull request #1083 from codeflash-ai/update-extension-docs
add vsc extension docs
2026-01-20 19:23:41 +02:00
Aseem Saxena
20fbecb046
Merge branch 'main' into update-extension-docs 2026-01-20 09:07:03 -08:00