A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
headed.py: loadshot exits 1 on BOOT FAIL (Refs #2697) (#2700)
Eyal Golane5d3e59e0387
diff --git a/tools/headed.py b/tools/headed.pyindex eaa682103..a9812adff 100644--- a/tools/headed.py+++ b/tools/headed.py@@ -9,7 +9,7 @@ serves a WebGL build with web_check's handler, and drives it over one browser-leboot boot-phase timings from ?bootlog (optionally under CPU throttling): where the start-up time goesnavpairs pairs of clicks on a screen button and a second target, d ms apart or in one frame, under ?navlog- loadshot screenshots during the load and once ready (the loading line, or the boot-failure line)+ loadshot screenshots during the load and once ready; a boot-failure line ends the run with exit 1profile visual v1's ?vprofile in a headed 1920x1080 window at --dpr (frame rate uncapped)wheel wheel zoom under ?camlog (#43): a touchpad-like swipe, mouse notches in pixels and lines, over the map and a panel@@ -382,12 +382,22 @@ async def navpairs(args):async def loadshot(args):async with Browser(args.build) as b:sid = await b.open("bootlog", args.cpu)- await b.wait_for(sid, r"BOOT phase=player started|BOOT FAIL")+ line = await b.wait_for(sid, r"BOOT phase=player started|BOOT FAIL")+ # #2697: a failed boot is a failed run, not a capture. wait_for returns the first match in console order, so a+ # BOOT FAIL already logged after "player started" is looked for too, before the loading screenshot.+ line = next((t for t in b.lines(sid) if "BOOT FAIL" in t), line)+ if "BOOT FAIL" in line:+ print(f"FAIL: {line}")+ return 1print(await b.shot(sid, args.out + "-loading.png"))line = await b.wait_for(sid, r"^GAME OK|BOOT FAIL")+ if "BOOT FAIL" in line:+ print(f"FAIL: {line}")+ return 1await asyncio.sleep(2)print(line)print(await b.shot(sid, args.out + "-after.png"))+ return 0async def wheel(args):diff --git a/tools/tests/test_headed.py b/tools/tests/test_headed.pyindex fb3043dd3..f9bc7db11 100644--- a/tools/tests/test_headed.py+++ b/tools/tests/test_headed.py@@ -135,3 +135,47 @@ def test_wheel_zoom_follows_a_swipe_and_keeps_a_notch_at_one_step():assert r["px150,px200,px49"]["px150"][0] == pytest.approx(1, abs=0.02)assert r["px150,px200,px49"]["px200"][0] == pytest.approx(1, abs=0.02)assert r["px150,px200,px49"]["px49"][0] == pytest.approx(0.49, abs=0.02)+++def test_loadshot_exits_1_on_a_boot_failure_before_or_after_loading(monkeypatch, tmp_path, capsys):+ """#2697: loadshot used to take its screenshots and exit 0 after BOOT FAIL. A BOOT FAIL already in the console when+ the first wait returns "player started" (wait_for gives the first match) takes no loading screenshot either."""+ shots = []++ class FakeBrowser:+ waits: list[str] = []+ console: list[str] = []++ def __init__(self, *args, **kwargs):+ pass++ async def __aenter__(self):+ return self++ async def __aexit__(self, *args):+ return None++ async def open(self, *args):+ return "sid"++ def lines(self, sid):+ return list(FakeBrowser.console)++ async def wait_for(self, *args, **kwargs):+ line = FakeBrowser.waits.pop(0)+ FakeBrowser.console.append(line)+ return line++ async def shot(self, sid, path):+ shots.append(path)+ return path++ monkeypatch.setattr(headed, "Browser", FakeBrowser)+ for waits, buffered, expected_shots in ((["BOOT FAIL content missing"], [], 0),+ (["BOOT phase=player started", "BOOT FAIL scene"], [], 1),+ (["BOOT phase=player started"], ["BOOT FAIL late"], 0)):+ shots.clear()+ FakeBrowser.waits, FakeBrowser.console = list(waits), list(buffered)+ assert headed.main(["loadshot", "--build", str(tmp_path), "--out", str(tmp_path / "shot")]) == 1+ assert len(shots) == expected_shots+ assert "FAIL: BOOT FAIL" in capsys.readouterr().out