Hubs keep their place, and peers nest instead of flattening

Node detail, the contacts list and the trophy case were each rebuilt every time
something they opened closed. Node detail was the sharpest: its constructor sets
the tab to Info, so Tab to Routes, pick a route, trace it, come back — and you
were on Info at the top again, two keypresses from the route you were working
through, every single time.

All three now stay pushed for the whole visit. The screen object is what carries
the tab, the cursor, the sort and the filter, so returning is a pop rather than
a rebuild. It also retires the pop-then-re-push-as-a-backdrop dance in three
places: a screen that never left the stack is already the backdrop its dialogs
draw over. Contacts still rebuilds after a purge or a removal, and the trophy
case after the record count moves — the rows they were holding a place in are
gone, which is the one thing worth losing the cursor over.

The two peer hand-offs stop flattening. Trace → trophy case used to resolve the
whole trace screen with a sentinel so it unwound before the trophy case opened;
trophy case → trace ran the trace only after the browser came down and then
returned outright. Both landed the reader on the main menu, both said in their
comments that this was to avoid a stack the user would have to Esc through.
That was a hand-built escape from a stack with no other way out, and ^W is the
real one, so both nest now: Esc goes back one, to the screen that opened it.

The trace screen takes an `open_trophy_case` callback rather than resolving a
sentinel the opener has to interpret, which is also what lets the two screens
open each other — a cycle a strict stack allows on purpose.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-08-30 13:27:53 -04:00
1 parent ea68b9f890
commit a409fd4e9b
6 files changed
+226 -174

No files matched your search

+19 -4
View File
@@ -206,6 +206,7 @@ def test_previous_walk_rejects_unusable_history() -> None:
def _trace_screen(
trace=None, compose_path=None, explore=None, pick_width=None, pick_samples=None,
previous=None, mode="target", samples=1, auto_spec=None, auto_source="",
open_trophy_case=None,
) -> tuple[TraceScreen, _FakeSession]:
session = _FakeSession()
@@ -233,6 +234,7 @@ def _trace_screen(
previous=previous,
auto_spec=auto_spec or (lambda: ""),
auto_source=auto_source,
open_trophy_case=open_trophy_case,
)
screen.note_viewport(40) # the frame records this before every real paint
return screen, session
@@ -614,13 +616,25 @@ async def test_record_run_floats_the_new_record_dialog() -> None:
assert screen._run_placed == {} # announced once, not again on the next run
async def test_record_dialog_trophy_case_hands_the_screen_off() -> None:
"""Choosing Trophy case resolves the screen with the hand-off sentinel."""
async def test_record_dialog_trophy_case_opens_over_the_trace_it_was_earned_on() -> None:
"""Choosing Trophy case opens it *above* the trace screen, which stays up underneath.
It used to resolve the whole screen with a sentinel so the trace unwound away first and
the reader landed on the main menu. Navigation is a strict stack now: a sub-view nests,
Esc from the trophy case is one pop back onto the trace that earned the record, and ^W is
what leaves the whole excursion.
"""
opened: list[str] = []
async def trace(path_spec, on_trace): # noqa: ANN001
on_trace(_trace(5.0), ["Most nodes — 4 nodes", "Longest distance — 12.4 km"])
screen, session = _trace_screen(trace=trace, samples=2)
async def open_trophy_case() -> None:
opened.append("trophy case")
screen, session = _trace_screen(
trace=trace, samples=2, open_trophy_case=open_trophy_case
)
session.dialog_answer = OPEN_TROPHY_CASE
screen.future = asyncio.get_running_loop().create_future()
screen.start_trace()
@@ -629,7 +643,8 @@ async def test_record_dialog_trophy_case_hands_the_screen_off() -> None:
_prompt, _buttons, kwargs = session.dialogs[0]
assert kwargs["title"] == "2 new records" # one dialog for the whole run
assert len(session.dialogs) == 1 # however many samples scored
assert screen.future.result() == OPEN_TROPHY_CASE
assert opened == ["trophy case"]
assert not screen.future.done(), "the trace screen stays up under the trophy case"
async def test_escaping_mid_run_skips_the_record_dialog() -> None:
+25 -14
View File
@@ -324,8 +324,10 @@ async def test_delete_all_confirm_floats_over_the_browser(tui_ctx) -> None:
"""The trophy case stays drawn full-frame behind the "Delete all records" confirm.
Regression: the browser was run *then popped* before the confirm opened, so the confirm
floated over a blank frame — the background "cleared". Re-pushing the browser as the
backdrop keeps it the full-frame base while the red typed-delete gate floats over it.
floated over a blank frame — the background "cleared". The browser never leaves the stack
now (``session.stay``), so it is the full-frame base while the red typed-delete gate
floats over it, and backing out returns to the very same screen — cursor included —
rather than to a rebuilt one.
"""
ctx = tui_ctx
session = ctx.ui.session
@@ -347,9 +349,9 @@ async def test_delete_all_confirm_floats_over_the_browser(tui_ctx) -> None:
assert session._base_screen() is browser # the browser is still the full-frame base
confirm.resolve(CANCEL) # Esc — back out without deleting
again = await _step_until(lambda: _trophy_case(session, other_than=browser))
assert again is not None, "the browser never reopened after the confirm"
again.resolve(None) # Esc leaves the trophy case
again = await _step_until(lambda: _trophy_case(session))
assert again is browser, "nothing was deleted, so the same screen carries on"
again.handle("escape") # Esc leaves the trophy case
result = await task
finally:
if not task.done():
@@ -386,9 +388,9 @@ async def test_delete_a_disciplines_records_is_a_popup_over_the_browser(tui_ctx)
assert session._base_screen() is browser # the browser stays behind it
picker.resolve(CANCEL) # Esc — abandon the pick
again = await _step_until(lambda: _trophy_case(session, other_than=browser))
assert again is not None
again.resolve(None) # Esc
again = await _step_until(lambda: _trophy_case(session))
assert again is browser, "the pick was abandoned, so the same screen carries on"
again.handle("escape") # Esc
result = await task
finally:
if not task.done():
@@ -484,14 +486,15 @@ async def test_the_board_pins_its_discipline_heading_and_description(tui_ctx) ->
task.cancel()
async def test_trace_this_path_unwinds_to_the_menu_not_the_browser(
async def test_trace_this_path_nests_above_the_browser_and_comes_back_to_it(
tui_ctx, monkeypatch
) -> None:
"""After the Trace path hand-off, ``open_records`` returns instead of reopening.
"""Trace this path opens *over* the trophy case, and Esc from it lands back on the record.
The anti-deep-stack rule: trophy case → Trace this path → (trace screen closes)
must land on the main menu, not back in the browser — otherwise bouncing between
the boards and the trace screens piles up states the user has to Esc through.
This used to flatten: the browser came down first and the whole flow returned when the
trace closed, landing the reader on the main menu — a hand-built escape from a stack that
had no other way out. Navigation is a strict stack now, so a sub-view nests like any
other and ^W is what leaves the whole excursion at once.
"""
ctx = tui_ctx
session = ctx.ui.session
@@ -503,6 +506,10 @@ async def test_trace_this_path_unwinds_to_the_menu_not_the_browser(
async def fake_trace_path(ctx_, spec=""): # noqa: ANN001
walked.append(spec)
# The browser is still on the stack underneath while the trace runs.
assert any(
isinstance(s, SelectScreen) and s.title == "Trophy case" for s in session._stack
)
return 0
monkeypatch.setattr("meshterm.ui.trace_screen.open_trace_path", fake_trace_path)
@@ -518,7 +525,11 @@ async def test_trace_this_path_unwinds_to_the_menu_not_the_browser(
)
assert isinstance(dialog, RecordDialog)
dialog.resolve("trace") # "Trace this path"
result = await task # …and the flow returns; no browser re-entry to unwind
# The trace ran and the browser is back on top — the same object, not a rebuild.
again = await _step_until(lambda: _trophy_case(session))
assert again is browser
again.handle("escape") # only Esc leaves the trophy case
result = await task
finally:
if not task.done():
task.cancel()