MCPcopy Create free account
hub / github.com/NVIDIA/NeMo-Relay / assert_round_trip

Function assert_round_trip

python/tests/test_integration_codecs.py:189–205  ·  view source on GitHub ↗

Verify that decode(encode(x)) preserves all fields in the original payload. Messages are compared semantically (key order and None values are normalized). All other keys are compared by exact equality.

(codec, payload)

Source from the content-addressed store, hash-verified

187
188
189def assert_round_trip(codec, payload):
190 """Verify that decode(encode(x)) preserves all fields in the original payload.
191
192 Messages are compared semantically (key order and None values are normalized).
193 All other keys are compared by exact equality.
194 """
195 original = LLMRequest({}, cast(JsonObject, payload))
196 annotated = codec.decode(original)
197 result = codec.encode(annotated, original)
198 for k, v in payload.items():
199 if k == "messages":
200 # Semantic comparison: normalize both sides
201 orig_msgs = [_normalize_message(m) for m in v]
202 result_msgs = [_normalize_message(m) for m in result.content[k]]
203 assert result_msgs == orig_msgs, f"Messages differ:\n orig: {orig_msgs}\n got: {result_msgs}"
204 else:
205 assert result.content[k] == v, f"Key {k!r} changed: {v!r} -> {result.content.get(k)!r}"
206
207
208# ---------------------------------------------------------------------------

Calls 5

LLMRequestStruct · 0.90
_normalize_messageFunction · 0.85
getMethod · 0.80
decodeMethod · 0.65
encodeMethod · 0.65

Tested by

no test coverage detected