fix(m0): a player that does not come back spoils its window instead of ending the stage

When loading the page again did not bring a player back, keep_room still
moved the missing player back to the start, the page script threw and the
stage stopped at the first window. Now a failed reload (or a refused
navigation) is recorded as "the video did not play again", only a playing
video is moved back (and the script checks the player exists), so the
window is measured as it is, not counted, and tried again up to the limit
before the stage goes on. The reload waits RELOAD_S for the video.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-11 02:04:59 +09:00
parent 6d0b3d5bec
commit 357f36afcc
2 changed files with 71 additions and 13 deletions

View File

@@ -1562,3 +1562,53 @@ def test_a_page_script_that_fails_while_the_page_loads_reads_as_a_lost_page():
raise RuntimeError("page script failed: Execution context was destroyed.")
assert video.VideoPage(Broken()).snapshot()["lost"] is True
class _DyingCdp:
"""A watch page that plays, then loses its player for good (loading it again does not help);
like Chrome, a page script that reaches for the missing player throws."""
def __init__(self, die_at: int):
from m0lib import video
self.v, self.die_at, self.snaps, self.total, self.navigated = video, die_at, 0, 0, 0
def evaluate(self, expr):
dead = self.snaps >= self.die_at
if expr == self.v._SNAPSHOT:
self.snaps += 1
if dead:
return {"lost": True, "error": False, "error_text": None}
self.total += 3600
return {**_snap(self.total, 0), "paused": False, "ad_now": False, "time": 30.0, "duration": 634.0}
if expr == self.v._STEP:
return {"state": "loading"} if dead else {"state": "playing", "levels": ["hd1080"]}
if expr in (self.v._INSTALL, self.v._RESET):
return not dead
if dead and "movie_player" in expr:
raise RuntimeError("page script failed: TypeError: Cannot read properties of null (reading 'seekTo')")
return True
def call(self, method, params=None):
self.navigated += method == "Page.navigate"
return {}
def test_a_player_that_never_comes_back_is_tried_again_per_window_and_the_stage_goes_on(
tmp_path, monkeypatch, fake_server):
from m0lib import video
for name, value in (("SETTLE_S", 0), ("REPLAY_S", 0.01), ("RELOAD_S", 0.01)):
monkeypatch.setattr(video, name, value)
cdp = _DyingCdp(die_at=4) # two snapshots while starting, then it dies during the first window
page = video.VideoPage(cdp)
closed = []
monkeypatch.setattr(page, "close", lambda: closed.append(True))
r, _, running, stt = _run_video_stage(tmp_path, monkeypatch, fake_server, page)
rows = r["video_rows"]
assert [x["key"] for x in rows] == ["video_only", "jarvis_idle", *video.ROUNDS, "video_only_again"]
assert all(not x["video"]["valid"] for x in rows)
# Every window was tried the full number of times, each time loading the page again.
assert all(len(x["video"]["earlier_attempts"]) == video.ATTEMPTS - 1 for x in rows)
assert all("the video did not play again" in x["video"]["player_fixes"] for x in rows)
assert cdp.navigated >= len(rows) * (video.ATTEMPTS - 1)
assert not any("seekTo" in e["error"] for e in r["errors"])
assert closed and running["now"] is None and stt.loaded is None and not running["held"]