test(micromate): a checksum landing on any of the four escape bytes is escaped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-10-22 17:48:04 -04:00
1 parent 137aa699c7
commit 93349ed040
1 file changed
+8 -4
+8 -4
View File
@@ -444,12 +444,16 @@ def test_a_literal_0x10_in_data_round_trips():
assert _destuffed_payload(build_request(0x71, 0x082C, bytes(10), data))[16:] == data
def test_a_checksum_that_lands_on_an_escape_byte_is_escaped():
# Pick the last data byte so SUM8 of the payload is exactly 0x03.
@pytest.mark.parametrize("target", [0x02, 0x03, 0x04, 0x10])
def test_a_checksum_that_lands_on_an_escape_byte_is_escaped(target):
# Pick the last data byte so SUM8 of the payload is exactly `target`. If that
# byte is itself an escape byte the earlier bytes shift, but the last three
# on the wire stay DLE target ETX.
head = bytes([0x10, 0x00, 0x7E, 0x00, 0x00, 0x7E]) + bytes(10) + b"\x01\x02"
last = (0x03 - sum(head)) & 0xFF
last = (target - sum(head)) & 0xFF
f = build_request(0x7E, 0x007E, bytes(10), b"\x01\x02" + bytes([last]))
assert f[-3:] == bytes([DLE, 0x03, ETX])
assert unstuff(f[2:-1])[-1] == target # the checksum byte itself
assert f[-3:] == bytes([DLE, target, ETX])
def test_without_data_the_frame_is_unchanged():