Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

scripts/oss/dev_setup_commands.py: every script in the dev-setup table exists (#360)

agamrafaeli-instinct6edaf93cd59c
diff --git a/docs/dev-setup.md b/docs/dev-setup.md
index 8fb5feac7..52995f0d1 100644
--- a/docs/dev-setup.md
+++ b/docs/dev-setup.md
@@ -27,6 +27,7 @@ Unity, a Unity licence and macOS are only needed for `unity/`. The sim, the cont
| Every content source with its check date and age (`--older-than DAYS`) | `uv run scripts/source_report.py` | none (helper) |
| Content records a branch adds, removes or re-dates (paste into the PR) | `uv run scripts/pr_content_summary.py [origin/main]` | none (helper) |
| Dead relative links in Markdown files (also run by the policy checker tests) | `uv run scripts/oss/md_links.py` | Repo policy |
+| Every script this table names exists (also run by the policy checker tests) | `uv run scripts/oss/dev_setup_commands.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 |
diff --git a/scripts/oss/dev_setup_commands.py b/scripts/oss/dev_setup_commands.py
new file mode 100644
index 000000000..5ef7eb332
--- /dev/null
+++ b/scripts/oss/dev_setup_commands.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+"""Every script named in the dev-setup table exists (#359): `uv run scripts/oss/dev_setup_commands.py [--root DIR]`.
+
+Reads docs/dev-setup.md, takes each backticked `scripts/...` or `tools/...` path ending in .py or .sh, and checks that
+the file is there. One line per missing file (line number and path); exit 1 if any."""
+import argparse
+import re
+import sys
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[2]
+PATH = re.compile(r"(?<![\w/.-])((?:scripts|tools)/[\w./-]+\.(?:py|sh))")
+
+
+def missing(root: Path) -> list[tuple[int, str]]:
+ doc = root / "docs/dev-setup.md"
+ bad = []
+ for n, line in enumerate(doc.read_text(encoding="utf-8").splitlines(), 1):
+ for span in re.findall(r"`([^`]+)`", line):
+ for p in PATH.findall(span):
+ if not (root / p).is_file():
+ bad.append((n, p))
+ return bad
+
+
+def main(argv: list[str]) -> int:
+ ap = argparse.ArgumentParser(description=__doc__)
+ ap.add_argument("--root", type=Path, default=ROOT)
+ args = ap.parse_args(argv)
+ bad = missing(args.root)
+ for n, p in bad:
+ print(f"docs/dev-setup.md:{n}: {p} does not exist")
+ return 1 if bad else 0
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv[1:]))
diff --git a/scripts/oss/tests/test_dev_setup_commands.py b/scripts/oss/tests/test_dev_setup_commands.py
new file mode 100644
index 000000000..483bd2d74
--- /dev/null
+++ b/scripts/oss/tests/test_dev_setup_commands.py
@@ -0,0 +1,29 @@
+"""dev_setup_commands: a script named in the dev-setup table must exist; the repo itself is clean."""
+import importlib.util
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[3]
+SPEC = importlib.util.spec_from_file_location('dev_setup_commands', ROOT / 'scripts/oss/dev_setup_commands.py')
+m = importlib.util.module_from_spec(SPEC)
+SPEC.loader.exec_module(m)
+
+
+def test_missing_script_is_reported_with_its_line(make_repo, capsys):
+ root = make_repo({
+ 'docs/dev-setup.md': '# Setup\n| a | `uv run scripts/here.py [x]` | none |\n| b | `uv run scripts/gone.py` | none |\n'
+ 'plain scripts/not_in_backticks.py\n| c | `bash tools/run.sh` | none |\n'
+ '| d | `uv run sim/tools/x.py` | `foo-scripts/a.py` |\n', # inside a longer path: not reported
+ 'scripts/here.py': 'x\n',
+ })
+ assert m.missing(root) == [(3, 'scripts/gone.py'), (5, 'tools/run.sh')]
+ assert m.main(['--root', str(root)]) == 1
+ assert 'docs/dev-setup.md:3: scripts/gone.py does not exist' in capsys.readouterr().out
+
+
+def test_clean_returns_zero(make_repo):
+ root = make_repo({'docs/dev-setup.md': '`uv run scripts/a.py`\n', 'scripts/a.py': 'x\n'})
+ assert m.main(['--root', str(root)]) == 0
+
+
+def test_this_repo_is_clean():
+ assert m.missing(ROOT) == []