fix(m0): count only video windows that played 1080p60 under the cap they claim

- A window counts only when the player kept the asked quality and height
  the whole time and played the source's 60 fps; a player stuck below
  1080p is a stage error, not a note.
- Pauses, seeks and buffering are counted inside the page during the
  window, so a pause that ended before the last snapshot no longer
  passes as GPU stutter.
- A capped window whose cap found nothing to pause, ran no pause cycle,
  or could not pause or resume a process is an error and does not count
  for the cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-11 01:01:28 +09:00
parent a6908c386e
commit 37e27a2648
3 changed files with 106 additions and 26 deletions

View File

@@ -455,7 +455,7 @@ def test_a_lying_model_fails_the_stage_and_the_next_model_is_measured(tmp_path):
def _run_levels_stage(tmp_path, monkeypatch, fake_server, gpu, ready=lambda sets: True, only="levels",
extra_opts=(), stt=None, procs=None, paused=None):
extra_opts=(), stt=None, procs=None, paused=None, suspend_ok=True):
"""Run the stage with Strata replaced; ``gpu(running)`` is nvidia-smi's (used, total), where
``running`` is the started placement ({"sets", "context", "kv", "mtp"}) or None. ``stt`` is a
_FakeStt whose loaded model adds to the used VRAM."""
@@ -498,7 +498,8 @@ def _run_levels_stage(tmp_path, monkeypatch, fake_server, gpu, ready=lambda sets
monkeypatch.setattr(gpucap, "process_table", lambda: list(procs))
held = set()
paused = set() if paused is None else paused
monkeypatch.setattr(gpucap, "suspend_pid", lambda pid: held.add(pid) or paused.add(pid) or True)
monkeypatch.setattr(gpucap, "suspend_pid",
lambda pid: (held.add(pid) or paused.add(pid) or True) if suspend_ok else False)
monkeypatch.setattr(gpucap, "resume_pid", lambda pid: held.discard(pid) or True)
monkeypatch.setattr(gpucap, "PERIOD_S", 0.002)
running["held"] = held
@@ -1286,7 +1287,8 @@ def test_devtools_errors_and_a_closed_socket_are_raised_not_hidden():
def _snap(total, dropped, **kw):
return {"total": total, "dropped": dropped, "shown": kw.pop("shown", total), "gaps": kw.pop("gaps", [0, 0]),
"max_gap_ms": kw.pop("max_gap_ms", 17.0), "waits": 0, "quality": "hd1080", "height": 1080, **kw}
"max_gap_ms": kw.pop("max_gap_ms", 17.0), "waits": 0, "pauses": 0, "seeks": 0,
"quality": kw.pop("quality", "hd1080"), "height": kw.pop("height", 1080), **kw}
def test_a_window_counts_the_frames_the_video_dropped_meanwhile():
@@ -1298,7 +1300,9 @@ def test_a_window_counts_the_frames_the_video_dropped_meanwhile():
@pytest.mark.parametrize("after", [_snap(4600, 9, ad=True), _snap(4600, 9, paused=True), _snap(4600, 9, ended=True),
_snap(300, 0), _snap(1000, 5)])
_snap(300, 0), _snap(1000, 5),
# paused, jumped or buffered for a while and playing again at the end
_snap(4600, 9, pauses=1), _snap(4600, 9, seeks=1), _snap(4600, 9, waits=2)])
def test_a_window_with_an_ad_a_pause_the_end_a_new_video_or_no_frames_is_kept_but_not_counted(after):
from m0lib import video
w = video.window_stats(_snap(1000, 5), after, 60.0)
@@ -1323,15 +1327,16 @@ def test_the_comparison_adds_up_only_valid_busy_windows_on_each_side_of_the_cap(
class _FakePage:
"""The watch page: 60 frames shown per snapshot step, a few dropped; records what the stage did."""
def __init__(self, starts=True):
self.starts = starts
def __init__(self, starts=True, quality="hd1080", height=1080):
self.starts, self.quality, self.height = starts, quality, height
self.total = self.dropped = 0
self.events: list[str] = []
self.closed = False
def start(self, quality="hd1080", timeout=180):
self.events.append("video_start")
return {"started": self.starts, "quality": quality if self.starts else None, "ad_seen": False}
return {"started": self.starts, "quality": self.quality if self.starts else None,
"height": self.height if self.starts else None, "ad_seen": False}
def keep_room(self):
pass
@@ -1342,19 +1347,19 @@ class _FakePage:
def snapshot(self):
self.total += 3600
self.dropped += 2
return _snap(self.total, self.dropped)
return _snap(self.total, self.dropped, quality=self.quality, height=self.height)
def close(self):
self.closed = True
def _run_video_stage(tmp_path, monkeypatch, fake_server, page, stt=None):
def _run_video_stage(tmp_path, monkeypatch, fake_server, page, stt=None, **kw):
from m0lib import video
monkeypatch.setattr(video, "QUIET_S", 0.01)
monkeypatch.setattr(video, "open_video_page", lambda work, *a, **k: page)
stt = _FakeStt() if stt is None else stt
r, started, running = _run_levels_stage(tmp_path, monkeypatch, fake_server, _vram, only="video",
extra_opts=["stt_python=py"], stt=stt)
extra_opts=["stt_python=py"], stt=stt, **kw)
return r, started, running, stt
@@ -1411,3 +1416,32 @@ def test_video_stage_is_on_demand_with_the_stt_python_and_a_one_click_runner():
assert "video_drops" in m0.ON_DEMAND and "video_drops" in m0.NEEDS_STT
bat = (Path(m0.KIT) / "run_m0_video.bat").read_text(encoding="utf-8")
assert "-Only video_drops" in bat and "-Redo" in bat
@pytest.mark.parametrize("before,after,why", [
(_snap(1000, 5, quality="medium", height=360), _snap(4600, 9, quality="medium", height=360), "quality"),
(_snap(1000, 5), _snap(4600, 9, min_height=720, max_height=1080), "lines high"), # dipped to 720p meanwhile
(_snap(1000, 5), _snap(2800, 9), "fps"), # a 30 fps format
])
def test_a_window_that_played_another_quality_or_frame_rate_is_not_counted(before, after, why):
from m0lib import video
w = video.window_stats(before, after, 60.0, video.WANT)
assert not w["valid"] and any(why in x for x in w["invalid_because"])
assert video.window_stats(_snap(1000, 5), _snap(4600, 9, min_height=1080, max_height=1080), 60.0,
video.WANT)["valid"]
def test_a_video_stuck_below_the_asked_quality_counts_no_window(tmp_path, monkeypatch, fake_server):
r, _, _, _ = _run_video_stage(tmp_path, monkeypatch, fake_server, _FakePage(quality="medium", height=360))
assert r["status"] == "partial" and any("medium" in e["error"] for e in r["errors"])
assert not any(x["video"]["valid"] for x in r["video_rows"])
assert r["comparison"]["no_cap"]["windows"] == 0 and r["comparison"]["cap95"]["windows"] == 0
def test_a_cap_that_could_not_pause_jarvis_does_not_count_as_a_capped_window(tmp_path, monkeypatch, fake_server):
r, _, running, _ = _run_video_stage(tmp_path, monkeypatch, fake_server, _FakePage(), suspend_ok=False)
capped = [x for x in r["video_rows"] if x["gpu_cap"]]
assert capped and all(not x["video"]["valid"] for x in capped)
assert r["comparison"]["cap95"]["windows"] == 0 and r["comparison"]["no_cap"]["windows"] == 2
assert r["status"] == "partial" and any("could not be paused" in e["error"] for e in r["errors"])
assert not running["held"]