@@ -741,6 +741,51 @@ def test_gecko_collector_basic(self):
741741 self .assertGreater (stack_table ["length" ], 0 )
742742 self .assertGreater (len (stack_table ["frame" ]), 0 )
743743
744+ def test_gecko_collector_preserves_source_file_paths (self ):
745+ """Test that GeckoCollector preserves source file paths and distinguishes
746+ files with the same basename in different directories."""
747+ collector = GeckoCollector (1000 )
748+ file_a = os .path .join ("pkg_a" , "__init__.py" )
749+ file_b = os .path .join ("pkg_b" , "__init__.py" )
750+
751+ test_frames = [
752+ MockInterpreterInfo (
753+ 0 ,
754+ [
755+ MockThreadInfo (
756+ 1 ,
757+ [
758+ MockFrameInfo (file_a , 10 , "func_a" ),
759+ MockFrameInfo (file_b , 20 , "func_b" ),
760+ ],
761+ status = THREAD_STATUS_MAIN_THREAD ,
762+ )
763+ ],
764+ )
765+ ]
766+ collector .collect (test_frames )
767+ profile_data = collector ._build_profile ()
768+
769+ string_array = profile_data ["shared" ]["stringArray" ]
770+ func_table = profile_data ["threads" ][0 ]["funcTable" ]
771+
772+ self .assertEqual (func_table ["length" ], 2 )
773+
774+ funcs_by_name = {
775+ string_array [func_table ["name" ][i ]]: (
776+ func_table ["fileName" ][i ],
777+ string_array [func_table ["fileName" ][i ]],
778+ )
779+ for i in range (func_table ["length" ])
780+ }
781+
782+ file_idx_a , resolved_file_a = funcs_by_name ["func_a" ]
783+ file_idx_b , resolved_file_b = funcs_by_name ["func_b" ]
784+
785+ self .assertEqual (resolved_file_a , file_a )
786+ self .assertEqual (resolved_file_b , file_b )
787+ self .assertNotEqual (file_idx_a , file_idx_b )
788+
744789 def test_gecko_collector_async_aware (self ):
745790 collector = GeckoCollector (1000 )
746791
0 commit comments