A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
package_release: refuse a build that lost every translation (Fixes #2641) (#2656)
Eyal Golanf81fb93dca54
diff --git a/changelog.d/2641.md b/changelog.d/2641.mdnew file mode 100644index 000000000..c2a8552e1--- /dev/null+++ b/changelog.d/2641.md@@ -0,0 +1,3 @@+### Fixed++- The release packaging gate refuses a web build that lost every translation, instead of passing it as empty.diff --git a/docs/translations.md b/docs/translations.mdindex 41770603f..26bdc4110 100644--- a/docs/translations.md+++ b/docs/translations.md@@ -94,8 +94,10 @@ sign-off.the English record's row and sources (an event's `text_he_sources`, else its own `sources`).A change to `translations/` is a change players get, so it needs a changelog entry (`scripts/oss/changelog_check.py`;-`translations/README.md` excepted). `tools/package_release.py` refuses a build whose `StreamingAssets/translations`-files and `bundle.json`'s packed texts differ, so the release gate checks the same translations every player reads.+`translations/README.md` excepted). `tools/package_release.py` refuses a build unless the repository's `translations/`,+the build's `manifest.json` and `bundle.json` lists and its `StreamingAssets/translations` files name the same files and+each packed text matches its file, so the release gate checks the same translations every player reads, and a build that+lost all of them is refused too (#2641).## Order and formatdiff --git a/tools/package_release.py b/tools/package_release.pyindex bbe91ac9a..eac200bbc 100644--- a/tools/package_release.py+++ b/tools/package_release.py@@ -19,8 +19,9 @@ is refused when one is missing, and a file it does not name (an earlier build's,The translations ship twice (#1618, step 2): as files in StreamingAssets/translations, which desktop players and the gateread, and as texts packed into StreamingAssets/content/bundle.json, which the web player reads. The zip is refused unless-manifest.json and bundle.json name exactly the files in StreamingAssets/translations and each packed text is that file's-text, so the gate checks the translations every player gets and a lost or changed file never falls back silently.+the repository's translations/, manifest.json, bundle.json and StreamingAssets/translations name exactly the same files,+and each packed text is that file's text, so the gate checks the translations every player gets and a lost or changed+file never falls back silently, even when every inventory of the build is empty (#2641)."""import argparseimport json@@ -67,8 +68,8 @@ def photo_refusal(build: Path):def _shipped_translations(folder: Path) -> list[str]:- """The language files under a build's translations folder as "<lang>/<file>", ordinal order (TranslationLoader.Collect- and ContentManifest.Verify: top-level files and hidden names are not translations)."""+ """The language files under a translations folder (a build's, or the repository's) as "<lang>/<file>", ordinal order+ (TranslationLoader.Collect and ContentManifest.Verify: top-level files and hidden names are not translations)."""if not folder.is_dir():return []return sorted(p.relative_to(folder).as_posix() for p in folder.rglob("*")@@ -76,7 +77,8 @@ def _shipped_translations(folder: Path) -> list[str]:def translation_refusal(build: Path):- """Why the build's translations do not match what its web bundle carries, or None (see the module docstring)."""+ """Why the build's translations do not match the repository's translations/ or what its web bundle carries, or None+ (see the module docstring)."""content, folder = build / "StreamingAssets" / "content", build / "StreamingAssets" / "translations"try:listed = json.loads((content / "manifest.json").read_text(encoding="utf-8")).get("translations") or []@@ -86,10 +88,11 @@ def translation_refusal(build: Path):raise TypeError("translations and translationTexts must be lists")except (OSError, ValueError, AttributeError, TypeError) as e:return f"{content} has no readable manifest.json and bundle.json ({e}): build it with Build.Web, which writes them"+ expected = _shipped_translations(REPO / "translations")found = _shipped_translations(folder)- if not listed == packed == found:- return (f"the translations do not match: manifest.json lists {listed}, bundle.json packs {packed}, "- f"StreamingAssets/translations holds {found}")+ if not expected == listed == packed == found:+ return (f"the translations do not match: the repository's translations/ holds {expected}, "+ f"manifest.json lists {listed}, bundle.json packs {packed}, StreamingAssets/translations holds {found}")if len(texts) != len(packed):return f"bundle.json packs {len(packed)} translation files but {len(texts)} texts"try:diff --git a/tools/tests/test_package_release.py b/tools/tests/test_package_release.pyindex a376f3af5..9e46201e5 100644--- a/tools/tests/test_package_release.py+++ b/tools/tests/test_package_release.py@@ -205,6 +205,26 @@ def test_the_zip_carries_the_translations_the_web_bundle_packs(tmp_path, capsys)assert "StreamingAssets/translations/ro/events.yaml" in z.namelist()+def test_losing_every_translation_is_refused(tmp_path, capsys):+ """#2641: a build with no translations folder and no translation lists, absent, null or empty, must not pass while+ the repository has translation files."""+ expected = package_release._shipped_translations(REPO / "translations")+ assert expected, "the repository ships at least one translation, or this test proves nothing"+ for case in ("missing", "null", "empty"):+ build = fake_build(tmp_path / case, reviewed=True)+ shutil.rmtree(build / "StreamingAssets" / "translations")+ content = build / "StreamingAssets" / "content"+ for name, fields in (("manifest.json", ("translations",)), ("bundle.json", ("translations", "translationTexts"))):+ data = json.loads((content / name).read_text(encoding="utf-8"))+ for field in fields:+ if case == "missing":+ data.pop(field, None)+ else:+ data[field] = None if case == "null" else []+ (content / name).write_text(json.dumps(data), encoding="utf-8")+ assert f"the repository's translations/ holds {expected}" in refused(build, tmp_path / case, capsys), case++def test_a_lost_changed_or_unlisted_translation_is_refused(tmp_path, capsys):"""#1618: the gate reads StreamingAssets/translations and the web player bundle.json; they must be one set."""build = fake_build(tmp_path, reviewed=True)