Auto traces walk proven routes: the device almost never has one
An auto (device-routed) Trace target went on the air as a bare destination hash — an observer confirmed no repeater hops — so any target past a direct neighbour could never answer. Dumping the radio's contact table showed why: every contact reports out_path_len -1 (flood). MeshCore firmware only learns a contact's out_path from two-way addressed traffic, and tracing repeaters teaches it nothing, so "device-routed" has nothing to route with. Auto now resolves a route the session can prove, in order: the device's learned route when one genuinely exists, else the outbound leg of the last successful stored walk (_previous_outbound extracts it from the recorded boomerang), else a bare direct attempt. One resolver feeds both the wire and the screen, so the planned route line renders exactly what Trace will transmit, with its provenance under it — (auto · device route), (auto · last trace · stamp), or (auto · direct — no known route) — and the summary's path row says the same instead of claiming a device route that never existed. The connection layer's path-less fallback keeps the mirrored return leg for contacts that do carry a learned route (the trace protocol reflects nothing home), and its docstring now says the firmware never routes a trace itself. Resolution verified against the real database and radio: a multi-hop target resolves to its full stored boomerang, the direct gateway stays a single-hop spec. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
944634939f
commit
c819fdfd2f
4 files changed
+235
-37
No files matched your search
@@ -68,12 +68,57 @@ def test_snr_bar_clamps_out_of_range_readings() -> None:
|
||||
assert snr_bar(-99.0).plain.count("▆") == 1 # a heard hop always shows something
|
||||
|
||||
|
||||
# --- _previous_outbound -----------------------------------------------------------
|
||||
|
||||
|
||||
def _walk(*nodes: str, success: bool = True) -> TraceResult:
|
||||
"""A stored walk whose hop hashes are ``nodes`` (plus the final hash-less us)."""
|
||||
hops = [Hop(index=i, node=n, snr=1.0) for i, n in enumerate(nodes)]
|
||||
hops.append(Hop(index=len(nodes), node=None, snr=1.0))
|
||||
return TraceResult(
|
||||
target="Alice", success=success, hops=hops, round_trip_ms=200.0, path_hash_bytes=2
|
||||
)
|
||||
|
||||
|
||||
def test_previous_outbound_extracts_the_proven_route() -> None:
|
||||
"""The last successful boomerang's first half is the reusable outbound leg.
|
||||
|
||||
Verified on hardware that the device itself almost never has a learned route
|
||||
(contacts report flood), so this stored evidence is what auto mode actually
|
||||
walks for a multi-hop target.
|
||||
"""
|
||||
from meshterm.ui.trace_screen import _previous_outbound
|
||||
|
||||
walk = _walk("3d63", "f2c2", "aabb", "f2c2", "3d63")
|
||||
assert _previous_outbound(walk, "aabb" + "00" * 30) == ("3d63", "f2c2")
|
||||
|
||||
|
||||
def test_previous_outbound_direct_walk_yields_no_repeaters() -> None:
|
||||
"""A direct answer (target only) extracts an empty outbound leg — dest-only again."""
|
||||
from meshterm.ui.trace_screen import _previous_outbound
|
||||
|
||||
assert _previous_outbound(_walk("aabb"), "aabb" + "00" * 30) == ()
|
||||
|
||||
|
||||
def test_previous_outbound_rejects_unusable_history() -> None:
|
||||
"""Failures, asymmetric walks, and walks that turned elsewhere are never reused."""
|
||||
from meshterm.ui.trace_screen import _previous_outbound
|
||||
|
||||
target = "aabb" + "00" * 30
|
||||
assert _previous_outbound(None, target) is None
|
||||
assert _previous_outbound(_walk("3d63", "aabb", "3d63", success=False), target) is None
|
||||
# Asymmetric: came home a different way — not a boomerang to this target.
|
||||
assert _previous_outbound(_walk("3d63", "aabb", "f2c2"), target) is None
|
||||
# Palindromic, but it turned at some other node, not our target.
|
||||
assert _previous_outbound(_walk("3d63", "9999", "3d63"), target) is None
|
||||
|
||||
|
||||
# --- TraceScreen ----------------------------------------------------------------
|
||||
|
||||
|
||||
def _trace_screen(
|
||||
trace=None, compose_path=None, explore=None, pick_width=None, pick_samples=None,
|
||||
previous=None, mode="target", samples=1,
|
||||
previous=None, mode="target", samples=1, auto_spec=None, auto_source="",
|
||||
) -> tuple[TraceScreen, _FakeSession]:
|
||||
session = _FakeSession()
|
||||
|
||||
@@ -99,6 +144,8 @@ def _trace_screen(
|
||||
sample_count=lambda: samples,
|
||||
pace_s=0.0, # tests never sleep; pacing is asserted through the statuses
|
||||
previous=previous,
|
||||
auto_spec=auto_spec or (lambda: ""),
|
||||
auto_source=auto_source,
|
||||
)
|
||||
return screen, session
|
||||
|
||||
@@ -359,6 +406,40 @@ def test_summary_appends_the_displayed_hop_count() -> None:
|
||||
assert "· 2 hops" in _plain(screen.render_body(100))
|
||||
|
||||
|
||||
def test_auto_resolved_route_renders_with_its_provenance() -> None:
|
||||
"""With no composed path, the auto route shows as the plan, labelled with its source.
|
||||
|
||||
What the screen draws is exactly what Trace will put on the air (both read the
|
||||
same resolver), so the user can see the forced boomerang — and where it came
|
||||
from — before committing a transmission.
|
||||
"""
|
||||
screen, _ = _trace_screen(
|
||||
auto_spec=lambda: "3d63,f2c2,aabb,f2c2,3d63", auto_source="last trace · Jul 09 14:32"
|
||||
)
|
||||
plan = screen._planned_route().plain
|
||||
assert "Us → 3d63 → f2c2 → aabb → f2c2 → 3d63 → Us" in plan
|
||||
assert "(auto · last trace · Jul 09 14:32)" in plan
|
||||
body = _plain(screen.render_body(100))
|
||||
assert "auto · last trace · Jul 09 14:32" in body # the summary's path row
|
||||
assert "· 5 hops" in body
|
||||
|
||||
|
||||
def test_composed_path_outranks_the_auto_route() -> None:
|
||||
"""A hand-composed spec replaces the auto plan everywhere — display and wire."""
|
||||
screen, _ = _trace_screen(auto_spec=lambda: "aabb", auto_source="device route")
|
||||
screen._path_spec = "3d63,aabb,3d63"
|
||||
plan = screen._planned_route().plain
|
||||
assert "Us → 3d63 → aabb → 3d63 → Us" in plan
|
||||
assert "(auto ·" not in plan
|
||||
assert screen._effective_spec() == ("3d63,aabb,3d63", False)
|
||||
|
||||
|
||||
def test_unaddressable_target_reads_as_path_less_auto() -> None:
|
||||
"""With nothing to force (no target hash), the summary says so instead of lying."""
|
||||
screen, _ = _trace_screen() # auto_spec resolves ""
|
||||
assert "auto — path-less (unknown target)" in _plain(screen.render_body(100))
|
||||
|
||||
|
||||
def test_trace_log_section_hidden_until_there_is_something_to_log() -> None:
|
||||
"""Idle with no traces, the Traces heading (and its old hint) don't render."""
|
||||
screen, _ = _trace_screen()
|
||||
|
||||
@@ -492,12 +492,14 @@ def _mc_with(contacts: dict, path_hash_mode: int = 2):
|
||||
|
||||
|
||||
async def test_three_byte_route_appends_destination_hash() -> None:
|
||||
"""A learned multi-hop route walks the repeaters then ends at the target (#1).
|
||||
"""A learned multi-hop route walks the repeaters, the target, then back (#1).
|
||||
|
||||
Two things matter for a non-power-of-two region (3-byte hashes): each 3-byte
|
||||
routing hash collapses to its leading 2 bytes (the widest representable trace
|
||||
width), and the destination's own hash is appended as the final hop — a trace
|
||||
only replies when its destination is the last hop.
|
||||
width), and the destination's own hash is appended as the final outbound hop —
|
||||
a trace only replies when its destination is the last outbound hop. The trace
|
||||
protocol has no separate return-path field, so the same repeaters are mirrored
|
||||
back afterwards — otherwise nothing relays the reply home.
|
||||
"""
|
||||
from meshterm.core.connection import MeshCoreDevice
|
||||
|
||||
@@ -518,8 +520,9 @@ async def test_three_byte_route_appends_destination_hash() -> None:
|
||||
resolved = await device._trace_path_to_contact(mc, "Repeater")
|
||||
assert resolved is not None
|
||||
path_bytes, flags = resolved
|
||||
# Two repeater hops collapsed to 2 bytes, then the target's own 2-byte hash.
|
||||
assert path_bytes == bytes.fromhex("1122" "4455" "aabb")
|
||||
# Two repeater hops collapsed to 2 bytes, the target's own 2-byte hash, then
|
||||
# the same two repeaters mirrored back to us.
|
||||
assert path_bytes == bytes.fromhex("1122" "4455" "aabb" "4455" "1122")
|
||||
assert flags == trace_runner.path_hash_flags(2) # 2-byte width
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user