A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Gate the shareable zip and Build.Mac -shareable on the sensitivity review
eyalgolanb8428591b3f4
diff --git a/docs/m3-release.md b/docs/m3-release.mdindex e6bdfe75b..99616e1d0 100644--- a/docs/m3-release.md+++ b/docs/m3-release.md@@ -5,7 +5,7 @@ start of M4, as a private Draft (owner ruling, 2026-10-10); their sections below## What ships- **Folder and zip:** `unity/Builds/Web-brotli/` uses Brotli compression with no decompression fallback. It is zipped as `unity/Builds/statecraft-m3-web.zip`, with `index.html` at the zip root. Both are build output and are not committed.-- **Built by:** `"$UNITY" -batchmode -quit -projectPath unity -buildTarget WebGL -executeMethod Statecraft.Game.EditorTools.Build.Web -compression brotli -logFile "$PWD/unity-build-web-br.log"`, then `(cd unity/Builds/Web-brotli && rm -f ../statecraft-m3-web.zip && zip -qr ../statecraft-m3-web.zip .)`.+- **Built by:** `"$UNITY" -batchmode -quit -projectPath unity -buildTarget WebGL -executeMethod Statecraft.Game.EditorTools.Build.Web -compression brotli -logFile "$PWD/unity-build-web-br.log"`, then `python3 tools/package_release.py` (it zips the folder, `index.html` at the root, and refuses until the sensitivity review below is done). Never zip by hand.- **After building:** drop the build's rewrites of the settings with`git checkout -- unity/Assets/Settings unity/ProjectSettings/ProjectSettings.asset` (as in `dev-setup.md`), so nobuild-cache change gets committed.@@ -83,9 +83,12 @@ war-casualties). The seven events below are only `fact-checked`. The owner revieby moving the event's `status:` in its YAML file to `sensitivity-reviewed` and committing it (the loader accepts thatvalue). Nothing else counts as a sign-off.-- **Gate:** `Build.Web ... -shareable` refuses to build while any sensitive event is not `sensitivity-reviewed`, and names- them (`Statecraft.Sim.ReleaseGate.SensitiveUnreviewed`). Use `-shareable` for every build that leaves this machine,- including the M4 private Draft once it is shared with anyone. Local builds (no flag) are not gated.+- **Gate:** `Build.Web ... -shareable` and `Build.Mac ... -shareable` refuse to build while any sensitive event is not+ `sensitivity-reviewed`, and name them (`Statecraft.Sim.ReleaseGate.SensitiveUnreviewed`). `tools/package_release.py`+ makes the shareable zip and runs the same check (`Statecraft.Cli --release-gate`) on the content inside the build, so+ it prints `PACKAGE REFUSED ...` and exits 1 until the review is done. Use `-shareable` and the script for every build+ that leaves this machine, including the M4 private Draft once it is shared with anyone. Local dev builds (no flag)+ are not gated, because web_check and the golden checks need them.- **Pinned set:** `FinalWaveTests.TheSensitiveEventsArePinned` lists the seven ids, and`TheOwnerTableListsEverySensitiveEvent` fails if a sensitive event is missing from this table, so a new one cannotskip the review.@@ -105,7 +108,7 @@ Deferred to the start of M4, as a private Draft (owner ruling, 2026-10-10). Theowner's itch.io account and is never automated, and the build must pass the sensitivity gate above (`-shareable`).1. Sign in at https://itch.io. Go to Dashboard, then **Create new project**.2. Set the title to "Statecraft: Israel (M3 preview)", Kind of project to **HTML**, and Classification to Games.-3. Under Uploads, upload `unity/Builds/statecraft-m3-web.zip` and tick **This file will be played in the browser**.+3. Under Uploads, upload `unity/Builds/statecraft-m3-web.zip` (made by `python3 tools/package_release.py`) and tick **This file will be played in the browser**.4. Embed options:- Viewport **1280 × 720**. It fits a 1366×768 or 1440×900 laptop page without scrolling, and under the UI'sScaleWithScreenSize (reference 1920×1080) it lays out exactly like 1920×1080; `UiLayoutTests` covers 1280×720.diff --git a/sim/Statecraft.Cli/Program.cs b/sim/Statecraft.Cli/Program.csindex 1d8a043d7..3cb5a700f 100644--- a/sim/Statecraft.Cli/Program.cs+++ b/sim/Statecraft.Cli/Program.cs@@ -4,6 +4,7 @@ using Statecraft.Sim;// Text front end for the headless sim.// dotnet run --project Statecraft.Cli -- [--content DIR] [--seed N] [--auto historical --turns N]+// dotnet run --project Statecraft.Cli -- --release-gate [--content DIR] (exit 0 when shareable, 3 when not)// Interactive commands: c EVENT OPTION | p POLICY LEVEL | m LEVEL | s DELTA | n (end turn) | qCultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;@@ -31,6 +32,17 @@ try { content = ContentLoader.Load(Arg("--content") ?? FindContent()); }catch (DirectoryNotFoundException) { Console.Error.WriteLine("Content error: content directory not found (use --content <path>)"); return 2; }catch (ContentException e) { Console.Error.WriteLine($"Content error: {e.Message}"); return 2; }+// --release-gate: the sensitivity gate before a build is shared (spec 5.5; tools/package_release.py, Build -shareable).+// Exit 0 and "RELEASE GATE OK" when every sensitive event is sensitivity-reviewed, else exit 3 naming them.+if (Array.IndexOf(args, "--release-gate") >= 0)+{+ var open = ReleaseGate.SensitiveUnreviewed(content);+ if (open.Count == 0) { Console.WriteLine("RELEASE GATE OK"); return 0; }+ Console.WriteLine("RELEASE GATE REFUSED: the owner's sensitivity review is missing for: " + string.Join(", ", open)+ + " (set status: sensitivity-reviewed in each event's YAML; see docs/m3-release.md)");+ return 3;+}+ulong seed = 1948;int turns = 1000;var seedText = Arg("--seed");diff --git a/tools/README.md b/tools/README.mdindex 44ddcdc9d..365ade20c 100644--- a/tools/README.md+++ b/tools/README.md@@ -13,6 +13,8 @@ Offline data tools (uv inline-script Python). Run from the repo root.`hexgrid.settlement_hex` rule. The sim reads it, so it needs no projection maths.- `web_check.py` serves a WebGL build on http://localhost and opens it in headless Chrome for Testing (Playwright'scache; macOS only, arm64 or x64); it passes when the console shows the expected lines (`GOLDEN OK ...`, `SMOKE OK ...`).+- `package_release.py` zips a Brotli WebGL build for sharing (`unity/Builds/statecraft-m3-web.zip`) and refuses+ (exit 1) until every sensitive event is `sensitivity-reviewed` (docs/m3-release.md).- `preview_map.py` renders the geography check image `tools/.cache/map-preview.png`.- `headed.py` drives a WebGL build in a headed Chrome for Testing over CDP (real GPU, real mouse events, a temporaryprofile deleted on exit): `boot` (?bootlog phase timings, optional CPU throttling), `navpairs` (same-frame click pairs@@ -26,7 +28,7 @@ Run from the repo root; this installs every pinned dependency (rasterio includeduv run --with pytest==9.1.1 --with rasterio==1.5.2 --with numpy==2.5.3 --with pyyaml==6.0.3 --with pillow==12.3.0 --with requests==2.32.5 pytest tools/tests -q```-Expected: `107 passed, 1 skipped` (the skipped one is the headed browser check; add `--headed` and `--with websockets==15.0.1` to run it). Omitting a dependency (e.g. rasterio) silently drops tests or fails collection.+Expected: `109 passed, 1 skipped` (the skipped one is the headed browser check; add `--headed` and `--with websockets==15.0.1` to run it). Omitting a dependency (e.g. rasterio) silently drops tests or fails collection.## Required attribution (Copernicus DEM licence, modified data)diff --git a/tools/package_release.py b/tools/package_release.pynew file mode 100644index 000000000..dbd5bbcf2--- /dev/null+++ b/tools/package_release.py@@ -0,0 +1,57 @@+"""Packages a WebGL release build as the itch.io zip, but only once the owner's sensitivity review is recorded for every+event with a sensitive tag (spec 5.5; docs/m3-release.md). The gate is the sim's own (Statecraft.Cli --release-gate),+run on the content INSIDE the build folder, so it checks exactly what would ship. Stdlib only (plus the .NET SDK).++ python3 tools/package_release.py [--build unity/Builds/Web-brotli] [--zip unity/Builds/statecraft-m3-web.zip]++Exit 0 and "PACKAGED <zip> <bytes>" on success; exit 1 and "PACKAGE REFUSED ..." when the gate refuses or the build is+not a WebGL build folder.+"""+import argparse+import subprocess+import sys+import zipfile+from pathlib import Path++REPO = Path(__file__).resolve().parents[1]+++def gate(content_dir: Path):+ """Runs the sim's release gate on a content folder: (passed, message)."""+ r = subprocess.run(["dotnet", "run", "--project", str(REPO / "sim/Statecraft.Cli"), "-v", "q", "--",+ "--release-gate", "--content", str(content_dir)], capture_output=True, text=True)+ lines = [l for l in (r.stdout + r.stderr).splitlines() if "RELEASE GATE" in l or "error" in l.lower()]+ return r.returncode == 0, "\n".join(lines) or f"release gate exited {r.returncode}"+++def package(build: Path, zip_path: Path) -> int:+ if not (build / "index.html").is_file():+ print(f"PACKAGE REFUSED: {build} has no index.html (not a WebGL build folder)")+ return 1+ content = build / "StreamingAssets" / "content"+ if not content.is_dir():+ print(f"PACKAGE REFUSED: {build} has no StreamingAssets/content")+ return 1+ ok, message = gate(content)+ print(message)+ if not ok:+ print("PACKAGE REFUSED: the build may not be shared until the sensitivity review is recorded")+ return 1+ zip_path.unlink(missing_ok=True)+ with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as z: # index.html at the zip root, as itch.io needs+ for f in sorted(p for p in build.rglob("*") if p.is_file()):+ z.write(f, f.relative_to(build).as_posix())+ print(f"PACKAGED {zip_path} {zip_path.stat().st_size} bytes")+ return 0+++def main(argv=None) -> int:+ p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)+ p.add_argument("--build", default=str(REPO / "unity/Builds/Web-brotli"))+ p.add_argument("--zip", default=str(REPO / "unity/Builds/statecraft-m3-web.zip"))+ a = p.parse_args(argv)+ return package(Path(a.build), Path(a.zip))+++if __name__ == "__main__":+ sys.exit(main())diff --git a/tools/tests/test_package_release.py b/tools/tests/test_package_release.pynew file mode 100644index 000000000..21a2960fc--- /dev/null+++ b/tools/tests/test_package_release.py@@ -0,0 +1,45 @@+"""tools/package_release.py: the itch.io zip is made only after the owner's sensitivity review of every sensitive event+(spec 5.5; M3 rereview). The gate is the sim's own (Statecraft.Cli --release-gate), run on the content inside the build."""+import re+import shutil+import zipfile+from pathlib import Path++import package_release++REPO = Path(package_release.REPO)+SENSITIVE = ["altalena", "bernadotte_assassination", "operation_hiram", "operation_horev", "operation_yoav", "reparations_claim", "ten_days"]+++def fake_build(tmp_path, reviewed):+ """A build folder with index.html and the real content copied into StreamingAssets/content."""+ build = tmp_path / "Web-brotli"+ (build / "StreamingAssets").mkdir(parents=True)+ (build / "index.html").write_text("<html></html>")+ content = build / "StreamingAssets" / "content"+ shutil.copytree(REPO / "content", content)+ if reviewed: # the owner's sign-off, as a fixture+ for e in SENSITIVE:+ f = content / "events" / f"{e}.yaml"+ f.write_text(re.sub(r"(?m)^status: .*$", "status: sensitivity-reviewed", f.read_text()))+ return build+++def test_packaging_is_refused_until_every_sensitive_event_is_reviewed(tmp_path, capsys):+ build, zip_path = fake_build(tmp_path, reviewed=False), tmp_path / "out.zip"+ assert package_release.main(["--build", str(build), "--zip", str(zip_path)]) == 1+ assert not zip_path.exists()+ out = capsys.readouterr().out+ assert "PACKAGE REFUSED" in out+ for e in SENSITIVE:+ assert e in out+++def test_packaging_writes_the_zip_once_all_are_reviewed(tmp_path, capsys):+ build, zip_path = fake_build(tmp_path, reviewed=True), tmp_path / "out.zip"+ assert package_release.main(["--build", str(build), "--zip", str(zip_path)]) == 0+ with zipfile.ZipFile(zip_path) as z:+ names = z.namelist()+ assert "index.html" in names # at the zip root, as itch.io needs+ assert "StreamingAssets/content/events/altalena.yaml" in names+ assert "PACKAGED" in capsys.readouterr().outdiff --git a/unity/Assets/Editor/Build.cs b/unity/Assets/Editor/Build.csindex 5fb0f9e23..3f6d660be 100644--- a/unity/Assets/Editor/Build.cs+++ b/unity/Assets/Editor/Build.cs@@ -43,15 +43,26 @@ namespace Statecraft.Game.EditorTools: "a shareable build needs the owner's sensitivity review of: " + string.Join(", ", open) + " (set status: sensitivity-reviewed; see docs/m3-release.md)";}+ /// <summary>The gate for a build made with these command-line args: a -shareable build (Web or Mac) is refused+ /// until the review is done; a dev build is never gated (web_check and the golden checks need them).</summary>+ public static string? GateRefusal(string[] args, Statecraft.Sim.Content c) =>+ Array.IndexOf(args, "-shareable") >= 0 ? ShareableRefusal(c) : null;++ /// <summary>Logs "BUILD REFUSED ..." and exits 1 when the gate refuses this build; true if it did.</summary>+ static bool RefuseUnlessShareable()+ {+ var args = Environment.GetCommandLineArgs();+ if (Array.IndexOf(args, "-shareable") < 0) return false;+ if (!(GateRefusal(args, Statecraft.Sim.ContentLoader.Load(Paths.Content)) is string refusal)) return false;+ Debug.LogError("BUILD REFUSED " + refusal);+ EditorApplication.Exit(1);+ return true;+ }+public static void Web(){+ if (RefuseUnlessShareable()) return;var name = Arg("-compression") ?? "disabled";- if (Flag("-shareable") && ShareableRefusal(Statecraft.Sim.ContentLoader.Load(Paths.Content)) is string refusal)- {- Debug.LogError("BUILD REFUSED " + refusal);- EditorApplication.Exit(1);- return;- }ProjectSetup.Apply();PlayerSettings.WebGL.compressionFormat = Compression(name);PlayerSettings.WebGL.decompressionFallback = false; // itch.io serves .br/.gz with Content-Encoding@@ -63,6 +74,7 @@ namespace Statecraft.Game.EditorToolspublic static void Mac(){+ if (RefuseUnlessShareable()) return;ProjectSetup.Apply();// Apple clang fuses a*b+c into fmadd by default (tech notes 4.2); turn it off if the Mac golden check fails.PlayerSettings.SetAdditionalIl2CppArgs(Flag("-ffp-contract-off") ? "--compiler-flags=-ffp-contract=off" : "");diff --git a/unity/Assets/Tests/EditMode/BuildGateTests.cs b/unity/Assets/Tests/EditMode/BuildGateTests.csindex 50c81da5f..ca21b3d3a 100644--- a/unity/Assets/Tests/EditMode/BuildGateTests.cs+++ b/unity/Assets/Tests/EditMode/BuildGateTests.cs@@ -27,4 +27,22 @@ public class BuildGateTestsforeach (var e in c.Events) if (ReleaseGate.SensitiveEvents(c).Contains(e.Id)) e.Status = ReleaseGate.ReviewedStatus; // as the owner's sign-off wouldAssert.IsNull(Refusal(c), "all reviewed: the build may be shared");}++ /// <summary>Rereview: the gate applies to every player build made with -shareable (Build.Web and Build.Mac call the same+ /// check); without the flag, dev builds stay ungated (web_check needs them).</summary>+ [Test]+ public void TheShareableFlagGatesEveryPlayerBuild()+ {+ var t = Type.GetType("Statecraft.Game.EditorTools.Build, Assembly-CSharp-Editor")!;+ var gate = t.GetMethod("GateRefusal", BindingFlags.Public | BindingFlags.Static)!;+ var c = ContentLoader.Load(Paths.Content);+ Assert.IsNull(gate.Invoke(null, new object[] { new[] { "Unity", "-executeMethod", "Statecraft.Game.EditorTools.Build.Mac" }, c }), "a dev build is not gated");+ StringAssert.Contains("reparations_claim", (string?)gate.Invoke(null, new object[] { new[] { "Unity", "-shareable" }, c }));+ var source = System.IO.File.ReadAllText("Assets/Editor/Build.cs");+ foreach (var method in new[] { "public static void Web()", "public static void Mac()" })+ {+ var body = source.Substring(source.IndexOf(method, StringComparison.Ordinal), 400);+ StringAssert.Contains("RefuseUnlessShareable()", body, method + " checks the gate first");+ }+ }}