A reactivated older conversation wasn't bumped to the top / into Today until a manual refresh when the viewing tab was backgrounded/unfocused: refreshSessionList early-returns on document.hidden unless force=true, and the sidebar SSE closes on blur — but the in-flight/pending coalescing only preserved the refresh REASON string, dropping the opts (force/refreshActive). So a coalesced 'sessions_changed' refresh lost its force flag and got skipped on a hidden tab. Now the pending request preserves merged opts (force/refreshActive OR-merged), and a dedicated resume-refresh path forces a catch-up when the sidebar regains focus, so cross-device recency re-sorts land without a manual refresh. Co-authored-by: rodboev <rodboev@users.noreply.github.com>
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
import re
|
|
from pathlib import Path
|
|
|
|
SESSIONS_JS = Path(__file__).resolve().parent.parent / "static" / "sessions.js"
|
|
|
|
|
|
def _function_body(src: str, name: str) -> str:
|
|
m = re.search(
|
|
rf"(?:async\s+)?function\s+{re.escape(name)}\b.*?^}}",
|
|
src,
|
|
re.DOTALL | re.MULTILINE,
|
|
)
|
|
assert m, f"{name} function not found"
|
|
return m.group(0)
|
|
|
|
|
|
def test_refreshActiveSessionIfExternallyUpdated_exists():
|
|
src = SESSIONS_JS.read_text(encoding="utf-8")
|
|
assert "async function refreshActiveSessionIfExternallyUpdated" in src
|
|
|
|
|
|
def test_poll_path_skips_non_external_sessions():
|
|
src = SESSIONS_JS.read_text(encoding="utf-8")
|
|
body = _function_body(src, "refreshActiveSessionIfExternallyUpdated")
|
|
assert re.search(
|
|
r"if\s*\(\s*\(\s*reason\s*\|\|\s*['\"]poll['\"]\s*\)\s*===\s*['\"]poll['\"]\s*&&\s*!\s*_isExternalSession\s*\(",
|
|
body,
|
|
), (
|
|
"the 30s poll fallback should early-return for WebUI-native sessions, "
|
|
"but non-poll refresh triggers must still be allowed"
|
|
)
|
|
|
|
|
|
def test_session_events_refresh_active_session():
|
|
src = SESSIONS_JS.read_text(encoding="utf-8")
|
|
body = _function_body(src, "_scheduleSessionEventsRefresh")
|
|
assert "void refreshSessionList(request.reason||'event', request.opts)" in body
|
|
assert "_scheduleSessionEventsRefresh(eventTargetsActiveSession?'event-active-session':'event', {force:true, refreshActive:true})" in src
|