1919from rich .tree import Tree
2020
2121from codeflash .api .aiservice import AiServiceClient , LocalAiServiceClient
22- from codeflash .api .cfapi import add_code_context_hash , mark_optimization_success , create_staging
22+ from codeflash .api .cfapi import add_code_context_hash , create_staging , mark_optimization_success
2323from codeflash .benchmarking .utils import process_benchmark_data
2424from codeflash .cli_cmds .console import code_print , console , logger , progress_bar
2525from codeflash .code_utils import env_utils
@@ -997,28 +997,50 @@ def find_and_process_best_optimization(
997997 original_code_combined [explanation .file_path ] = self .function_to_optimize_source_code
998998 new_code_combined = new_helper_code .copy ()
999999 new_code_combined [explanation .file_path ] = new_code
1000- self .process_review (original_code_baseline , best_optimization , generated_tests ,
1001- test_functions_to_remove , concolic_test_str , original_code_combined , new_code_combined ,
1002- explanation , function_to_all_tests , exp_type , original_helper_code )
1000+ self .process_review (
1001+ original_code_baseline ,
1002+ best_optimization ,
1003+ generated_tests ,
1004+ test_functions_to_remove ,
1005+ concolic_test_str ,
1006+ original_code_combined ,
1007+ new_code_combined ,
1008+ explanation ,
1009+ function_to_all_tests ,
1010+ exp_type ,
1011+ original_helper_code ,
1012+ )
10031013 self .log_successful_optimization (explanation , generated_tests , exp_type )
10041014 return best_optimization
10051015
10061016 def process_review (
1007- self , original_code_baseline , best_optimization , generated_tests ,
1008- test_functions_to_remove , concolic_test_str , original_code_combined ,
1009- new_code_combined , explanation , function_to_all_tests , exp_type , original_helper_code
1010- ):
1017+ self ,
1018+ original_code_baseline : OriginalCodeBaseline ,
1019+ best_optimization : BestOptimization ,
1020+ generated_tests : GeneratedTestsList ,
1021+ test_functions_to_remove : list [str ],
1022+ concolic_test_str : str | None ,
1023+ original_code_combined : dict [Path , str ],
1024+ new_code_combined : dict [Path , str ],
1025+ explanation : Explanation ,
1026+ function_to_all_tests : dict [str , set [FunctionCalledInTest ]],
1027+ exp_type : str ,
1028+ original_helper_code : dict [Path , str ],
1029+ ) -> None :
10111030 coverage_message = (
10121031 original_code_baseline .coverage_results .build_message ()
1013- if original_code_baseline .coverage_results else "Coverage data not available"
1032+ if original_code_baseline .coverage_results
1033+ else "Coverage data not available"
10141034 )
10151035
10161036 generated_tests = remove_functions_from_generated_tests (
10171037 generated_tests = generated_tests , test_functions_to_remove = test_functions_to_remove
10181038 )
10191039
10201040 original_runtime_by_test = original_code_baseline .benchmarking_test_results .usable_runtime_data_by_test_case ()
1021- optimized_runtime_by_test = best_optimization .winning_benchmarking_test_results .usable_runtime_data_by_test_case ()
1041+ optimized_runtime_by_test = (
1042+ best_optimization .winning_benchmarking_test_results .usable_runtime_data_by_test_case ()
1043+ )
10221044
10231045 generated_tests = add_runtime_comments_to_generated_tests (
10241046 self .test_cfg , generated_tests , original_runtime_by_test , optimized_runtime_by_test
@@ -1038,15 +1060,17 @@ def process_review(
10381060 optimized_runtimes_all = optimized_runtime_by_test ,
10391061 )
10401062
1041- data = dict (
1042- original_code = original_code_combined ,
1043- new_code = new_code_combined ,
1044- explanation = explanation ,
1045- existing_tests_source = existing_tests ,
1046- generated_original_test_source = generated_tests_str ,
1047- function_trace_id = self .function_trace_id [:- 4 ] + exp_type if self .experiment_id else self .function_trace_id ,
1048- coverage_message = coverage_message ,
1049- )
1063+ data = {
1064+ "original_code" : original_code_combined ,
1065+ "new_code" : new_code_combined ,
1066+ "explanation" : explanation ,
1067+ "existing_tests_source" : existing_tests ,
1068+ "generated_original_test_source" : generated_tests_str ,
1069+ "function_trace_id" : self .function_trace_id [:- 4 ] + exp_type
1070+ if self .experiment_id
1071+ else self .function_trace_id ,
1072+ "coverage_message" : coverage_message ,
1073+ }
10501074
10511075 if not self .args .no_pr and not self .args .staging_review :
10521076 data ["git_remote" ] = self .args .git_remote
@@ -1059,13 +1083,12 @@ def process_review(
10591083 trace_id = self .function_trace_id , is_optimization_found = best_optimization is not None
10601084 )
10611085
1062- if (not self .args .no_pr ) or not self .args .staging_review :
1063- if self .args .all or env_utils .get_pr_number () or (self .args .file and not self .args .function ):
1064- self .write_code_and_helpers (
1065- self .function_to_optimize_source_code ,
1066- original_helper_code ,
1067- self .function_to_optimize .file_path ,
1068- )
1086+ if ((not self .args .no_pr ) or not self .args .staging_review ) and (
1087+ self .args .all or env_utils .get_pr_number () or (self .args .file and not self .args .function )
1088+ ):
1089+ self .write_code_and_helpers (
1090+ self .function_to_optimize_source_code , original_helper_code , self .function_to_optimize .file_path
1091+ )
10691092
10701093 def establish_original_code_baseline (
10711094 self ,
0 commit comments