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.

tools: source report, every content source with its check date (fixes #330) (#331)

agamrafaeli-instincta201d4556d53
diff --git a/docs/dev-setup.md b/docs/dev-setup.md
index c50bfee48..79f9fee25 100644
--- a/docs/dev-setup.md
+++ b/docs/dev-setup.md
@@ -24,6 +24,7 @@ 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 |
| Every event by date, with era, anchor and review status | `uv run scripts/event_timeline.py [--status draft]` | none (helper) |
+| Every content source with its check date and age (`--older-than DAYS`) | `uv run scripts/source_report.py` | none (helper) |
| 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 |
diff --git a/scripts/oss/tests/test_source_report.py b/scripts/oss/tests/test_source_report.py
new file mode 100644
index 000000000..f65f6b6c2
--- /dev/null
+++ b/scripts/oss/tests/test_source_report.py
@@ -0,0 +1,54 @@
+"""Source report (#330): nested sources found, oldest first, flags, the age filter and the real content."""
+import importlib.util
+from datetime import date
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[3]
+SPEC = importlib.util.spec_from_file_location('source_report', ROOT / 'scripts/source_report.py')
+m = importlib.util.module_from_spec(SPEC)
+SPEC.loader.exec_module(m)
+TODAY = date(2026, 10, 13)
+
+
+def repo(tmp_path):
+ (tmp_path / 'content/map').mkdir(parents=True)
+ (tmp_path / 'content/a.yaml').write_text(
+ "x:\n - id: 1\n sources:\n - { url: 'https://a.example/1', checked: 2026-10-10 }\n"
+ " - { url: 'http://old.example', checked: 2026-01-01 }\n")
+ (tmp_path / 'content/map/b.yaml').write_text("y:\n source: { url: 'https://b.example', checked: '2026-10-12' }\n bad: { url: 'https://c.example', checked: soon }\n")
+ return tmp_path
+
+
+def test_collects_nested_sources_oldest_first_with_flags(tmp_path):
+ rows = m.collect(repo(tmp_path), TODAY)
+ assert [r['url'] for r in rows] == ['https://c.example', 'http://old.example', 'https://a.example/1', 'https://b.example']
+ assert [r['age'] for r in rows] == [None, 285, 3, 1]
+ out = m.render(rows)
+ assert 'NO-DATE' in out.splitlines()[0] and out.splitlines()[1].endswith(' http')
+ assert out.splitlines()[-1] == '4 sources'
+
+
+def test_older_than_keeps_stale_and_undated(tmp_path, capsys):
+ assert m.main(['--root', str(repo(tmp_path)), '--older-than', '30', '--today', '2026-10-13']) == 0
+ out = capsys.readouterr().out
+ assert 'old.example' in out and 'c.example' in out and 'b.example' not in out and out.splitlines()[-1] == '2 sources'
+
+
+def test_real_content_has_sources_and_all_are_dated():
+ rows = m.collect(ROOT, date.today())
+ assert rows and all(r['checked'] is not None for r in rows)
+
+
+def test_render_shows_the_date(tmp_path):
+ assert '2026-10-10' in m.render(m.collect(repo(tmp_path), TODAY))
+
+
+def test_alias_counts_once_and_plain_url_lists_are_read(tmp_path):
+ (tmp_path / 'content/map').mkdir(parents=True)
+ (tmp_path / 'content/p.yaml').write_text(
+ "a:\n name: &bio [{ url: 'https://p.example', checked: 2026-10-01 }]\n born: *bio\n died: *bio\n")
+ (tmp_path / 'content/map/l.yaml').write_text(
+ "- id: x\n checked: '2026-10-11'\n sources:\n - https://l.example/1\n - https://l.example/2\n")
+ rows = m.collect(tmp_path, TODAY)
+ assert sorted((r['url'], r['age']) for r in rows) == [('https://l.example/1', 2), ('https://l.example/2', 2),
+ ('https://p.example', 12)]
diff --git a/scripts/source_report.py b/scripts/source_report.py
new file mode 100644
index 000000000..3b22e6157
--- /dev/null
+++ b/scripts/source_report.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python3
+# /// script
+# requires-python = ">=3.10"
+# dependencies = ["pyyaml==6.0.3"]
+# ///
+"""List every source in content/ with its check date and age (#330):
+`uv run scripts/source_report.py [--root DIR] [--older-than DAYS] [--today YYYY-MM-DD]`.
+
+A source is any mapping with `url` and `checked` anywhere in content/**/*.yaml, or a url in a plain `sources` list next
+to a `checked` date. A YAML alias counts once. One line per source, oldest check first:
+age in days, checked date, file, url. `--older-than N` keeps only sources checked more than N days ago. A non-https url
+is marked `http`; a source with no valid check date is marked `NO-DATE`. A report, not a gate: always exits 0. Reads only."""
+import argparse
+import sys
+from datetime import date
+from pathlib import Path
+
+import yaml
+
+ROOT = Path(__file__).resolve().parents[1]
+
+
+def walk(node, out: list[dict], seen: set[int]) -> None:
+ # A YAML alias (*name) is the same object as its anchor: count it once, where it is defined.
+ if isinstance(node, (dict, list)):
+ if id(node) in seen:
+ return
+ seen.add(id(node))
+ if isinstance(node, dict):
+ if "url" in node and "checked" in node:
+ out.append(node)
+ elif "checked" in node and isinstance(node.get("sources"), list):
+ # a row with one check date and a plain list of urls (content/map/localities_1948.yaml)
+ out += [{"url": u, "checked": node["checked"]} for u in node["sources"] if isinstance(u, str)]
+ for v in node.values():
+ walk(v, out, seen)
+ elif isinstance(node, list):
+ for v in node:
+ walk(v, out, seen)
+
+
+def to_date(v) -> date | None:
+ if isinstance(v, date):
+ return v
+ try:
+ return date.fromisoformat(str(v))
+ except ValueError:
+ return None
+
+
+def collect(root: Path, today: date) -> list[dict]:
+ rows = []
+ for f in sorted((root / "content").rglob("*.yaml")):
+ found: list[dict] = []
+ walk(yaml.safe_load(f.read_text(encoding="utf-8")), found, set())
+ for s in found:
+ d = to_date(s["checked"])
+ rows.append({"file": str(f.relative_to(root)), "url": str(s["url"]), "checked": d,
+ "age": (today - d).days if d else None})
+ # no date first (worst), then oldest
+ return sorted(rows, key=lambda r: (r["age"] is not None, -(r["age"] or 0), r["file"], r["url"]))
+
+
+def render(rows: list[dict]) -> str:
+ lines = []
+ for r in rows:
+ flags = (" NO-DATE" if r["checked"] is None else "") + ("" if r["url"].startswith("https://") else " http")
+ age = "?" if r["age"] is None else str(r["age"])
+ lines.append(f"{age:>5}d {str(r['checked'] or '-'):<10} {r['file']} {r['url']}{flags}")
+ lines.append(f"{len(rows)} sources")
+ return "\n".join(lines)
+
+
+def main(argv: list[str] | None = None) -> int:
+ p = argparse.ArgumentParser(description=__doc__.split("\n")[0])
+ p.add_argument("--root", type=Path, default=ROOT)
+ p.add_argument("--older-than", type=int, metavar="DAYS")
+ p.add_argument("--today", type=date.fromisoformat, default=date.today())
+ a = p.parse_args(argv)
+ rows = collect(a.root, a.today)
+ if a.older_than is not None:
+ rows = [r for r in rows if r["age"] is None or r["age"] > a.older_than]
+ print(render(rows))
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())