Files
hermes-webui/tests/test_session_jump_buttons.py
T
fe12eebbf3 perf(chat): virtualize long message transcripts (#500) (#4214)
* perf(chat): virtualize long message transcripts (#500)

* fix(chat): preserve virtual height cache on append (#500)

* fix(chat): bound virtual tail follow-up (#500)

* fix(chat): surface older history and bound virtual rerenders (#500)

* fix(chat): stabilize virtual history fallback (#500)

* fix(chat): preserve virtual compression anchors (#500)

* Keep virtualization regressions aligned with rebased sources (#500)

* fix(chat): preserve virtual heights across prepends (#500)

* test(update): isolate restart timing checks (#814)

* fix(chat): restore render contracts around virtual cache

* fix(chat): preserve legacy assistant anchor predicates

* fix(#3714): restore worklog-disclosure capture after HTML-cache early-return

Deep-review finding: the capture of _captureWorklogDetailDisclosureState was
moved before the HTML-cache fast-path return, failing the invariant test
test_render_rebuild_preserves_worklog_detail_disclosure_click_state (it must
not traverse the previous-session DOM when the cache path returns early).
Moved it back to just before inner.innerHTML='' (after the cache return).

Co-authored-by: Rod Boev <rod.boev@gmail.com>

* fix(#3714): restore Transparent Stream rehydration in HTML-cache fast path

Full-suite gate caught test_issue3820_chat_activity_display_mode failure: the
virtualization rewrite of the renderMessages HTML-cache fast-path block dropped
the _rehydrateTransparentStreamDom(inner) call (master has it; PR had 2 of 3
occurrences). On a cache-restore session switch, Transparent Stream controls
lost their property-assigned handlers. Restored the call in the same position
master has it (right after _sessionHtmlCacheSid=sid).

Co-authored-by: Rod Boev <rod.boev@gmail.com>

* fix(#3714): preserve live turn on scroll-rebuild even with zero streamed text

Opus ship-review residual (now fixed, not deferred): the live-turn re-attach
after a scroll-triggered virtualized rebuild was gated on _preservedLen>0, so a
turn showing only Activity/tool/worklog blocks with no streamed text yet (mid
tool-call) would not be preserved — scrolling up into history on a >80-row
transcript mid-stream could blink those live-only blocks for a frame. Broaden
the gate to also restore when the preserved turn has MORE structural blocks than
the rebuilt (lagging-S.messages) turn. Hoisted the _structuralCount helper above
the gate; whole-turn-vs-segment restore logic unchanged.

Co-authored-by: Rod Boev <rod.boev@gmail.com>

* chore(release): stamp v0.51.423 (Release OJ) for #500 transcript virtualization

---------

Co-authored-by: Rod Boev <rod.boev@gmail.com>
Co-authored-by: nesquena-hermes <agent@nesquena-hermes>
2026-06-14 19:11:32 -07:00

87 lines
4.5 KiB
Python

from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
UI_JS = (REPO / "static" / "ui.js").read_text(encoding="utf-8")
BOOT_JS = (REPO / "static" / "boot.js").read_text(encoding="utf-8")
INDEX_HTML = (REPO / "static" / "index.html").read_text(encoding="utf-8")
STYLE_CSS = (REPO / "static" / "style.css").read_text(encoding="utf-8")
I18N_JS = (REPO / "static" / "i18n.js").read_text(encoding="utf-8")
PANELS_JS = (REPO / "static" / "panels.js").read_text(encoding="utf-8")
CONFIG_PY = (REPO / "api" / "config.py").read_text(encoding="utf-8")
def _function_body(src: str, signature: str) -> str:
start = src.index(signature)
brace = src.index("{", start)
depth = 0
for i in range(brace, len(src)):
if src[i] == "{":
depth += 1
elif src[i] == "}":
depth -= 1
if depth == 0:
return src[start : i + 1]
raise AssertionError(f"function body not found: {signature}")
def test_session_jump_buttons_are_opt_in_and_keep_existing_bottom_button():
assert '"session_jump_buttons": False' in CONFIG_PY
assert '"session_jump_buttons"' in CONFIG_PY
assert "window._sessionJumpButtonsEnabled=!!s.session_jump_buttons" in BOOT_JS
assert "window._sessionJumpButtonsEnabled=false" in BOOT_JS
assert "session_jump_buttons: !!($('settingsSessionJumpButtons')||{}).checked" in PANELS_JS
scroll_listener = UI_JS[UI_JS.index("el.addEventListener('scroll'") : UI_JS.index("})();", UI_JS.index("el.addEventListener('scroll'"))]
assert "const showBottomButton=!_scrollPinned && el.scrollHeight-top-el.clientHeight>80" in scroll_listener
assert "_syncScrollToBottomCue(showBottomButton,{newMessage:_newMessageCueVisible})" in scroll_listener
assert "!_isSessionJumpButtonsEnabled()||_scrollPinned" not in UI_JS
def test_jump_to_session_start_button_loads_full_history_and_scrolls_top():
jump = _function_body(UI_JS, "async function jumpToSessionStart")
update = _function_body(UI_JS, "function _updateSessionStartJumpButton")
assert 'id="jumpToSessionStartBtn"' in INDEX_HTML
assert 'class="session-jump-btn session-jump-btn--start"' in INDEX_HTML
assert "data-i18n=\"session_jump_start\"" in INDEX_HTML
assert "data-i18n=\"session_jump_end\"" in INDEX_HTML
assert "data-i18n-aria-label=\"session_jump_start_label\"" in INDEX_HTML
assert "data-i18n-aria-label=\"session_jump_end_label\"" in INDEX_HTML
assert "_ensureAllMessagesLoaded" in jump
assert "_messageRenderWindowSize=Math.max(_currentMessageRenderWindowSize(),_messageRenderableMessageCount())" in jump
expand_idx = jump.index("_messageRenderWindowSize=Math.max(_currentMessageRenderWindowSize(),_messageRenderableMessageCount())")
top_idx = jump.index("container.scrollTop=0")
render_idx = jump.index("renderMessages({ preserveScroll:true })")
assert expand_idx < top_idx < render_idx
assert "_messageVirtualWindowKey=''" in jump
assert "renderMessages({ preserveScroll:true })" in jump
assert "container.scrollTop=0" in jump
assert "btn.style.display=(hasSession&&canRevealStart&&awayFromStart)?'flex':'none'" in update
def test_session_jump_buttons_match_pill_layout_without_regressing_default_arrow():
assert ".session-jump-btn" in STYLE_CSS
assert ".session-jump-btn--start{top:16px" in STYLE_CSS
assert ".session-jump-btn__text{display:none" in STYLE_CSS
assert ".messages.session-nav-enabled .scroll-to-bottom-btn" in STYLE_CSS
assert ".messages.session-nav-enabled .session-jump-btn__text{display:inline" in STYLE_CSS
assert "classList.toggle('session-nav-enabled',_isSessionJumpButtonsEnabled())" in UI_JS
def test_session_jump_buttons_are_i18n_localized_in_text_tooltip_and_aria():
english_literals = {
"session_jump_start": "Start",
"session_jump_start_label": "Jump to beginning of session",
"session_jump_end": "End",
"session_jump_end_label": "Jump to end of session",
"settings_label_session_jump_buttons": "Show session jump buttons",
"settings_desc_session_jump_buttons": "Show floating Start and End buttons while reading long session histories.",
}
for key in english_literals:
assert I18N_JS.count(f"{key}:") >= 8, f"missing locale entries for {key}"
for key, value in english_literals.items():
assert I18N_JS.count(f"{key}: '{value}'") == 1, f"non-English locale still uses English literal for {key}"
assert "document.querySelectorAll('[data-i18n-aria-label]')" in I18N_JS
assert "el.setAttribute('aria-label', val)" in I18N_JS