A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
tools: event scaffold, one command makes a valid new event file (fixes #323) (#326)
agamrafaeli-instinct52b655199317
diff --git a/docs/dev-setup.md b/docs/dev-setup.mdindex cbf0395cc..006eea875 100644--- a/docs/dev-setup.md+++ b/docs/dev-setup.md@@ -14,7 +14,7 @@## Without Unity (Linux, a container, a sandbox)-Unity, a Unity licence and macOS are only needed for `unity/`. The sim, the content and the policy checks run headless, also in the dev container (`.devcontainer/README.md`, for a local container or a Codespace). These are the commands CI runs (`.github/workflows/ci.yml`), with the .NET SDK 10.0.401 and `uv`:+Unity, a Unity licence and macOS are only needed for `unity/`. The sim, the content and the policy checks run headless, also in the dev container (`.devcontainer/README.md`, for a local container or a Codespace). These are the commands CI runs (`.github/workflows/ci.yml`), with the .NET SDK 10.0.401 and `uv`, and the helpers CI does not run (CI job "none"):| Check | Command | CI job ||---|---|---|@@ -24,9 +24,10 @@ Unity, a Unity licence and macOS are only needed for `unity/`. The sim, the cont| Data tool tests (one runs the sim's release gate, so they need the .NET SDK too) | `uv 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 --with pyproj==3.8.0 pytest tools/tests -q` | Tools (pytest) || GDD feature sections (also run by the policy checker tests) | `uv run scripts/oss/gdd_lint.py` | Repo policy || Dead relative links in Markdown files (also run by the policy checker tests) | `uv run scripts/oss/md_links.py` | Repo policy |+| New event file (skeleton with every required field) | `uv run scripts/new_event.py <id> [--from D] [--to D]` | none (helper) || Changelog line | `uv run scripts/oss/changelog_check.py --base origin/main` | Changelog |-`scripts/check.sh` runs all of them in one go, cheapest first, plus a sim build with warnings as errors. It stops at the first failure and shows the end of its output. It takes the base ref as its argument (default `origin/main`); set `CHECK_NO_CHANGELOG=1` if the PR has the `no-changelog` label.+`scripts/check.sh` runs all the checks in one go, cheapest first, plus a sim build with warnings as errors. It stops at the first failure and shows the end of its output. It takes the base ref as its argument (default `origin/main`); set `CHECK_NO_CHANGELOG=1` if the PR has the `no-changelog` label.To try a rules.yaml change without editing it, use the writer preview: `dotnet run --project sim/Statecraft.Cli -- --preview --set tax_per_capita_per_year=0.00007 --show morale,treasury,fx`. It plays the historical run on the real content and on the same content with the change applied in memory, then prints the changed final-state lines (grouped like a golden failure) and a table of the values you ask for. Other options: `--until YYYY-MM-DD` (default 1950-01-01), `--seed N`, `--every N` (turns between table rows, default 8). It takes single-value top-level keys of `rules.yaml` (an era's own `content/rules/<era>.yaml` value still wins in that era) and writes nothing. A typo fails with the key named, a wrong type with the line.diff --git a/scripts/new_event.py b/scripts/new_event.pynew file mode 100644index 000000000..fd59e31a5--- /dev/null+++ b/scripts/new_event.py@@ -0,0 +1,73 @@+#!/usr/bin/env python3+# /// script+# requires-python = ">=3.10"+# ///+"""Write a valid skeleton for a new event (#323): `uv run scripts/new_event.py <id> [--from YYYY-MM-DD] [--to YYYY-MM-DD]`.++The file has the schema line, every required field of content/schema/event.schema.json and an empty `sources` list the+writer must fill (docs/CONTENT_POLICY.md). The sim loads it as written; the content tests fail until `sources` is filled.+It refuses an existing file and an id that is not lower_snake_case. It never overwrites and writes nothing else."""+import argparse+import re+import sys+from datetime import date+from pathlib import Path++ROOT = Path(__file__).resolve().parents[1]++TEMPLATE = """# yaml-language-server: $schema=../schema/event.schema.json+id: @ID@+title: TODO title+text: TODO what the player reads, and who must decide+# text may name an office, e.g. {defense_minister}; the office needs a holder on every day of the window.+anchor: soft+# tags: [security] # holocaust, terror, massacre and war-casualties are sensitive (docs/CONTENT_POLICY.md)+# office: prime_minister+# Say in a comment what happened and when, with the source.+from: @FROM@+@TO@options:+ - id: todo_option # lower_snake_case, like every id+ text: TODO what the player does+ effects:+ - { target: morale, delta: 0.0 }+sources: [] # each { url: "https://...", checked: YYYY-MM-DD }+status: draft+"""+++def build(event_id: str, start: str, end: str | None) -> str:+ return TEMPLATE.replace("@ID@", event_id).replace("@FROM@", start).replace("@TO@", f"to: {end}\n" if end else "")+++def main(argv: list[str] | None = None, root: Path = ROOT) -> int:+ p = argparse.ArgumentParser(description=__doc__.split("\n")[0])+ p.add_argument("id")+ p.add_argument("--from", dest="start", default="1948-05-15")+ p.add_argument("--to", dest="end")+ a = p.parse_args(argv)+ if not re.fullmatch(r"[a-z][a-z0-9_]*", a.id):+ print(f"bad id {a.id!r}: use lower_snake_case", file=sys.stderr)+ return 2+ for d in filter(None, (a.start, a.end)):+ try:+ if not re.fullmatch(r"\d{4}-\d{2}-\d{2}", d):+ raise ValueError+ date.fromisoformat(d)+ except ValueError:+ print(f"bad date {d!r}: use YYYY-MM-DD", file=sys.stderr)+ return 2+ if a.end and a.end <= a.start:+ print("--to must be after --from", file=sys.stderr)+ return 2+ path = root / "content" / "events" / f"{a.id}.yaml"+ if path.exists():+ print(f"{path} exists; not overwriting", file=sys.stderr)+ return 1+ path.parent.mkdir(parents=True, exist_ok=True)+ path.write_text(build(a.id, a.start, a.end), encoding="utf-8")+ print(f"wrote {path.relative_to(root)}; fill the TODOs and sources, then run scripts/check.sh")+ return 0+++if __name__ == "__main__":+ sys.exit(main())diff --git a/scripts/oss/tests/test_new_event.py b/scripts/oss/tests/test_new_event.pynew file mode 100644index 000000000..cca529325--- /dev/null+++ b/scripts/oss/tests/test_new_event.py@@ -0,0 +1,47 @@+"""Event scaffold (#323): the file it writes has every required field and loads as YAML; bad input is refused."""+import importlib.util+import json+import re+from pathlib import Path++import yaml++ROOT = Path(__file__).resolve().parents[3]+SPEC = importlib.util.spec_from_file_location('new_event', ROOT / 'scripts/new_event.py')+m = importlib.util.module_from_spec(SPEC)+SPEC.loader.exec_module(m)+++def test_writes_every_required_field(tmp_path):+ assert m.main(['my_event', '--from', '1949-01-01', '--to', '1949-02-01'], root=tmp_path) == 0+ doc = yaml.safe_load((tmp_path / 'content/events/my_event.yaml').read_text())+ required = json.loads((ROOT / 'content/schema/event.schema.json').read_text())['required']+ assert all(k in doc for k in required)+ assert doc['id'] == 'my_event' and doc['sources'] == [] and doc['status'] == 'draft'+ assert str(doc['to']) == '1949-02-01'+++def test_ids_match_the_schema_pattern(tmp_path):+ # the sim's loader rejects an id outside this pattern (ContentLoader), so a scaffold with one would not load+ schema = json.loads((ROOT / 'content/schema/event.schema.json').read_text())+ pattern = schema['definitions']['id']['pattern']+ m.main(['e1'], root=tmp_path)+ doc = yaml.safe_load((tmp_path / 'content/events/e1.yaml').read_text())+ assert all(re.search(pattern, i) for i in [doc['id']] + [o['id'] for o in doc['options']])+ # an office placeholder fails the loader on an open window (no holder on every day), so the default has none+ assert '{' not in doc['text'] + doc['title']+++def test_no_to_means_no_to_key(tmp_path):+ m.main(['e1'], root=tmp_path)+ assert 'to' not in yaml.safe_load((tmp_path / 'content/events/e1.yaml').read_text())+++def test_refuses_overwrite_bad_id_and_bad_dates(tmp_path):+ assert m.main(['e1'], root=tmp_path) == 0+ assert m.main(['e1'], root=tmp_path) == 1+ assert m.main(['Bad-Id'], root=tmp_path) == 2+ assert m.main(['e2', '--from', '1949-13-01'], root=tmp_path) == 2+ assert m.main(['e3', '--from', '1949-02-01', '--to', '1949-01-01'], root=tmp_path) == 2+ assert m.main(['e4', '--from', '19490101'], root=tmp_path) == 2+ assert not (tmp_path / 'content/events/e2.yaml').exists()