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).
This commit is contained in:
nesquena-hermes
2026-06-01 19:46:36 +00:00
parent c0cfc1b975
commit 042294e2a1
3 changed files with 19 additions and 5 deletions

View File

@@ -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 = <var>;` 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 = <var>;` 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-"

View File

@@ -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

View File

@@ -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():