From 042294e2a12dc089b9d588556927f94597fb1287 Mon Sep 17 00:00:00 2001 From: nesquena-hermes <[email protected]> Date: Mon, 1 Jun 2026 19:46:36 +0000 Subject: [PATCH] test: update sessions.js string-assertions for #3313 carry-forward rename #3313 applies the ephemeral-field carry-forward at all 5 wholesale S.messages replace sites (loadSession/_ensureMessagesLoaded/_loadOlderMessages/ _ensureAllMessagesLoaded/startGatewaySSE), renaming the replace RHS from msgs/next to _msgsToAssign/_nextToAssign. These pre-existing tests pinned the old literals; updated to match the new RHS (or made LHS-agnostic) while preserving the invariants they protect (bump-before-replace, session-switch guard, shorter-transcript guard). --- ...t_issue1937_endless_scroll_jumpstart_race.py | 17 ++++++++++++++--- tests/test_session_import_cli_sse_refresh.py | 5 ++++- tests/test_tool_call_history_paging.py | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/test_issue1937_endless_scroll_jumpstart_race.py b/tests/test_issue1937_endless_scroll_jumpstart_race.py index f2ec54f4..c772a4b0 100644 --- a/tests/test_issue1937_endless_scroll_jumpstart_race.py +++ b/tests/test_issue1937_endless_scroll_jumpstart_race.py @@ -122,10 +122,16 @@ def test_load_older_generation_check_runs_before_replace(): # --------------------------------------------------------------------------- def test_ensure_all_bumps_generation_before_replace(): - """Bump must happen BEFORE `S.messages = msgs` so racing prefetch sees it.""" + """Bump must happen BEFORE the wholesale `S.messages =` replace so racing prefetch sees it.""" + import re body = _function_body(SESSIONS_JS, "_ensureAllMessagesLoaded") bump_idx = body.rindex("_bumpMessagesGeneration()") - replace_idx = body.index("S.messages = msgs;") + # Match the wholesale replace by its LHS, not the RHS variable name — #3306 + # added an ephemeral-field carry-forward so the RHS is now `_msgsToAssign` + # rather than the literal `msgs`. The invariant we protect is bump-before-replace. + m = re.search(r"S\.messages\s*=\s*\w+;", body) + assert m is not None, "expected a wholesale `S.messages = ;` replace in _ensureAllMessagesLoaded" + replace_idx = m.start() assert bump_idx < replace_idx, ( "_ensureAllMessagesLoaded must bump the generation token BEFORE the " "wholesale replace, otherwise an in-flight prefetch's post-await " @@ -201,10 +207,15 @@ def test_ensure_all_resets_oldest_idx(): def test_ensure_all_guards_against_session_switch_mid_await(): """Same-session check must run after await — old version skipped this.""" + import re body = _function_body(SESSIONS_JS, "_ensureAllMessagesLoaded") await_idx = body.index("await api(") sid_check_idx = body.index("S.session.session_id !== sid", await_idx) - replace_idx = body.index("S.messages = msgs;", await_idx) + # #3306 renamed the replace RHS from `msgs` to `_msgsToAssign` (carry-forward); + # match by LHS so the ordering invariant survives the rename. + m = re.search(r"S\.messages\s*=\s*\w+;", body[await_idx:]) + assert m is not None, "expected a wholesale `S.messages = ;` replace after the await" + replace_idx = await_idx + m.start() assert await_idx < sid_check_idx < replace_idx, ( "_ensureAllMessagesLoaded must guard against session-switch races " "(re-check S.session.session_id after await) BEFORE wholesale-" diff --git a/tests/test_session_import_cli_sse_refresh.py b/tests/test_session_import_cli_sse_refresh.py index 62b9ad7a..3a726dc5 100644 --- a/tests/test_session_import_cli_sse_refresh.py +++ b/tests/test_session_import_cli_sse_refresh.py @@ -16,7 +16,10 @@ def test_sse_import_cli_guard_skips_shorter_transcript_overwrite(): assert "const next = res.session.messages.filter(m => m && m.role);" in sse_block assert "if (next.length < prev) return;" in sse_block assert "if (prev > 0 && !_isCliImportRefreshPrefixMatch(S.messages, next)) return;" in sse_block - assert "S.messages = next;" in sse_block + # #3306 added an ephemeral-field carry-forward before the assignment, so the + # replace RHS is now `_nextToAssign` (= carry-forward of `next`). The guard + # invariants above are what this test protects; the wholesale replace remains. + assert "S.messages = _nextToAssign;" in sse_block assert "S.session.message_count = next.length;" in sse_block assert "renderMessages({preserveScroll:true});" in sse_block diff --git a/tests/test_tool_call_history_paging.py b/tests/test_tool_call_history_paging.py index 23cf9b34..f7528c86 100644 --- a/tests/test_tool_call_history_paging.py +++ b/tests/test_tool_call_history_paging.py @@ -16,7 +16,7 @@ def test_sessions_js_resyncs_tool_calls_after_history_window_replacement(): assert "function _syncToolCallsForLoadedMessages(messages, sessionToolCalls)" in SESSIONS_JS assert "_syncToolCallsForLoadedMessages(msgs, data.session.tool_calls);" in SESSIONS_JS assert "S.messages = nextMessages;\n _syncToolCallsForLoadedMessages(nextMessages, responseSession.tool_calls);" in SESSIONS_JS - assert "S.messages = msgs;\n _messagesTruncated = false;\n _oldestIdx = 0;\n _syncToolCallsForLoadedMessages(msgs, data.session.tool_calls);" in SESSIONS_JS + assert "S.messages = _msgsToAssign;\n _messagesTruncated = false;\n _oldestIdx = 0;\n _syncToolCallsForLoadedMessages(msgs, data.session.tool_calls);" in SESSIONS_JS def test_sessions_js_clears_session_tool_calls_when_messages_have_own_metadata():