@@ -80,7 +80,8 @@ def run_codeflash_command(
8080) -> bool :
8181 logging .basicConfig (level = logging .INFO )
8282 if config .trace_mode :
83- return run_trace_test (cwd , config , expected_improvement_pct )
83+ # return run_trace_test(cwd, config, expected_improvement_pct)
84+ return run_trace_test2 (cwd , config , expected_improvement_pct )
8485
8586 path_to_file = cwd / config .file_path
8687 file_contents = path_to_file .read_text ("utf-8" )
@@ -228,6 +229,55 @@ def run_trace_test(cwd: pathlib.Path, config: TestConfig, expected_improvement_p
228229 return validate_output (stdout , return_code , expected_improvement_pct , config )
229230
230231
232+ def run_trace_test2 (cwd : pathlib .Path , config : TestConfig , expected_improvement_pct : int ) -> bool :
233+ # First command: Run the tracer
234+ test_root = cwd / "tests" / (config .test_framework or "" )
235+ clear_directory (test_root )
236+ command = ["python" , "-m" , "codeflash.tracer" , "-o" , "codeflash.trace" , "testbench.py" ]
237+ process = subprocess .Popen (
238+ command , stdout = subprocess .PIPE , stderr = subprocess .STDOUT , text = True , cwd = str (cwd ), env = os .environ .copy ()
239+ )
240+
241+ output = []
242+ for line in process .stdout :
243+ logging .info (line .strip ())
244+ output .append (line )
245+
246+ return_code = process .wait ()
247+ stdout = "" .join (output )
248+
249+ if return_code != 0 :
250+ logging .error (f"Tracer command returned exit code { return_code } " )
251+ return False
252+
253+ functions_traced = re .search (r"Traced (\d+) function calls successfully and replay test created at - (.*)$" , stdout )
254+ if not functions_traced or int (functions_traced .group (1 )) != 3 :
255+ logging .error ("Expected 3 traced functions" )
256+ return False
257+
258+ replay_test_path = pathlib .Path (functions_traced .group (2 ))
259+ if not replay_test_path .exists ():
260+ logging .error (f"Replay test file missing at { replay_test_path } " )
261+ return False
262+
263+ # Second command: Run optimization
264+ command = ["python" , "../../../codeflash/main.py" , "--replay-test" , str (replay_test_path ), "--no-pr" ]
265+ process = subprocess .Popen (
266+ command , stdout = subprocess .PIPE , stderr = subprocess .STDOUT , text = True , cwd = str (cwd ), env = os .environ .copy ()
267+ )
268+
269+ output = []
270+ for line in process .stdout :
271+ logging .info (line .strip ())
272+ output .append (line )
273+
274+ return_code = process .wait ()
275+ stdout = "" .join (output )
276+
277+ return validate_output (stdout , return_code , expected_improvement_pct , config )
278+
279+
280+
231281def run_with_retries (test_func , * args , ** kwargs ) -> bool :
232282 max_retries = int (os .getenv ("MAX_RETRIES" , 3 ))
233283 retry_delay = int (os .getenv ("RETRY_DELAY" , 5 ))
0 commit comments