Test that a companion's traced route goes on the companion

A walk to a companion turns at the repeater that hears it, but the route
that it proves is the route to the companion: every relay, with the one
at the turn. Use writes it on the companion's contact, never on the
repeater's, and never as the shorter route to the repeater.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5.5 committed 2026-11-08 03:49:17 -05:00
1 parent d3166170ff
commit 1f20013d49
1 file changed
+22
+22
View File
@@ -96,10 +96,12 @@ class _Routes:
def __init__(self, found: DiscoveredRoute | None = None) -> None:
self.calls: list[tuple[str, tuple]] = []
self.contacts: list[str] = [] # the contact of each set, in order
self.found = found
async def set(self, contact: Contact, hops: tuple) -> tuple:
self.calls.append(("set", tuple(hops)))
self.contacts.append(contact.name)
return tuple(hops)
async def keep(self, contact: Contact, hops: tuple) -> RouteOwner:
@@ -136,6 +138,26 @@ async def test_a_picked_route_replaces_a_kept_route() -> None:
assert routes.calls == [("keep", (HUB, "27d4")), ("set", ())]
async def test_a_companions_traced_route_is_set_on_the_companion() -> None:
"""A walk to Alice turns at her last repeater, but the route that it proves is Alice's.
Alice is a companion, so the walk ``27d4 → Hilltop → 27d4`` turned at Hilltop, the
repeater that hears her. The route that came home is the route *to Alice*: both
relays, with Hilltop. Use writes it on Alice's contact. It is not the route to Hilltop
(``27d4`` alone), and it never goes on Hilltop's contact.
"""
from meshterm.services.trace_plan import previous_outbound
from tests.test_live_screens import _walk
route = previous_outbound(_walk("27d4", "3d63", "27d4"), ALICE_KEY, relays=False)
assert route == ("27d4", "3d63")
routes = _Routes()
ctx, _ = _ctx(routes)
assert await _apply(ctx, _env(), RouteStatus(None, ORIGIN_FLOOD), route)
assert routes.calls == [("set", ("27d4", "3d63"))]
assert routes.contacts == ["Alice"]
async def test_discover_shows_both_routes_and_uses_the_route_out() -> None:
"""One discovery, a dialog with the route each way, and Use sets the route out."""
routes = _Routes(DiscoveredRoute(out_hops=("3d",), in_hops=("27", "3d")))