From 81085fcc9dc2e99d77129ef8504ab18eb99d00e5 Mon Sep 17 00:00:00 2001 From: Tristan Simas Date: Wed, 18 Nov 2026 11:35:27 -0500 Subject: [PATCH] history: a burst of arrivals shows its latest message, and the pin stacks the others' headers Tristan, 2026-11-18: "when there's a lot of messages that come in at once, maybe we should show the headers for all of them, like stacked, and then scroll up and show the most recent one. So it'd be like, three came in, here's the latest." One shared owner, both frontends: - `ArrivalBurst` (history_changes): messages published at the followed end within 4 s of each other are one burst; the pager hands every followed arrival to `PagingWindow.arrivals_followed` on both publish paths (an edge extended, a newest page shown). - `HeaderPin.pin` draws a stack: a "N new" count line, then the header of each earlier burst message whose head is above the top row (the latest 3), then the top row's own header as before. The pin draws the messages' own header blocks; nothing is collapsed or copied. - `PinsMessageHeader`: the reader scrolling up by hand ends the burst (the window's own scrolls only follow down, inside `layout_scroll`); `open_pinned` scrolls a chosen stacked message's head to the top row and ends it. Each window answers only `message_top(key)`. - Textual's `StickyHeader` draws its tuple through `LineBlockRow.drawn_blocks` and opens a clicked header; Qt's pin lays out one document per header and opens a tapped one, passing taps through as before when nothing is stacked. - Textual's `hold_arrival` places the latest shown arrival (from its head when it is taller than the window), not the first. Verified: Qt `arrival` drive at phone speed (BURST=5): one burst of 7, "7 new" over 3 stacked heads, a tap puts the chosen head on the top row; tests/textual/test_arrival_burst_stack.py the same in the terminal. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3 --- src/toad/client/fragments.py | 6 + src/toad/client/history_changes.py | 153 +++++++++++++++++++--- src/toad/client/history_pager.py | 12 ++ src/toad/qt/history.py | 45 +++++-- src/toad/widgets/conversation.py | 8 +- src/toad/widgets/message_divider.py | 36 +++-- src/toad/widgets/transcript_history.py | 16 ++- tests/textual/test_arrival_burst_stack.py | 63 +++++++++ tools/qt_drive.py | 53 +++++++- 9 files changed, 350 insertions(+), 42 deletions(-) create mode 100644 tests/textual/test_arrival_burst_stack.py diff --git a/src/toad/client/fragments.py b/src/toad/client/fragments.py index abb487a6b..2401c59c2 100644 --- a/src/toad/client/fragments.py +++ b/src/toad/client/fragments.py @@ -297,6 +297,12 @@ def source_identity(self) -> EventSourceKey | ToolCallId: def key(self) -> FragmentKey: return FragmentKey(self.source_identity, self.part_position.index) + @property + def pinned_dividers(self) -> tuple[Divider, ...]: + """The header a top row in this fragment pins, and an arrival burst stacks: none for a + fragment that draws no header.""" + return () + @property def details_link(self) -> FragmentDetails: return FragmentDetails(self.key) diff --git a/src/toad/client/history_changes.py b/src/toad/client/history_changes.py index 4bc9854e9..a7009d5ea 100644 --- a/src/toad/client/history_changes.py +++ b/src/toad/client/history_changes.py @@ -12,7 +12,7 @@ from abc import abstractmethod from contextlib import asynccontextmanager from dataclasses import dataclass, field -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, ClassVar from toad.client.reader_position import ( BlockPosition, @@ -21,8 +21,10 @@ ) +from toad.client.line_blocks import Divider, MutedRole + if TYPE_CHECKING: - from toad.client.line_blocks import Divider + from toad.client.fragments import FragmentKey, HistoryFragment from toad.client.transcript_fragments import TranscriptFragment from toad.widgets.history_anchor import HistoryWindow from toad.widgets.transcript_history import FragmentSpan, TranscriptPageView @@ -94,23 +96,113 @@ class PinnedHeader: width: int +@dataclass(frozen=True) +class BurstMessage: + """One message of an arrival burst: where it is drawn (`key`, its first arriving part) and + the header its flow draws, which the pin draws again.""" + + key: FragmentKey + header: Divider + + +@dataclass(frozen=True) +class StackedHeaders: + """The burst's headers a pin stacks above the top row's own: a count line, then each + earlier message of the burst whose head the reader has scrolled past. `keys[i]` is the + message `headers[i]` opens; the count line opens the earliest one.""" + + headers: tuple[Divider, ...] = () + keys: tuple[FragmentKey, ...] = () + + +NO_STACK = StackedHeaders() + + +@dataclass(frozen=True) +class ArrivalBurst: + """Messages that arrived together at the end a reader follows (Tristan, 2026-11-18: "show + the headers for all of them, like stacked, and then ... show the most recent one. So it'd + be like, three came in, here's the latest"). + + Arrivals whose publications come within `gap` seconds of each other are one burst; one + after the gap starts the next. The window shows the latest as it shows any arrival, and its + pin stacks the headers of the others the reader has scrolled past (`stack`). Nothing is + collapsed or copied: the pin draws the messages' own header blocks. The burst ends when + the reader scrolls up by hand or opens a stacked header (`PinsMessageHeader`).""" + + messages: tuple[BurstMessage, ...] = () + last: float = float("-inf") + gap: ClassVar[float] = 4.0 + shown: ClassVar[int] = 3 + """The most earlier headers stacked; the count line says how many came.""" + + def live(self, now: float) -> bool: + return bool(self.messages) and now - self.last <= self.gap + + def arrived(self, fragments: tuple[HistoryFragment, ...], now: float) -> ArrivalBurst: + """`fragments` arrived at the followed end: each message among them with a header + joins this burst, or starts the next one after the gap.""" + kept = self.messages if self.live(now) else () + seen = {message.key.source for message in kept} + joined = [] + for fragment in fragments: + if fragment.pinned_dividers and fragment.source_identity not in seen: + seen.add(fragment.source_identity) + joined.append(BurstMessage(fragment.key, fragment.pinned_dividers[-1])) + if not joined: + return self + return ArrivalBurst(kept + tuple(joined), now) + + def stack(self, window: PinsMessageHeader, pinned: PinnedHeader) -> StackedHeaders: + """The earlier messages whose head is scrolled above the top row, the most recent + `shown` of them, under a count line; none for a burst of one, or once the reader is + above the burst (no head is above the top row then). The top row's own message pins + its header as before and is not stacked twice.""" + if len(self.messages) < 2 or not pinned.width: + return NO_STACK + own = pinned.headers[-1:] + above = [message for message in self.messages[:-1] + if message.header not in own + and (top := window.message_top(message.key)) is not None and top < window.scroll_y] + if not above: + return NO_STACK + stacked = above[-self.shown:] + count = Divider.titled(f"{len(self.messages)} new", MutedRole) + return StackedHeaders((count, *(message.header for message in stacked)), + (above[0].key, *(message.key for message in stacked))) + + +NO_BURST = ArrivalBurst() + + class HeaderPin: """The overlay a history window floats over its top row: the header of the message the reader is in, while that header is scrolled above, so the reader of a long message still sees who - sent it to whom, and when. It draws the message's own header block, as the flow does, and - keeps no copy of the message. A plain mixin, as `LatestJumpBar` is: Textual's widget - metaclass refuses an `ABC` base and Qt's shiboken metaclass clashes with one.""" - - def pin(self, pinned: PinnedHeader) -> None: - """Draw the one header the window's top row needs, or none, in the column its message - draws it in, so it sits and wraps exactly as the flow's own header does.""" - if pinned.headers: - self.draw_pinned(pinned.headers[-1], pinned.x, pinned.width) - self.show_pin(bool(pinned.headers)) + sent it to whom, and when; above it, a burst's stacked headers (`ArrivalBurst`). It draws + the messages' own header blocks, as the flow does, and keeps no copy of a message. A plain + mixin, as `LatestJumpBar` is: Textual's widget metaclass refuses an `ABC` base and Qt's + shiboken metaclass clashes with one.""" + + stacked: StackedHeaders = NO_STACK + + def pin(self, pinned: PinnedHeader, stacked: StackedHeaders = NO_STACK) -> None: + """Draw the headers the window's top row needs, or none, in the column its message + draws them in, so each sits and wraps exactly as the flow's own header does.""" + self.stacked = stacked + headers = stacked.headers + pinned.headers[-1:] + if headers: + self.draw_pinned(headers, pinned.x, pinned.width) + self.show_pin(bool(headers)) + + def opened_at(self, index: int) -> FragmentKey | None: + """The message the pin's `index`th drawn header opens: a stacked one's, none for the + top row's own (the reader is already in that message).""" + keys = self.stacked.keys + return keys[index] if 0 <= index < len(keys) else None @abstractmethod - def draw_pinned(self, header: Divider, x: int, width: int) -> None: - """Draw `header` in the column at `x`, `width` wide, in the toolkit's unit.""" + def draw_pinned(self, headers: tuple[Divider, ...], x: int, width: int) -> None: + """Draw `headers`, top to bottom, in the column at `x`, `width` wide, in the toolkit's unit.""" @abstractmethod def show_pin(self, shown: bool) -> None: @@ -125,6 +217,10 @@ class PinsMessageHeader: `top_page` and `live_message_header` answer.""" sticky_header: HeaderPin + arrival_burst: ArrivalBurst + _restoring: bool + pinned_scroll_y: float = 0.0 + """The offset the pin was last drawn at: a reader's own scroll up from it ends a burst.""" def top_message_header(self) -> PinnedHeader: """The header of the message drawn on the window's top row, when that header is scrolled @@ -134,8 +230,33 @@ def top_message_header(self) -> PinnedHeader: def repin_header(self) -> None: """Pin from where the reader is now. The window calls this on every scroll offset and every committed geometry change: a reflow, a filter, replaced rows or a restored tab can - change the top row's message at an unchanged offset.""" - self.sticky_header.pin(self.top_message_header()) + change the top row's message at an unchanged offset. Only the reader scrolls a window up: + following, gliding and placing an arrival move it down or keep it (`layout_scroll`).""" + burst = self.arrival_burst + if burst.messages and self.scroll_y < self.pinned_scroll_y and not self._restoring: + burst = self.arrival_burst = NO_BURST + self.pinned_scroll_y = self.scroll_y + pinned = self.top_message_header() + self.sticky_header.pin(pinned, burst.stack(self, pinned) if burst.messages else NO_STACK) + + def open_pinned(self, index: int) -> bool: + """The reader chose the pin's `index`th header: a stacked one scrolls to its message, + whose head comes to the top row, and the burst ends. False for the top row's own.""" + key = self.sticky_header.opened_at(index) + if key is None: + return False + top = self.message_top(key) + self.arrival_burst = NO_BURST + if top is not None: + self.release_anchor() + self.scroll_y = top + self.repin_header() + return True + + @abstractmethod + def message_top(self, key: FragmentKey) -> float | None: + """The offset that puts the drawn message `key`'s first row on the window's top row, in + the window's unit; None when no drawn row holds it.""" class NoHistoryChange: diff --git a/src/toad/client/history_pager.py b/src/toad/client/history_pager.py index 0455fd045..d65d41d87 100644 --- a/src/toad/client/history_pager.py +++ b/src/toad/client/history_pager.py @@ -24,6 +24,7 @@ from agent_comms.messaging.message_reference import MessageReference from toad.client.fragments import FragmentKey, HistoryFragment +from toad.client.history_changes import NO_BURST, ArrivalBurst from toad.client.history_preparation import ( NEWER_END, OLDER_END, @@ -172,6 +173,15 @@ class PagingWindow(ReaderWindow): histories: set scroll_target_y: float max_scroll_y: float + arrival_burst: ArrivalBurst = NO_BURST + """The messages that last arrived together at the end the reader follows.""" + + def arrivals_followed(self, arrivals: tuple[HistoryFragment, ...]) -> None: + """`arrivals` were published at the followed end: they join the burst while the reader + follows it, or while the burst is still arriving (Textual stops following where it + shows a tall arrival from its head).""" + if arrivals and (self.follows_tail or self.arrival_burst.live(monotonic())): + self.arrival_burst = self.arrival_burst.arrived(arrivals, monotonic()) lookahead: DirectionalPreparation presentation_budget: PresentationBudget configuration_state: object @@ -808,6 +818,7 @@ def current() -> bool: arrivals = self._source_state.arriving(staged, followed_end) await self._extend_and_trim(edge, end, local, protected, staged, current=current) self._require_can_draw() + self.window.arrivals_followed(arrivals) self.hold_arrival(arrivals) self.repaint(arrivals) self.rows_published() @@ -1205,6 +1216,7 @@ async def show_newest(self, request: ReplacementViewportRequest, *, self._generation += 1 published = await self.jump_latest(request, publication_current) if published: + self.window.arrivals_followed(arrivals) self.repaint(arrivals, continuing=retained) return published diff --git a/src/toad/qt/history.py b/src/toad/qt/history.py index c77f12676..175a6ad88 100644 --- a/src/toad/qt/history.py +++ b/src/toad/qt/history.py @@ -729,26 +729,29 @@ class QtStickyHeader(HeaderPin, QWidget): """`HeaderPin` floated over the history's top edge, drawn by the history rows' own delegate. A child of the window, not the viewport, as `QtJumpBar` is: the viewport's children scroll with its contents, and QScroller's grab on the viewport would take its - taps. Opaque, so the row it covers does not show through, as Textual's overlay is.""" + taps. Opaque, so the row it covers does not show through, as Textual's overlay is. Taps + pass through to the row beneath, except on a burst's stacked headers, which open their + messages.""" def __init__(self, window: QtHistoryWindow) -> None: super().__init__(window) self.history_window = window - self.document: QTextDocument | None = None + self.documents: tuple[QTextDocument, ...] = () self.drawn: tuple = () self.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents) self.hide() - def draw_pinned(self, header: Divider, x: int, width: int) -> None: - """Every scroll offset pins; only a different header, column, font or link context - lays the header out again.""" + def draw_pinned(self, headers: tuple[Divider, ...], x: int, width: int) -> None: + """Every scroll offset pins; only different headers, column, font or link context lay + them out again.""" window = self.history_window - drawn = (header, x, width, window.font().key(), window.rows.links_revision) + drawn = (headers, x, width, window.font().key(), window.rows.links_revision) if drawn == self.drawn: return self.drawn = drawn - self.document = window.rows.header_document(header, window.font(), width) - self.resize(width, int(self.document.size().height())) + self.documents = tuple(window.rows.header_document(header, window.font(), width) for header in headers) + self.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents, not self.stacked.keys) + self.resize(width, sum(int(document.size().height()) for document in self.documents)) self.move(window.viewport().mapTo(window, QPoint(x, 0))) self.raise_() self.update() @@ -757,14 +760,28 @@ def show_pin(self, shown: bool) -> None: if self.isVisible() != shown: self.setVisible(shown) + def mouseReleaseEvent(self, event) -> None: # type: ignore[override] + """A tap on a stacked header opens its message; the top row's own passes through.""" + y, top = event.position().y(), 0 + for index, document in enumerate(self.documents): + top += int(document.size().height()) + if y < top: + if self.history_window.open_pinned(index): + event.accept() + return + break + event.ignore() + def paintEvent(self, event) -> None: # type: ignore[override] - if self.document is None: + if not self.documents: return painter = QPainter(self) painter.fillRect(self.rect(), QColor(BackgroundColour.rgb(self.history_window.rows.renderer.scheme).hex)) context = QAbstractTextDocumentLayout.PaintContext() context.palette = self.palette() - self.document.documentLayout().draw(painter, context) + for document in self.documents: + document.documentLayout().draw(painter, context) + painter.translate(0, document.size().height()) painter.end() @@ -1422,6 +1439,14 @@ def live_message_header(self) -> PinnedHeader: """Qt draws no live blocks: the draft is rows, so a row under the top edge pins.""" return PinnedHeader((), 0, 0) + def message_top(self, key) -> float | None: + """Qt keeps rows by pixel: the row's top under the viewport, plus the offset.""" + model_rows = self.model_rows + row = model_rows.row_of(key) + if row < 0: + return None + return self.scroll_y + self.visualRect(model_rows.index(row, 0)).top() + def placements(self, bodies) -> Iterator[tuple[object, int]]: return iter(()) diff --git a/src/toad/widgets/conversation.py b/src/toad/widgets/conversation.py index d434837ee..d58e8871d 100644 --- a/src/toad/widgets/conversation.py +++ b/src/toad/widgets/conversation.py @@ -173,6 +173,8 @@ from toad.widgets.goal_bar import GoalBar from toad.widgets.history_anchor import HistoryWindow from toad.client.history_changes import PinsMessageHeader +from toad.client.fragments import FragmentKey +from toad.client.reader_position import FragmentPosition from toad.widgets.input_delivery import InputDeliveryBar, InputDeliveryDetails from toad.widgets.markdown_note import MarkdownNote, StopReasonNote from toad.widgets.menu import Menu @@ -488,7 +490,7 @@ class Window( def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) self.jump_bar = JumpBar(BackToBottom(JumpBar.label)) - self.sticky_header = StickyHeader() + self.sticky_header = StickyHeader(self) def apply_native_layout(self) -> None: super().apply_native_layout() @@ -502,6 +504,10 @@ def watch_scroll_y(self, old_value: float, new_value: float) -> None: super().watch_scroll_y(old_value, new_value) self.repin_header() + def message_top(self, key: FragmentKey) -> float | None: + location = FragmentPosition(key, 0.0, 1, block=0).page(self) + return location.destination(self, 0.0) if location.laid_out(self) else None + def prepare_viewport(self) -> None: """Committed geometry can change the top row's message at an unchanged offset (a reflow, a filter, replaced pages, a restored tab); pin from that scene too.""" diff --git a/src/toad/widgets/message_divider.py b/src/toad/widgets/message_divider.py index d859c7313..74e93bebd 100644 --- a/src/toad/widgets/message_divider.py +++ b/src/toad/widgets/message_divider.py @@ -36,9 +36,9 @@ RowAcquisition, RichLineRenderer, ) -from toad.client.history_changes import HeaderPin +from toad.client.history_changes import HeaderPin, PinsMessageHeader from toad.widgets.agent_activity import AgentActivityPresentation -from textual.events import Mount +from textual.events import Click, Mount from textual import on @@ -65,9 +65,14 @@ def update_block(self, block: LineBlock) -> None: def line_sets(self) -> tuple[BlockLines, ...]: return (self.prepared_lines(self.size.width),) + @property + def drawn_blocks(self) -> tuple[LineBlock, ...]: + """The blocks this row draws, top to bottom: its one block.""" + return (self.block,) + def prepared_lines(self, width: int) -> BlockLines: measured = self._lines.plain( - width, RichLineRenderer(self.line_theme, width), (self.block,) + width, RichLineRenderer(self.line_theme, width), self.drawn_blocks ) self._lines = measured return measured.lines @@ -94,26 +99,41 @@ def get_selection(self, selection: Selection) -> tuple[str, str]: class StickyHeader(HeaderPin, StartsHidden, ScreenOverlay, LineBlockRow): - """`HeaderPin` as a line block docked over the window's top row, drawn as the flow draws - the message's own header block.""" + """`HeaderPin` as line blocks docked over the window's top row, drawn as the flow draws the + messages' own header blocks. A click on a stacked header opens its message.""" ALLOW_SELECT = False - def __init__(self) -> None: + def __init__(self, window: PinsMessageHeader) -> None: super().__init__(Gap()) + self.window = window + self.headers: tuple[LineBlock, ...] = () def apply_native_layout(self) -> None: super().apply_native_layout() self.styles.dock = "top" self.styles.layer = "float" - def draw_pinned(self, header: Divider, x: int, width: int) -> None: - self.update_block(header) + @property + def drawn_blocks(self) -> tuple[LineBlock, ...]: + return self.headers + + def draw_pinned(self, headers: tuple[Divider, ...], x: int, width: int) -> None: + if headers != self.headers: + self.headers, self._lines = headers, NoRows() + self.refresh(layout=True) if self.styles.width is None or self.styles.width.value != width: self.styles.width = width if self.styles.offset.x.value != x: self.styles.offset = (x, 0) + @on(Click) + def open_header(self, event: Click) -> None: + """The header under the click opens its message, as a tap on Qt's pin does.""" + span = self.prepared_lines(self.size.width).block_span(lambda span: span.contains(event.y)) + if span.placed_by(lambda span: self.window.open_pinned(span.index), lambda: False): + event.stop() + def show_pin(self, shown: bool) -> None: self.display = shown diff --git a/src/toad/widgets/transcript_history.py b/src/toad/widgets/transcript_history.py index 8783d43ef..e414774c1 100644 --- a/src/toad/widgets/transcript_history.py +++ b/src/toad/widgets/transcript_history.py @@ -869,15 +869,19 @@ def cascade_runs(self) -> Iterable[int]: return (page.arrival_run.cascade_rows() for page in self.pages) def hold_arrival(self, arrivals: tuple[TranscriptFragment, ...]) -> None: - """The first shown arriving message places a following reader: from its head when it is taller than the window.""" + """The latest shown arriving message places a following reader, from its head when it is + taller than the window: a burst shows its most recent message, and the pin stacks the + others' headers (`ArrivalBurst`).""" window = self.window if not window.shown: return - for head in arrivals: - page = self.page_holding(head.key) - if head.shown_in(page.visible_categories): - window.reader_position = window.reader_position.arrived(page, head.key) - return + shown = [fragment for fragment in arrivals + if fragment.shown_in(self.page_holding(fragment.key).visible_categories)] + if not shown: + return + latest = shown[-1].source_identity + head = next(fragment for fragment in shown if fragment.source_identity == latest) + window.reader_position = window.reader_position.arrived(self.page_holding(head.key), head.key) def repaint(self, fragments: tuple[TranscriptFragment, ...] = (), *, continuing=()) -> None: phase = self.effect_phase(ARRIVAL) diff --git a/tests/textual/test_arrival_burst_stack.py b/tests/textual/test_arrival_burst_stack.py new file mode 100644 index 000000000..c95fe8f90 --- /dev/null +++ b/tests/textual/test_arrival_burst_stack.py @@ -0,0 +1,63 @@ +"""A burst of arrivals: the window shows the latest, and its pin stacks the others' headers. + +Tristan, 2026-11-18: "when there's a lot of messages that come in at once, maybe we should +show the headers for all of them, like stacked, and then scroll up and show the most recent +one. So it'd be like, three came in, here's the latest." Qt's `arrival` drive (BURST=5) +checks the same state on the phone's layout; this is the terminal's. +""" + +import os +from pathlib import Path + +from support.textual_steps import refresh_chat +from toad.widgets.comms_chat import CommsChatView + +BURST = 5 + + +async def test_a_burst_stacks_the_earlier_headers_and_a_click_opens_one(workspace, tmp_path): + workspace.thread("sender", "burst", running=True) + comms = workspace.comms + for index in range(30): + comms.messaging.send("sender", "#burst", f"Message {index}: " + "earlier body " * 6) + shots = Path(os.environ.get("BURST_SHOTS", tmp_path)) + async with workspace.app(size=(80, 30)) as ui: + app, pilot = ui.textual + await ui.open_channel("#burst", actor="sender") + chat = app.screen.query_one(CommsChatView) + history, window = chat.message_history, chat.window + await ui.until(lambda: history.state.accepts_source_work, why="the channel's messages") + await ui.until(lambda: window.follows_tail, why="the reader on the tail") + + # Messages a third of the window tall, all at once: the earlier heads leave the top row. + for index in range(BURST): + comms.messaging.send("sender", "#burst", f"BURST {index}\n" + "\n".join( + f"line {row} of burst message {index}" for row in range(8))) + await refresh_chat(chat) + await ui.until_shows(f"BURST {BURST - 1}") + pin = window.sticky_header + await ui.until(lambda: pin.stacked.keys, why="the burst's earlier headers stacked", seconds=15) + app.save_screenshot("burst-stack.svg", str(shots)) + + burst = window.arrival_burst.messages + assert len(burst) == BURST, [message.header.label for message in burst] + above = [message for message in burst[:-1] if window.message_top(message.key) < window.scroll_y] + assert above, "every burst head is on screen" + lines = pin.prepared_lines(pin.size.width) + assert pin.display and pin.headers[0].label == f"{BURST} new", pin.headers[:1] + assert [header.label for header in pin.stacked.headers[1:]] == [ + message.header.label for message in above[-type(window.arrival_burst).shown:]] + latest = window.message_top(burst[-1].key) + assert latest is not None and latest < window.scroll_y + window.scrollable_content_region.height, \ + "the latest message is not on screen" + + # A click on the first stacked header opens its message: its head on the top row. + chosen = pin.stacked.keys[1] + first = lines.block_span(lambda span: span.index == 1).first + await pilot.click(pin, offset=(2, first)) + await ui.until(lambda: window.message_top(chosen) == window.scroll_y, + why="the clicked message's head on the top row") + await pilot.pause() + app.save_screenshot("burst-opened.svg", str(shots)) + assert not window.arrival_burst.messages and not pin.stacked.keys + assert not window.follows_tail diff --git a/tools/qt_drive.py b/tools/qt_drive.py index d319ab7e4..4ef38a90c 100644 --- a/tools/qt_drive.py +++ b/tools/qt_drive.py @@ -907,7 +907,8 @@ def pinned(self) -> dict[str, object]: pin = window.sticky_header top = window.top_page() return dict(shown=pin.isVisible(), - text=pin.document.toPlainText().strip() if pin.document is not None else "", + text="\n".join(document.toPlainText().strip() for document in pin.documents), + stacked=len(pin.stacked.keys), top=getattr(top, "under", None) and (top.under.block, top.under.row), geometry=(pin.x(), pin.y(), pin.width(), pin.height())) @@ -2462,6 +2463,16 @@ def wrapper(*arguments, **options): setattr(owner, name, timing(name, call)) scrolled_up = bool(os.environ.get("SCROLLED")) window = view.messages + # Each publish at the followed end, and the burst it leaves (`ArrivalBurst`). + followed: list[tuple[float, int, bool, int]] = [] + handed = window.arrivals_followed + + def followed_arrivals(arrivals): + following = window.follows_tail + handed(arrivals) + followed.append((round(time.monotonic() - started, 2), len(arrivals), following, + len(window.arrival_burst.messages))) + window.arrivals_followed = followed_arrivals if scrolled_up: # A reader scrolled up: arrivals must not move what they read, and the jump bar shows. window.scroll_y = max(0, window.scroll_y - 300) @@ -2548,6 +2559,46 @@ def wrapper(*arguments, **options): key=lambda gap: -gap[1])[:6], flush=True) self.report("arrival", updates=len(updates), longest_stall_ms=gaps[-1], flicker=flicker, plain_first_draws=plain, queue_hide_then_show=flips, queue_changes=len(toggles), largest_scroll_step=max(map(abs, jumps), default=0)) + print("followed arrivals (s, fragments, following, burst size after):", followed, flush=True) + if not scrolled_up: + await self.burst_stack(window, burst) + + async def burst_stack(self, window, burst: int) -> None: + """Tristan, 2026-11-18: "show the headers for all of them, like stacked, and then ... show + the most recent one". After the burst, the window shows its latest message, and the pin + stacks, under a count line, the header of each earlier message whose head is above the + top row; a tap on a stacked header brings that message's head to the top row.""" + arrived = window.arrival_burst.messages + pin = window.sticky_header + above = [message for message in arrived[:-1] + if (top := window.message_top(message.key)) is not None and top < window.scroll_y] + texts = [document.toPlainText().strip() for document in pin.documents] + latest_top = window.message_top(arrived[-1].key) if arrived else None + self.report("burst-stack", arrived=len(arrived), above=len(above), stacked=len(pin.stacked.keys), + shown=pin.isVisible(), pin=texts, following=window.follows_tail, + latest_on_screen=latest_top is not None + and latest_top < window.scroll_y + window.viewport().height()) + if burst >= 5: + assert len(arrived) >= burst, f"the burst holds {len(arrived)} messages of {burst} posted" + assert above, "every burst message's head is on screen: nothing to stack at this height" + if not above: + return + assert latest_top is not None and latest_top < window.scroll_y + window.viewport().height(), \ + "the burst's latest message is not on screen" + assert pin.isVisible() and pin.stacked.keys, f"{len(above)} burst heads above the top row, none stacked" + assert texts[0] == f"{len(arrived)} new", f"the stack's count line reads {texts[0]!r}" + for message, text in zip(above[-type(window.arrival_burst).shown:], texts[1:]): + assert message.header.label.split()[0] in text, f"stacked {text!r} is not {message.header.label!r}" + # A tap on the first stacked header (below the count line) opens its message. + chosen = pin.stacked.keys[1] + y = int(pin.documents[0].size().height() + pin.documents[1].size().height() / 2) + QTest.mouseClick(pin, Qt.MouseButton.LeftButton, Qt.KeyboardModifier.NoModifier, QPoint(20, y)) + await asyncio.sleep(0.6) + top = window.message_top(chosen) + self.report("burst-opened", head_offset=None if top is None else round(top - window.scroll_y), + following=window.follows_tail, stacked=len(pin.stacked.keys), burst=len(window.arrival_burst.messages)) + assert top is not None and abs(top - window.scroll_y) <= 1, "the tapped message's head is not on the top row" + assert not window.arrival_burst.messages and not pin.stacked.keys, "opening a stacked header left the burst" class CliSyncScenario(Scenario):