Some checks failed
CI / test-backend (push) Successful in 32s
CI / lint (push) Failing after 2m12s
CI / build-frontend (pull_request) Successful in 1m38s
Build and Publish Docker Image / build (pull_request) Has been skipped
CI / test-backend (pull_request) Successful in 24s
OSV-Scanner PR Scan / scan-pr (pull_request) Successful in 53s
CI / test-lang (pull_request) Successful in 1m15s
CI / lint (pull_request) Failing after 5m8s
CI / build-frontend (push) Successful in 9m46s
CI / test-lang (push) Successful in 9m48s
Tests / test (push) Successful in 13m32s
Tests / test (pull_request) Successful in 11m23s
Build Test / Build and Test (push) Successful in 15m56s
Build and Publish Docker Image / build-dev (pull_request) Successful in 13m42s
Build Test / Build and Test (pull_request) Successful in 16m9s
- Introduced new test files for telemetry functionality, including integration, fuzzing, and extended tests to ensure robustness and performance. - Added tests for parsing LXMF display names and telemetry data, addressing potential bugs and ensuring correct handling of various input formats. - Implemented performance tests for the InterfacesPage component, validating rendering efficiency with a large number of discovered interfaces. - Enhanced existing tests for markdown rendering and link utilities to cover additional edge cases and improve stability.
97 lines
3.3 KiB
Python
97 lines
3.3 KiB
Python
import base64
|
|
from unittest.mock import MagicMock, patch
|
|
import LXMF
|
|
from meshchatx.src.backend.meshchat_utils import parse_lxmf_display_name
|
|
from meshchatx.src.backend.telemetry_utils import Telemeter
|
|
import RNS.vendor.umsgpack as msgpack
|
|
|
|
|
|
def test_parse_lxmf_display_name_bug_fix():
|
|
"""
|
|
Test that parse_lxmf_display_name handles both bytes and strings
|
|
in the msgpack list, fixing the 'str' object has no attribute 'decode' bug.
|
|
"""
|
|
# 1. Test with bytes (normal case)
|
|
display_name_bytes = b"Test User"
|
|
app_data_list = [display_name_bytes, None, None]
|
|
app_data_bytes = msgpack.packb(app_data_list)
|
|
app_data_base64 = base64.b64encode(app_data_bytes).decode()
|
|
|
|
assert parse_lxmf_display_name(app_data_base64) == "Test User"
|
|
|
|
# 2. Test with string (the bug case where msgpack already decoded it)
|
|
# We simulate this by mocking msgpack.unpackb to return strings
|
|
display_name_str = "Test User Str"
|
|
app_data_list_str = [display_name_str, None, None]
|
|
|
|
with patch("RNS.vendor.umsgpack.unpackb", return_value=app_data_list_str):
|
|
# The input app_data_base64 doesn't really matter much here since we mock unpackb,
|
|
# but it must be valid base64 for the initial decode.
|
|
assert parse_lxmf_display_name(app_data_base64) == "Test User Str"
|
|
|
|
# 3. Test with bytes directly passed (as in meshchat.py updated call)
|
|
assert parse_lxmf_display_name(app_data_bytes) == "Test User"
|
|
|
|
|
|
def test_lxmf_telemetry_decoding():
|
|
"""
|
|
Test decoding of LXMF telemetry fields.
|
|
"""
|
|
# Create some dummy telemetry data
|
|
ts = 1736264575
|
|
lat, lon = 52.5200, 13.4050
|
|
|
|
# Use Telemeter.pack to create valid telemetry bytes
|
|
location = {
|
|
"latitude": lat,
|
|
"longitude": lon,
|
|
"altitude": 100,
|
|
"speed": 10,
|
|
"bearing": 90,
|
|
"accuracy": 5,
|
|
"last_update": ts,
|
|
}
|
|
|
|
packed_telemetry = Telemeter.pack(time_utc=ts, location=location)
|
|
|
|
# Decode it back
|
|
unpacked = Telemeter.from_packed(packed_telemetry)
|
|
|
|
assert unpacked is not None
|
|
assert unpacked["time"]["utc"] == ts
|
|
assert unpacked["location"]["latitude"] == lat
|
|
assert unpacked["location"]["longitude"] == lon
|
|
assert unpacked["location"]["altitude"] == 100.0
|
|
assert unpacked["location"]["speed"] == 10.0
|
|
assert unpacked["location"]["bearing"] == 90.0
|
|
assert unpacked["location"]["accuracy"] == 5.0
|
|
|
|
|
|
def test_lxmf_telemetry_mapping_in_app():
|
|
"""
|
|
Test how the app handles telemetry fields from an LXMF message.
|
|
"""
|
|
# Mock lxmf_message
|
|
lxmf_message = MagicMock(spec=LXMF.LXMessage)
|
|
source_hash = b"\x01" * 32
|
|
lxmf_message.source_hash = source_hash
|
|
lxmf_message.hash = b"\x02" * 32
|
|
|
|
ts = 1736264575
|
|
packed_telemetry = Telemeter.pack(
|
|
time_utc=ts, location={"latitude": 1.23, "longitude": 4.56}
|
|
)
|
|
|
|
lxmf_message.get_fields.return_value = {LXMF.FIELD_TELEMETRY: packed_telemetry}
|
|
|
|
# Test unpacking directly using the same logic as in meshchat.py
|
|
fields = lxmf_message.get_fields()
|
|
assert LXMF.FIELD_TELEMETRY in fields
|
|
|
|
telemetry_data = fields[LXMF.FIELD_TELEMETRY]
|
|
unpacked = Telemeter.from_packed(telemetry_data)
|
|
|
|
assert unpacked["time"]["utc"] == ts
|
|
assert unpacked["location"]["latitude"] == 1.23
|
|
assert unpacked["location"]["longitude"] == 4.56
|