1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
"""
An open application asks for the notification list again when somebody comes back.
Reported live on 2026-10-09: a member posted in a group, the hub wrote the
owner's notification 20 ms later, and the owner, whose application was open,
never saw it. Nothing was broken on the hub or the node. The page asked for the
list at sign-in (and at a token renewal, every few hours) and at no other time,
so a notification created after the application started waited for the next
launch.
The hub has no channel to the page and is deliberately not polled on a timer,
so the list is asked for again on a gesture: the application returning to the
foreground, or the home page, where the list is shown. Two in a row are one
question. These read the source; there is no browser for the SPA's state here.
"""
import re
from pathlib import Path
APP = (Path(__file__).resolve().parents[1] / "src" / "meshbay_hub" / "static"
/ "app.js").read_text()
def _block(start: str) -> str:
i = APP.index(start)
return APP[i:APP.index("\n }, [", i)]
def test_coming_back_to_the_application_asks_again():
listeners = [m.start() for m in re.finditer(r"addEventListener\('visibilitychange'", APP)]
bodies = [APP[APP.rfind("useEffect(", 0, i):i] for i in listeners]
assert any("refreshNotifications()" in b and "'visible'" in b for b in bodies), \
"no visibilitychange listener asks for the notification list"
def test_the_home_page_asks_again():
assert re.search(r"if \(user && route === '/'\) refreshNotifications\(\);", APP)
def test_two_askings_in_a_row_are_one_and_no_timer_asks():
refresh = _block("const refreshNotifications = useCallback(")
assert "NOTIF_REFRESH_MS" in refresh and "fetchNotifications()" in refresh
# The stamp is taken where the request leaves, so the sign-in fetch counts
# and the home page right after it does not ask a second time.
fetch = _block("const fetchNotifications = useCallback(")
assert "notifAskedAtRef.current = Date.now()" in fetch
for timer in re.finditer(r"setInterval\(([^,]+),", APP):
assert "otif" not in timer.group(1), "the notification list is polled on a timer"
|