* 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>
76 lines
3.7 KiB
Python
76 lines
3.7 KiB
Python
from pathlib import Path
|
|
|
|
REPO = Path(__file__).resolve().parents[1]
|
|
SESSIONS_JS = (REPO / "static" / "sessions.js").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_loading_older_messages_expands_render_window_before_rendering():
|
|
body = _function_body(SESSIONS_JS, "async function _loadOlderMessages")
|
|
|
|
replace_idx = body.index("S.messages = nextMessages")
|
|
expand_idx = body.index("_messageRenderWindowSize=_currentMessageRenderWindowSize()")
|
|
render_idx = body.index("renderMessages({ preserveScroll: true });")
|
|
|
|
assert replace_idx < expand_idx < render_idx, (
|
|
"scroll-to-top paging must expand the DOM render window before renderMessages(); "
|
|
"otherwise fetched older messages stay hidden and only the hidden counter changes"
|
|
)
|
|
assert "if(typeof _messageIsRenderable==='function') return _messageIsRenderable(m);" in body
|
|
assert "Math.max(addedRenderable, MESSAGE_RENDER_WINDOW_DEFAULT)" in body
|
|
|
|
|
|
def test_loading_older_messages_preserves_viewport_without_bottom_snap():
|
|
body = _function_body(SESSIONS_JS, "async function _loadOlderMessages")
|
|
|
|
assert "renderMessages({ preserveScroll: true });" in body
|
|
assert "const viewportAnchor = (container && typeof _captureMessageViewportAnchor === 'function')" in body
|
|
assert "_captureMessageViewportAnchor()" in body
|
|
assert "_restoreMessageViewportAnchor(viewportAnchor, olderMsgs.length)" in body
|
|
assert "const restoredViaAnchor = (viewportAnchor && typeof _restoreMessageViewportAnchor === 'function')" in body
|
|
assert "if (!restoredViaAnchor) {" in body
|
|
assert "const virtualAddedHeight = (typeof _messageVirtualPrependedHeightDelta === 'function')" in body
|
|
assert "_messageVirtualPrependedHeightDelta(addedRenderable)" in body
|
|
assert "const addedHeight = Number.isFinite(virtualAddedHeight)" in body
|
|
assert "container.scrollTop = oldTop + addedHeight" in body
|
|
assert "container.scrollTop = newScrollH - prevScrollH" not in body
|
|
|
|
restore_idx = body.index("_restoreMessageViewportAnchor(viewportAnchor, olderMsgs.length)")
|
|
virtual_idx = body.index("_messageVirtualPrependedHeightDelta(addedRenderable)")
|
|
scroll_delta_idx = body.index("Math.max(0, newScrollH - prevScrollH)")
|
|
unpin_idx = body.rindex("_scrollPinned = false")
|
|
assert restore_idx < virtual_idx < scroll_delta_idx < unpin_idx
|
|
|
|
|
|
def test_loading_older_messages_marks_scroll_programmatic_while_anchoring():
|
|
body = _function_body(SESSIONS_JS, "async function _loadOlderMessages")
|
|
|
|
set_idx = body.index("_programmaticScroll = true;")
|
|
restore_idx = body.index("container.scrollTop = oldTop + addedHeight")
|
|
clear_idx = body.index("requestAnimationFrame(()=>{ _programmaticScroll = false; })")
|
|
assert set_idx < restore_idx < clear_idx
|
|
|
|
|
|
def test_loading_older_messages_captures_anchor_before_replacing_messages():
|
|
body = _function_body(SESSIONS_JS, "async function _loadOlderMessages")
|
|
|
|
anchor_idx = body.index("const viewportAnchor = (container && typeof _captureMessageViewportAnchor === 'function')")
|
|
replace_idx = body.index("S.messages = nextMessages")
|
|
render_idx = body.index("renderMessages({ preserveScroll: true });")
|
|
restore_idx = body.index("_restoreMessageViewportAnchor(viewportAnchor, olderMsgs.length)")
|
|
|
|
assert anchor_idx < replace_idx < render_idx < restore_idx
|