Files
hermes-webui/tests/test_issue3709_thinking_double_render.py
T
e3a7c93dc6 [HELD — independent review pending] Release v0.51.294 — stage-3401 (live-to-final redesign #3401 + 4 deep-review fixes) (#3741)
* Harden interrupted recovery control filtering

* Redesign live-to-final assistant replies

* Fix live activity anchor test fixture

* Fix CI lint issues for live reply tests

* Strengthen live progress prompt contract

* Recover PR #3401 refresh on origin/master

* Repair live-to-final refresh regressions

* Fix live worklog refresh regressions

* Show live footer timer on initial stream start

* Restore live stream shell after reload

* Preserve per-frame live SSE replay cursors

* Preserve reasoning as Worklog Thinking cards

* Quiet Worklog Thinking card styling

* Align Worklog Thinking card styling

* Scope live Worklog Thinking cards by segment

* Suppress exact duplicate settled Thinking

* Close #3401 merge review test gaps

* fix(#3401): resolve 4 deep-review regressions (inline-think, reconnect-dup, neon skin, busy-gate worklog)

Deep review (Codex diff-vs-master + live-browser drive) of the live-to-final refactor
surfaced 4 regressions vs master that the rewritten suite no longer guarded:

1. Inline <think>…</think>answer reasoning vanished — _assistantReasoningPayloadText
   used $-anchored regexes so a leading think block + visible answer extracted nothing
   and the Thinking card never rendered. Removed the 3 $ anchors to match the
   (non-anchored) display stripper. Live: inline-think thinking-only turn now renders.
2. (CORE) reconnect/reload duplicated the live reply — _rememberRunJournalCursor advanced
   a closure-local seq but never wrote INFLIGHT[activeSid].lastRunJournalSeq, so a reload
   replayed the journal from after_seq=0 over restored lastAssistantText. Now mirrors the
   cursor onto INFLIGHT + schedules a throttled persist.
3. Neon skin silently broke — PR deleted the :root[data-skin="neon"] CSS but left Neon in
   the picker. Restored the neon CSS block from master.
4. Settled tool-worklog rebuild gated purely on !S.busy — dropped every prior settled
   turn's worklog when renderMessages re-ran during an active stream (switch-back to an
   in-progress session). Restored master's !S.busy || (S.toolCalls && S.toolCalls.length).
   Live: busy re-render now preserves tool cards (4→4, was 4→0).

Live-verified all 4 + confirmed #3709/#3592 invariants still hold (1 thinking card, none
below footer; distinct siblings preserved). + tests/test_issue3401_deep_review_fixes.py (7).

* test(#3401): realign 3 stale source-shape assertions to the deep-review fixes

Fix commit changed two source literals that existing stage tests scanned for:
- test_live_activity_timeline.py (x2): split anchor 'if(!S.busy){' → the restored
  'if(!S.busy || (S.toolCalls&&S.toolCalls.length)){' guard (fix 4).
- test_run_journal_frontend_static.py: 'after_seq=0' not in source — fix 2's comment
  contained that literal; rephrased the comment to 'the zero floor (after_seq of 0)'.
Intent of all three assertions unchanged; only the matched string updated. No code
behavior change.

* docs(changelog): v0.51.294 — Release JJ (stage-3401, #3401 live-to-final redesign)

---------

Co-authored-by: Frank Song <franksong2702@gmail.com>
Co-authored-by: Nathan-Hermes <nesquena-hermes@users.noreply.github.com>
Co-authored-by: nesquena-hermes <[email protected]>
2026-06-06 12:12:37 -07:00

144 lines
5.4 KiB
Python

"""#3709 -- #3401 Worklog Thinking must not render exact duplicates.
Master fixed a double-render bug in the older Activity rendering path: a turn
with tools plus a sibling thinking-only message could show the same Thinking
card twice. #3401 replaces that old structure with a folded Worklog made of
sibling items: process prose, Thinking Card, and Tool Card/Group.
These static assertions keep the #3709 invariant in the #3401 model:
* settled Thinking is rendered through the Worklog item path, not the old inline
sibling path below the answer;
* exact duplicate Thinking cards are keyed by normalized content and suppressed;
* different sibling reasoning can still become distinct Worklog items.
"""
from __future__ import annotations
import re
from pathlib import Path
UI_JS = (Path(__file__).resolve().parent.parent / "static" / "ui.js").read_text(encoding="utf-8")
def _render_messages_body() -> str:
start = UI_JS.find("function renderMessages(")
assert start != -1, "renderMessages() not found"
return UI_JS[start:start + 80000]
def _function_body(name: str) -> str:
match = re.search(rf"function\s+{re.escape(name)}\s*\(", UI_JS)
assert match, f"{name}() not found"
brace = UI_JS.find("{", match.end())
assert brace != -1, f"{name}() has no body"
depth = 1
i = brace + 1
in_string = None
escaped = False
in_line_comment = False
in_block_comment = False
while i < len(UI_JS) and depth:
ch = UI_JS[i]
nxt = UI_JS[i + 1] if i + 1 < len(UI_JS) else ""
if in_line_comment:
if ch == "\n":
in_line_comment = False
i += 1
continue
if in_block_comment:
if ch == "*" and nxt == "/":
in_block_comment = False
i += 2
continue
i += 1
continue
if in_string:
if escaped:
escaped = False
elif ch == "\\":
escaped = True
elif ch == in_string:
in_string = None
i += 1
continue
if ch == "/" and nxt == "/":
in_line_comment = True
i += 2
continue
if ch == "/" and nxt == "*":
in_block_comment = True
i += 2
continue
if ch in ("'", '"', "`"):
in_string = ch
i += 1
continue
if ch == "{":
depth += 1
elif ch == "}":
depth -= 1
i += 1
return UI_JS[brace + 1:i - 1]
def test_settled_thinking_renders_through_worklog_item_path():
body = _render_messages_body()
assert "_appendWorklogStep(state.group, anchorRow, cards, thinkingText" in body, (
"Settled Thinking should render through the #3401 Worklog item path."
)
assert "_thinkingActivityNode(thinkingText, false)" in UI_JS, (
"Thinking should remain a dedicated Worklog Thinking Card node."
)
assert "data-worklog-thinking-card" in UI_JS, (
"Thinking Cards need a stable Worklog-specific hook."
)
def test_settled_worklog_thinking_uses_content_key_for_exact_duplicate_suppression():
body_min = re.sub(r"\s+", "", _render_messages_body())
assert "thinkingKey:thinkingText?`thinking:${_normalizeThinkingEchoCompare(thinkingText)}`:''" in body_min, (
"Settled Worklog should suppress duplicate Thinking by normalized content, "
"not by assistant message index."
)
append_body = _function_body("_appendWorklogStep")
assert "seenReasons.has(thinkingKey)" in append_body
assert "seenReasons.add(thinkingKey)" in append_body
def test_exact_echo_suppression_compares_turn_visible_texts():
body = _render_messages_body()
helper = _function_body("_worklogReasoningTextFromMessage")
assert "assistantTurnVisibleContentByRawIdx" in body
assert "_worklogReasoningTextFromMessage(m, rawIdx, toolCallAssistantIdxs, displayContent, turnFinalVisibleContent, turnVisibleContents)" in body
assert "_stripVisibleAssistantEchoFromThinking(thinkingText, visibleContent, turnFinalVisibleContent, ...visibleTexts)" in helper, (
"A thinking-only sibling that exactly echoes the visible process/final text "
"should be suppressed after settlement."
)
def test_distinct_sibling_reasoning_is_still_available_to_worklog():
body = _render_messages_body()
assert "for(const aIdx of assistantThinking.keys())" in body, (
"Each assistant reasoning entry should still be eligible for a Worklog item."
)
assert "const thinkingText=thinkingIdx!==null?assistantThinking.get(thinkingIdx):''" in body
assert "seenReasons:state.seenReasons" in body, (
"Duplicate suppression should be scoped to rendered Worklog keys, not by "
"dropping reasoning metadata up front."
)
def test_old_inline_activity_double_render_path_is_not_restored():
body = _render_messages_body()
assert "!cards.length&&assistantThinking.has(aIdx)" not in body, (
"The old thinking-only inline Activity branch should not return in the "
"#3401 Worklog model."
)
assert "anchorRow.insertAdjacentHTML('beforeend',_thinkingCardHtml(assistantThinking.get(aIdx)))" not in body, (
"Thinking must not be appended below the final answer/footer."
)
assert "mergedThinking" not in body, (
"The old Activity mergedThinking implementation should not be required "
"after #3401 moves Thinking into Worklog sibling items."
)