From 551a86f47a34dd1b376af169add2285ce83b57da Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Mon, 21 Sep 2026 03:37:03 -0400 Subject: [PATCH] The splash surface learns the argument the session already knew `live` went onto `TuiSession.select_startup` and nowhere else, but the picker calls the *surface* -- `ui.select_startup`, which delegates. So MeshTerm crashed on the startup path with a `TypeError` about an unexpected keyword, on the first screen, every time. The whole test suite passed through it. Every fake Ui in `test_tui.py` takes `**kwargs`, which is the reasonable thing for a double to do and is exactly what hid this: the picker's new argument was absorbed by a stand-in that would accept anything, while the real surface would accept nothing of the sort. Five tests written specifically for the rescan ran green against code that could not start. So the double stops being infinitely accommodating. The test added here binds what the picker sends against the real `Ui.select_startup` signature, which raises on an unknown keyword exactly where a running MeshTerm does. It fails against this commit's parent and passes against this one. Co-Authored-By: Claude Opus 5 (1M context) --- meshterm/ui/surface.py | 10 +++++++++- tests/test_tui.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/meshterm/ui/surface.py b/meshterm/ui/surface.py index 743f733..6df5687 100644 --- a/meshterm/ui/surface.py +++ b/meshterm/ui/surface.py @@ -18,7 +18,7 @@ only), so :class:`PlainUi` leaves them unsupported. from __future__ import annotations -from collections.abc import AsyncIterator, Callable, Mapping +from collections.abc import AsyncIterator, Awaitable, Callable, Mapping from contextlib import asynccontextmanager from typing import Any @@ -222,9 +222,14 @@ class Ui: footer_hint: str | None = None, keys: Mapping[str, Any] | None = None, key_hint: Callable[[Any], str] | None = None, + live: Callable[[Callable[[list], None]], Awaitable[None]] | None = None, ) -> Any: """Choose one item on a chromeless startup splash; ``None`` if skipped. + ``live`` is work to run while the splash is up, handed a ``redraw(items)`` that + swaps the rows under the reader and repaints -- the device picker's rescan. It is + cancelled when the splash resolves. + ``keys`` declares bare-key shortcuts the splash answers, resolving with a :class:`~meshterm.ui.tui.select.KeyRequest` (the picker's hide/show-all pair), and ``key_hint`` names them per highlighted row so the footer only advertises a key @@ -516,6 +521,7 @@ class PlainUi(Ui): footer_hint: str | None = None, keys: Mapping[str, Any] | None = None, key_hint: Callable[[Any], str] | None = None, + live: Callable[[Callable[[list], None]], Awaitable[None]] | None = None, ) -> Any: """Unsupported in scripted CLI mode.""" raise self._no_prompt() @@ -779,6 +785,7 @@ class TuiUi(Ui): footer_hint: str | None = None, keys: Mapping[str, Any] | None = None, key_hint: Callable[[Any], str] | None = None, + live: Callable[[Callable[[list], None]], Awaitable[None]] | None = None, ) -> Any: """Delegate to the session's chromeless startup select splash.""" return await self.session.select_startup( @@ -789,6 +796,7 @@ class TuiUi(Ui): footnote=footnote, keys=keys, key_hint=key_hint, + live=live, **({} if footer_hint is None else {"footer_hint": footer_hint}), ) diff --git a/tests/test_tui.py b/tests/test_tui.py index 29d6498..d93473a 100644 --- a/tests/test_tui.py +++ b/tests/test_tui.py @@ -3573,3 +3573,33 @@ def test_bluetooth_is_not_scanned_on_every_poll(tmp_path, monkeypatch) -> None: assert calls["serial"] > calls["ble"], ( f"bluetooth scanned {calls['ble']} time(s) against {calls['serial']} serial poll(s)" ) + + +def test_the_picker_only_passes_arguments_the_splash_surface_accepts(tmp_path) -> None: + """Every keyword `prompt_device` sends must exist on `Ui.select_startup`. + + This is the shape of bug a test double hides. `prompt_device` calls the *surface*, + which delegates to the session; adding an argument to the session alone crashes the + startup path and nothing else, because every fake Ui in this file absorbs unknown + keywords with `**kwargs` and is perfectly happy. So the fake here binds what it is + given against the real signature, and a keyword the surface has never heard of raises + exactly where a running MeshTerm would. + """ + import inspect + + from meshterm.core.device_store import DeviceStore + from meshterm.ui.device_picker import prompt_device + from meshterm.ui.surface import Ui + + signature = inspect.signature(Ui.select_startup) + + class _Ui: + async def select_startup(self, title, items, **kw): # noqa: ANN001, ANN003, ANN201 + signature.bind(self, title, items, **kw) # TypeError on an unknown keyword + return None + + async def _never(_device): + raise AssertionError("verify should not run when selection is skipped") + + store = DeviceStore(tmp_path / "devices.json") + asyncio.run(prompt_device(_Ui(), [], store, _never))