@@ -62,36 +62,49 @@ def generate_tests(
6262 generated_test_source , instrumented_behavior_test_source , instrumented_perf_test_source = response
6363 temp_run_dir = get_run_tmp_file (Path ()).as_posix ()
6464
65- instrumented_behavior_test_source = instrumented_behavior_test_source .replace (
66- "{codeflash_run_tmp_dir_client_side}" , temp_run_dir
67- )
68- instrumented_perf_test_source = instrumented_perf_test_source .replace (
69- "{codeflash_run_tmp_dir_client_side}" , temp_run_dir
70- )
71-
72- # For JavaScript/TypeScript, validate and fix import styles to match source exports
65+ # For JavaScript/TypeScript, instrumentation is done locally (aiservice returns uninstrumented code)
7366 if is_javascript ():
74- from codeflash .languages .javascript .instrument import validate_and_fix_import_style
67+ from codeflash .languages .javascript .instrument import (
68+ TestingMode ,
69+ instrument_generated_js_test ,
70+ validate_and_fix_import_style ,
71+ )
7572 from codeflash .languages .javascript .module_system import ensure_module_system_compatibility
7673
7774 source_file = Path (function_to_optimize .file_path )
7875 func_name = function_to_optimize .function_name
76+ qualified_name = function_to_optimize .qualified_name
7977
78+ # First validate and fix import styles
8079 generated_test_source = validate_and_fix_import_style (generated_test_source , source_file , func_name )
81- instrumented_behavior_test_source = validate_and_fix_import_style (
82- instrumented_behavior_test_source , source_file , func_name
83- )
84- instrumented_perf_test_source = validate_and_fix_import_style (
85- instrumented_perf_test_source , source_file , func_name
86- )
8780
8881 # Convert module system if needed (e.g., CommonJS -> ESM for ESM projects)
8982 generated_test_source = ensure_module_system_compatibility (generated_test_source , project_module_system )
90- instrumented_behavior_test_source = ensure_module_system_compatibility (
91- instrumented_behavior_test_source , project_module_system
83+
84+ # Instrument for behavior verification (writes to SQLite)
85+ instrumented_behavior_test_source = instrument_generated_js_test (
86+ test_code = generated_test_source ,
87+ function_name = func_name ,
88+ qualified_name = qualified_name ,
89+ mode = TestingMode .BEHAVIOR ,
90+ )
91+
92+ # Instrument for performance measurement (prints to stdout)
93+ instrumented_perf_test_source = instrument_generated_js_test (
94+ test_code = generated_test_source ,
95+ function_name = func_name ,
96+ qualified_name = qualified_name ,
97+ mode = TestingMode .PERFORMANCE ,
98+ )
99+
100+ logger .debug (f"Instrumented JS/TS tests locally for { func_name } " )
101+ else :
102+ # Python: instrumentation is done by aiservice, just replace temp dir placeholders
103+ instrumented_behavior_test_source = instrumented_behavior_test_source .replace (
104+ "{codeflash_run_tmp_dir_client_side}" , temp_run_dir
92105 )
93- instrumented_perf_test_source = ensure_module_system_compatibility (
94- instrumented_perf_test_source , project_module_system
106+ instrumented_perf_test_source = instrumented_perf_test_source . replace (
107+ "{codeflash_run_tmp_dir_client_side}" , temp_run_dir
95108 )
96109 else :
97110 logger .warning (f"Failed to generate and instrument tests for { function_to_optimize .function_name } " )
0 commit comments