Docs & tests

This commit is contained in:
Jack Kingsman
2026-03-07 22:58:48 -08:00
parent d776f3d09b
commit 20af50585b
7 changed files with 86 additions and 8 deletions
+15
View File
@@ -280,6 +280,21 @@ class TestPacketFormatConversion:
assert "path" in result
assert result["path"] == ""
def test_direct_multibyte_route_formats_path_as_hop_identifiers(self):
# route=2 (DIRECT), payload_type=2, path_byte=0x82 -> 2 hops x 3 bytes
data = {"timestamp": 0, "data": "0A82AABBCCDDEEFF11", "snr": 1.0, "rssi": -70}
result = _format_raw_packet(data, "Node", "AA" * 32)
assert result["route"] == "D"
assert result["payload_len"] == "1"
assert result["path"] == "aabbcc,ddeeff"
def test_flood_multibyte_route_omits_path_field(self):
# route=1 (FLOOD), payload_type=2, path_byte=0x82 -> 2 hops x 3 bytes
data = {"timestamp": 0, "data": "0982AABBCCDDEEFF11", "snr": 1.0, "rssi": -70}
result = _format_raw_packet(data, "Node", "AA" * 32)
assert result["route"] == "F"
assert "path" not in result
def test_unknown_version_uses_defaults(self):
# version=1 in high bits, type=5, route=1
header = (1 << 6) | (5 << 2) | 1
+34 -2
View File
@@ -57,6 +57,9 @@ async def _insert_contact(
contact_type=0,
last_contacted=None,
last_advert=None,
last_path=None,
last_path_len=-1,
out_path_hash_mode=0,
):
"""Insert a contact into the test database."""
await ContactRepository.upsert(
@@ -65,8 +68,9 @@ async def _insert_contact(
"name": name,
"type": contact_type,
"flags": 0,
"last_path": None,
"last_path_len": -1,
"last_path": last_path,
"last_path_len": last_path_len,
"out_path_hash_mode": out_path_hash_mode,
"last_advert": last_advert,
"lat": None,
"lon": None,
@@ -345,6 +349,34 @@ class TestSyncRecentContactsToRadio:
assert result["loaded"] == 0
assert result["failed"] == 1
@pytest.mark.asyncio
async def test_add_contact_preserves_explicit_multibyte_hash_mode(self, test_db):
"""Radio offload uses the stored hash mode rather than inferring from path bytes."""
await _insert_contact(
KEY_A,
"Alice",
last_contacted=2000,
last_path="aa00bb00",
last_path_len=2,
out_path_hash_mode=1,
)
mock_mc = MagicMock()
mock_mc.get_contact_by_key_prefix = MagicMock(return_value=None)
mock_result = MagicMock()
mock_result.type = EventType.OK
mock_mc.commands.add_contact = AsyncMock(return_value=mock_result)
radio_manager._meshcore = mock_mc
result = await sync_recent_contacts_to_radio()
assert result["loaded"] == 1
payload = mock_mc.commands.add_contact.call_args.args[0]
assert payload["public_key"] == KEY_A
assert payload["out_path"] == "aa00bb00"
assert payload["out_path_len"] == 2
assert payload["out_path_hash_mode"] == 1
@pytest.mark.asyncio
async def test_mc_param_bypasses_lock_acquisition(self, test_db):
"""When mc is passed, the function uses it directly without acquiring radio_operation.