From 2ba05401a14e47b94d2c15ea4d5277930b01b2fd Mon Sep 17 00:00:00 2001 From: Lukas Wallrich Date: Sun, 8 Nov 2026 19:19:31 +0000 Subject: [PATCH 1/3] Exclude generator scripts and draft outputs from site bundles --- config/_default/config.toml | 2 +- scripts/tests/test_bundle_exclusions.py | 60 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 scripts/tests/test_bundle_exclusions.py diff --git a/config/_default/config.toml b/config/_default/config.toml index bea15ca4dee..3ebaa0669f0 100644 --- a/config/_default/config.toml +++ b/config/_default/config.toml @@ -39,7 +39,7 @@ summaryLength = 50 # Listing summary length in words. Also, see `abstract_lengt paginate = 10 # Number of items per page in paginated lists. enableEmoji = true footnotereturnlinkcontents = "^" -ignoreFiles = ["\\.ipynb$", ".ipynb_checkpoints$", "\\.Rmd$", "\\.Rmarkdown$", "_files$", "_cache$"] +ignoreFiles = ["\\.ipynb$", ".ipynb_checkpoints$", "\\.Rmd$", "\\.Rmarkdown$", "_files$", "_cache$", "\\.py$", "\\.mdOUT$"] # Workaround Hugo publishing taxonomy URLs as plurals - consistently use singular across Academic. [permalinks] diff --git a/scripts/tests/test_bundle_exclusions.py b/scripts/tests/test_bundle_exclusions.py new file mode 100644 index 00000000000..e20fdc56ca4 --- /dev/null +++ b/scripts/tests/test_bundle_exclusions.py @@ -0,0 +1,60 @@ +"""Build with Hugo, or check an existing build via FORRT_TEST_BUILD_DIR. + +Run: python3 -m unittest discover -s scripts/tests -p test_bundle_exclusions.py +""" + +import os +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[2] + + +class BundleExclusionTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + existing = os.environ.get("FORRT_TEST_BUILD_DIR") + if existing: + cls.build = Path(existing).resolve() + return + if not shutil.which("hugo"): + raise unittest.SkipTest("Hugo is required to check bundle publication") + scratch = tempfile.TemporaryDirectory(prefix="scratch-bundle-exclusions-", dir=ROOT) + cls.addClassCleanup(scratch.cleanup) + scratch_path = Path(scratch.name) + cls.build = scratch_path / "public" + result = subprocess.run( + ["hugo", "--destination", str(cls.build), + "--cacheDir", str(scratch_path / "cache")], + cwd=ROOT, + env={**os.environ, "HUGO_RESOURCEDIR": str(scratch_path / "resources")}, + capture_output=True, text=True, + ) + if result.returncode: + raise AssertionError(f"Hugo build failed:\n{result.stdout}\n{result.stderr}") + + def test_generator_scripts_and_draft_outputs_are_not_published(self): + self.assertTrue((self.build / "index.html").is_file(), "Expected a complete Hugo build") + unwanted = sorted( + str(path.relative_to(self.build)) + for pattern in ("*.py", "*.mdOUT") + for path in self.build.rglob(pattern) + if path.is_file() + ) + self.assertEqual(unwanted, [], "Generator scripts and draft outputs must stay unpublished") + + def test_legitimate_pages_and_bundle_assets_remain(self): + for page in ("resources/index.html", "summaries/index.html", "glossary/references/index.html"): + with self.subTest(page=page): + self.assertTrue((self.build / page).is_file(), f"Missing page: {page}") + for asset in ("summaries/FORRT_O&R_101_Syllabus.pdf", "glossary/apa_lookup.json"): + with self.subTest(asset=asset): + self.assertEqual((self.build / asset).read_bytes(), (ROOT / "content" / asset).read_bytes()) + + +if __name__ == "__main__": + unittest.main() From 36a880e3c345216bd33d3fcd1610c09edd063c93 Mon Sep 17 00:00:00 2001 From: Lukas Wallrich Date: Sun, 8 Nov 2026 19:23:26 +0000 Subject: [PATCH 2/3] Allow the removed generator outputs in Doors comparison --- scripts/rebrand/allowed_changes.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/rebrand/allowed_changes.txt b/scripts/rebrand/allowed_changes.txt index abad4c66659..b2ca42a2459 100644 --- a/scripts/rebrand/allowed_changes.txt +++ b/scripts/rebrand/allowed_changes.txt @@ -7,6 +7,11 @@ resources/directory.json # The directory's filter data (D16, #868) resources/search.json # The directory's search data, fetched on first search (D16, #868) resources/index.html # Became a list page for its pager, so its SEO tags gain CollectionPage home/7-newsletter.md.old # A retired draft that Hugo copied out by accident, not a page +resources/resource.py # #976: generator script (or draft) Hugo published by accident, not a page +summaries/summaries.py # #976: generator script (or draft) Hugo published by accident, not a page +glossary/_create_glossaries.py # #976: generator script (or draft) Hugo published by accident, not a page +glossary/_build_references.py # #976: generator script (or draft) Hugo published by accident, not a page +replication-hub/submit/submit.mdOUT # #976: generator script (or draft) Hugo published by accident, not a page about/visitors/index.html # Its generated description quotes the stats table, whose link text lost "https://" for the preview js/load-theme.js # The theme's day/night script, gone with the theme's look js/academic.min.FINGERPRINT.js # The theme's script bundle, without its search, under a new name while some pages still need it From e74d3c000a1756cdd599f560c7993781f065f872 Mon Sep 17 00:00:00 2001 From: Lukas Wallrich Date: Sun, 8 Nov 2026 19:52:58 +0000 Subject: [PATCH 3/3] Check the ignoreFiles patterns directly instead of building the site in a unit test The test now reads ignoreFiles from config.toml and checks that every script and draft under content/ is ignored while pages and bundle assets are not. It runs in milliseconds and needs no Hugo. Co-Authored-By: Claude Opus 5.5 --- scripts/tests/test_bundle_exclusions.py | 63 +++++++------------------ 1 file changed, 18 insertions(+), 45 deletions(-) diff --git a/scripts/tests/test_bundle_exclusions.py b/scripts/tests/test_bundle_exclusions.py index e20fdc56ca4..8f21c0a5cca 100644 --- a/scripts/tests/test_bundle_exclusions.py +++ b/scripts/tests/test_bundle_exclusions.py @@ -1,59 +1,32 @@ -"""Build with Hugo, or check an existing build via FORRT_TEST_BUILD_DIR. +"""Hugo's ignoreFiles keeps generator scripts and drafts in content/ out of the site (#976). Run: python3 -m unittest discover -s scripts/tests -p test_bundle_exclusions.py """ -import os from pathlib import Path -import shutil -import subprocess -import tempfile +import re +import tomllib import unittest - ROOT = Path(__file__).resolve().parents[2] +CONFIG = tomllib.loads((ROOT / "config/_default/config.toml").read_text(encoding="utf-8")) + + +def ignored(path): + return any(re.search(pattern, path) for pattern in CONFIG["ignoreFiles"]) class BundleExclusionTests(unittest.TestCase): - @classmethod - def setUpClass(cls): - existing = os.environ.get("FORRT_TEST_BUILD_DIR") - if existing: - cls.build = Path(existing).resolve() - return - if not shutil.which("hugo"): - raise unittest.SkipTest("Hugo is required to check bundle publication") - scratch = tempfile.TemporaryDirectory(prefix="scratch-bundle-exclusions-", dir=ROOT) - cls.addClassCleanup(scratch.cleanup) - scratch_path = Path(scratch.name) - cls.build = scratch_path / "public" - result = subprocess.run( - ["hugo", "--destination", str(cls.build), - "--cacheDir", str(scratch_path / "cache")], - cwd=ROOT, - env={**os.environ, "HUGO_RESOURCEDIR": str(scratch_path / "resources")}, - capture_output=True, text=True, - ) - if result.returncode: - raise AssertionError(f"Hugo build failed:\n{result.stdout}\n{result.stderr}") - - def test_generator_scripts_and_draft_outputs_are_not_published(self): - self.assertTrue((self.build / "index.html").is_file(), "Expected a complete Hugo build") - unwanted = sorted( - str(path.relative_to(self.build)) - for pattern in ("*.py", "*.mdOUT") - for path in self.build.rglob(pattern) - if path.is_file() - ) - self.assertEqual(unwanted, [], "Generator scripts and draft outputs must stay unpublished") - - def test_legitimate_pages_and_bundle_assets_remain(self): - for page in ("resources/index.html", "summaries/index.html", "glossary/references/index.html"): - with self.subTest(page=page): - self.assertTrue((self.build / page).is_file(), f"Missing page: {page}") - for asset in ("summaries/FORRT_O&R_101_Syllabus.pdf", "glossary/apa_lookup.json"): - with self.subTest(asset=asset): - self.assertEqual((self.build / asset).read_bytes(), (ROOT / "content" / asset).read_bytes()) + def test_generator_scripts_and_drafts_are_ignored(self): + for path in sorted(ROOT.glob("content/**/*.py")) + sorted(ROOT.glob("content/**/*.mdOUT")): + with self.subTest(path=path): + self.assertTrue(ignored(str(path.relative_to(ROOT)))) + + def test_pages_and_bundle_assets_are_not_ignored(self): + for path in ("content/summaries/_index.md", "content/summaries/FORRT_O&R_101_Syllabus.pdf", + "content/glossary/apa_lookup.json", "content/clusters/FORRT_Clusters.webp"): + with self.subTest(path=path): + self.assertFalse(ignored(path)) if __name__ == "__main__":