Repeater admin: float the login over the node picker, not a blank frame
The admin-login password prompt ran on an empty stack (the picker was popped when it returned), so session.text pushed a blank base and the prompt — and any "wrong password" rejection — floated over an erased background. open_repeater_admin now redraws the node picker as a static backdrop (extracted admin_picker_rows, shared with the live pick so they can't drift) and keeps it pushed across _login, with the picked node highlighted. The password box and the rejection float over the picker, matching the device-picker and trophy-case dialogs. floating=True stays on the prompt as a belt-and-suspenders fallback. Also drop the inert floating=True on tx_optimize._resolve_password: that resolver only runs on the scripted CLI path (PlainUi, no stack), so the flag never did anything — the menu path logs in inside the pushed sweep screen. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
59b26ae616
commit
310783c6a3
4 files changed
+154
-28
No files matched your search
@@ -308,9 +308,9 @@ class TxOptimizeTool(Tool):
|
||||
f"no admin password for {admin_node.name!r}; pass --password or run once "
|
||||
"interactively to store it."
|
||||
)
|
||||
entered = await ctx.ui.text(
|
||||
f"Admin password for {admin_node.name}:", password=True, floating=True
|
||||
)
|
||||
# This resolver only runs on the scripted CLI path (the menu logs in inside the pushed
|
||||
# sweep screen), so the surface here is PlainUi — no screen stack, no floating.
|
||||
entered = await ctx.ui.text(f"Admin password for {admin_node.name}:", password=True)
|
||||
if not entered:
|
||||
raise DeviceCommandError("an admin password is required to tune a remote node.")
|
||||
return entered
|
||||
|
||||
+41
-15
@@ -20,23 +20,25 @@ if TYPE_CHECKING:
|
||||
from ..context import AppContext
|
||||
|
||||
|
||||
async def pick_admin_node(
|
||||
ctx: "AppContext",
|
||||
contacts: list[Contact],
|
||||
*,
|
||||
title: str,
|
||||
prompt: str,
|
||||
) -> Optional[Contact]:
|
||||
"""Pick a remote node to administer, credentialed and infrastructure nodes first.
|
||||
def admin_picker_rows(
|
||||
ctx: "AppContext", contacts: list[Contact]
|
||||
) -> tuple[list, list[Contact]]:
|
||||
"""Build the admin-node picker's grouped rows and the contacts they map to.
|
||||
|
||||
Shared so the pick and any later redraw are guaranteed identical: :func:`pick_admin_node`
|
||||
runs these rows, and a caller can rebuild the same list as a static backdrop to float a
|
||||
follow-up dialog (the admin login) over the very list the node was picked from. Rows carry
|
||||
``value = contact.name``, so a picked name (or a backdrop's ``default``) resolves through
|
||||
``candidates``.
|
||||
|
||||
Args:
|
||||
ctx: Shared application context (for the UI surface and the admin store).
|
||||
ctx: Shared application context (for the admin store, which sorts remembered nodes up).
|
||||
contacts: The device's known contacts.
|
||||
title: The select screen's heading (names the calling feature).
|
||||
prompt: One line above the list saying what the pick is for.
|
||||
|
||||
Returns:
|
||||
The chosen contact, or ``None`` if cancelled (or there is nothing to pick).
|
||||
``(rows, candidates)`` — the select rows (grouped, with the exit group) and the
|
||||
offerable contacts (those holding a key). ``candidates`` is empty when nothing is
|
||||
offerable; ``rows`` is then just the exit group.
|
||||
"""
|
||||
from .menus import back_rows, section_heading
|
||||
from .tui import Choice
|
||||
@@ -44,9 +46,7 @@ async def pick_admin_node(
|
||||
|
||||
candidates = [c for c in contacts if (c.public_key or c.key_prefix).strip()]
|
||||
if not candidates:
|
||||
ctx.ui.note("[err]no contacts with a key — receive an advert first[/err]")
|
||||
await ctx.ui.present(title=title)
|
||||
return None
|
||||
return list(back_rows()), candidates
|
||||
|
||||
def row(contact: Contact) -> Choice:
|
||||
glyph, style = _NODE_GLYPHS.get(contact.node_type, _DEFAULT_GLYPH)
|
||||
@@ -75,6 +75,32 @@ async def pick_admin_node(
|
||||
items.append(section_heading("Other contacts"))
|
||||
items.extend(row(c) for c in sorted(others, key=recency))
|
||||
items.extend(back_rows())
|
||||
return items, candidates
|
||||
|
||||
|
||||
async def pick_admin_node(
|
||||
ctx: "AppContext",
|
||||
contacts: list[Contact],
|
||||
*,
|
||||
title: str,
|
||||
prompt: str,
|
||||
) -> Optional[Contact]:
|
||||
"""Pick a remote node to administer, credentialed and infrastructure nodes first.
|
||||
|
||||
Args:
|
||||
ctx: Shared application context (for the UI surface and the admin store).
|
||||
contacts: The device's known contacts.
|
||||
title: The select screen's heading (names the calling feature).
|
||||
prompt: One line above the list saying what the pick is for.
|
||||
|
||||
Returns:
|
||||
The chosen contact, or ``None`` if cancelled (or there is nothing to pick).
|
||||
"""
|
||||
items, candidates = admin_picker_rows(ctx, contacts)
|
||||
if not candidates:
|
||||
ctx.ui.note("[err]no contacts with a key — receive an advert first[/err]")
|
||||
await ctx.ui.present(title=title)
|
||||
return None
|
||||
|
||||
choice = await ctx.ui.select(title, items, prompt=prompt, wrap=False)
|
||||
if choice is None:
|
||||
|
||||
@@ -76,8 +76,9 @@ async def open_repeater_admin(ctx: "AppContext") -> Optional[dict[str, Any]]:
|
||||
Raises:
|
||||
RuntimeError: If called outside the interactive menu (no full-screen session).
|
||||
"""
|
||||
from .admin_picker import pick_admin_node
|
||||
from .admin_picker import admin_picker_rows, pick_admin_node
|
||||
from .surface import TuiUi
|
||||
from .tui import SelectScreen
|
||||
|
||||
if not isinstance(ctx.ui, TuiUi): # pragma: no cover - guarded by the menu-only caller
|
||||
raise RuntimeError("repeater admin is only available in the menu")
|
||||
@@ -89,16 +90,23 @@ async def open_repeater_admin(ctx: "AppContext") -> Optional[dict[str, Any]]:
|
||||
# :class:`~meshterm.services.device_state.DeviceState`); the device handle below is still
|
||||
# needed for the admin login and the CLI session that follow.
|
||||
contacts = await ctx.devstate.contacts()
|
||||
node = await pick_admin_node(
|
||||
ctx,
|
||||
contacts,
|
||||
title="Repeater admin — node to manage",
|
||||
prompt="The remote node to set up (you need its admin password):",
|
||||
)
|
||||
pick_title = "Repeater admin — node to manage"
|
||||
pick_prompt = "The remote node to set up (you need its admin password):"
|
||||
node = await pick_admin_node(ctx, contacts, title=pick_title, prompt=pick_prompt)
|
||||
if node is None:
|
||||
return None
|
||||
if not await _login(ctx, device, node):
|
||||
return None
|
||||
# The picker was popped when it returned. Redraw it as a static backdrop and keep it
|
||||
# pushed across the login, so the password prompt (and any rejection) floats over the
|
||||
# node list the pick came from — the picked node still highlighted — rather than over a
|
||||
# blank frame. The backdrop takes no input; the dialog above it owns the keyboard.
|
||||
items, _candidates = admin_picker_rows(ctx, contacts)
|
||||
backdrop = SelectScreen(pick_title, items, prompt=pick_prompt, default=node.name, wrap=False)
|
||||
session.push(backdrop)
|
||||
try:
|
||||
if not await _login(ctx, device, node):
|
||||
return None
|
||||
finally:
|
||||
session.pop(backdrop)
|
||||
return await _admin_session(ctx, device, node)
|
||||
|
||||
|
||||
@@ -116,7 +124,9 @@ async def _login(ctx: "AppContext", device: "Device", node: Contact) -> bool:
|
||||
f"Admin password for {node.name}",
|
||||
prompt="The node ignores admin commands without a login.",
|
||||
password=True,
|
||||
floating=True, # a modal step between the node picker and the admin menu
|
||||
# Floats over the picker backdrop the caller keeps pushed; the flag is the
|
||||
# belt-and-suspenders so it never fills the frame even if that backdrop is absent.
|
||||
floating=True,
|
||||
)
|
||||
if not password:
|
||||
return False
|
||||
|
||||
@@ -3,9 +3,18 @@ remote CLI, and the command-line screen's readline behavior."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import io
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from rich.console import Console
|
||||
|
||||
from meshterm.context import AppContext
|
||||
from meshterm.core.admin_store import AdminStore
|
||||
from meshterm.core.config import Settings
|
||||
from meshterm.core.connection import MockDevice
|
||||
from meshterm.core.device_store import DeviceStore
|
||||
from meshterm.core.models import Contact
|
||||
from meshterm.core.remote_config import (
|
||||
REPEATER_SETTINGS,
|
||||
@@ -15,7 +24,14 @@ from meshterm.core.remote_config import (
|
||||
validate_value,
|
||||
)
|
||||
from meshterm.core.remote_store import HISTORY_CAP, RemoteStore
|
||||
from meshterm.persistence.repository import Repository
|
||||
from meshterm.ui.remote_cli import RemoteCliScreen
|
||||
from meshterm.ui.repeater_admin import open_repeater_admin
|
||||
from meshterm.ui.surface import TuiUi
|
||||
from meshterm.ui.tui.prompt import TextScreen
|
||||
from meshterm.ui.tui.screen import CANCEL
|
||||
from meshterm.ui.tui.select import SelectScreen
|
||||
from meshterm.ui.tui.session import TuiSession
|
||||
|
||||
NODE = Contact(name="Yagi-Repeater", public_key="a1" * 32, key_prefix="a1b2c3d4")
|
||||
|
||||
@@ -132,6 +148,80 @@ async def test_mock_remote_cli_round_trips_settings() -> None:
|
||||
await device.disconnect()
|
||||
|
||||
|
||||
# --- the login flow: the password floats over the node picker, never a blank frame ----
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def tui_ctx(tmp_path: Path) -> AppContext:
|
||||
"""A mock-backed context wired to a headless TUI session (no prompt_toolkit app)."""
|
||||
settings = Settings(config_dir=tmp_path, db_path=tmp_path / "admin.db")
|
||||
ctx = AppContext(
|
||||
console=Console(file=io.StringIO()),
|
||||
settings=settings,
|
||||
repo=Repository(settings.db_path),
|
||||
device_store=DeviceStore(tmp_path / "devices.json"),
|
||||
admin_store=AdminStore(tmp_path / "admin.json"),
|
||||
mock=True,
|
||||
)
|
||||
ctx.ui = TuiUi(TuiSession())
|
||||
yield ctx
|
||||
ctx.repo.close()
|
||||
|
||||
|
||||
async def _step_until(predicate, *, limit: int = 200):
|
||||
"""Yield to the event loop until ``predicate()`` is truthy; return it (or its last value)."""
|
||||
value = predicate()
|
||||
for _ in range(limit):
|
||||
if value:
|
||||
return value
|
||||
await asyncio.sleep(0)
|
||||
value = predicate()
|
||||
return value
|
||||
|
||||
|
||||
async def test_login_password_floats_over_the_node_picker(tui_ctx) -> None:
|
||||
"""The admin-login password prompt floats over the picker, not an erased background.
|
||||
|
||||
Regression: ``_login`` ran on an empty stack (the picker was popped when it returned),
|
||||
so ``session.text`` pushed a *blank* base and the password box floated over an erased
|
||||
frame. ``open_repeater_admin`` now redraws the node picker as a static backdrop and keeps
|
||||
it pushed across the login, so the base under the floating prompt is the picker — the
|
||||
picked node still highlighted — never a blank frame.
|
||||
"""
|
||||
ctx = tui_ctx
|
||||
session = ctx.ui.session
|
||||
pick_title = "Repeater admin — node to manage"
|
||||
|
||||
task = asyncio.ensure_future(open_repeater_admin(ctx))
|
||||
try:
|
||||
picker = await _step_until(
|
||||
lambda: session.top
|
||||
if isinstance(session.top, SelectScreen) and session.top.title == pick_title
|
||||
else None
|
||||
)
|
||||
assert picker is not None, "the node picker never opened"
|
||||
|
||||
picker.resolve("Yagi-Repeater") # pick the repeater to administer
|
||||
prompt = await _step_until(
|
||||
lambda: session._float_layers()[0] if session._has_float() else None
|
||||
)
|
||||
assert isinstance(prompt, TextScreen) # the password box floats
|
||||
|
||||
base = session._base_screen()
|
||||
assert isinstance(base, SelectScreen) and base.title == pick_title # the picker backdrop
|
||||
assert base is not picker # a fresh redraw kept as the backdrop, not the popped picker
|
||||
current = base._current_choice() # the picked node stays highlighted behind the prompt
|
||||
assert current is not None and current.value == "Yagi-Repeater"
|
||||
|
||||
prompt.resolve(CANCEL) # Esc — abandon the login
|
||||
result = await task
|
||||
finally:
|
||||
if not task.done():
|
||||
task.cancel()
|
||||
|
||||
assert result is None # cancelling the password bows the flow out
|
||||
|
||||
|
||||
# --- the command-line screen -----------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user