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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
"""
Sending a chat message must come back.
The node answers a chat message with a bare `{"type": "ack"}` — no request id,
no type of its own — so `_dispatch` had nothing to match it on and left it to
the arrival-order guess at the end of the function. That guess is wrong as soon
as anything else this browser asked for is still waiting: the ack was handed to
*that* request, and the send waited out `_sendAndWait`'s 30s timeout. Since the
composer is disabled while a send is in flight, the Chat tab stopped taking
clicks and keys, the message never appeared — and it was there on the next
visit, because the node had stored it and answered.
An outstanding request is the ordinary case, not a rare one: the node refuses
an unknown file_id with a bare `error`, which names no request either, so a
Videos tab that asked about a file the index no longer has leaves a
`media_meta_req` in `_pending` for a full 30s.
None of that is visible in `chat-app.js`, where every line is correct, so this
drives the real panel over the real transport in a browser rather than reading
either source.
"""
import json
import shutil
import subprocess
from pathlib import Path
import pytest
HARNESS = Path(__file__).parent / "harness" / "chat_send_probe.py"
STATIC = Path(__file__).resolve().parents[1] / "src" / "meshbay_hub" / "static"
pytestmark = pytest.mark.skipif(
shutil.which("google-chrome") is None or not (STATIC / "chat-app.js").exists(),
reason="Chrome or the SPA sources are not available")
@pytest.fixture(scope="module")
def probe():
run = subprocess.run(["python3", str(HARNESS)], capture_output=True, timeout=180)
assert run.returncode == 0, run.stderr.decode()[-2000:]
data = json.loads(run.stdout.decode())
return data, {s["label"]: s for s in data["steps"]}
def test_the_composer_comes_back(probe):
"""The one thing a person sees: the tab is usable again."""
_, steps = probe
assert steps["stale request pending"]["composerDisabled"] is False, (
"the composer was already unusable before the send")
assert steps["after send"]["composerDisabled"] is False, (
"the composer is still disabled well inside the 30s request timeout -- "
"the send never came back, which is what reads as a frozen Chat tab")
def test_the_message_is_displayed(probe):
"""A sent message appears at once, not on the next visit to the tab."""
_, steps = probe
before = steps["stale request pending"]["bubbles"]
assert steps["after send"]["bubbles"] == before + 1, (
"the message was not added to the conversation")
assert steps["after send"]["lastText"] == "hello"
assert steps["after send"]["composerValue"] == "", (
"the text came back into the composer, so the send was treated as failed")
def test_the_ack_is_not_handed_to_another_request(probe):
"""The other half of the same defect: whatever was waiting got the ack and
carried on with a reply to a question it never asked."""
data, _ = probe
assert "media_meta resolved with ack" not in data["log"], (
"the chat ack was routed to the pending media_meta_req -- that request "
"now believes it has an answer, and the chat send is waiting for a "
"reply that already arrived")
|