@@ -915,3 +915,39 @@ def test_forward_only_config_falls_back_to_plan_config(
915915
916916 controller ._context .config .plan .forward_only = False
917917 assert controller .forward_only_plan is False
918+
919+
920+ def test_chunk_up_api_message_preserves_ascii_behavior (
921+ github_client , make_event_issue_comment , make_controller
922+ ):
923+ controller = make_controller (make_event_issue_comment ("created" , "test" ), github_client )
924+
925+ max_bytes = controller .MAX_BYTE_LENGTH
926+ message = ("a" * max_bytes ) + ("b" * max_bytes ) + "c"
927+
928+ assert controller ._chunk_up_api_message ("" ) == []
929+ assert controller ._chunk_up_api_message (message ) == [
930+ "a" * max_bytes ,
931+ "b" * max_bytes ,
932+ "c" ,
933+ ]
934+
935+
936+ @pytest .mark .parametrize ("multibyte_char" , ["🙂" , "界" ])
937+ def test_chunk_up_api_message_preserves_multibyte_chars (
938+ github_client , make_event_issue_comment , make_controller , multibyte_char
939+ ):
940+ controller = make_controller (make_event_issue_comment ("created" , "test" ), github_client )
941+
942+ max_bytes = controller .MAX_BYTE_LENGTH
943+ # Place a multibyte character exactly on the byte boundary between two chunks so
944+ # that byte-oriented slicing would bisect its UTF-8 encoding and drop it.
945+ message = ("a" * (max_bytes - 1 )) + multibyte_char + "b"
946+ assert len (message .encode ("utf-8" )) > max_bytes
947+
948+ chunks = controller ._chunk_up_api_message (message )
949+
950+ # No character is lost, so the chunks reassemble into the original message.
951+ assert "" .join (chunks ) == message
952+ # Each chunk still respects the GitHub API byte limit.
953+ assert all (len (chunk .encode ("utf-8" )) <= max_bytes for chunk in chunks )
0 commit comments