33from typing import Any , Literal , cast
44from uuid import uuid1
55
6+ import pytest
7+
68from sentry .eventstore .models import Event
79from sentry .seer .similarity .utils import (
810 BASE64_ENCODED_PREFIXES ,
11+ MAX_FRAME_COUNT ,
912 SEER_ELIGIBLE_PLATFORMS ,
13+ TooManyOnlySystemFramesException ,
1014 _is_snipped_context_line ,
1115 event_content_is_seer_eligible ,
1216 filter_null_from_string ,
@@ -670,18 +674,18 @@ def test_chained_too_many_frames_minified_js_frame_limit(self):
670674 )
671675
672676 def test_chained_too_many_exceptions (self ):
673- """Test that we restrict number of chained exceptions to 30 ."""
677+ """Test that we restrict number of chained exceptions to MAX_FRAME_COUNT ."""
674678 data_chained_exception = copy .deepcopy (self .CHAINED_APP_DATA )
675679 data_chained_exception ["app" ]["component" ]["values" ][0 ]["values" ] = [
676680 self .create_exception (
677681 exception_type_str = "Exception" ,
678682 exception_value = f"exception { i } message!" ,
679683 frames = self .create_frames (num_frames = 1 , context_line_factory = lambda i : f"line { i } " ),
680684 )
681- for i in range (1 , 32 )
685+ for i in range (1 , MAX_FRAME_COUNT + 2 )
682686 ]
683687 stacktrace_str = get_stacktrace_string (data_chained_exception )
684- for i in range (2 , 32 ):
688+ for i in range (2 , MAX_FRAME_COUNT + 2 ):
685689 assert f"exception { i } message!" in stacktrace_str
686690 assert "exception 1 message!" not in stacktrace_str
687691
@@ -710,9 +714,35 @@ def test_no_app_no_system(self):
710714 stacktrace_str = get_stacktrace_string (data )
711715 assert stacktrace_str == ""
712716
713- def test_over_30_contributing_frames (self ):
714- """Check that when there are over 30 contributing frames, the last 30 are included."""
717+ def test_too_many_system_frames_single_exception (self ):
718+ data_system = copy .deepcopy (self .BASE_APP_DATA )
719+ data_system ["system" ] = data_system .pop ("app" )
720+ data_system ["system" ]["component" ]["values" ][0 ]["values" ][0 ][
721+ "values"
722+ ] += self .create_frames (MAX_FRAME_COUNT + 1 , True )
723+
724+ with pytest .raises (TooManyOnlySystemFramesException ):
725+ get_stacktrace_string (data_system )
726+
727+ def test_too_many_system_frames_chained_exception (self ):
728+ data_system = copy .deepcopy (self .CHAINED_APP_DATA )
729+ data_system ["system" ] = data_system .pop ("app" )
730+ # Split MAX_FRAME_COUNT across the two exceptions
731+ data_system ["system" ]["component" ]["values" ][0 ]["values" ][0 ]["values" ][0 ][
732+ "values"
733+ ] += self .create_frames (MAX_FRAME_COUNT // 2 , True )
734+ data_system ["system" ]["component" ]["values" ][0 ]["values" ][1 ]["values" ][0 ][
735+ "values"
736+ ] += self .create_frames (MAX_FRAME_COUNT // 2 , True )
737+
738+ with pytest .raises (TooManyOnlySystemFramesException ):
739+ get_stacktrace_string (data_system )
715740
741+ def test_too_many_in_app_contributing_frames (self ):
742+ """
743+ Check that when there are over MAX_FRAME_COUNT contributing frames, the last MAX_FRAME_COUNT
744+ are included.
745+ """
716746 data_frames = copy .deepcopy (self .BASE_APP_DATA )
717747 # Create 30 contributing frames, 1-20 -> last 10 should be included
718748 data_frames ["app" ]["component" ]["values" ][0 ]["values" ][0 ]["values" ] = self .create_frames (
@@ -739,7 +769,7 @@ def test_over_30_contributing_frames(self):
739769 for i in range (41 , 61 ):
740770 num_frames += 1
741771 assert ("test = " + str (i ) + "!" ) in stacktrace_str
742- assert num_frames == 30
772+ assert num_frames == MAX_FRAME_COUNT
743773
744774 def test_too_many_frames_minified_js_frame_limit (self ):
745775 """Test that we restrict fully-minified stacktraces to 20 frames, and all other stacktraces to 30 frames."""
0 commit comments