@@ -686,19 +686,6 @@ def test_empty_file_returns_skeleton(self):
686686 finally :
687687 os .unlink (path )
688688
689- def test_unknown_entry_type_silently_ignored (self ):
690- path = _write_jsonl (
691- [
692- {"type" : "custom" , "timestamp" : "2026-01-01T00:00:00Z" },
693- ]
694- )
695- try :
696- s = parse_session (path )
697- assert s ["messages" ] == []
698- assert s ["metadata" ]["entry_counts" ].get ("custom" ) == 1
699- finally :
700- os .unlink (path )
701-
702689 def test_is_sidechain_increments_counter (self ):
703690 path = _write_jsonl (
704691 [
@@ -729,6 +716,26 @@ def test_file_history_snapshot_timestamp(self):
729716 s = parse_session (path )
730717 assert s ["metadata" ]["first_timestamp" ] == "2026-01-02T12:00:00Z"
731718 assert s ["metadata" ]["last_timestamp" ] == "2026-01-02T12:00:00Z"
719+ assert len (s ["messages" ]) == 0
720+ finally :
721+ os .unlink (path )
722+
723+ def test_summary_entry_type_produces_no_message (self , caplog ):
724+ path = _write_jsonl (
725+ [
726+ {
727+ "type" : "summary" ,
728+ "timestamp" : "2026-01-03T08:00:00Z" ,
729+ "summary" : "Session recap metadata" ,
730+ },
731+ ]
732+ )
733+ try :
734+ with caplog .at_level ("WARNING" , logger = "utils.jsonl_parser" ):
735+ s = parse_session (path )
736+ assert len (s ["messages" ]) == 0
737+ assert s ["metadata" ]["entry_counts" ].get ("summary" ) == 1
738+ assert "Unknown message role" not in caplog .text
732739 finally :
733740 os .unlink (path )
734741
@@ -981,3 +988,82 @@ def test_tool_use_result_string_returns_none(self):
981988 ]
982989 )
983990 assert s ["messages" ][0 ]["tool_result_parsed" ] is None
991+
992+
993+ # ---------------------------------------------------------------------------
994+ # Unknown role coercion
995+ # ---------------------------------------------------------------------------
996+
997+
998+ class TestUnknownRoleCoercion :
999+ def test_unknown_entry_type_maps_to_system_with_warning (self , caplog ):
1000+ path = _write_jsonl (
1001+ [
1002+ {
1003+ "type" : "mystery_future_type" ,
1004+ "timestamp" : "2026-01-01T00:00:00Z" ,
1005+ "content" : "forward-compat payload" ,
1006+ }
1007+ ]
1008+ )
1009+ try :
1010+ with caplog .at_level ("WARNING" , logger = "utils.jsonl_parser" ):
1011+ s = parse_session (path )
1012+ assert len (s ["messages" ]) == 1
1013+ assert s ["messages" ][0 ]["role" ] == "system"
1014+ assert s ["messages" ][0 ]["text" ] == "forward-compat payload"
1015+ assert s ["messages" ][0 ]["content" ] == "forward-compat payload"
1016+ assert "Unknown message role" in caplog .text
1017+ assert "mystery_future_type" in caplog .text
1018+ finally :
1019+ os .unlink (path )
1020+
1021+ def test_fallback_message_extracts_text_from_structured_content (self ):
1022+ path = _write_jsonl (
1023+ [
1024+ {
1025+ "type" : "result" ,
1026+ "timestamp" : "2026-01-01T00:00:00Z" ,
1027+ "content" : [{"type" : "text" , "text" : "block body" }],
1028+ }
1029+ ]
1030+ )
1031+ try :
1032+ s = parse_session (path )
1033+ assert s ["messages" ][0 ]["text" ] == "block body"
1034+ assert s ["messages" ][0 ]["content" ] == "block body"
1035+ finally :
1036+ os .unlink (path )
1037+
1038+ def test_valid_unhandled_result_type_emits_result_role (self ):
1039+ path = _write_jsonl (
1040+ [
1041+ {
1042+ "type" : "result" ,
1043+ "timestamp" : "2026-01-01T00:00:00Z" ,
1044+ "content" : "task outcome" ,
1045+ }
1046+ ]
1047+ )
1048+ try :
1049+ s = parse_session (path )
1050+ assert len (s ["messages" ]) == 1
1051+ assert s ["messages" ][0 ]["role" ] == "result"
1052+ finally :
1053+ os .unlink (path )
1054+
1055+
1056+ class TestCoerceRole :
1057+ def test_known_roles_returned_unchanged (self ):
1058+ from utils .jsonl_parser import _coerce_role
1059+
1060+ for role in ("user" , "assistant" , "system" , "result" , "progress" ):
1061+ assert _coerce_role (role ) == role
1062+
1063+ def test_unknown_role_maps_to_system_with_warning (self , caplog ):
1064+ from utils .jsonl_parser import _coerce_role
1065+
1066+ with caplog .at_level ("WARNING" , logger = "utils.jsonl_parser" ):
1067+ result = _coerce_role ("totally_unknown" )
1068+ assert result == "system"
1069+ assert "totally_unknown" in caplog .text
0 commit comments