Commit graph

64 commits

Author SHA1 Message Date
Kevin Turcios
2652e71617 Merge remote-tracking branch 'origin/main' into call-graphee
# Conflicts:
#	.codex/skills/.gitignore
#	.gemini/skills/.gitignore
#	codeflash/languages/python/context/code_context_extractor.py
2026-02-19 01:05:42 -05:00
Kevin Turcios
6a5c9c1b40 test: update expected context values for statement-type helpers 2026-02-18 21:07:03 -05:00
Kevin Turcios
0bcc483a95 Merge branch 'main' into call-graphee 2026-02-16 22:50:24 -05:00
Kevin Turcios
bba3e0aa4d Merge branch 'main' into call-graphee 2026-02-16 22:43:03 -05:00
Kevin Turcios
547c02e8bc refactor: move context extraction modules to languages/python/context/
Move code_context_extractor.py and unused_definition_remover.py from
codeflash/context/ to codeflash/languages/python/context/ and update
all import sites.
2026-02-16 14:49:04 -05:00
Kevin Turcios
fa00422fea refactor: simplify and deduplicate code_context_extractor
Consolidate three enricher functions (get_imported_class_definitions,
get_external_base_class_inits, get_external_class_inits) into a single
enrich_testgen_context that parses code context once. Extract shared
helpers, unify prune_cst variants, deduplicate loop bodies, and remove
dead UsedNameCollector class.
2026-02-16 13:34:07 -05:00
Kevin Turcios
e837ad9d17 feat: resolve transitive type dependencies in get_external_class_inits
Add BFS-based transitive resolution so that classes referenced in __init__
type annotations of imported external classes are also extracted. This gives
the LLM the constructor signatures it needs to instantiate parameter types.
2026-02-13 09:35:30 -05:00
claude[bot]
8eb1c86245 fix: resolve mypy union-attr error in test_get_external_class_inits
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 14:09:28 +00:00
Kevin Turcios
f4c0208f49 test: add unit tests for get_external_class_inits
Tests cover: extracting __init__ from site-packages classes (click.Option),
skipping project classes, non-classes, already-defined classes, builtins,
classes with trivial object.__init__, and empty import scenarios.
2026-02-13 09:03:09 -05:00
Kevin Turcios
fc42548f9f test: update token limit tests for 64K default 2026-02-12 01:03:34 -05:00
Kevin Turcios
9e904483d8 fix: use explicit token limits in tests to decouple from global constant 2026-02-12 01:02:21 -05:00
misrasaurabh1
198487bf81 format and lint all 2026-01-29 01:39:48 -08:00
Kevin Turcios
65ff392d20 add tests 2026-01-24 10:14:54 -05:00
Kevin Turcios
571b2ba694 skip for 3.9 2026-01-24 07:05:27 -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
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
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
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
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
722d05345d decorators & annotations 2026-01-23 06:52:45 -05:00
Kevin Turcios
0312c37631 feat: extract imported class definitions for testgen context
When generating tests, the LLM now receives class definitions for
types imported from project modules. This helps the LLM understand:
- Constructor signatures (avoiding incorrect argument guessing)
- Base classes (e.g., abstract classes that can't be instantiated)
- Class structure for creating proper test instances

Previously, the LLM only saw import statements like:
  from mypackage.elements import Element

Now it also sees the actual class definition with constructor details.

Changes:
- Add get_imported_class_definitions() to extract class definitions
  from project modules referenced in import statements
- Integrate into get_code_optimization_context() to include extracted
  classes in testgen context
- Gracefully handle token limits by dropping class definitions if needed
- Add 4 unit tests covering extraction, deduplication, and filtering
2026-01-07 16:09:29 -05:00
Kevin Turcios
3048ece4da fix: track class __init__ as helper when class is instantiated
Ensures LLM sees constructor signatures for proper test generation.
2026-01-01 02:25:10 -05:00
ali
b464c4d869
typo 2025-11-21 20:53:35 +02:00
ali
15d2027bb0
keep the refrenced global definitions 2025-11-21 20:10:26 +02:00
Kevin Turcios
f978a406bb Merge branch 'main' into part-1-windows-fixes 2025-09-29 14:46:25 -07:00
Kevin Turcios
c9cfaacaaa macos symlink shenanigans 2025-09-27 23:21:15 -07:00
Kevin Turcios
09e9d12813 update context extractor 2025-09-28 04:47:46 +00:00
Kevin Turcios
a826252277 Update test_code_context_extractor.py 2025-09-28 04:38:25 +00:00
Kevin Turcios
c6c9d9559f few missing things 2025-09-26 16:25:28 -07:00
Kevin Turcios
4325416827 resolve paths
in my case, i've started using symlinks a bit more often, and the current impl causes issues, we need to resolve the symlinked path too.
2025-09-26 14:49:29 -07:00
mohammed
a7ff701309
eleminate the use of flat code for parsing 2025-08-06 22:48:03 +03:00
mohammed
989b1f30a2
unit tests fixing 2025-08-06 03:33:46 +03:00
mohammed
654a6ec251
refactoring 2025-07-26 08:49:23 +03:00
mohammed
f48c77df38
flat method rename 2025-07-25 17:50:13 +03:00
mohammed
99cd9dc706
fix tests for context extractor 2025-07-25 15:13:10 +03:00
mohammed
216eb7e794
start using markdown representation for read writable context 2025-07-16 18:48:31 +03:00
mohammed
2e394f6b8f tests and fix global assignments imports 2025-06-29 00:23:36 +03:00
mohammed
2acda6a411 initial test files 2025-06-28 21:14:26 +03:00
Saurabh Misra
7167d2b75d edge case for python 39
Some checks failed
CodeFlash / Optimize new Python code (pull_request) Failing after 2s
PR Labeler / label-workflow-changes (pull_request) Failing after 1s
Mypy Type Checking for CLI / type-check-cli (pull_request) Failing after 1s
/ Run pr agent on every pull request, respond to user comments (pull_request) Failing after 1s
Lint / Run pre-commit hooks (pull_request) Failing after 6s
unit-tests / unit-tests (3.10) (pull_request) Failing after 2s
unit-tests / unit-tests (3.11) (pull_request) Failing after 2s
unit-tests / unit-tests (3.12) (pull_request) Failing after 2s
unit-tests / unit-tests (3.9) (pull_request) Failing after 1s
2025-06-09 00:14:45 -07:00
Saurabh Misra
51c936f421 normalize code before hashing 2025-06-09 00:02:59 -07:00
Saurabh Misra
be1ef9b7d9 fix for test 2025-06-08 01:14:53 -07:00
Saurabh Misra
6ed93871b4 add more tests 2025-06-08 01:13:17 -07:00
Saurabh Misra
2c1314dc91 fix more tests 2025-06-08 00:41:25 -07:00
Saurabh Misra
9e14cfe7a0 fix bugs with docstring removal 2025-06-08 00:30:47 -07:00
Alvin Ryanputra
0d77ea4a0b reworked tests 2025-04-18 20:29:38 -04:00
Alvin Ryanputra
7cda6aafa7 tests for code context extractor 2025-04-17 18:44:15 -04:00
Alvin Ryanputra
9b4ede56a3 initial implementation 2025-04-16 14:14:05 -04:00