"""Quick validation of the protocol module.""" import sys sys.path.insert(0, "C:\\Users\\Administrator\\Documents\\fl_control\\mcp") from protocol.sysex import nibble_encode, nibble_decode, encode_command, decode_command, SYSEX_ID # Test 1: nibble roundtrip for original in [b"Hello", b"", b"\x00\x7f", b'{"cmd":"ping"}']: encoded = nibble_encode(original) decoded = nibble_decode(encoded) assert decoded == original, f"Roundtrip failed for {original}" print("PASS: nibble roundtrip") # Test 2: encode/decode command result = encode_command("ping", {"ts": 1}) assert result[0] == 0xF0 and result[1] == 0x7D and result[-1] == 0xF7 decoded = decode_command(result) assert decoded["cmd"] == "ping" assert decoded["params"] == {"ts": 1} print("PASS: encode/decode command") # Test 3: SYSEX_ID assert SYSEX_ID == 0x7D print("PASS: SYSEX_ID == 0x7D") print("All unit tests passed!")