HERMES-GIELIE/tests/test_session_jump_buttons.py

87 lines
4.5 KiB
Python
Raw Permalink Normal View History

2026-05-08 18:31:43 +00:00
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
Release v0.51.334 — Release KX (new-message cue when scrolled up, #3631) (#3849) * fix(streaming): show new-message cue when preserving scroll position (#3545) # Conflicts: # static/ui.js # tests/test_issue1690_scroll_completion.py # tests/test_tars_scroll_reset_regressions.py * i18n: add missing Polish (pl) translation for session_new_message keys The PR added session_new_message / session_new_message_label to 12 of 13 locales; Polish was missing both, which fails the per-locale parity test. Co-authored-by: rodboev <rodboev@users.noreply.github.com> * fix(streaming): keep forced follow path for pinned users in preserve-scroll branch Codex CORE catch: the PR's preserve-scroll branch used 'if(_scrollPinned) scrollIfPinned()' which skips the synchronous bottom write unless distance>500 and can have its delayed settles cancelled by the DOM-rebuild scroll event — leaving a pinned reader a few lines above the settled final response. Restore master's _followMessagesAfterDomReplace() forced-scrollToBottom() path for pinned/near-bottom users; only genuinely scrolled-up (unpinned, not near bottom) users restore their viewport and get the new-message cue. Updated the 3 structure-pinning tests to assert the corrected (safer) shape while preserving their behavioral intent. Co-authored-by: rodboev <rodboev@users.noreply.github.com> * Release v0.51.334 — Release KX (new-message cue when scrolled up, #3631) New-message cue on the jump-to-bottom button when the user has scrolled up during a live turn (#3545/#3631, @rodboev). Deep-reviewed (Opus+Codex); maintainer fixes during re-gate: (1) restored master's forced follow path for pinned/near-bottom users (Codex CORE: scrollIfPinned could leave a pinned reader short of the settled response) + updated 3 structure-pinning tests to the corrected shape; (2) added missing Polish (pl) i18n keys (PR had 12/13). Full suite 8308, ESLint/scope-undef CLEAN, Opus SHIP-safe, Codex SAFE-TO-SHIP. Co-authored-by: rodboev <rodboev@users.noreply.github.com> --------- Co-authored-by: Rod Boev <rod.boev@gmail.com> Co-authored-by: Hermes Agent <hermes-agent@nesquena-hermes.local> Co-authored-by: rodboev <rodboev@users.noreply.github.com>
2026-06-08 22:58:13 +00:00
assert "_syncScrollToBottomCue(showBottomButton,{newMessage:_newMessageCueVisible})" in scroll_listener
2026-05-08 18:31:43 +00:00
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
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-15 02:11:32 +00:00
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
2026-05-08 18:31:43 +00:00
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():
2026-05-09 02:03:27 +00:00
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:
2026-05-08 18:31:43 +00:00
assert I18N_JS.count(f"{key}:") >= 8, f"missing locale entries for {key}"
2026-05-09 02:03:27 +00:00
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}"
2026-05-08 18:31:43 +00:00
assert "document.querySelectorAll('[data-i18n-aria-label]')" in I18N_JS
assert "el.setAttribute('aria-label', val)" in I18N_JS