Drop the via chain from the feed row. Whatever the fixed lanes left it was a handful of cells, so a route never actually arrived — it arrived elided to a stub that named one hop and hinted at the rest, which is the least useful form a route can take. A route is a shape rather than a lane, and the packet viewer already draws it properly one keypress away: a wrapped path line over the route graph, with the room to say the whole thing. So the feed says what arrived and how well it was heard; Enter says how it got here. What that buys is the whole row fitting a 72-column screen — 69 cells, class label included. The label was being dropped on exactly the screens where it mattered most, to make room for a route that never fitted either; now nothing competes for those cells and the class reads in words down to the width where it genuinely can't. ←→ stays: it just has less to do, firing only on a terminal too narrow for the lanes themselves, and its footer atom appears only there. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
218 lines
9.1 KiB
Python
218 lines
9.1 KiB
Python
"""Live feed tests: the promoted feed screen's state, rows, and windowing.
|
|
|
|
The screen is driven headless against fake sessions and canned observations — the
|
|
same approach as the dashboard tests, whose feed panel this screen grew out of.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from datetime import timedelta
|
|
|
|
from meshterm.core.events import MeshEvent
|
|
from meshterm.core.models import Ack, Message, Observation, utcnow
|
|
from meshterm.ui.livefeed_screen import LiveFeedScreen
|
|
|
|
|
|
class _FakeSession:
|
|
def __init__(self) -> None:
|
|
self.repaints = 0
|
|
|
|
def invalidate(self) -> None:
|
|
self.repaints += 1
|
|
|
|
|
|
def _screen(seed=None, active=True) -> LiveFeedScreen:
|
|
screen = LiveFeedScreen(
|
|
session=_FakeSession(),
|
|
resolve=lambda h: {"a1b2": "Alice", "3d63": "YUL"}.get(h, ""),
|
|
seed=list(seed or []),
|
|
hub_active=lambda: active,
|
|
)
|
|
screen.note_viewport(48) # the frame records this before every real paint
|
|
return screen
|
|
|
|
|
|
def _obs(node="a1b2", kind="advert", snr=5.0, rssi=-90.0, age_s=0, **extra) -> Observation:
|
|
return Observation(
|
|
node=node, name=node, kind=kind, snr=snr, rssi=rssi,
|
|
observed_at=utcnow() - timedelta(seconds=age_s), **extra,
|
|
)
|
|
|
|
|
|
def _plain(lines: list[str]) -> str:
|
|
return "\n".join(lines)
|
|
|
|
|
|
def _stripped(lines: list[str]) -> list[str]:
|
|
"""The rendered lines with ANSI escapes removed, for structural assertions."""
|
|
return [re.sub(r"\x1b\[[0-9;]*m", "", line) for line in lines]
|
|
|
|
|
|
def test_livefeed_tool_registers_under_the_dashboard() -> None:
|
|
"""The livefeed tool lands in the Mesh section, right below the dashboard."""
|
|
from meshterm.tools import load_all_tools
|
|
from meshterm.tools.base import all_tools
|
|
|
|
load_all_tools()
|
|
tools = {t.name: t for t in all_tools()}
|
|
tool = tools["livefeed"]
|
|
assert tool.title == "Live feed" and tool.category == "Mesh"
|
|
assert tools["dashboard"].order < tool.order < tools["contacts"].order
|
|
|
|
|
|
def test_livefeed_live_events_land_in_the_feed() -> None:
|
|
"""Observations, messages, and acks each fold into the feed as they arrive."""
|
|
screen = _screen()
|
|
screen.on_event(MeshEvent.observation_event(_obs(snr=7.5)))
|
|
screen.on_event(MeshEvent.message_event(Message(text="hi", sender="a1b2")))
|
|
screen.on_event(MeshEvent.ack_event(Ack(code="01c3")))
|
|
body = _plain(screen.render_body(100))
|
|
assert "+7.5 dB" in body
|
|
assert "message" in body and "ack" in body
|
|
# Newest first: the ack row sits above the message row, which sits above the advert.
|
|
assert body.index("ack") < body.index("message") < body.index("advert")
|
|
|
|
|
|
def test_livefeed_rows_leave_the_relay_path_to_the_viewer() -> None:
|
|
"""A row says what arrived and how well it was heard; the route is Enter's job.
|
|
|
|
Whatever the fixed lanes left a route was never enough to draw one in — it arrived
|
|
elided to a stub — so the feed carries none, and the whole row fits a 72-column
|
|
screen with its class label intact.
|
|
"""
|
|
screen = _screen()
|
|
screen.on_event(
|
|
MeshEvent.observation_event(_obs(kind="packet", path="3d63,a1b2", snr=1.0))
|
|
)
|
|
row = _stripped(screen.render_body(72))[1]
|
|
assert "via" not in row and "YUL" not in row # no route, not even a stub of one
|
|
assert "📦 packet" in row # the class still reads in words at 72
|
|
assert "+1.0 dB" in row and "-90 dBm" in row # …as does the reception it was heard at
|
|
assert len(row.rstrip()) <= 72
|
|
|
|
|
|
def test_livefeed_class_lane_names_the_payload_class_once() -> None:
|
|
"""A raw frame is filed under what it *is*, and the node lane doesn't repeat it.
|
|
|
|
``packet`` names only the event family the frame arrived in, so the class lane
|
|
reads its parsed payload class — the very label the viewer's card headlines. The
|
|
node lane is then free to be about the node, and an origin-less flood says so with
|
|
a dash rather than standing the class in a second time.
|
|
"""
|
|
screen = _screen()
|
|
raw = {"payload_typename": "TRACE", "route_typename": "FLOOD"}
|
|
screen.on_event(
|
|
MeshEvent.observation_event(
|
|
_obs(node="", kind="packet", snr=1.0, path="3d63,a1b2", raw=raw)
|
|
)
|
|
)
|
|
row = _stripped(screen.render_body(100))[1]
|
|
assert "🎯 trace" in row # the class lane, under the payload class's own icon
|
|
assert row.count("trace") == 1 # said once, not once per lane
|
|
assert "packet" not in row # …and never as the generic event family
|
|
assert "—" in row # the node lane: nobody identified themselves
|
|
assert "?" not in row # …but never the useless placeholder
|
|
|
|
|
|
def test_livefeed_names_a_channel_message_by_its_sender() -> None:
|
|
"""A channel message's ``Name:`` prefix names the node lane, not the bare channel."""
|
|
screen = _screen()
|
|
screen.on_event(
|
|
MeshEvent.message_event(Message(text="Alice: hi all", channel=3, is_channel=True))
|
|
)
|
|
body = _plain(screen.render_body(100))
|
|
assert "Alice" in body # the parsed sender leads the row
|
|
assert "ch 3" in body # …with the channel kept as the trailing context
|
|
|
|
|
|
def test_livefeed_page_keys_move_the_feed_selection() -> None:
|
|
"""With a feed row highlighted, PgUp/PgDn walk the selection a windowful at a time."""
|
|
seed = [_obs(node=f"n{i}", age_s=i) for i in range(20)]
|
|
screen = _screen(seed=seed)
|
|
screen._feed_window.page = 5 # as if the last paint settled a five-row window
|
|
assert screen._selected == 0 # the newest packet is highlighted from the start
|
|
screen.handle("pagedown")
|
|
assert screen._selected == 5 # the selection travelled down a page, not just the view
|
|
screen.handle("pageup")
|
|
assert screen._selected == 0
|
|
|
|
# With nothing highlighted, the page keys slide the feed window instead.
|
|
screen._selected = None
|
|
screen.handle("pagedown")
|
|
assert screen._feed_window.top > 0 and screen._selected is None
|
|
|
|
|
|
def test_livefeed_windows_inside_the_fixed_screen() -> None:
|
|
"""The heading stays pinned: the body fits the viewport and the feed rows window."""
|
|
seed = [_obs(node=f"n{i}", age_s=i) for i in range(40)]
|
|
screen = _screen(seed=seed)
|
|
screen.note_viewport(24)
|
|
lines = screen.render_body(100)
|
|
assert len(lines) <= 24 # heading + feed window == the viewport, never more
|
|
body = _plain(_stripped(lines))
|
|
assert "newest first" in body # the pinned status line is still there
|
|
assert "↓" in body and "more" in body # hidden feed rows are counted below
|
|
|
|
|
|
#: A terminal too narrow to hold the feed's fixed lanes — the only thing that makes a
|
|
#: row overflow now that no route rides in it (see ``_FEED_LABEL_MIN_WIDTH``).
|
|
_CRAMPED = 44
|
|
|
|
|
|
def test_livefeed_the_whole_row_fits_a_72_column_screen() -> None:
|
|
"""No row overflows at 72 — which is why ←→ has nothing to advertise there."""
|
|
screen = _screen(seed=[_obs(node="n0", kind="telemetry")])
|
|
for line in _stripped(screen.render_body(72))[1:]:
|
|
assert len(line.rstrip()) <= 72
|
|
assert screen._hmax == 0
|
|
assert "←→" not in screen.footer_hint
|
|
|
|
|
|
def test_livefeed_highlighted_row_scrolls_sideways_to_its_tail() -> None:
|
|
"""On a terminal too narrow for the lanes, ←→ slide the highlighted row to its end."""
|
|
screen = _screen(seed=[_obs()])
|
|
opening = _stripped(screen.render_body(_CRAMPED))[1]
|
|
assert screen._hmax > 0 # the row does run past the right edge
|
|
assert not opening.rstrip().endswith("dBm") # …so its reception tail is off-screen
|
|
|
|
for _ in range(40): # → saturates at the row's own end, never past it
|
|
screen.handle("right")
|
|
scrolled = _stripped(screen.render_body(_CRAMPED))[1]
|
|
assert screen._hshift == screen._hmax
|
|
assert scrolled.startswith("▸ ") # the pointer lane stays pinned while the row slides
|
|
assert scrolled.rstrip().endswith("-90 dBm") # the tail is now readable
|
|
assert opening[2:10] not in scrolled # …at the cost of the time lane, slid off left
|
|
|
|
for _ in range(40):
|
|
screen.handle("left")
|
|
assert screen._hshift == 0
|
|
assert _stripped(screen.render_body(_CRAMPED))[1] == opening # back where it started
|
|
|
|
|
|
def test_livefeed_moving_the_selection_abandons_the_rows_scroll() -> None:
|
|
"""Each row scrolls on its own: landing on another packet starts it at its beginning."""
|
|
screen = _screen(seed=[_obs(node="n0", age_s=1), _obs(node="n1", age_s=0)])
|
|
screen.render_body(_CRAMPED)
|
|
screen.handle("right")
|
|
assert screen._hshift > 0
|
|
screen.handle("down")
|
|
assert screen._hshift == 0
|
|
|
|
|
|
def test_livefeed_advertises_line_scroll_only_where_it_acts() -> None:
|
|
"""←→ earns its footer atom exactly while the highlighted row overflows."""
|
|
screen = _screen(seed=[_obs()])
|
|
screen.render_body(100)
|
|
assert "←→" not in screen.footer_hint # a row with room to spare scrolls nowhere
|
|
|
|
screen.render_body(_CRAMPED)
|
|
assert "←→ scroll line" in screen.footer_hint
|
|
assert len(screen.footer_hint) <= 72 # the screens-at-72 rule, fullest state
|
|
|
|
|
|
def test_livefeed_without_a_device_reads_as_waiting() -> None:
|
|
"""With the hub idle the heading says so instead of pretending to be live."""
|
|
screen = _screen(active=False)
|
|
assert "○ waiting for a device" in _plain(screen.render_body(100))
|