@@ -27,7 +27,7 @@ def generate_tests(
2727 test_index : int ,
2828 test_path : Path ,
2929 test_perf_path : Path ,
30- ) -> tuple [str , str , Path ] | None :
30+ ) -> tuple [str , str , str , Path , Path , Path | None , Path | None ] | None :
3131 # TODO: Sometimes this recreates the original Class definition. This overrides and messes up the original
3232 # class import. Remove the recreation of the class definition
3333 start_time = time .perf_counter ()
@@ -43,8 +43,8 @@ def generate_tests(
4343 trace_id = function_trace_id ,
4444 test_index = test_index ,
4545 )
46- if response and isinstance (response , tuple ) and len (response ) == 3 :
47- generated_test_source , instrumented_behavior_test_source , instrumented_perf_test_source = response
46+ if response and isinstance (response , tuple ) and len (response ) == 5 :
47+ generated_test_source , instrumented_behavior_test_source , instrumented_perf_test_source , instrumented_behavior_source , instrumented_perf_source = response
4848 temp_run_dir = get_run_tmp_file (Path ()).as_posix ()
4949
5050 instrumented_behavior_test_source = instrumented_behavior_test_source .replace (
@@ -53,6 +53,29 @@ def generate_tests(
5353 instrumented_perf_test_source = instrumented_perf_test_source .replace (
5454 "{codeflash_run_tmp_dir_client_side}" , temp_run_dir
5555 )
56+
57+ behavior_source_path = None
58+ perf_source_path = None
59+
60+ if instrumented_behavior_source and function_to_optimize .is_async :
61+ behavior_source_path = get_run_tmp_file (Path (f"instrumented_behavior_source_{ test_index } _{ function_to_optimize .function_name } .py" ))
62+ try :
63+ with behavior_source_path .open ("w" , encoding = "utf8" ) as f :
64+ f .write (instrumented_behavior_source )
65+ logger .debug (f"Written instrumented behavior source to { behavior_source_path } " )
66+ except Exception as e :
67+ logger .warning (f"Failed to write instrumented behavior source file: { e } " )
68+ behavior_source_path = None
69+
70+ if instrumented_perf_source and function_to_optimize .is_async :
71+ perf_source_path = get_run_tmp_file (Path (f"instrumented_perf_source_{ test_index } _{ function_to_optimize .function_name } .py" ))
72+ try :
73+ with perf_source_path .open ("w" , encoding = "utf8" ) as f :
74+ f .write (instrumented_perf_source )
75+ logger .debug (f"Written instrumented performance source to { perf_source_path } " )
76+ except Exception as e :
77+ logger .warning (f"Failed to write instrumented performance source file: { e } " )
78+ perf_source_path = None
5679 else :
5780 logger .warning (f"Failed to generate and instrument tests for { function_to_optimize .function_name } " )
5881 return None
@@ -64,6 +87,8 @@ def generate_tests(
6487 instrumented_perf_test_source ,
6588 test_path ,
6689 test_perf_path ,
90+ behavior_source_path ,
91+ perf_source_path ,
6792 )
6893
6994
0 commit comments