HERMES-GIELIE/tests/test_issue1360_streaming_scroll_hardening.py
nesquena-hermes 3edbec7c97
stage #4613 (dso2ng): preserve reader scroll position across re-render/reload (#4675)
Sticky-unpin across idle renderMessages(), 3-tier anchor restore (data-message-anchor-key
-> data-session-msg-idx -> data-msg-idx) for tail-window->full-session reloads, deferred
external refresh while unpinned (flushed on explicit scrollToBottom), iOS/touch momentum
protection. CONFLICT RESOLVED with tonight's shipped #4584: kept #4584's deltaY<-30
jitter-resistant unpin threshold AND #4613's _markMessageTouchScrollIntent(true) on touchmove
(both present, 34 scroll-family tests pass). Authoritative head 03343e04b3f2.

Co-authored-by: nesquena-hermes <agent@nesquena-hermes>
Co-authored-by: dso2ng <dso2ng@users.noreply.github.com>
2026-06-21 23:57:24 -07:00

79 lines
3.3 KiB
Python

"""Regression tests for #1360: streaming must not re-pin user scroll."""
from pathlib import Path
REPO = Path(__file__).parent.parent
UI_JS = (REPO / "static" / "ui.js").read_text(encoding="utf-8")
STYLE_CSS = (REPO / "static" / "style.css").read_text(encoding="utf-8")
def _extract_function(src: str, name: str) -> str:
marker = f"function {name}("
idx = src.find(marker)
assert idx != -1, f"{name} not found"
depth = 0
for i, ch in enumerate(src[idx:], idx):
if ch == "{":
depth += 1
elif ch == "}":
depth -= 1
if depth == 0:
return src[idx:i + 1]
raise AssertionError(f"Could not extract {name}")
def test_messages_scroller_disables_browser_scroll_anchoring():
assert "overflow-anchor:none" in STYLE_CSS, (
"#messages must disable browser scroll anchoring so tool/card inserts "
"cannot yank the transcript while the user reads earlier content."
)
def test_scroll_repin_dead_zone_is_wider_for_mac_app_windows():
assert "clientHeight<250" in UI_JS or "bottomDistance<250" in UI_JS, (
"The near-bottom re-pin threshold should be at least 250px so small "
"macOS app windows and trackpad momentum do not re-pin too eagerly."
)
def test_queue_card_measurement_respects_manual_unpin_even_when_idle():
fn = _extract_function(UI_JS, "_renderQueueChips")
measurement_idx = fn.find("setTimeout(()=>")
assert measurement_idx != -1, "queue card measurement timeout not found"
measurement_block = fn[measurement_idx:measurement_idx + 500]
assert "scrollIfPinned()" in measurement_block
assert "scrollToBottom()" not in measurement_block, (
"queue-card layout measurement is a background update; it must not clear "
"manual _messageUserUnpinned state by calling explicit scrollToBottom()."
)
def test_queue_pill_click_respects_manual_unpin_even_when_idle():
fn = _extract_function(UI_JS, "_updateQueuePill")
click_idx = fn.find("pill.onclick=()=>")
assert click_idx != -1, "queue pill click handler not found"
click_block = fn[click_idx:click_idx + 700]
assert "scrollIfPinned()" in click_block
assert "scrollToBottom()" not in click_block, (
"queue-pill expansion is a layout update, not an explicit transcript jump; "
"it must not reset manual unpin state."
)
def test_idle_render_preserves_manual_unpin_until_explicit_bottom():
render_body = _extract_function(UI_JS, "renderMessages")
scroll_helper = _extract_function(UI_JS, "_scrollAfterMessageRender")
assert "preserveScroll||_messageUserUnpinned" in render_body.replace(" ", ""), (
"renderMessages() must capture a scroll snapshot whenever the reader is "
"manually unpinned, even for idle/non-preserve renders."
)
assert "if(_messageUserUnpinned){" in scroll_helper.replace(" ", ""), (
"idle render must restore the manually-unpinned viewport instead of "
"falling through to scrollToBottom()."
)
manual_unpin_block = scroll_helper[scroll_helper.index("if(_messageUserUnpinned)") : scroll_helper.index("scrollToBottom();")]
assert "_restoreMessageScrollSnapshot(scrollSnapshot);" in manual_unpin_block
assert "_maybeShowNewMessageScrollCue(scrollSnapshot);" in manual_unpin_block