A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
ci: check the Mac x86_64 slice under Rosetta on macos-15 (Fixes #548) (#643)
Adam Moradd0d393e29cc3
diff --git a/.github/workflows/player-golden.yml b/.github/workflows/player-golden.ymlindex 628c1ce30..3c96ead94 100644--- a/.github/workflows/player-golden.yml+++ b/.github/workflows/player-golden.yml@@ -18,8 +18,8 @@ name: Player golden# Asset names (the contract with the release script, tools/release_build.py; ASSETS in tools/player_golden_check.py):# statecraft-israel-<tag>-windows-x64.zip Windows x64 (Mono, built on the Mac; decision O8)# statecraft-israel-<tag>-linux-x64.tar.gz Linux x64 (tar keeps the executable bit)-# statecraft-israel-<tag>-macos-universal.zip macOS Universal (IL2CPP), the .app inside; checked twice, on macos-15-# (arm64 slice) and macos-15-intel (x86_64 slice; GitHub ends it in Aug 2027: #548)+# statecraft-israel-<tag>-macos-universal.zip macOS Universal (IL2CPP), the .app inside; checked twice on macos-15,+# the arm64 slice and the x86_64 slice under Rosetta (`arch -x86_64`; #548)# Each archive also carries the notices (REQUIRED_NOTICES in tools/player_golden_check.py) at its top level, beside the# player or the .app; a missing one fails before the player runs.# <tag> is the release tag with its v (statecraft-israel-v0.2.0-windows-x64.zip), like the web zip in docs/RELEASING.md.diff --git a/docs/RELEASING.md b/docs/RELEASING.mdindex e7efa2858..26d601d59 100644--- a/docs/RELEASING.md+++ b/docs/RELEASING.md@@ -125,8 +125,9 @@ GitHub Releases page (and, from M4, on itch.io). Steps 1–3 are a normal pull rPublishing starts the `Player golden` workflow (`.github/workflows/player-golden.yml`). It downloads each player,checks it against the SHA-256 GitHub records for the asset, and runs `-batchmode -nographics -golden` on GitHub's- Windows and Linux machines (the Linux player under `xvfb-run -a`: with no display at all it crashes, issue #533), and the Mac app twice: on Apple silicon (`macos-15`, its arm64 slice) and on Intel- (`macos-15-intel`, its x86_64 slice; issue #548 tracks its end in August 2027). It fails when only one or two of the+ Windows and Linux machines (the Linux player under `xvfb-run -a`: with no display at all it crashes, issue #533), and the Mac app twice on Apple silicon (`macos-15`):+ its arm64 slice, and its x86_64 slice under Rosetta (`arch -x86_64`; GitHub retires its last Intel image,+ `macos-15-intel`, in August 2027, issue #548). It fails when only one or two of thethree archives are attached. A release with none (a web-only release, before desktop players ship) passes, but itsrun summary says UNCHECKED.- **The release stays a pre-release marked "unchecked" until that run is green.** Testers can download a pre-releasediff --git a/tools/player_golden_check.py b/tools/player_golden_check.pyindex 810ef89be..3b81470a4 100644--- a/tools/player_golden_check.py+++ b/tools/player_golden_check.py@@ -21,7 +21,8 @@ player or the .app), runs it with`-batchmode -nographics -golden -logFile <absolute path>` (docs/determinism.md), the Linux player under `xvfb-run -a`(DISPLAY_WRAPPER: it crashes with no display at all), and passes only when it exits 0 and its logholds one `GOLDEN OK <name> <hash>` line for every entry in the golden manifest, and no FAIL line. On failure-it prints the whole player log. With --arch (the Mac app, run once per slice) the runner's `uname -m` must be that+it prints the whole player log. With --arch (the Mac app, run once per slice) the player is started as+`arch -<arch>` (the x86_64 slice under Rosetta on an arm64 runner), `uname -m` behind the same prefix must be thatarchitecture and `lipo -archs` must list it. Exit 0 when the check passes, 1 when it fails, 2 on bad input.The release asset names are a contract with the release script (tools/release_build.py): see ASSETS.@@ -56,13 +57,18 @@ ASSETS = {}# The GitHub-hosted runners each player is checked on (standard runners, free and unlimited for a public repository,# plan 6.1): (runner label, the CPU architecture it must report). The Universal Mac app runs twice, so each of its two-# native IL2CPP slices is checked on its own CPU: macos-15 is Apple silicon, macos-15-intel is x86_64 (GitHub offers it-# until August 2027, runner-images#13045; what replaces it is issue #548). An empty architecture is not checked.+# native IL2CPP slices is checked on its own: both on macos-15 (Apple silicon), the x86_64 one under Rosetta (MAC_SLICE).+# GitHub retires macos-15-intel, its last x86_64 image, in August 2027 (runner-images#13045; issue #548). An empty+# architecture is not checked.RUNNERS = {"windows": [("windows-2025", "")],"linux": [("ubuntu-24.04", "")],- "macos": [("macos-15", "arm64"), ("macos-15-intel", "x86_64")],+ "macos": [("macos-15", "arm64"), ("macos-15", "x86_64")],}+# How the Mac player and the CPU probe are started for a slice. A Universal app started bare runs the machine's native+# slice; `arch -x86_64` runs the x86_64 one under Rosetta (installed on GitHub's arm64 macOS images), and `arch -arm64`+# fails on an Intel Mac. `uname -m` behind the same prefix reports the CPU the player will see (issue #548).+MAC_SLICE = ["arch", "-{arch}"]# The notices every archive carries at its top level, beside the player (tools/release_build.py adds them and takes# this list; the web packager, scripts/oss/package_web.sh, copies the same files: test_release_build pins that).@@ -235,20 +241,25 @@ def check_arch(exe: Path, arch: str, machine: str, archs: str) -> list[str]:return problems-def player_command(exe: Path, log: Path, platform: str) -> list[str]:+def slice_prefix(arch: str) -> list[str]:+ """The MAC_SLICE prefix for a Mac slice; nothing when no architecture is checked."""+ return [p.format(arch=arch) for p in MAC_SLICE] if arch else []+++def player_command(exe: Path, log: Path, platform: str, arch: str = "") -> list[str]:"""The golden run's command line: the player with -batchmode -nographics -golden and an absolute -logFile, behind- the platform's DISPLAY_WRAPPER if it has one."""- return [*DISPLAY_WRAPPER.get(platform, []), str(exe), "-batchmode", "-nographics", "-golden", "-logFile",- str(log.resolve())]+ the platform's DISPLAY_WRAPPER if it has one, and behind MAC_SLICE for a Mac slice."""+ return [*DISPLAY_WRAPPER.get(platform, []), *slice_prefix(arch), str(exe), "-batchmode", "-nographics", "-golden",+ "-logFile", str(log.resolve())]-def run_player(exe: Path, log: Path, timeout: int, platform: str) -> int | None:+def run_player(exe: Path, log: Path, timeout: int, platform: str, arch: str = "") -> int | None:"""Runs the golden check; the exit code, or None on timeout. subprocess waits for a Windows GUI-subsystem playertoo, which a plain PowerShell call would not. On POSIX the run gets its own process group and a timeout stops thewhole group: xvfb-run starts the player and Xvfb as its children, and killing only xvfb-run would leave them."""if os.name != "nt":exe.chmod(exe.stat().st_mode | 0o111)- cmd = player_command(exe, log, platform)+ cmd = player_command(exe, log, platform, arch)print("RUN", " ".join(cmd), flush=True)with subprocess.Popen(cmd, cwd=exe.parent, start_new_session=os.name != "nt") as proc:try:@@ -341,7 +352,8 @@ def cmd_run(a) -> int:if problems := layout_problems(work / "player", a.platform, exe):raise ValueError("; ".join(problems))if a.arch:- machine = subprocess.run(["uname", "-m"], capture_output=True, text=True, check=True).stdout.strip()+ machine = subprocess.run([*slice_prefix(a.arch), "uname", "-m"], capture_output=True, text=True,+ check=True).stdout.strip()archs = subprocess.run(["lipo", "-archs", str(exe)], capture_output=True, text=True, check=True).stdoutprint(f"ARCH runner {machine}, player slices {archs.strip()}", flush=True)if problems := check_arch(exe, a.arch, machine, archs):@@ -355,7 +367,7 @@ def cmd_run(a) -> int:return 2log = work / "player.log"try:- code = run_player(exe, log, a.timeout, a.platform)+ code = run_player(exe, log, a.timeout, a.platform, a.arch or "")except OSError as e: # the player could not be started at all (for example: Exec format error); it has no exit codecode, start_error = None, f"the player could not be started: {e}"else:diff --git a/tools/tests/test_player_golden_check.py b/tools/tests/test_player_golden_check.pyindex 84ff74107..25865bb91 100644--- a/tools/tests/test_player_golden_check.py+++ b/tools/tests/test_player_golden_check.py@@ -147,17 +147,20 @@ def test_plan_lists_all_three_players_with_githubs_digests():"sha256": digest(lin)[7:]},{"platform": "macos", "label": "macos arm64", "runner": "macos-15", "arch": "arm64", "asset": mac,"sha256": digest(mac)[7:]},- {"platform": "macos", "label": "macos x86_64", "runner": "macos-15-intel", "arch": "x86_64", "asset": mac,+ {"platform": "macos", "label": "macos x86_64", "runner": "macos-15", "arch": "x86_64", "asset": mac,"sha256": digest(mac)[7:]},]-def test_the_mac_player_runs_on_apple_silicon_and_on_intel():- # Review S3: the Universal app has two native IL2CPP slices; each is run on its own CPU, never under Rosetta.- assert pg.RUNNERS["macos"] == [("macos-15", "arm64"), ("macos-15-intel", "x86_64")]+def test_the_mac_player_runs_both_slices_on_apple_silicon():+ # Review S3: the Universal app has two native IL2CPP slices and each is checked on its own. #548: GitHub retires+ # macos-15-intel, its last x86_64 image, in August 2027, so the x86_64 slice runs under Rosetta on the arm64 runner+ # (`arch -x86_64`, MAC_SLICE) and no runner is an Intel one.+ assert pg.RUNNERS["macos"] == [("macos-15", "arm64"), ("macos-15", "x86_64")]include, _, ok = pg.plan("v0.2.0", release("v0.2.0", *players("v0.2.0")), "workflow_dispatch")assert ok and [(e["runner"], e["arch"]) for e in include if e["platform"] == "macos"] == [- ("macos-15", "arm64"), ("macos-15-intel", "x86_64")]+ ("macos-15", "arm64"), ("macos-15", "x86_64")]+ assert not any("intel" in e["runner"] for e in include)assert len({e["label"] for e in include}) == len(include) # the job names differ@@ -301,7 +304,15 @@ def test_the_linux_player_runs_under_a_virtual_x_display_and_the_others_run_bareargs = [str(exe), "-batchmode", "-nographics", "-golden", "-logFile", str(log.resolve())]assert pg.player_command(exe, log, "linux") == ["xvfb-run", "-a", *args]assert pg.player_command(exe, log, "windows") == args- assert pg.player_command(exe, log, "macos") == args+++def test_the_mac_player_runs_the_slice_it_checks(tmp_path):+ # #548: a Universal app started bare runs the runner's native slice, so each slice is started through `arch`: the+ # x86_64 one under Rosetta on an arm64 runner.+ exe, log = tmp_path / "Statecraft Israel", tmp_path / "player.log"+ args = [str(exe), "-batchmode", "-nographics", "-golden", "-logFile", str(log.resolve())]+ assert pg.player_command(exe, log, "macos", "x86_64") == ["arch", "-x86_64", *args]+ assert pg.player_command(exe, log, "macos", "arm64") == ["arch", "-arm64", *args]@pytest.mark.skipif(sys.platform == "win32", reason="the fake player is a shell script")@@ -499,20 +510,71 @@ def test_arch_is_required_for_macos_and_refused_elsewhere(tmp_path, capsys):pg.main(base + ["--platform", "macos", "--arch", "", "--work", str(tmp_path / "w3")])[email protected](sys.platform != "darwin" or not shutil.which("ditto"), reason="needs ditto, lipo and uname")-def test_run_refuses_a_mac_runner_of_the_other_architecture_before_running(tmp_path, capsys):- # Review T53 nit: pins the call into check_arch (the `if a.arch:` wiring), not only check_arch itself.+def fake_mac_release(tmp_path):(tmp_path / "manifest.txt").write_text(MANIFEST)macos = tmp_path / "build" / "Statecraft.app" / "Contents" / "MacOS"macos.mkdir(parents=True)shutil.copy("/usr/bin/true", macos / "Statecraft Israel")z = mac_release_zip(tmp_path)- here = subprocess.run(["uname", "-m"], capture_output=True, text=True, check=True).stdout.strip()- other = "x86_64" if here == "arm64" else "arm64"- code = pg.main(["run", "--platform", "macos", "--arch", other, "--manifest", str(tmp_path / "manifest.txt"),- "--archive", str(z), "--sha256", pg.sha256(z), "--work", str(tmp_path / "w")])+ return ["run", "--platform", "macos", "--manifest", str(tmp_path / "manifest.txt"), "--archive", str(z),+ "--sha256", pg.sha256(z), "--work", str(tmp_path / "w")]++[email protected](sys.platform != "darwin" or not shutil.which("ditto"), reason="needs ditto, lipo and uname")+def test_run_refuses_a_mac_slice_the_runner_cannot_run_before_running(tmp_path, capsys, monkeypatch):+ # #548: the CPU is read through `arch -<slice>`. On an arm64 runner without Rosetta (or an Intel one asked for+ # arm64) `arch` cannot start uname at all ("Bad CPU type in executable"), so the run stops before the player.+ real_run = subprocess.run+ seen = []++ def fake_run(cmd, *a, **k):+ seen.append(cmd)+ if cmd == ["arch", "-x86_64", "uname", "-m"]:+ raise subprocess.CalledProcessError(1, cmd, "", "arch: posix_spawnp: uname: Bad CPU type in executable\n")+ return real_run(cmd, *a, **k)+ monkeypatch.setattr(pg.subprocess, "run", fake_run)+ code = pg.main(fake_mac_release(tmp_path) + ["--arch", "x86_64"])out = capsys.readouterr().out- assert code == 2 and f"the runner is {here}, not {other}: check the runner label" in out and "RUN " not in out+ assert code == 2 and "PLAYER GOLDEN ERROR macos" in out and "RUN " not in out+ assert "['arch', '-x86_64', 'uname', '-m']" in out+ assert ["arch", "-x86_64", "uname", "-m"] in seen and ["uname", "-m"] not in seen++[email protected](sys.platform != "darwin" or not shutil.which("ditto"), reason="needs ditto, lipo and uname")+def test_run_refuses_a_mac_player_without_the_slice_before_running(tmp_path, capsys, monkeypatch):+ # Review T53 nit: pins the call into check_arch (the `if a.arch:` wiring), not only check_arch itself.+ real_run = subprocess.run++ def fake_run(cmd, *a, **k):+ if cmd == ["arch", "-x86_64", "uname", "-m"]:+ return subprocess.CompletedProcess(cmd, 0, "x86_64\n", "")+ if cmd[:2] == ["lipo", "-archs"]:+ return subprocess.CompletedProcess(cmd, 0, "arm64\n", "")+ return real_run(cmd, *a, **k)+ monkeypatch.setattr(pg.subprocess, "run", fake_run)+ code = pg.main(fake_mac_release(tmp_path) + ["--arch", "x86_64"])+ out = capsys.readouterr().out+ assert code == 2 and "Statecraft Israel has no x86_64 slice (lipo -archs: arm64)" in out and "RUN " not in out++[email protected](sys.platform != "darwin" or not shutil.which("ditto"), reason="needs ditto, lipo and uname")+def test_run_starts_the_mac_player_through_arch_for_its_slice(tmp_path, capsys, monkeypatch):+ # Review of #643: a bare start would run the runner's native arm64 slice and could pass green for x86_64.+ real_run = subprocess.run+ started = []++ def fake_run(cmd, *a, **k):+ if cmd == ["arch", "-x86_64", "uname", "-m"]:+ return subprocess.CompletedProcess(cmd, 0, "x86_64\n", "") # Rosetta on an arm64 runner+ if cmd[:2] == ["lipo", "-archs"]:+ return subprocess.CompletedProcess(cmd, 0, "x86_64 arm64\n", "")+ return real_run(cmd, *a, **k)+ monkeypatch.setattr(pg.subprocess, "run", fake_run)+ monkeypatch.setattr(pg, "run_player", lambda *args: started.append(args) or 0)+ pg.main(fake_mac_release(tmp_path) + ["--arch", "x86_64"])+ assert len(started) == 1 and started[0][4:] == ("x86_64",)+ exe, log, _, platform, arch = started[0]+ assert pg.player_command(exe, log, platform, arch)[:2] == ["arch", "-x86_64"]def mac_release_zip(tmp_path, notices=pg.REQUIRED_NOTICES, extra=()):