mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-10-23 14:22:22 +00:00
fix(web_viewer): store packet hash on captured channel messages
Decoded packet_stream rows had no way back to the original packet, so alternate routes could not be joined. The hash is already on routing_info; keep it in the existing JSON blob.
This commit is contained in:
1 parent
1e7951b3a5
commit
c5cdd63d7e
2 files changed
+42
No files matched your search
@@ -594,6 +594,12 @@ class BotIntegration:
|
||||
'path': getattr(message, 'path', ''),
|
||||
'is_dm': bool(getattr(message, 'is_dm', False)),
|
||||
}
|
||||
routing_info = getattr(message, 'routing_info', None) or {}
|
||||
if not isinstance(routing_info, dict):
|
||||
routing_info = {}
|
||||
packet_hash = routing_info.get('packet_hash')
|
||||
if packet_hash and str(packet_hash).strip('0'):
|
||||
data['packet_hash'] = packet_hash
|
||||
self._insert_packet_stream_row(json.dumps(data), 'message', "channel message")
|
||||
except Exception as e:
|
||||
self.bot.logger.debug(f"Error storing channel message for web viewer: {e}")
|
||||
|
||||
@@ -364,10 +364,46 @@ class TestCaptureChannelMessage:
|
||||
msg.hops = 0
|
||||
msg.path = ""
|
||||
msg.is_dm = True
|
||||
msg.routing_info = None
|
||||
bi.capture_channel_message(msg)
|
||||
ts, data, _, *_dims = bi._write_queue.get_nowait()
|
||||
parsed = json.loads(data)
|
||||
assert parsed["is_dm"] is True
|
||||
assert "packet_hash" not in parsed
|
||||
|
||||
def test_stores_packet_hash_from_routing_info(self):
|
||||
"""#270: message rows carry packet_hash so routes can link back to the packet."""
|
||||
bi = _make_bot_integration()
|
||||
msg = MeshMessage(
|
||||
content="hello",
|
||||
sender_id="aa",
|
||||
channel="general",
|
||||
hops=1,
|
||||
is_dm=False,
|
||||
routing_info={"packet_hash": "ABCDEF0123456789", "path_length": 1},
|
||||
)
|
||||
bi.capture_channel_message(msg)
|
||||
_, data, row_type, *_dims = bi._write_queue.get_nowait()
|
||||
assert row_type == "message"
|
||||
parsed = json.loads(data)
|
||||
assert parsed["packet_hash"] == "ABCDEF0123456789"
|
||||
|
||||
def test_omits_missing_or_all_zero_packet_hash(self):
|
||||
"""#270: do not invent a hash when routing_info lacks a real one."""
|
||||
bi = _make_bot_integration()
|
||||
for routing_info in (None, {}, {"packet_hash": ""}, {"packet_hash": "0000000000000000"}):
|
||||
msg = MeshMessage(
|
||||
content="hello",
|
||||
sender_id="aa",
|
||||
channel="general",
|
||||
hops=0,
|
||||
is_dm=False,
|
||||
routing_info=routing_info,
|
||||
)
|
||||
bi.capture_channel_message(msg)
|
||||
_, data, _, *_dims = bi._write_queue.get_nowait()
|
||||
parsed = json.loads(data)
|
||||
assert "packet_hash" not in parsed, routing_info
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user