A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Release tools: four more failures refuse instead of succeeding (Fixes #2690) (#2692)
Eyal Golan773627426514
diff --git a/tools/release_build.py b/tools/release_build.pyindex 863c35603..3e3bb619e 100644--- a/tools/release_build.py+++ b/tools/release_build.py@@ -637,7 +637,11 @@ def main(argv: list[str] | None = None) -> int:stamp(nightly) # restored by the checkout below, so each build stamps againcode = run(build_command(unity, p, target, log, shareable, a.steam), cwd=REPO).returncodefinally:- run(["git", "checkout", "--", "unity/ProjectSettings", "unity/Assets/Settings"], cwd=REPO)+ restore = run(["git", "checkout", "--", "unity/ProjectSettings", "unity/Assets/Settings"], cwd=REPO)+ if restore.returncode != 0:+ print(f"FAILED: restoring Unity settings after the {p.name} build exited {restore.returncode}; "+ "no build record was written.", file=sys.stderr)+ return 1wall = round(time.monotonic() - t0)log_text = log.read_text(errors="replace") if log.exists() else ""if code != 0 or not target.exists():@@ -671,7 +675,12 @@ def main(argv: list[str] | None = None) -> int:return 1arch = Noneif p.name == "mac":- arch = run(["lipo", "-archs", str(mac_executable(target))], capture=True).stdout.strip() or None+ inspected = run(["lipo", "-archs", str(mac_executable(target))], capture=True)+ arch = inspected.stdout.strip()+ if inspected.returncode != 0 or not arch:+ print(f"FAILED: lipo could not inspect the macOS player architecture (exit {inspected.returncode}"+ f"{', no output' if not arch else ''}); no build record was written.", file=sys.stderr)+ return 1golden = {"status": "unchecked", "exit_code": None, "lines": [],"note": "this player cannot run on the Mac; the CI player golden check runs it (spec 6.3)"}if p.runs_here:@@ -699,6 +708,10 @@ def main(argv: list[str] | None = None) -> int:print(f"FAILED: cannot prove the working tree remained clean after the builds: {e}; ""no build record was written.", file=sys.stderr)return 1+ if dirty_after:+ print("FAILED: the working tree is dirty after the builds: " + ", ".join(dirty_after) ++ "; no build record was written.", file=sys.stderr)+ return 1record = {"schema": 1, "tool": "tools/release_build.py", "commit": commit,"describe": describe, "branch": branch, "release": release,# checked before the builds: a dirty tree is refused (a nightly may carry only its own bundleVersion stamp)diff --git a/tools/tests/test_nightly.py b/tools/tests/test_nightly.pyindex 90806bb6d..2ec74b582 100644--- a/tools/tests/test_nightly.py+++ b/tools/tests/test_nightly.py@@ -675,6 +675,20 @@ def test_editmode_failure_or_missing_results_or_timeout_refuses(night, env):assert e.value.gate == "editmode"+def test_editmode_unreadable_results_refuse_and_still_restore_settings(night, env, monkeypatch):+ r = editmode_runner(night)++ def unreadable(path):+ assert Path(path).name == "editmode.xml"+ raise OSError("permission denied")++ monkeypatch.setattr(nightly.unity_postmerge.ET, "parse", unreadable)+ with pytest.raises(Refused) as e:+ nightly.run_editmode(night, r)+ assert e.value.gate == "editmode" and "result file could not be read: permission denied" in e.value.detail+ assert r.envs[-1][0] == nightly.RESTORE_ARGV++def test_settings_are_restored_when_the_runner_raises(night, env):r = editmode_runner(night)real = r.rundiff --git a/tools/tests/test_release_build.py b/tools/tests/test_release_build.pyindex 9aa8948ad..ad5f14319 100644--- a/tools/tests/test_release_build.py+++ b/tools/tests/test_release_build.py@@ -67,7 +67,7 @@ class Fake:def __init__(self, dirty="", golden_ok=True, build_ok=True, branch="main", tags=("v0.1.0",), worktrees=None,build_raises=None, dirty_after="", on_origin_main=True, fail_status=False,- fail_status_after=False, fail_worktree_list=False):+ fail_status_after=False, fail_worktree_list=False, fail_checkout=False, lipo_code=0, lipo_out="x86_64 arm64\n"):self.calls: list[list[str]] = []self.dirty, self.golden_ok, self.build_ok = dirty, golden_ok, build_okself.branch, self.tags, self.worktrees = branch, tags, worktrees@@ -76,6 +76,9 @@ class Fake:self.fail_status = fail_statusself.fail_status_after = fail_status_afterself.fail_worktree_list = fail_worktree_list+ self.fail_checkout = fail_checkout+ self.lipo_code = lipo_code+ self.lipo_out = lipo_outdef __call__(self, cmd, **kw):cmd = [str(c) for c in cmd]@@ -102,6 +105,8 @@ class Fake:out = "v0.1.0-5-g1b7a36cb\n"elif cmd[:2] == ["git", "check-ignore"]:code = 0 # as if git ignored every path: being ignored must not make a folder in a checkout acceptable+ elif cmd[:3] == ["git", "checkout", "--"]:+ code = 1 if self.fail_checkout else 0elif "-executeMethod" in cmd:self.built = Trueif self.build_raises:@@ -143,7 +148,8 @@ class Fake:if p.is_file():z.write(p, (Path(src.name) / p.relative_to(src)).as_posix())elif cmd[0] == "lipo":- out = "x86_64 arm64\n"+ out = self.lipo_out+ code = self.lipo_codereturn rb.Result(code, out)@@ -321,6 +327,38 @@ def test_the_settings_are_restored_when_the_build_call_raises(repo, editor, monkassert [c for c in fake.calls[build + 1:] if c[:3] == ["git", "checkout", "--"]]+def test_a_failed_settings_restore_stops_before_goldens_or_records(repo, editor, monkeypatch, tmp_path, capsys):+ fake = Fake(fail_checkout=True)+ out = tmp_path / "o"+ assert run_main(["--platform", "mac", "--out", str(out)], repo, editor, fake, monkeypatch) == 1+ assert [c for c in fake.calls if c[:3] == ["git", "checkout", "--"]]+ assert not [c for c in fake.calls if "-golden" in c]+ assert not (out / "build-record.json").exists()+ assert "restoring Unity settings" in capsys.readouterr().err+++def test_a_failed_lipo_with_plausible_output_stops_before_goldens_or_records(repo, editor, monkeypatch, tmp_path, capsys):+ fake = Fake(lipo_code=1)+ out = tmp_path / "o"+ assert run_main(["--platform", "mac", "--out", str(out)], repo, editor, fake, monkeypatch) == 1+ lipo = [c for c in fake.calls if c[0] == "lipo"]+ assert len(lipo) == 1 and lipo[0][1] == "-archs"+ assert not [c for c in fake.calls if "-golden" in c]+ assert not (out / "build-record.json").exists()+ assert "lipo could not inspect" in capsys.readouterr().err+++def test_a_silent_lipo_that_exits_zero_stops_before_goldens_or_records(repo, editor, monkeypatch, tmp_path, capsys):+ """#2690 review: an empty architecture list is as unknown as a failed lipo."""+ fake = Fake(lipo_out="")+ out = tmp_path / "o"+ assert run_main(["--platform", "mac", "--out", str(out)], repo, editor, fake, monkeypatch) == 1+ assert [c for c in fake.calls if c[0] == "lipo"]+ assert not [c for c in fake.calls if "-golden" in c]+ assert not (out / "build-record.json").exists()+ assert "lipo could not inspect" in capsys.readouterr().err++def test_a_failed_unity_exit_fails_even_when_a_player_is_left_behind(repo, editor, monkeypatch, tmp_path):"""Mutation M1: Unity's exit code counts, not only whether the target exists."""fake = Fake(build_ok=False)@@ -337,16 +375,16 @@ def test_an_empty_or_malformed_manifest_never_passes():# --- the record's tree state -------------------------------------------------------------------------------------------def test_the_record_says_whether_the_tree_stayed_clean(repo, editor, monkeypatch, tmp_path):- fake = Fake(dirty_after=" M unity/Packages/packages-lock.json\n")+def test_a_dirty_tree_after_the_build_is_named_and_writes_no_record(repo, editor, monkeypatch, tmp_path, capsys):+ dirty = "M unity/Packages/packages-lock.json"+ fake = Fake(dirty_after=f" {dirty}\n")out = tmp_path / "o"- assert run_main(["--platform", "mac", "--out", str(out)], repo, editor, fake, monkeypatch) == 0- record = json.loads((out / "build-record.json").read_text())- assert record["tree_clean"] is True, "checked before the builds"- assert record["tree_clean_after_builds"] is False- assert record["dirty_after_builds"] == ["M unity/Packages/packages-lock.json"]+ assert run_main(["--platform", "mac", "--out", str(out)], repo, editor, fake, monkeypatch) == 1+ assert not (out / "build-record.json").exists()describe = next(i for i, c in enumerate(fake.calls) if c[:2] == ["git", "describe"])assert describe < next(i for i, c in enumerate(fake.calls) if "-executeMethod" in c), "describe is taken before"+ err = capsys.readouterr().err+ assert "working tree is dirty after the builds" in err and dirty in errdef test_a_failed_postbuild_git_status_writes_no_clean_record(repo, editor, monkeypatch, tmp_path, capsys):diff --git a/tools/tests/test_unity_postmerge.py b/tools/tests/test_unity_postmerge.pyindex 96dbd5b4c..12c2fdcba 100644--- a/tools/tests/test_unity_postmerge.py+++ b/tools/tests/test_unity_postmerge.py@@ -300,6 +300,41 @@ def test_a_failed_warm_up_is_a_broken_run_and_the_tests_never_start(tmp_path, moassert launches == ["warm-up"] and code == 1 and "warm-up" in r.broken and not up.passed(r, code)+def test_main_records_and_reports_an_unreadable_editmode_result(tmp_path, monkeypatch):+ home, repo = tmp_path / "home", tmp_path / "repo"+ wt = home / "worktree"+ (wt / "unity/ProjectSettings").mkdir(parents=True)+ (wt / "unity/ProjectSettings/ProjectVersion.txt").write_text("m_EditorVersion: 6000.3.25f1\n")+ repo.mkdir()+ gh = FakeGh()++ monkeypatch.setattr(up, "fetch_tip", lambda git: SHA)+ monkeypatch.setattr(up, "commit_time", lambda git, sha: time.time())+ monkeypatch.setattr(up, "prepare_worktree", lambda *a: None)+ monkeypatch.setattr(up.subprocess, "run", lambda *a, **k: subprocess.CompletedProcess(a[0], 0))+ monkeypatch.setattr(up, "unity_path", lambda version: sys.executable)+ monkeypatch.setattr(up, "tidy", lambda *a: "library 0 MiB")+ monkeypatch.setattr(up, "_gh", gh)++ def fake_unity(cmd, record, **kw):+ if "-runTests" in cmd:+ Path(cmd[cmd.index("-testResults") + 1]).write_text('<test-run total="1" passed="1" failed="0"/>')+ return 0, None++ def unreadable(path):+ assert Path(path).name == "editmode.xml"+ raise OSError("permission denied")++ monkeypatch.setattr(up, "run_with_timeout", fake_unity)+ monkeypatch.setattr(up.ET, "parse", unreadable)++ assert up.main(["--repo", str(repo), "--home", str(home)]) == 0+ log = (home / "results.log").read_text()+ assert f"{SHA} FAIL" in log and "broken" in log+ assert len(gh.created) == 1+ assert "result file could not be read: permission denied" in gh.created[0][1]++def test_the_plist_template_polls_no_more_often_than_every_ten_minutes():text = (up.TOOLS / "unity_postmerge.plist.in").read_text(encoding="utf-8")filled = up.fill_plist(text, uv="/opt/uv", repo="/r", home="/h", path="/usr/bin:/bin")diff --git a/tools/tests/test_web_check.py b/tools/tests/test_web_check.pyindex 4005a905d..a737b4b7e 100644--- a/tools/tests/test_web_check.py+++ b/tools/tests/test_web_check.py@@ -5,6 +5,7 @@ import queueimport reimport shutilimport socket+import sysimport threadingimport timeimport urllib.request@@ -954,6 +955,20 @@ def test_url_and_build_are_exclusive_and_one_is_required(capsys):wc.check_source(ap, ap.parse_args(["--url", "https://x.invalid/index.html"]))[email protected]("expect", [(), ("--expect", ""), ("--expect", " ")],+ ids=["absent", "empty", "whitespace"])+def test_main_refuses_without_a_positive_check(expect, tmp_path, monkeypatch, capsys):+ build = tmp_path / "build"+ build.mkdir()+ (build / "index.html").write_text("<!doctype html>")+ monkeypatch.setattr(sys, "argv", ["web_check.py", str(build), *expect])+ monkeypatch.setattr(wc, "find_chrome", lambda: (_ for _ in ()).throw(AssertionError("Chrome was reached")))+ with pytest.raises(SystemExit) as e:+ wc.main()+ assert e.value.code == 2+ assert "require at least one positive check" in capsys.readouterr().err++def test_a_url_takes_the_query_after_a_question_mark_or_an_ampersand():assert wc.with_query("https://h/index.html", "navlog") == "https://h/index.html?navlog"assert wc.with_query("https://h/index.html?v=1", "navlog") == "https://h/index.html?v=1&navlog"diff --git a/tools/unity_postmerge.py b/tools/unity_postmerge.pyindex cc516a150..c579143b5 100644--- a/tools/unity_postmerge.py+++ b/tools/unity_postmerge.py@@ -148,7 +148,7 @@ def parse_results(path: Path) -> Results:return Results(broken=f"no result file was written ({path.name}): Unity did not run the tests")try:root = ET.parse(path).getroot()- except ET.ParseError as e:+ except (ET.ParseError, OSError) as e:return Results(broken=f"the result file could not be read: {e}")r = Results(total=int(root.get("total", 0)), passed=int(root.get("passed", 0)), failed=int(root.get("failed", 0)))for case in root.iter("test-case"):diff --git a/tools/web_check.py b/tools/web_check.pyindex 7baa6fa5a..479c28d93 100644--- a/tools/web_check.py+++ b/tools/web_check.py@@ -11,6 +11,7 @@ Usage (from the repo root):uv run tools/web_check.py unity/Builds/Web-disabled --query "golden" --expect "GOLDEN OK hash1950 a08ff8504d862925563c8523a707b58ebe3bcaac0b504dc9ce7e028fc19eb0e4" --expect "GOLDEN OK hash1952 5561fc51a03a25e7bad499bd2c9d8de156dea241118ac4c80bbf2e0fb50c97ef"uv run tools/web_check.py unity/Builds/Web-disabled --query "smoke-orders" --expect "SMOKE ORDERS OK 1948-06-15 08d9800eda4462ef165cc7ea6285fad059c030c0f87ad563e35c9789cc352d78"(the smoke-orders golden: one Move given through the unit card, docs/determinism.md)+Every run needs a positive check: a nonblank --expect, --startscreen, --persistence or --first-save (#2690).Options: --query Q (page URL query, without '?'), --expect TEXT (repeatable), --fail REGEX (default: GOLDEN FAIL|SMOKE FAIL|BOOT FAIL),--timeout SECONDS (default 300), --stall SECONDS (fail when no console message arrives for that long; 0 = off),--swiftshader (software WebGL when there is no GPU), --dpr N (default 1), --shots DIR (reassemble the player's@@ -983,6 +984,12 @@ def check_source(ap: argparse.ArgumentParser, a) -> None:ap.error("give exactly one of build and --url")+def check_positive(ap: argparse.ArgumentParser, a) -> None:+ """Every run must name console evidence to see or a driver whose completion proves success."""+ if not any(text.strip() for text in a.expect) and not (a.startscreen or a.persistence or a.first_save):+ ap.error("require at least one positive check: a nonblank --expect, --startscreen, --persistence or --first-save")++def with_query(url: str, query: str) -> str:"""`url` with `query` added: after ? or, when the URL already has a query, after &."""if not query:@@ -1002,6 +1009,7 @@ def main() -> int:ap = parser()a = ap.parse_args()check_source(ap, a)+ check_positive(ap, a)if a.build is not None and not (a.build / "index.html").exists():sys.exit(f"{a.build}/index.html not found")server, proc, page = None, None, None