From 433ad2993910d573315d513b8c7a4660bfed5596 Mon Sep 17 00:00:00 2001 From: Frank Song Date: Sat, 16 May 2026 12:07:18 +0800 Subject: [PATCH] Fix compression reference card anchoring --- static/ui.js | 2 +- tests/test_auto_compression_card.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/static/ui.js b/static/ui.js index 0704cc33..c050811c 100644 --- a/static/ui.js +++ b/static/ui.js @@ -5562,7 +5562,7 @@ function renderMessages(options){ const turn=anchorSeg.closest('.assistant-turn'); const blocks=_assistantTurnBlocks(turn); if(blocks){ - blocks.appendChild(node); + blocks.insertBefore(node, anchorSeg); return; } const turnParent=turn && turn.parentElement; diff --git a/tests/test_auto_compression_card.py b/tests/test_auto_compression_card.py index f27760ec..21d7d5d0 100644 --- a/tests/test_auto_compression_card.py +++ b/tests/test_auto_compression_card.py @@ -274,6 +274,19 @@ def test_reference_message_uses_raw_transcript_position_before_anchor_fallback() assert "else _insertCompressionLikeNode(referenceNode);" in src +def test_reference_message_inserted_before_future_assistant_anchor(): + src = _read("static/ui.js") + start = src.find("function _insertCompressionLikeNodeByRawIdx") + assert start != -1, "raw-index insertion helper not found" + end = src.find("const preservedOnlyNode", start) + assert end != -1, "raw-index insertion helper end marker not found" + helper = src[start:end] + + assert "const anchorSeg=assistantSegments.get(anchorRawIdx);" in helper + assert "blocks.insertBefore(node, anchorSeg);" in helper + assert helper.index("blocks.insertBefore(node, anchorSeg);") < helper.index("const userRow=userRows.get(anchorRawIdx);") + + def test_reference_message_selection_prefers_latest_matching_marker(): src = _read("static/ui.js") start = src.find("function _latestCompressionReferenceMessage")