Skip to content

Commit e747ca1

Browse files
committed
fix: send only function source to testgen review/repair, not entire module
The review and repair endpoints were receiving the full module source code as function_source_code, causing prompt overflow (210k > 200k token limit) for large files. Extract just the function using existing line number info.
1 parent 1f74810 commit e747ca1

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

codeflash/optimization/function_optimizer.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,11 +2026,18 @@ def review_and_repair_tests(
20262026
"unexecuted_branches": dc.unexecuted_branches,
20272027
}
20282028

2029+
# Extract just the function source (not the entire module) for the review prompt
2030+
func = self.function_to_optimize
2031+
source_lines = self.function_to_optimize_source_code.splitlines(keepends=True)
2032+
func_start = (func.doc_start_line or func.starting_line or 1) - 1
2033+
func_end = func.ending_line or len(source_lines)
2034+
function_only_source = "".join(source_lines[func_start:func_end])
2035+
20292036
console.rule()
20302037
with progress_bar("Reviewing generated tests for quality issues..."):
20312038
review_results = self.aiservice_client.review_generated_tests(
20322039
tests=tests_for_review,
2033-
function_source_code=self.function_to_optimize_source_code,
2040+
function_source_code=function_only_source,
20342041
function_name=self.function_to_optimize.function_name,
20352042
trace_id=self.function_trace_id,
20362043
coverage_summary=coverage_summary,
@@ -2089,7 +2096,7 @@ def review_and_repair_tests(
20892096
repair_result = self.aiservice_client.repair_generated_tests(
20902097
test_source=gt.generated_original_test_source,
20912098
functions_to_repair=review.functions_to_repair,
2092-
function_source_code=self.function_to_optimize_source_code,
2099+
function_source_code=function_only_source,
20932100
function_to_optimize=self.function_to_optimize,
20942101
helper_function_names=[f.fully_qualified_name for f in code_context.helper_functions],
20952102
module_path=Path(self.original_module_path),

0 commit comments

Comments
 (0)