diff options
Diffstat (limited to 'packages/meshbay-hub/tests/test_downloads.py')
| -rw-r--r-- | packages/meshbay-hub/tests/test_downloads.py | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/packages/meshbay-hub/tests/test_downloads.py b/packages/meshbay-hub/tests/test_downloads.py index 41d61bf..85bf488 100644 --- a/packages/meshbay-hub/tests/test_downloads.py +++ b/packages/meshbay-hub/tests/test_downloads.py @@ -161,6 +161,45 @@ def test_backpressure_is_real(tmp_path): src = DOWNLOADS.read_text() fn = src[src.index("export async function openStreamedDownload"):] assert "new TransformStream()" in fn - assert "[readable]" in fn, "the readable half must be transferred, not copied" + # The transfer list may carry more than the stream — a reply port rides + # along now — so this asserts that `readable` is transferred, not the exact + # shape of the list. + transfer = fn[fn.index("worker.postMessage("):] + transfer = transfer[transfer.index("["):transfer.index("]") + 1] + assert "readable" in transfer, "the readable half must be transferred, not copied" assert "writer.write(bytes)" in fn assert "return null" in fn, "a browser that cannot transfer streams must say so" + + +def test_the_streamed_path_gives_up_rather_than_blocking_for_ever(): + """Reported 2026-08-16: a download frozen at exactly one chunk. + + The writable half applies real backpressure, which is the whole point — and + the trap. If nothing ever reads the readable half, `writer.write()` waits + for room that never comes, and the transfer stops dead after the stream's + internal queue fills. Two ways that happens on a phone: the page is not yet + *controlled* by the worker, so the iframe's request is never handed to its + fetch handler; or the browser refuses a download started from a hidden + iframe. Both are silent. + + So the worker confirms that it actually answered, and this path reports + failure instead of returning a sink nobody drains. + """ + src = DOWNLOADS.read_text() + fn = src[src.index("export async function openStreamedDownload"):] + assert "mbdl-serving" in fn, "the worker has to confirm it served the request" + assert "Promise.race" in fn, "the confirmation needs a deadline" + assert "writable.abort" in fn, "give up cleanly so the caller can fall back" + + sw = (DOWNLOADS.parent / "sw.js").read_text() + assert "mbdl-serving" in sw, "and the worker has to send that confirmation" + + +def test_an_uncontrolled_page_is_not_treated_as_ready(): + """`registration.active` says a worker exists, not that it will see our fetch.""" + src = DOWNLOADS.read_text() + fn = src[src.index("async function serviceWorker()"):] + fn = fn[:fn.index("\n}")] + assert "navigator.serviceWorker.controller" in fn + assert "controllerchange" in fn, ( + "control can arrive a tick after registration; waiting beats refusing") |