"""The warm-up gives up on a silent canvas instead of waiting forever. a participant crossed the handoff into this task on 26 October, reached the warm-up, and stayed there for two hours: no traceback, pings still arriving, stage 2 of 38 for the whole time. `_run_js` awaited a future that only the canvas resolves, with nothing to end the wait, so a canvas that went quiet took the session with it and every reload started the same wait again. MAX_BOXES_FALLBACK already existed for a warm-up that cannot run. These tests pin the path that reaches it. """ import os os.environ["RELOAD"] = "0" os.environ["STORAGE_SECRET"] = "test" os.environ["PORT"] = "8092" import asyncio import pytest from nicegui import app, ui from nicegui.testing import User import effort_design as D import effort_stages as E import web_app # noqa: F401 (registers the pages the User harness opens) async def _never_answers(*_a, **_kw): """Stand in for a canvas call that reaches the browser and says nothing.""" return None @pytest.mark.module_under_test(web_app) async def test_a_silent_canvas_ends_the_warm_up_wait(user: User) -> None: await user.open("/?dev=1&pid=SMOKE_calib_timeout&theme=harvest") with user.client: E.get_bridge().fut = None with pytest.raises(asyncio.TimeoutError): await E._run_js("startCalibration", {"repIndex": 0}, wait_s=0.2) @pytest.mark.module_under_test(web_app) async def test_the_unbounded_wait_still_hangs(user: User) -> None: """The old shape, kept so the fix is visibly the difference. Without wait_s the await has nothing to end it, which is correct for a trial and was the whole fault in the warm-up. """ await user.open("/?dev=1&pid=SMOKE_calib_hang&theme=harvest") with user.client: E.get_bridge().fut = None # Nothing inside the call ends this. The wait_for around it is the only # reason the test finishes, which is the point. with pytest.raises(asyncio.TimeoutError): await asyncio.wait_for( E._run_js("startCalibration", {"repIndex": 0}), 0.3) @pytest.mark.module_under_test(web_app) async def test_the_warm_up_falls_back_and_says_so(user: User, monkeypatch) -> None: await user.open("/?dev=1&pid=SMOKE_calib_fallback&theme=harvest") monkeypatch.setattr(E, "_CALIB_WAIT_S", 0.2) monkeypatch.setattr(E, "calib_slides", lambda: []) monkeypatch.setattr(E, "_mount_canvas", _never_answers) monkeypatch.setattr(ui, "run_javascript", _never_answers) with user.client: container = ui.column() res = await E.calibration_display(None, container) assert app.storage.user["max_boxes"] == D.MAX_BOXES_FALLBACK assert res["calib_timed_out"] is True assert res["reps"] == [] assert res["max_boxes"] == D.MAX_BOXES_FALLBACK assert len(set(res["effort_levels"].values())) == res["n_distinct_levels"]