@@ -1963,6 +1963,15 @@ def review_and_repair_tests(
19631963 behavioral_results : TestResults | None = None
19641964 coverage_results : CoverageData | None = None
19651965 previous_repair_errors : dict [int , dict [str , str ]] = {}
1966+ # Apply token limit to function source (same progressive fallback as optimization/testgen context)
1967+ function_source_for_prompt = self .function_to_optimize_source_code
1968+ if encoded_tokens_len (function_source_for_prompt ) > OPTIMIZATION_CONTEXT_TOKEN_LIMIT :
1969+ logger .debug ("Function source exceeds token limit for review, extracting function only" )
1970+ func = self .function_to_optimize
1971+ source_lines = self .function_to_optimize_source_code .splitlines (keepends = True )
1972+ func_start = (func .doc_start_line or func .starting_line or 1 ) - 1
1973+ func_end = func .ending_line or len (source_lines )
1974+ function_source_for_prompt = "" .join (source_lines [func_start :func_end ])
19661975 max_cycles = getattr (self .args , "testgen_review_turns" , None ) or MAX_TEST_REPAIR_CYCLES
19671976 for cycle in range (max_cycles ):
19681977 with progress_bar ("Running generated tests to validate quality..." ):
@@ -2026,16 +2035,6 @@ def review_and_repair_tests(
20262035 "unexecuted_branches" : dc .unexecuted_branches ,
20272036 }
20282037
2029- # Apply token limit to function source (same progressive fallback as optimization/testgen context)
2030- function_source_for_prompt = self .function_to_optimize_source_code
2031- if encoded_tokens_len (function_source_for_prompt ) > OPTIMIZATION_CONTEXT_TOKEN_LIMIT :
2032- logger .debug ("Function source exceeds token limit for review, extracting function only" )
2033- func = self .function_to_optimize
2034- source_lines = self .function_to_optimize_source_code .splitlines (keepends = True )
2035- func_start = (func .doc_start_line or func .starting_line or 1 ) - 1
2036- func_end = func .ending_line or len (source_lines )
2037- function_source_for_prompt = "" .join (source_lines [func_start :func_end ])
2038-
20392038 console .rule ()
20402039 with progress_bar ("Reviewing generated tests for quality issues..." ):
20412040 review_results = self .aiservice_client .review_generated_tests (
@@ -2143,6 +2142,7 @@ def review_and_repair_tests(
21432142 repaired_indices .add (review .test_index )
21442143
21452144 if not any_repaired :
2145+ logger .warning ("All repair API calls failed; proceeding with unrepaired tests" )
21462146 break
21472147
21482148 generated_tests = self .language_support .postprocess_generated_tests (
0 commit comments