Outbound paths start the suggested routes, for each site and fixed device
The user names the ways out of their node, one or more hops long, in order. Each site of this computer (Home, Foulab) has its own list, one site is active, and a fixed device keeps its own list. - Explore > Outbound paths: the sites with the active mark, the fixed devices, and a staged editor for each list. Each path shows how well its first hop hears us (out) and how well we hear it (in). Measure sends one trace out along a path and back, after the cooldown. - The path composer has an outbound mode, and puts the active paths first while the insertion slot is at our node (trace target, trace path, the TX sweep route). - MeshTopology.outbound_scenarios: one route through each path. It scores from the link after the path, lets the user's order win a near tie, and skips a path whose first hop was silent for outbound_silent_hours. These routes lead Explore paths, the node page's Routes tab, and the trace auto route, ahead of a device route that starts on another hop. - A first link out of our node is scored from what the far end measured, when a trace gave such readings. - The site suggestion: when the radio hears the first hop of another site three times, the main menu asks to use that site and says what it heard. "Never suggest" sets the new suggest_site preference off. - CLI: meshterm outbound [show|sites|use|set|remove|fix|unfix], plain and --json. Refs: #35 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c50656c586
commit
ec64076d44
19 files changed
+2468
-55
No files matched your search
@@ -1292,6 +1292,80 @@ def _path_composer(cols: int, rows: int) -> Screen:
|
||||
)
|
||||
|
||||
|
||||
def _outbound_env(): # noqa: ANN202 - a private type of the module under test
|
||||
"""The session values of the Outbound paths pages: two nodes, and one trace through both."""
|
||||
from meshterm.persistence.repository import TracedPath
|
||||
from meshterm.services.outbound import DeviceIdentity
|
||||
from meshterm.ui.outbound_screen import _Env
|
||||
|
||||
hub = Contact(name="Hilltop-Repeater", public_key=_HUB_KEY, key_prefix="3d63c6429436")
|
||||
far = Contact(name="Alice", public_key=_FAR_KEY, key_prefix="f2c24f54551e")
|
||||
self_key = "aaaaaaaaaaaa" + "0" * 52
|
||||
walk = TracedPath(when=utcnow(), hops=[("3d", 9.5), ("f2", -4.0), ("3d", -3.5), (None, 11.0)])
|
||||
topo = build_topology(
|
||||
self_id=self_key,
|
||||
contacts=[hub, far],
|
||||
trace_paths=[walk] * 1200, # a count of four digits, the widest that the lane draws
|
||||
packet_paths=[],
|
||||
neighbour_links=[],
|
||||
)
|
||||
return _Env(DeviceIdentity(self_key, "Homestead"), [hub, far], topo, 1)
|
||||
|
||||
|
||||
def _outbound_store(): # noqa: ANN202
|
||||
"""Two sites (one with a name of the longest length) and a fixed device."""
|
||||
from meshterm.core.outbound_store import OutboundStore
|
||||
|
||||
store = OutboundStore(Path(tempfile.mkdtemp(prefix="meshterm-gallery-outbound-")) / "o.json")
|
||||
store.put_site("Home", [("3d63c6429436",), ("3d63c6429436", "f2c24f54551e", "9a9a")])
|
||||
store.put_site("A-site-named-24-chars-xx", [("f2c24f54551e",)])
|
||||
store.set_active("Home")
|
||||
store.fix_device("bb" * 32, "Rooftop-Companion-Unit", [("3d63c6429436",)])
|
||||
return store
|
||||
|
||||
|
||||
def _outbound_page(cols: int, rows: int) -> Screen:
|
||||
"""The Outbound paths page: sites, the active mark, and a fixed device."""
|
||||
from meshterm.ui.outbound_screen import _PAGE_HINT, _page
|
||||
|
||||
title, prompt, items = _page(_outbound_store(), _outbound_env())
|
||||
return SelectScreen(title, items, prompt=prompt, footer_hint=_PAGE_HINT, filterable=False)
|
||||
|
||||
|
||||
def _outbound_site(cols: int, rows: int) -> Screen:
|
||||
"""The page of the active site with staged changes: paths, evidence, actions, Apply."""
|
||||
from meshterm.ui.outbound_screen import (
|
||||
_EDIT_HINT,
|
||||
_editor_items,
|
||||
_site_actions,
|
||||
_site_summary,
|
||||
)
|
||||
|
||||
store = _outbound_store()
|
||||
paths = store.site("Home").paths
|
||||
return SelectScreen(
|
||||
"Site — Home",
|
||||
_editor_items(_outbound_env(), paths, _site_actions(store, "Home"), 2),
|
||||
prompt=_site_summary(store, "Home", paths),
|
||||
footer_hint=_EDIT_HINT,
|
||||
filterable=False,
|
||||
delete_hint="Del remove",
|
||||
)
|
||||
|
||||
|
||||
def _outbound_composer(cols: int, rows: int) -> Screen:
|
||||
"""The composer in outbound mode: an open path of two hops."""
|
||||
env = _outbound_env()
|
||||
return PathComposerScreen(
|
||||
device_label="Homestead",
|
||||
device_hash=env.identity.key,
|
||||
topology=env.topology,
|
||||
width_bytes=1,
|
||||
hops=["3d63c6429436", "f2c24f54551e"],
|
||||
outbound=True,
|
||||
)
|
||||
|
||||
|
||||
class _CourierStubDevice:
|
||||
async def get_contacts(self) -> list:
|
||||
return []
|
||||
@@ -1878,6 +1952,9 @@ _ENTRIES: list[_Entry] = [
|
||||
_Entry("message_paths_sent_scope", _message_paths_sent_scope),
|
||||
_Entry("remote_cli", _remote_cli),
|
||||
_Entry("path_composer", _path_composer),
|
||||
_Entry("outbound_composer", _outbound_composer),
|
||||
_Entry("outbound_page", _outbound_page),
|
||||
_Entry("outbound_site", _outbound_site),
|
||||
_Entry("courier_outbox", _courier_outbox),
|
||||
_Entry("record_dialog", _record_dialog),
|
||||
_Entry("record_route", _record_route),
|
||||
|
||||
+4
-3
@@ -182,8 +182,9 @@ def test_main_menu_sections_answer_the_menus_own_question() -> None:
|
||||
The menu asks "What would you like to do?". Thus the groups are by verb and not by
|
||||
subject. The address book is with the features that send messages from it. The recorded
|
||||
history is with the live views, because it is their past tense. The two walks are with
|
||||
the topology that they walk over. A setting goes in the section that says whose it is:
|
||||
this radio, the radio of another node over the mesh, or MeshTerm itself.
|
||||
the topology that they walk over. The outbound paths are with the two trace tools that
|
||||
start their routes on them. A setting goes in the section that says whose it is: this
|
||||
radio, the radio of another node over the mesh, or MeshTerm itself.
|
||||
|
||||
This app is the last of these three sections, and this is the reason that it sorts last.
|
||||
It holds the preferences that change the program, the diagnostics that state what the
|
||||
@@ -203,7 +204,7 @@ def test_main_menu_sections_answer_the_menus_own_question() -> None:
|
||||
assert sections == {
|
||||
"Message": ["chat", "channels", "rooms", "courier", "contacts"],
|
||||
"Watch": ["dashboard", "livefeed", "watchtower", "clocks", "timemachine"],
|
||||
"Explore": ["map", "walk", "trace", "trace-path", "records"],
|
||||
"Explore": ["map", "walk", "trace", "trace-path", "outbound", "records"],
|
||||
"This node": ["info", "config", "advert"],
|
||||
"Managed nodes": ["repeater-admin", "tx-optimize", "forget-admin-passwords"],
|
||||
"This app": [
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
"""Tests for the Outbound paths pages: the rows, the evidence line, and the measure walk."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from meshterm.core.models import Contact, Hop, TraceResult, utcnow
|
||||
from meshterm.core.outbound_store import OutboundStore
|
||||
from meshterm.persistence.repository import TracedPath
|
||||
from meshterm.services.outbound import DeviceIdentity, FirstLink, first_link
|
||||
from meshterm.services.topology import build_topology
|
||||
from meshterm.ui.outbound_screen import (
|
||||
_count,
|
||||
_editor_items,
|
||||
_Env,
|
||||
_evidence,
|
||||
_measured,
|
||||
_page,
|
||||
_site_actions,
|
||||
measure_walk,
|
||||
)
|
||||
from meshterm.ui.tui.select import Choice
|
||||
|
||||
US = "aaaaaaaaaaaa" + "0" * 52
|
||||
HUB = Contact(name="Hub", public_key="3d63c6429436" + "0" * 52, key_prefix="3d63c6429436")
|
||||
FAR = Contact(name="Far", public_key="f2c24f54551e" + "0" * 52, key_prefix="f2c24f54551e")
|
||||
|
||||
|
||||
def _env(walks: int = 3) -> _Env:
|
||||
"""A session with one trace walk through Hub to Far, repeated."""
|
||||
walk = TracedPath(when=utcnow(), hops=[("3d", 9.0), ("f2", -4.0), ("3d", -3.0), (None, 11.0)])
|
||||
topo = build_topology(
|
||||
self_id=US, contacts=[HUB, FAR], trace_paths=[walk] * walks, packet_paths=[]
|
||||
)
|
||||
return _Env(DeviceIdentity(US, "Me"), [HUB, FAR], topo, 1)
|
||||
|
||||
|
||||
def _plain(items: list) -> list[str]:
|
||||
"""The text of each row and separator, as the user reads it."""
|
||||
out = []
|
||||
for item in items:
|
||||
if isinstance(item, Choice):
|
||||
text = item.text(200)
|
||||
else:
|
||||
text = item.title(200) if callable(item.title) else item.title
|
||||
out.append(text if isinstance(text, str) else text.plain)
|
||||
return out
|
||||
|
||||
|
||||
def test_measure_walk_turns_at_the_last_hop() -> None:
|
||||
"""Out along the path and back the same way: each link in both directions."""
|
||||
assert measure_walk(("a1",)) == ("a1",)
|
||||
assert measure_walk(("a1", "b2", "c3")) == ("a1", "b2", "c3", "b2", "a1")
|
||||
|
||||
|
||||
def test_first_link_keeps_the_two_directions_apart() -> None:
|
||||
"""OUT is what the first hop measured from us. IN is what we measured from it."""
|
||||
link = first_link(_env().topology, ("3d63c6429436", "f2c24f54551e"))
|
||||
assert (link.out_snr, link.out_count, link.in_snr, link.in_count) == (9.0, 3, 11.0, 3)
|
||||
assert first_link(_env().topology, ("9a9a",)) == FirstLink()
|
||||
|
||||
|
||||
def test_the_evidence_line_names_both_directions_or_says_there_is_none() -> None:
|
||||
"""The line under a path reads ``out … · in … · age``, or says that nothing is known."""
|
||||
line = _evidence(FirstLink(9.0, 12, None, 0, utcnow())).plain
|
||||
assert line.strip().startswith("out +9 dB ×12 · in -")
|
||||
assert "no readings" in _evidence(FirstLink()).plain
|
||||
assert [_count(n) for n in (12, 980, 2140, 14600)] == ["12", "980", "2.1k", "14k"]
|
||||
|
||||
|
||||
def test_the_tool_page_marks_the_active_site_and_offers_to_fix_the_device(tmp_path: Path) -> None:
|
||||
"""Sites first, with ✓ on the active one, then the fixed devices and the fix row."""
|
||||
store = OutboundStore(tmp_path / "o.json")
|
||||
store.put_site("Home", [("3d63c6429436",)])
|
||||
store.put_site("Lab", [])
|
||||
store.set_active("Home")
|
||||
title, prompt, items = _page(store, _env())
|
||||
rows = _plain(items)
|
||||
assert (title, prompt) == ("Outbound paths", "Now: site Home")
|
||||
assert any(row.startswith("✓ Home") and "1 path" in row for row in rows)
|
||||
assert any("Fix Me…" in row for row in rows)
|
||||
store.fix_device(US, "Me", [])
|
||||
_, prompt, items = _page(store, _env())
|
||||
assert prompt.startswith("Now: Me's own paths")
|
||||
assert not any("Fix Me…" in row for row in _plain(items))
|
||||
|
||||
|
||||
def test_the_editor_shows_apply_only_with_staged_changes(tmp_path: Path) -> None:
|
||||
"""An editor ends on its last action until a change is staged, then on Apply over Back."""
|
||||
store = OutboundStore(tmp_path / "o.json")
|
||||
store.put_site("Home", [("3d63c6429436",)])
|
||||
clean = _plain(_editor_items(_env(), [("3d63c6429436",)], _site_actions(store, "Home"), 0))
|
||||
assert not any("Apply" in row for row in clean)
|
||||
assert any("Use this site" in row for row in clean)
|
||||
staged = _plain(_editor_items(_env(), [], _site_actions(store, "Home"), 1))
|
||||
assert any("Apply 1 staged change" in row for row in staged)
|
||||
assert any("none yet" in row for row in staged)
|
||||
|
||||
|
||||
def test_a_measure_says_who_heard_whom() -> None:
|
||||
"""Each hop of the reply is one line: the receiver, the sender, and the SNR."""
|
||||
walk = measure_walk(("3d63c6429436", "f2c24f54551e"))
|
||||
result = TraceResult(
|
||||
target="(path)",
|
||||
success=True,
|
||||
hops=[Hop(0, None, 9.0), Hop(1, None, -4.0), Hop(2, None, -3.0), Hop(3, None, 11.0)],
|
||||
round_trip_ms=1500.0,
|
||||
)
|
||||
lines = _measured(_env(), walk, result).plain.splitlines()
|
||||
assert lines == [
|
||||
"✓ the trace came back in 1.5 s",
|
||||
"Hub heard you at +9.0 dB",
|
||||
"Far heard Hub at -4.0 dB",
|
||||
"Hub heard Far at -3.0 dB",
|
||||
"you heard Hub at +11.0 dB",
|
||||
]
|
||||
failed = TraceResult(target="(path)", success=False)
|
||||
assert _measured(_env(), walk, failed).plain.startswith("✗ no reply")
|
||||
@@ -0,0 +1,97 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
"""Tests for the site suggestion: what counts as heard, and when a suggestion is due."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from meshterm.core.models import Observation
|
||||
from meshterm.core.outbound_store import Site
|
||||
from meshterm.services.site_suggest import HEARD_TO_SUGGEST, SiteSuggestion, SiteWatch, heard_hop
|
||||
|
||||
HOME = Site("Home", [("3d63c6429436",), ("27d4396a2967", "f2c24f54551e")])
|
||||
LAB = Site("Foulab", [("a100008dc55e", "b2b2")])
|
||||
|
||||
|
||||
def test_the_heard_node_is_the_last_relay_or_the_sender() -> None:
|
||||
"""A relayed packet names its last relay. A direct packet names its sender."""
|
||||
assert heard_hop(Observation(node="aa", kind="packet", path="11,22,A1")) == "a1"
|
||||
assert heard_hop(Observation(node="BB", kind="packet", path="")) == "bb"
|
||||
assert heard_hop(Observation(node="cc", kind="advert", path=None)) is None
|
||||
assert heard_hop(Observation(node=None, kind="packet", path="")) is None
|
||||
|
||||
|
||||
def test_three_packets_from_another_sites_first_hop_make_a_suggestion() -> None:
|
||||
"""The first hop of the Foulab path, heard three times, suggests Foulab."""
|
||||
watch = SiteWatch([HOME, LAB], "Home")
|
||||
for _ in range(HEARD_TO_SUGGEST - 1):
|
||||
assert watch.note("a1") is None # a 1-byte hash matches the stored key prefix
|
||||
assert watch.note("a100") == SiteSuggestion("Foulab", "a100008dc55e", HEARD_TO_SUGGEST)
|
||||
assert watch.settled
|
||||
assert watch.note("a1") is None # one question for each session
|
||||
|
||||
|
||||
def test_a_first_hop_of_the_active_site_settles_the_question() -> None:
|
||||
"""Once the radio hears the way out of the active site, there is nothing to suggest."""
|
||||
watch = SiteWatch([HOME, LAB], "home")
|
||||
watch.note("a1")
|
||||
assert watch.note("27d4") is None
|
||||
assert watch.settled
|
||||
assert all(watch.note("a1") is None for _ in range(5))
|
||||
|
||||
|
||||
def test_a_hop_that_is_not_a_first_hop_counts_for_nothing() -> None:
|
||||
"""Only the first hop of a path says where the radio is: the second hop is far away."""
|
||||
watch = SiteWatch([HOME, LAB], "Home")
|
||||
assert all(watch.note("b2b2") is None for _ in range(5))
|
||||
assert not watch.settled
|
||||
|
||||
|
||||
async def test_the_service_keeps_one_suggestion_for_the_menu(tmp_path) -> None: # noqa: ANN001
|
||||
"""Packets from the hub make a pending suggestion, unless the connected device is fixed."""
|
||||
from types import SimpleNamespace
|
||||
|
||||
from meshterm.core.events import MeshEvent
|
||||
from meshterm.core.outbound_store import OutboundStore
|
||||
from meshterm.services.site_suggest import SiteSuggester
|
||||
|
||||
store = OutboundStore(tmp_path / "o.json")
|
||||
store.put_site("Home", list(HOME.paths))
|
||||
store.put_site("Foulab", list(LAB.paths))
|
||||
store.set_active("Home")
|
||||
handlers: list = []
|
||||
|
||||
async def self_info() -> dict:
|
||||
return {"public_key": "c0" * 32}
|
||||
|
||||
ctx = SimpleNamespace(
|
||||
preferences=SimpleNamespace(suggest_site=True),
|
||||
outbound_store=store,
|
||||
events=SimpleNamespace(subscribe=lambda handler, *kinds: handlers.append(handler) or None),
|
||||
devstate=SimpleNamespace(self_info=self_info),
|
||||
)
|
||||
service = SiteSuggester(ctx)
|
||||
ready: list = []
|
||||
service.on_ready = lambda: ready.append(True)
|
||||
await service.start()
|
||||
packet = MeshEvent.observation_event(Observation(node="99", kind="packet", path="77,a1"))
|
||||
pending = [handlers[0](packet) for _ in range(HEARD_TO_SUGGEST)]
|
||||
assert pending[:-1] == [None, None]
|
||||
await pending[-1]
|
||||
assert ready == [True]
|
||||
assert service.take() == SiteSuggestion("Foulab", "a100008dc55e", HEARD_TO_SUGGEST)
|
||||
assert service.take() is None # one time only
|
||||
|
||||
store.fix_device("c0" * 32, "Roof", [])
|
||||
fixed = SiteSuggester(ctx)
|
||||
handlers.clear()
|
||||
await fixed.start()
|
||||
last = [handlers[0](packet) for _ in range(HEARD_TO_SUGGEST)][-1]
|
||||
await last
|
||||
assert fixed.take() is None # the active site does not apply to a fixed device
|
||||
|
||||
|
||||
def test_with_no_active_site_any_site_can_be_suggested_and_one_site_needs_no_watch() -> None:
|
||||
"""No active site: the first site heard is suggested. A single active site settles at once."""
|
||||
watch = SiteWatch([HOME, LAB], None)
|
||||
suggestions = [watch.note("3d") for _ in range(HEARD_TO_SUGGEST)]
|
||||
assert suggestions[-1] == SiteSuggestion("Home", "3d63c6429436", HEARD_TO_SUGGEST)
|
||||
assert SiteWatch([HOME], "Home").settled
|
||||
@@ -247,6 +247,101 @@ def test_coalesce_keeps_the_direction_of_the_readings_of_a_stub() -> None:
|
||||
assert sorted(topo.readings(far, leaf)) == [-4.5, -3.5]
|
||||
|
||||
|
||||
# --- outbound paths -----------------------------------------------------------------
|
||||
|
||||
HUB, LEAF_ID, FAR_ID = "3d63c6429436", "27d4396a2967", "f2c24f54551e"
|
||||
|
||||
|
||||
def _two_ways(strong: int = 5, weak: int = 1, weak_age_hours: float = 0.0): # noqa: ANN202
|
||||
"""Two ways to Far: through Hub (strong, often heard) and through Leaf (weak)."""
|
||||
return _topo(
|
||||
trace_paths=[
|
||||
*[_traced(("3d", 12.0), ("f2", 10.0), ("3d", 10.0), (None, 12.0))] * strong,
|
||||
*[_traced(("27", 2.0), ("f2", 0.0), ("27", 0.0), (None, 2.0), age_hours=weak_age_hours)]
|
||||
* weak,
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_an_outbound_path_starts_the_routes_although_the_evidence_prefers_another() -> None:
|
||||
"""The user knows the way out. The graph ranks a first hop by what our node heard."""
|
||||
topo = _two_ways()
|
||||
assert topo.scenarios(FAR_ID)[0].hops != (LEAF_ID,) # the evidence alone prefers Hub
|
||||
first = topo.scenarios(FAR_ID, outbound=[(LEAF_ID,)])[0]
|
||||
assert (first.source, first.hops, first.rank) == ("outbound", (LEAF_ID,), 1)
|
||||
assert topo.suggested(FAR_ID, outbound=[(LEAF_ID,)]).hops == (LEAF_ID,)
|
||||
|
||||
|
||||
def test_a_target_inside_an_outbound_path_is_reached_along_the_path() -> None:
|
||||
"""A route to a hop of the path is the part of the path before it, and it is trusted."""
|
||||
topo = _two_ways()
|
||||
(scenario,) = topo.outbound_scenarios(FAR_ID, [(LEAF_ID, FAR_ID, HUB)])
|
||||
assert scenario.hops == (LEAF_ID,)
|
||||
assert scenario.score > topo.scenarios(FAR_ID)[0].score
|
||||
|
||||
|
||||
def test_the_best_score_wins_and_the_order_of_the_user_breaks_a_near_tie() -> None:
|
||||
"""A much better second path wins. Two paths that score the same keep the user's order."""
|
||||
topo = _two_ways(strong=5, weak=1)
|
||||
ranked = topo.outbound_scenarios(FAR_ID, [(LEAF_ID,), (HUB,)])
|
||||
assert [s.hops for s in ranked] == [(HUB,), (LEAF_ID,)] # Hub is far stronger
|
||||
even = _topo(
|
||||
trace_paths=[
|
||||
_traced(("3d", 5.0), ("f2", 5.0), ("3d", 5.0), (None, 5.0)),
|
||||
_traced(("27", 5.0), ("f2", 5.0), ("27", 5.0), (None, 5.0)),
|
||||
]
|
||||
)
|
||||
assert [s.hops for s in even.outbound_scenarios(FAR_ID, [(LEAF_ID,), (HUB,)])] == [
|
||||
(LEAF_ID,),
|
||||
(HUB,),
|
||||
]
|
||||
assert [s.hops for s in even.outbound_scenarios(FAR_ID, [(HUB,), (LEAF_ID,)])] == [
|
||||
(HUB,),
|
||||
(LEAF_ID,),
|
||||
]
|
||||
|
||||
|
||||
def test_an_outbound_path_whose_first_hop_went_silent_is_skipped() -> None:
|
||||
"""A first hop that our node did not hear for too long is probably off, or out of reach."""
|
||||
topo = _two_ways(weak_age_hours=48.0)
|
||||
quiet_since = utcnow() - timedelta(hours=24)
|
||||
assert topo.outbound_scenarios(FAR_ID, [(LEAF_ID,)], silent_before=quiet_since) == []
|
||||
assert topo.outbound_scenarios(FAR_ID, [(LEAF_ID,)]) # with no window, it stays
|
||||
unknown = topo.outbound_scenarios(FAR_ID, [("9a9a",)], silent_before=quiet_since)
|
||||
assert unknown == [] # no evidence at all is not silence, but no route continues from it
|
||||
|
||||
|
||||
def test_outbound_routes_go_before_a_device_route_that_starts_elsewhere() -> None:
|
||||
"""The firmware learns its route from what our node received. The user's way out wins."""
|
||||
topo = _two_ways()
|
||||
elsewhere = topo.scenarios(FAR_ID, device_route=(HUB,), outbound=[(LEAF_ID,)])
|
||||
assert [s.source for s in elsewhere[:2]] == ["outbound", "device"]
|
||||
agreed = topo.scenarios(FAR_ID, device_route=(LEAF_ID,), outbound=[(LEAF_ID,)])
|
||||
assert agreed[0].hops == (LEAF_ID,) # the device learned the user's way out
|
||||
assert [s.hops for s in agreed].count((LEAF_ID,)) == 1
|
||||
|
||||
|
||||
def test_a_first_link_is_scored_by_how_well_the_far_end_hears_us() -> None:
|
||||
"""Our node hears Hub well, but Hub hears our node badly. Leaf is the better way out."""
|
||||
packets = [
|
||||
*[PacketPath(when=utcnow(), origin=None, snr=10.0, hops=[HUB])] * 20,
|
||||
*[PacketPath(when=utcnow(), origin=None, snr=2.0, hops=[LEAF_ID])] * 20,
|
||||
]
|
||||
walks = [
|
||||
_traced(("3d", -12.0), ("f2", 5.0), ("3d", 5.0), (None, 10.0)),
|
||||
_traced(("27", 8.0), ("f2", 5.0), ("27", 5.0), (None, 2.0)),
|
||||
]
|
||||
topo = _topo(trace_paths=walks, packet_paths=packets)
|
||||
us = topo.self_id
|
||||
assert topo.link(us, HUB).median_snr > topo.link(us, LEAF_ID).median_snr # the pool
|
||||
assert [s.node for s in topo.next_hops(us)][:2] == [LEAF_ID, HUB]
|
||||
assert topo.scenarios(FAR_ID)[0].hops == (LEAF_ID,)
|
||||
# Away from our node, the pooled strength is unchanged.
|
||||
assert topo.outward_strength(HUB, FAR_ID, topo.link(HUB, FAR_ID)) == topo.link(
|
||||
HUB, FAR_ID
|
||||
).strength(topo._now)
|
||||
|
||||
|
||||
# --- suggestions and scenarios ----------------------------------------------------
|
||||
|
||||
|
||||
@@ -797,6 +892,56 @@ def test_composer_path_mode_opens_star_to_star_without_auto(monkeypatch) -> None
|
||||
assert "Auto" not in _rows_plain(screen)
|
||||
|
||||
|
||||
async def test_composer_outbound_mode_returns_full_ids_and_keeps_its_end_open(
|
||||
monkeypatch, # noqa: ANN001
|
||||
) -> None:
|
||||
"""An outbound path has no return, no node two times, and the full id of each hop."""
|
||||
import asyncio
|
||||
|
||||
monkeypatch.setattr(pathline, "powerline_enabled", lambda: False) # assert the words
|
||||
walks = [_traced(("3d", 12.0), ("f2", 5.0), ("3d", 5.0), (None, 12.0))]
|
||||
topo = _topo(trace_paths=walks)
|
||||
screen = PathComposerScreen(
|
||||
device_label="Me", topology=topo, width_bytes=1, hops=["3d63c6429436"], outbound=True
|
||||
)
|
||||
assert screen.title == "Compose outbound path"
|
||||
preview = screen._route_preview().text().plain
|
||||
assert preview.endswith(f"{CURSOR_GLYPH} →") # open: the route goes on from here
|
||||
assert SELF_GLYPH not in preview[1:] # our node only at the start
|
||||
suggested = [s.node for s in screen._suggestions()]
|
||||
assert "3d63c6429436" not in suggested and "f2c24f54551e" in suggested
|
||||
screen.future = asyncio.get_running_loop().create_future()
|
||||
screen.handle("enter") # the top suggestion: Far
|
||||
screen.handle("end")
|
||||
screen.handle("enter") # Use this path
|
||||
assert screen.future.result() == "3d63c6429436,f2c24f54551e"
|
||||
|
||||
|
||||
def test_composer_offers_the_outbound_paths_first_at_our_node_only() -> None:
|
||||
"""At our node, the user's ways out lead the rows. Enter inserts the whole path."""
|
||||
walks = [_traced(("3d", 12.0), ("f2", 5.0), ("3d", 5.0), (None, 12.0))]
|
||||
topo = _topo(trace_paths=walks)
|
||||
screen = PathComposerScreen(
|
||||
device_label="Me",
|
||||
topology=topo,
|
||||
width_bytes=1,
|
||||
outbound_paths=((LEAF_ID, HUB), (FAR_ID,)),
|
||||
)
|
||||
kinds = [kind for kind, _ in screen._rows()]
|
||||
assert kinds[:2] == ["outbound", "outbound"]
|
||||
assert "your paths first" in _rows_plain(screen)
|
||||
screen.handle("enter") # outbound path 1: Leaf → Hub
|
||||
assert screen.hops == [LEAF_ID, HUB]
|
||||
assert "outbound" not in [kind for kind, _ in screen._rows()] # the slot left our node
|
||||
screen.handle("left")
|
||||
screen.handle("left") # back at our node, but path 1 is in the route already
|
||||
assert [p for kind, p in screen._rows() if kind == "outbound"] == [(2, (FAR_ID,))]
|
||||
outbound_mode = PathComposerScreen(
|
||||
device_label="Me", topology=topo, width_bytes=1, outbound=True, outbound_paths=((HUB,),)
|
||||
)
|
||||
assert "outbound" not in [kind for kind, _ in outbound_mode._rows()]
|
||||
|
||||
|
||||
def test_composer_names_an_ambiguous_hop_through_the_owning_screens_resolver() -> None:
|
||||
"""A short hop that the topology does not name still shows a name, with its hash beside it.
|
||||
|
||||
|
||||
Reference in new issue
Block a user