Skip to content

Commit e6c7ee2

Browse files
committed
test: keep map header intact in first simulator part
Split only the encrypted map body across map_parts and prepend the 24-byte header to the first part so high part counts cannot split the endpoint header.
1 parent 8099f97 commit e6c7ee2

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

‎roborock/testing/v1_simulator.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,18 +427,19 @@ def _map_response_messages(self, request_id: int, map_bytes: bytes) -> list[Robo
427427
raise ValueError("map_parts must be at least 1")
428428
body = Utils.encrypt_cbc(gzip.compress(map_bytes), self.security_data.nonce)
429429
header = struct.pack("<8s8sH6s", self.security_data.endpoint.encode(), bytes(8), request_id & 0xFFFF, bytes(6))
430-
payload = header + body
431430
if self.map_parts == 1:
432431
if self.map_part_order is not None and list(self.map_part_order) != [0]:
433432
raise ValueError("map_part_order must be a permutation of range(map_parts)")
434-
return [RoborockMessage(protocol=RoborockMessageProtocol.MAP_RESPONSE, payload=payload)]
435-
if self.map_parts > len(payload):
436-
raise ValueError("map_parts cannot exceed encrypted map payload length")
433+
return [RoborockMessage(protocol=RoborockMessageProtocol.MAP_RESPONSE, payload=header + body)]
434+
if self.map_parts > len(body):
435+
raise ValueError("map_parts cannot exceed encrypted map body length")
437436

438-
# Split evenly into map_parts non-empty contiguous slices.
439-
total = len(payload)
437+
# Keep the 24-byte header intact on the first part and split the encrypted
438+
# body evenly into map_parts non-empty contiguous slices.
439+
total = len(body)
440440
boundaries = [(i * total) // self.map_parts for i in range(self.map_parts + 1)]
441-
chunks = [payload[boundaries[i] : boundaries[i + 1]] for i in range(self.map_parts)]
441+
chunks = [body[boundaries[i] : boundaries[i + 1]] for i in range(self.map_parts)]
442+
chunks[0] = header + chunks[0]
442443
random_id = get_next_int(10000, 99999)
443444
timestamp = int(time.time())
444445
messages = [

‎tests/testing/test_v1_simulator.py‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from roborock.devices.traits.v1.consumeable import ConsumableAttribute
1414
from roborock.exceptions import RoborockException
1515
from roborock.map.map_parser import MapParser, MapParserConfig
16-
from roborock.roborock_message import RoborockMessageProtocol
16+
from roborock.roborock_message import RoborockMessage, RoborockMessageProtocol
1717
from roborock.testing import (
1818
DEFAULT_NETWORK_INFO,
1919
DEFAULT_STATUS,
@@ -317,18 +317,32 @@ async def test_simulator_multipart_map_framing() -> None:
317317
simulator.map_parts = 3
318318
simulator.map_part_order = [2, 0, 1]
319319

320-
emitted: list[tuple[RoborockMessageProtocol, int]] = []
321-
unsub = await simulator.mqtt_channel.subscribe(lambda msg: emitted.append((msg.protocol, msg.seq)))
320+
emitted: list[RoborockMessage] = []
321+
unsub = await simulator.mqtt_channel.subscribe(emitted.append)
322322
try:
323323
raw = await simulator.v1_channel.map_rpc_channel.send_command("get_map_v1")
324324
finally:
325325
unsub()
326326

327-
assert emitted == [
327+
assert [(msg.protocol, msg.seq) for msg in emitted] == [
328328
(RoborockMessageProtocol.MAP_RESPONSE, 3),
329329
(RoborockMessageProtocol.MAP_RESPONSE_PART, 1),
330330
(RoborockMessageProtocol.MAP_RESPONSE_PART, 2),
331331
]
332+
first_part = next(msg for msg in emitted if msg.seq == 1)
333+
assert first_part.payload is not None
334+
assert first_part.payload.startswith(simulator.security_data.endpoint.encode())
335+
assert len(first_part.payload) > 24
336+
assert raw == simulator.build_map_bytes()
337+
338+
339+
async def test_simulator_multipart_preserves_header_at_high_part_count() -> None:
340+
"""High part counts keep the complete 24-byte header on the first part."""
341+
simulator = V1VacuumSimulator(duid="s7_many_parts")
342+
simulator.connect()
343+
simulator.map_parts = 20
344+
345+
raw = await simulator.v1_channel.map_rpc_channel.send_command("get_map_v1")
332346
assert raw == simulator.build_map_bytes()
333347

334348

0 commit comments

Comments
 (0)