Packet viewer: a walked trace is not a direct shot

Emptying a trace's relay path — right, since those bytes were readings all
along — left the card contradicting itself: three legs on the links row,
"direct — no relays" two lines under it, and a note crediting the reading
to a sender nothing had relayed for.

An empty chain means different things by class. For every other frame it
means the sender was heard straight off the air. For a trace it means the
relays went unrecorded, which is not the same claim at all — the readings
are proof something forwarded it. So the row says how far the packet got,
which is the one thing those readings do establish, and the reception note
goes back to naming the last relay.
This commit is contained in:
Jean-Pierre Martineau committed 2026-08-22 14:27:15 -04:00
1 parent bfd396da69
commit 1b6a5cc1e7
2 files changed
+58 -2

No files matched your search

+22 -2
View File
@@ -731,15 +731,31 @@ class PacketViewer(Screen):
mid-chip — and hanging its continuations under the value block. The dialog has
the rows to spend, so a long chain reads whole here, unlike the feed row behind
it, which has to elide its middle to stay on one line.
A trace with no hops is the one case where an empty chain does not mean a direct
shot. A trace names its relays nowhere — it records a *reading* per hop instead
(see :func:`~meshterm.core.frames.trace_link_snrs`) — so a walked trace arrives
with an empty path and a full set of readings, and "direct — no relays" would be
a flat contradiction of the ``links`` row two lines above. It says how far the
packet got instead, which is the one thing those readings do establish.
"""
return path_line(
(entry.path or "").split(","),
self._resolve,
prefix_bytes=self._prefix_bytes,
self_name=self._self_name,
empty="direct — no relays",
empty=self._empty_via(entry),
)
@staticmethod
def _empty_via(entry: PacketEntry) -> str:
"""What an empty relay chain means for this frame's class."""
readings = (entry.raw or {}).get("trace_snrs") if isinstance(entry.raw, dict) else None
if readings:
hops = len(readings)
return f"{hops} hop{'' if hops == 1 else 's'} walked — a trace logs each leg, not its relays"
return "direct — no relays"
def _packet_rows(self, entry: PacketEntry) -> list[tuple[str, RenderableType]]:
"""A raw ``packet`` entry's addressing, parsed class/route, relay path, and — for a
channel frame naming a channel we hold the key for — its channel and plaintext.
@@ -756,7 +772,11 @@ class PacketViewer(Screen):
# last repeater, and saying so stops the figure being read as the origin's signal;
# on one that crossed nothing it *is* the origin's, which is worth saying outright
# — a frame heard straight off its sender is the best evidence a link ever gives.
relayed = bool([hop for hop in (entry.path or "").split(",") if hop])
# A trace that walked counts as relayed even with no hops to name: its readings
# are the proof something forwarded it (see :meth:`_via_path`).
relayed = bool(
[hop for hop in (entry.path or "").split(",") if hop] or raw.get("trace_snrs")
)
rows.append((
"", Text(
"reception describes the last relay, not the origin" if relayed
+36
View File
@@ -414,3 +414,39 @@ def test_packet_viewer_says_whose_signal_the_reading_is() -> None:
assert "last relay, not the origin" in note("a1b2c3,d4e5f6")
assert "the sender itself" in note("")
assert "last relay" not in note("")
def test_packet_viewer_does_not_call_a_walked_trace_direct() -> None:
"""A trace names no relays, so an empty chain there means "unrecorded", not "none".
Its readings prove three nodes forwarded it; saying "direct — no relays" two lines
under a links row listing three legs would contradict the card's own evidence.
"""
entry = PacketEntry(
when=utcnow(), kind="packet", path="", snr=13.75,
raw={"payload_typename": "TRACE", "trace_snrs": [13.25, -5.0, -4.25]},
)
body = _plain(_viewer(entry).render_body(80))
assert "3 hops walked" in body
assert "direct — no relays" not in body
assert "last relay, not the origin" in body # something *did* relay it
def test_packet_viewer_still_calls_an_unwalked_frame_direct() -> None:
"""Nothing forwarded it and nothing measured it — that really is a direct shot."""
for raw in ({"payload_typename": "TRACE", "trace_snrs": []},
{"payload_typename": "TEXT_MSG"}):
body = _plain(_viewer(
PacketEntry(when=utcnow(), kind="packet", path="", snr=9.0, raw=raw)
).render_body(80))
assert "direct — no relays" in body, raw
assert "the sender itself" in body, raw
def test_packet_viewer_counts_one_walked_hop_in_the_singular() -> None:
"""One leg is "1 hop walked", not "1 hops walked"."""
entry = PacketEntry(
when=utcnow(), kind="packet", path="", snr=13.75,
raw={"payload_typename": "TRACE", "trace_snrs": [13.25]},
)
assert "1 hop walked" in _plain(_viewer(entry).render_body(80))