A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
art_checkpoint.sh: fail when an editor render is missing (Refs #2697 item 3) (#2898)
Beri11d689866b9d
diff --git a/tools/art_checkpoint.sh b/tools/art_checkpoint.shindex 4955b5385..64a3cc745 100755--- a/tools/art_checkpoint.sh+++ b/tools/art_checkpoint.sh@@ -61,6 +61,17 @@ for pose in $poses; do[[ -s "$out/$pose.png" ]] || { echo "art_checkpoint: $out/$pose.png is missing" >&2; exit 1; }doneshared "$UNITY" -batchmode -CI false -GITHUB_ACTIONS false -TF_BUILD false -quit -projectPath unity -buildTarget OSXUniversal -executeMethod MapCapture.Promo -captureDir "$root/$out/editor" ${units_arg[@]+"${units_arg[@]}"} ${proof_arg[@]+"${proof_arg[@]}"} -logFile "$root/unity-capture-promo.log"+# The editor renders are one PNG per quality tier and PromoPose.All pose (MapCapture.Promo, named <tier>-<pose>.png). art_compare+# only measures the files it finds, so a missing render would pass unseen here (#2697): fail on any that is absent or empty.+tiers=$(grep -E '^ name: ' unity/ProjectSettings/QualitySettings.asset | sed 's/^ name: //')+all_poses=$(grep -E 'PromoPose> All ' unity/Assets/Scripts/Map/PromoPose.cs | sed -E 's/.*new\[\] \{ *(.*[^ ]) *\}.*/\1/' | tr -d ',')+[[ -n "$tiers" && -n "$all_poses" ]] || { echo "art_checkpoint: no quality tier or no PromoPose.All found" >&2; exit 1; }+for tier in $tiers; do+ for ident in $all_poses; do+ pose=$(grep -oE "PromoPose $ident = new PromoPose\(\"[A-Za-z0-9_]*\"" unity/Assets/Scripts/Map/PromoPose.cs | cut -d'"' -f2)+ [[ -s "$out/editor/$tier-$pose.png" ]] || { echo "art_checkpoint: the editor render $out/editor/$tier-$pose.png is missing" >&2; exit 1; }+ done+donegit checkout -- unity/ProjectSettings/QualitySettings.asset # SetQualityLevel may have written m_CurrentQuality (no unstaged edits: checked above)# art_compare's exit codes (tools/art_compare.py): 0 passed; 1 no screenshot matched a pose, or a crash; 2 a blank# capture; 3 a material guard FAIL (#695: the art is off its promo-02 band); 4 a material too rare to measure. 1, 2 and 4diff --git a/tools/tests/test_art_compare.py b/tools/tests/test_art_compare.pyindex 3a38d2b35..528eeb9b6 100644--- a/tools/tests/test_art_compare.py+++ b/tools/tests/test_art_compare.py@@ -244,12 +244,12 @@ def test_a_gating_material_missing_from_the_capture_exits_4_not_3(tmp_path, capsSTUB_UV = r"""#!/usr/bin/env bash-# A stand-in for uv: Unity (through machine_lock) and the browser do nothing; web_check writes each pose's PNG (every+# A stand-in for uv: machine_lock just runs its command (the Unity stub below) and the browser does nothing; web_check writes each pose's PNG (every# PromoPose.cs pose VisualShots shoots: All, CloseChecks and #659's CloseUps and TownChecks);# art_compare writes a compare image, prints what STUB_ART_OUT holds and exits STUB_ART_EXIT.shiftcase "$1" in- tools/machine_lock.py) exit 0 ;;+ tools/machine_lock.py) while [[ "$1" != -- ]]; do shift; done; shift; "$@" ;; # the lock is a no-op, the command (the Unity stub) runstools/web_check.py) while [[ $# -gt 0 && "$1" != --shots ]]; do shift; donefor p in gameplay03 diorama02 hero06judea hero06negev tel_aviv30 jaffa12 jerusalem12 haifa12 rishon08 degania06 nazareth08 nahalal06 start120; do echo x > "$2/$p.png"; done ;;tools/art_compare.py) mkdir -p "$2/editor"; echo x > "$2/gameplay03-compare.png"; echo x > "$2/editor/a-compare.png"@@ -258,23 +258,35 @@ esac"""-def run_checkpoint(tmp_path, art_exit, art_out=""):+STUB_UNITY = """#!/usr/bin/env bash+# A stand-in for Unity: MapCapture.Promo writes <tier>-<pose>.png per quality tier and PromoPose.All pose into -captureDir,+# except the one render named by STUB_MISSING (a file name, e.g. PC-diorama02.png), left out to play a failed capture.+while [[ $# -gt 0 && "$1" != -captureDir ]]; do shift; done+mkdir -p "$2"+for f in Mobile-gameplay03 Mobile-diorama02 PC-gameplay03 PC-diorama02; do [[ "$f.png" == "${STUB_MISSING:-}" ]] || echo x > "$2/$f.png"; done+"""+++def run_checkpoint(tmp_path, art_exit, art_out="", missing=""):"""tools/art_checkpoint.sh in a scratch git repository holding only what it reads, with uv stubbed (no Unity)."""import shutilimport subprocessrepo, tools = tmp_path / "repo", Path(__file__).resolve().parents[1]- for rel, text in {"unity/ProjectSettings/QualitySettings.asset": "q\n", "unity/Builds/Web-disabled/index.html": "x\n",+ for rel, text in {"unity/Builds/Web-disabled/index.html": "x\n","sim/Statecraft.Sim.Tests/golden/manifest.txt": "hash1950 aa\nhash1952 bb\n"}.items():(repo / rel).parent.mkdir(parents=True, exist_ok=True); (repo / rel).write_text(text)(repo / "tools").mkdir(); shutil.copy(tools / "art_checkpoint.sh", repo / "tools")(repo / "unity/Assets/Scripts/Map").mkdir(parents=True)shutil.copy(tools.parent / "unity/Assets/Scripts/Map/PromoPose.cs", repo / "unity/Assets/Scripts/Map")+ (repo / "unity/ProjectSettings").mkdir(parents=True, exist_ok=True)+ shutil.copy(tools.parent / "unity/ProjectSettings/QualitySettings.asset", repo / "unity/ProjectSettings")git = ["git", "-C", str(repo), "-c", "user.name=t", "-c", "[email protected]"]subprocess.run(git + ["init", "-q"], check=True); subprocess.run(git + ["add", "-A"], check=True)subprocess.run(git + ["commit", "-qm", "t"], check=True)stub = tmp_path / "bin"; stub.mkdir(); (stub / "uv").write_text(STUB_UV); (stub / "uv").chmod(0o755)- env = {**os.environ, "PATH": f"{stub}:{os.environ['PATH']}", "UNITY": "/bin/true",- "STUB_ART_EXIT": str(art_exit), "STUB_ART_OUT": art_out}+ (stub / "unity").write_text(STUB_UNITY); (stub / "unity").chmod(0o755)+ env = {**os.environ, "PATH": f"{stub}:{os.environ['PATH']}", "UNITY": str(stub / "unity"),+ "STUB_MISSING": missing, "STUB_ART_EXIT": str(art_exit), "STUB_ART_OUT": art_out}return subprocess.run(["bash", "tools/art_checkpoint.sh", "--no-build", "cp"], cwd=repo, env=env, capture_output=True, text=True)@@ -343,3 +355,11 @@ def test_the_material_guard_and_main_leave_a_navy_minimap_out_of_the_sea(tmp_patpromos={"gameplay03": promo, "diorama02": promo})sea = [l.split(" vs ")[0] for l in capsys.readouterr().out.splitlines() if l.startswith("MATERIAL diorama02.png sea")]assert len(sea) == 2 and sea[0] == sea[1], sea+++def test_the_checkpoint_fails_when_an_editor_render_is_missing(tmp_path):+ """#2697 item 3: art_compare measures only the renders it finds, so a tier's missing pose render passed unseen."""+ assert run_checkpoint(tmp_path / "ok", 0).returncode == 0+ for missing in ("PC-diorama02.png", "Mobile-gameplay03.png"):+ r = run_checkpoint(tmp_path / missing, 0, missing=missing)+ assert r.returncode == 1 and f"editor/{missing} is missing" in r.stderr and "ART CHECKPOINT" not in r.stdout, missing