Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

feat(tools): web_check --startscreen runs the real start screen in a browser (Fixes #908) (#967)

Eyal Golanf32ba67e0961
diff --git a/docs/RELEASING.md b/docs/RELEASING.md
index 64ad72e8b..2435fcd9a 100644
--- a/docs/RELEASING.md
+++ b/docs/RELEASING.md
@@ -22,6 +22,10 @@ GitHub Releases page (and, from M4, on itch.io). Steps 1–3 are a normal pull r
--expect "GOLDEN OK 1950 7cf678b6b2b3d55dc0fee7b2efdee9ec7688cdf18964dcaa6e5a7c0018e34a51" \
--expect "GOLDEN OK 1952 9496947232f0c97ed21c0a0b98e6727e7d59c892f9aff12049b5d7e5ee2230e8" \
--expect "SMOKE OK 5 turns 1948-10-15 3005405d64abc6e7418fa1f0d35c36ce5f64ed3af7c5a4c24a73d5dfdb16121f"
+ uv run tools/web_check.py unity/Builds/Web-gzip --startscreen new --timeout 300 --stall 90
+ uv run tools/web_check.py unity/Builds/Web-gzip --startscreen recording --timeout 300 --stall 90
+ uv run tools/web_check.py unity/Builds/Web-gzip --startscreen new --query lang=he --timeout 300 --stall 90
+ uv run tools/web_check.py unity/Builds/Web-gzip --startscreen recording --query lang=he --timeout 300 --stall 90
bash scripts/oss/package_web.sh unity/Builds/Web-gzip unity/Builds/statecraft-israel-vX.Y.Z-web.zip
```
@@ -31,6 +35,10 @@ GitHub Releases page (and, from M4, on itch.io). Steps 1–3 are a normal pull r
build's files, that is about 34 MB to download per player instead of about 46 MB. Both load in a browser with Decompression
Fallback off, as `Build.Web` sets it, and `web_check.py` serves `*.gz` with `Content-Encoding: gzip`.
+ The four `--startscreen` passes (owner decision on #967, 17 October 2026) open the start screen every player sees
+ first, which the golden and smoke run skips: New game, and Play the recording then New game, in English and in
+ Hebrew. Each must print `PASS`. A console exception, `RECORDING failed` or `BOOT FAIL` fails it (#908).
+
`package_web.sh` copies the licence and attribution files into the build folder, then runs
`tools/package_release.py`, M3's sensitivity gate, which zips the folder and prints `PACKAGED …` or
`PACKAGE REFUSED …`. It refuses a build that was not made with `-shareable` (the build's `event-photos.json` says
diff --git a/tools/tests/test_web_check.py b/tools/tests/test_web_check.py
index 57345e6ac..5ed46c943 100644
--- a/tools/tests/test_web_check.py
+++ b/tools/tests/test_web_check.py
@@ -250,3 +250,135 @@ def test_watch_names_the_unfinished_persistence_run(capsys):
sleep=lambda s: t.__setitem__(0, t[0] + 1), complete=lambda: False)
assert rc == 1
assert "TIMEOUT: never saw the end of the --persistence run" in capsys.readouterr().out
+
+
+def _clicks(*points):
+ return [f"click:{x},{y}" for x, y in points]
+
+
+def test_start_screen_check_presses_new_game_then_end_turn_and_needs_turn_1(capsys):
+ actions = []
+ check = wc.StartScreenCheck(actions.append, recording=False, hebrew=False, settle=lambda s: None)
+ check.feed("GAME OK 1948-05-15 turn 0 hash aa")
+ assert actions == _clicks(wc.NEW_GAME, wc.END_TURN)
+ assert not check.done
+ check.feed("TURN 1 1948-06-15 hash bb")
+ assert check.done
+ assert "START SCREEN OK New game reached the map: TURN 1" in capsys.readouterr().out
+
+
+def test_start_screen_check_plays_the_recording_first_and_waits_for_it_hebrew_layout():
+ actions = []
+ check = wc.StartScreenCheck(actions.append, recording=True, hebrew=True, settle=lambda s: None)
+ check.feed("GAME OK 1948-05-15 turn 0 hash aa")
+ assert actions == _clicks(wc.PLAY_RECORDING_HE)
+ check.feed("TURN 1 1948-06-15 hash bb") # no New game before the recording plays
+ assert actions == _clicks(wc.PLAY_RECORDING_HE) and not check.done
+ check.feed("RECORDING playing audio/declaration.wav (9.29 s, at 0.20 s)")
+ assert actions == _clicks(wc.PLAY_RECORDING_HE, wc.NEW_GAME, wc.END_TURN_HE)
+ check.feed("TURN 1 1948-06-15 hash bb")
+ assert check.done
+
+
+def test_start_screen_check_fails_on_a_saved_game_or_a_wrong_turn():
+ with pytest.raises(ValueError, match="START SCREEN FAIL the first boot is turn 3"):
+ wc.StartScreenCheck(lambda a: None, False, False, lambda s: None).feed("GAME OK 1948-08-15 turn 3 hash aa")
+ check = wc.StartScreenCheck(lambda a: None, False, False, lambda s: None)
+ check.feed("GAME OK 1948-05-15 turn 0 hash aa")
+ with pytest.raises(ValueError, match="START SCREEN FAIL End turn after New game logged turn 2"):
+ check.feed("TURN 2 1948-07-15 hash cc")
+ assert not check.done
+
+
+def test_query_value():
+ assert wc.query_value("lang=he&smoke", "lang") == "he"
+ assert wc.query_value("smoke", "lang") is None
+ assert wc.query_value("", "lang") is None
+
+
+def test_start_screen_check_english_recording_uses_the_english_layout():
+ actions = []
+ check = wc.StartScreenCheck(actions.append, recording=True, hebrew=False, settle=lambda s: None)
+ check.feed("GAME OK 1948-05-15 turn 0 hash aa")
+ check.feed("RECORDING playing audio/declaration.wav (9.29 s, at 0.20 s)")
+ assert actions == _clicks(wc.PLAY_RECORDING, wc.NEW_GAME, wc.END_TURN)
+
+
+def _args(*argv):
+ return wc.parser().parse_args(["build", *argv])
+
+
+def _plan(*argv):
+ driver, fail, plan = wc.run_plan(_args(*argv), lambda action: None)
+ if driver is not None:
+ driver.settle = lambda seconds: None
+ return driver, fail, plan
+
+
+def test_every_run_fails_on_boot_fail_by_default():
+ _, fail, plan = _plan()
+ assert fail.search("BOOT FAIL manifest.json: timeout") and plan == {}
+
+
[email protected]("mode", ["new", "recording"])
+def test_a_start_screen_run_fails_on_boot_fail_exceptions_and_the_recording_whatever_fail_says(mode):
+ for argv in ((), ("--fail", "SOMETHING ELSE")):
+ _, fail, _ = _plan("--startscreen", mode, *argv)
+ for text in ("BOOT FAIL manifest.json: timeout", "NullReferenceException: Object reference not set",
+ "RECORDING failed audio/declaration.wav: no audio"):
+ assert fail.search(text), (argv, text)
+ assert _plan("--startscreen", mode, "--fail", "SOMETHING ELSE")[1].search("SOMETHING ELSE")
+
+
+def test_the_start_screen_run_takes_the_hebrew_layout_from_the_query():
+ he, _, _ = _plan("--startscreen", "recording", "--query", "lang=he&smoke=0")
+ en, _, _ = _plan("--startscreen", "recording")
+ assert (he.play, he.end_turn) == (wc.PLAY_RECORDING_HE, wc.END_TURN_HE)
+ assert (en.play, en.end_turn) == (wc.PLAY_RECORDING, wc.END_TURN)
+
+
+def test_persistence_and_start_screen_are_separate_runs():
+ with pytest.raises(ValueError, match="separate runs"):
+ _plan("--persistence", "--startscreen", "new")
+
+
+def _run(plan_args, lines, late=()):
+ """Feeds `lines` to watch through run_plan's driver; `late` arrive at the first sleep, after them."""
+ driver, fail, plan = _plan(*plan_args)
+ inbox = queue.Queue()
+ for text in lines:
+ inbox.put(line(text))
+ t, late = [0.0], list(late)
+
+ def sleep(seconds):
+ while late:
+ inbox.put(line(late.pop(0)))
+ t[0] += seconds
+
+ return wc.watch(inbox, lambda: None, lambda: None, [], fail, 60, now=lambda: t[0], sleep=sleep,
+ on_text=lambda text: driver.feed(text) and False, **plan)
+
+
+BOOTED_AND_TURNED = ["GAME OK 1948-05-15 turn 0 hash aa", "TURN 1 1948-06-15 hash bb"]
+
+
+def test_a_start_screen_run_passes_after_turn_1_and_names_itself(capsys):
+ assert _run(("--startscreen", "new"), BOOTED_AND_TURNED) == 0
+ assert "PASS: saw the end of the --startscreen new run" in capsys.readouterr().out
+
+
+def test_an_exception_logged_just_after_turn_1_still_fails_the_run(capsys):
+ assert _run(("--startscreen", "new"), BOOTED_AND_TURNED, late=["NullReferenceException: late presenter"]) == 1
+ assert "FAIL: NullReferenceException: late presenter" in capsys.readouterr().out
+
+
+def test_a_start_screen_run_that_never_reaches_turn_1_fails_naming_itself(capsys):
+ assert _run(("--startscreen", "recording"), ["GAME OK 1948-05-15 turn 0 hash aa"]) == 1
+ assert "TIMEOUT: never saw the end of the --startscreen recording run" in capsys.readouterr().out
+
+
[email protected]("bad", ["BOOT FAIL manifest.json: timeout", "RECORDING failed audio/declaration.wav: no audio",
+ "InvalidOperationException: presenter"])
+def test_a_failure_line_during_a_start_screen_run_fails_it(bad, capsys):
+ assert _run(("--startscreen", "recording"), ["GAME OK 1948-05-15 turn 0 hash aa", bad]) == 1
+ assert f"FAIL: {bad}" in capsys.readouterr().out
diff --git a/tools/web_check.py b/tools/web_check.py
index b744f2ca9..d5336870c 100644
--- a/tools/web_check.py
+++ b/tools/web_check.py
@@ -14,7 +14,10 @@ Options: --query Q (page URL query, without '?'), --expect TEXT (repeatable), --
--swiftshader (software WebGL when there is no GPU), --dpr N (default 1), --shots DIR (reassemble the player's
"SHOT" console lines, from ?shot, into DIR/<pose>.png; a "SHOT done" with an unfinished shot fails the run),
--persistence (play one normal turn, reload and Continue after a settling delay, then play another turn and reload
-immediately; both reloads must report the saved date, turn and hash).
+immediately; both reloads must report the saved date, turn and hash), --startscreen new|recording (#908: on a fresh
+profile, the real start screen every player sees first: "new" presses New game, "recording" first presses Play the
+recording and waits for RECORDING playing; then End turn must log TURN 1; any console Exception, RECORDING failed or
+BOOT FAIL fails the run; add --query lang=he for the Hebrew layout).
The page is opened over the DevTools protocol with its viewport fixed to 1920x1080 at the DPR before it loads
(Emulation.setDeviceMetricsOverride: --window-size alone gives a 1920x937 viewport in --headless=new), and the run
fails on any "res=" line, or any screenshot, of another size. Headed runs go through tools/headed.py.
@@ -36,6 +39,7 @@ import shutil
import tempfile
import threading
import time
+import urllib.parse
from pathlib import Path
# A console message's first line; warnings and errors carry a stack trace on later lines (ProjectSetup sets none for
@@ -363,6 +367,9 @@ def drain(inbox: queue.Queue) -> list:
# bar's End turn (clickable while the first event card is open). Keys do not work here: Enter sent over CDP before any
# click reaches no Unity button, and after New game the first event card, not End turn, takes the focus.
NEW_GAME, CONTINUE, END_TURN = (960, 1002), (840, 1002), (1840, 45)
+# The same buttons in the Hebrew layout (?lang=he), measured the same way: the top bar is mirrored, so End turn is at the
+# left, and Play the recording sits left of its credit line. Play the recording in the English layout too.
+PLAY_RECORDING, PLAY_RECORDING_HE, END_TURN_HE = (812, 940), (851, 940), (80, 45)
GAME_STATE = re.compile(r"^GAME OK (\d{4}-\d{2}-\d{2}) turn (\d+) hash ([0-9a-f]+)$")
TURN_STATE = re.compile(r"^TURN (\d+) (\d{4}-\d{2}-\d{2}) hash ([0-9a-f]+)$")
@@ -431,21 +438,70 @@ class PersistenceCheck:
f"saved {date} turn {turn} hash {digest}; file a follow-up save-persistence bug")
+def query_value(query: str, key: str) -> str | None:
+ """The value of `key` in a page query without its '?' ("lang=he&smoke" -> "he"); None when absent."""
+ values = urllib.parse.parse_qs(query, keep_blank_values=True).get(key)
+ return values[0] if values else None
+
+
+class StartScreenCheck:
+ """Issue #908: the start screen of a fresh profile, as a player meets it (no automation flag skips it). New game
+ (after Play the recording when `recording`) and End turn must reach the map's first turn. `action` is Page.command."""
+
+ def __init__(self, action, recording: bool, hebrew: bool, settle=time.sleep):
+ self.action, self.recording, self.settle = action, recording, settle
+ self.play, self.end_turn = (PLAY_RECORDING_HE, END_TURN_HE) if hebrew else (PLAY_RECORDING, END_TURN)
+ self.stage, self.done = "boot", False
+
+ def feed(self, text: str) -> None:
+ game, turn = GAME_STATE.match(text), TURN_STATE.match(text)
+ if self.stage == "boot" and game:
+ if int(game.group(2)) != 0:
+ raise ValueError(f"START SCREEN FAIL the first boot is turn {game.group(2)}, not a fresh game")
+ self.settle(3) # the start screen lays out and takes input
+ if self.recording:
+ self.click(self.play)
+ self.stage = "recording"
+ else:
+ self.new_game()
+ elif self.stage == "recording" and text.startswith("RECORDING playing "):
+ print("START SCREEN recording OK")
+ self.settle(2)
+ self.new_game()
+ elif self.stage == "turn" and turn:
+ if int(turn.group(1)) != 1:
+ raise ValueError(f"START SCREEN FAIL End turn after New game logged turn {turn.group(1)}, not turn 1")
+ print(f"START SCREEN OK New game reached the map: TURN 1 {turn.group(2)} hash {turn.group(3)}")
+ self.done = True
+
+ def new_game(self) -> None:
+ self.click(NEW_GAME)
+ self.settle(2)
+ self.click(self.end_turn)
+ self.stage = "turn"
+
+ def click(self, point: tuple[int, int]) -> None:
+ self.action(f"click:{point[0]},{point[1]}")
+
+
def watch(inbox, poll, join_reader, expect, fail, timeout, now=time.time, sleep=time.sleep, on_text=None, stall=0,
- complete=None) -> int:
+ complete=None, complete_what="the end of the --persistence run", grace=0.0) -> int:
"""The check loop: 0 on PASS, 1 on a failure line, on BROWSER EXITED, on TIMEOUT, or (stall > 0) when no console
message arrives for stall seconds (STALLED). poll() is the browser's returncode (None while running); join_reader()
waits briefly for the stderr reader thread to hit EOF, so output written just before the exit is still scanned.
- on_text(text) -> True consumes a message (it is not printed)."""
+ on_text(text) -> True consumes a message (it is not printed). With grace > 0, PASS waits that many seconds after
+ the run is complete, still reading, so a failure line that follows the last expected one (an exception logged
+ after TURN 1) fails the run instead of being lost when the browser closes."""
pending, deadline = list(expect), now() + timeout
last = now()
- end = ["the end of the --persistence run"] if complete is not None else []
+ passes_at = None
+ end = [complete_what] if complete is not None else []
def missing() -> str:
return ", ".join(pending + [e for e in end if not complete()]) or "nothing"
def look():
- nonlocal pending, last
+ nonlocal pending, last, passes_at
status, pending, texts = scan(drain(inbox), pending, fail)
if texts:
last = now()
@@ -457,8 +513,11 @@ def watch(inbox, poll, join_reader, expect, fail, timeout, now=time.time, sleep=
print(f"FAIL: {texts[-1]}")
return 1
if status == "pass" and (complete is None or complete()):
- print("PASS: saw " + ", ".join(list(expect) + end))
- return 0
+ if passes_at is None:
+ passes_at = now() + grace
+ if now() >= passes_at:
+ print("PASS: saw " + ", ".join(list(expect) + end))
+ return 0
return None
while now() < deadline:
@@ -481,7 +540,28 @@ def watch(inbox, poll, join_reader, expect, fail, timeout, now=time.time, sleep=
return 1
-def main() -> int:
+# Failure lines every --startscreen run adds to --fail, whatever --fail says (#908).
+START_SCREEN_FAILS = r"BOOT FAIL|Exception|RECORDING failed"
+# Seconds a scripted run keeps reading after it is complete, before PASS (watch's grace).
+DRIVER_GRACE = 3.0
+
+
+def run_plan(a, command):
+ """What a run drives and fails on: (driver or None, the failure regex, watch's keyword arguments). `command` is
+ Page.command."""
+ if a.persistence and a.startscreen:
+ raise ValueError("--persistence and --startscreen are separate runs")
+ if a.startscreen:
+ driver = StartScreenCheck(command, a.startscreen == "recording", query_value(a.query, "lang") == "he")
+ fail, what = f"(?:{a.fail})|{START_SCREEN_FAILS}", f"the end of the --startscreen {a.startscreen} run"
+ elif a.persistence:
+ driver, fail, what = PersistenceCheck(command), a.fail, "the end of the --persistence run"
+ else:
+ return None, re.compile(a.fail), {}
+ return driver, re.compile(fail), {"complete": lambda: driver.done, "complete_what": what, "grace": DRIVER_GRACE}
+
+
+def parser() -> argparse.ArgumentParser:
ap = argparse.ArgumentParser()
ap.add_argument("build", type=Path)
ap.add_argument("--query", default="")
@@ -493,7 +573,12 @@ def main() -> int:
ap.add_argument("--dpr", type=float, default=1.0)
ap.add_argument("--stall", type=float, default=0)
ap.add_argument("--persistence", action="store_true")
- a = ap.parse_args()
+ ap.add_argument("--startscreen", choices=["new", "recording"])
+ return ap
+
+
+def main() -> int:
+ a = parser().parse_args()
if not (a.build / "index.html").exists():
sys.exit(f"{a.build}/index.html not found")
server, proc, page, profile = None, None, None, tempfile.mkdtemp(prefix="web-check-")
@@ -527,16 +612,15 @@ def main() -> int:
page = Page(profile, url, w, h, a.dpr)
page.open()
print(f"viewport {w}x{h} at DPR {a.dpr:g} (expect res={res})")
- persistence = PersistenceCheck(page.command) if a.persistence else None
+ driver, fail, plan = run_plan(a, page.command)
def handle_text(text: str) -> bool:
consumed = on_text(text)
- if persistence is not None:
- persistence.feed(text)
+ if driver is not None:
+ driver.feed(text)
return consumed
- return watch(inbox, proc.poll, lambda: reader.join(2), list(a.expect), re.compile(a.fail), a.timeout,
- on_text=handle_text, stall=a.stall,
- complete=(lambda: persistence.done) if persistence is not None else None)
+ return watch(inbox, proc.poll, lambda: reader.join(2), list(a.expect), fail, a.timeout,
+ on_text=handle_text, stall=a.stall, **plan)
except ValueError as e:
print(f"FAIL: {e}")
return 1