@@ -96,6 +96,62 @@ def test_message_version_serialization():
9696 assert reconstructed .description == version .description
9797 assert reconstructed .metadata == version .metadata
9898
99+ # RSL15b, RTL32b, TM2i
100+ def test_message_extras_preserved_in_as_dict ():
101+ """Test that extras are included when a Message with extras is serialized.
102+
103+ Regression test: _send_update() in both RestChannel and RealtimeChannel
104+ constructed a new Message without copying extras or annotations from the
105+ user-supplied message, violating RSL15b/RTL32b which require "whatever
106+ fields were in the user-supplied Message" to be sent.
107+ See commits 1723f5d (REST) and 0b93c10 (Realtime).
108+ """
109+ extras = {'headers' : {'status' : 'complete' }}
110+ message = Message (
111+ name = 'test' ,
112+ data = 'updated data' ,
113+ serial = 'abc123' ,
114+ action = MessageAction .MESSAGE_UPDATE ,
115+ extras = extras ,
116+ )
117+
118+ msg_dict = message .as_dict ()
119+ assert msg_dict ['extras' ] == extras
120+ assert msg_dict ['extras' ]['headers' ]['status' ] == 'complete'
121+
122+
123+ # RSL15b, RTL32b, TM2i
124+ def test_message_extras_none_excluded_from_as_dict ():
125+ """Test that extras=None does not appear in as_dict output."""
126+ message = Message (
127+ name = 'test' ,
128+ data = 'data' ,
129+ serial = 'abc123' ,
130+ action = MessageAction .MESSAGE_UPDATE ,
131+ )
132+
133+ msg_dict = message .as_dict ()
134+ assert 'extras' not in msg_dict
135+
136+
137+ # RSL15b, RTL32b, TM2u
138+ def test_message_annotations_preserved_in_as_dict ():
139+ """Test that annotations are included when a Message with annotations is serialized."""
140+ from ably .types .message import MessageAnnotations
141+ annotations = MessageAnnotations (summary = {'reaction:distinct.v1' : {'thumbsup' : 5 }})
142+ message = Message (
143+ name = 'test' ,
144+ data = 'data' ,
145+ serial = 'abc123' ,
146+ action = MessageAction .MESSAGE_UPDATE ,
147+ annotations = annotations ,
148+ )
149+
150+ msg_dict = message .as_dict ()
151+ assert msg_dict ['annotations' ] is not None
152+ assert msg_dict ['annotations' ]['summary' ]['reaction:distinct.v1' ] == {'thumbsup' : 5 }
153+
154+
99155def test_message_operation_serialization ():
100156 """Test MessageOperation can be serialized and deserialized"""
101157 operation = MessageOperation (
0 commit comments