Repository navigation
Description
Summary
scripts/build_gallery.py is a 1,918-line file that holds about 990 lines of CSS/JS/HTML in Python string literals, a hand-rolled Markdown renderer, entry validation and page assembly, and it has no unit tests. Its only check is a regenerate-and-diff against committed output, which is circular: a generator bug is committed together with its output.
Where
scripts/build_gallery.py:180-1166(SHELL, GALLERY_CSS at :220, INDEX_JS at :611, DETAIL_JS at :1000, CARD/MINI_CARD with__PLACEHOLDER__replace chains at :1428-1433)scripts/build_gallery.py:1177-1347(render_inline,slugify,md_to_html)scripts/build_gallery.py:102-178(load_gallery_entries,check_alts,check_categories)scripts/build_gallery.py:1635(first_sentence).github/workflows/validate.yml:103-107(staleness diff)
Details
The landing build (scripts/site/build_site.py) uses Jinja2 templates on disk, so the site has two templating systems. No test in tests/ imports build_gallery. Precedent: PR #68 (teaches.split(".")[0] truncated 14 of 21 card alts), which CLAUDE.md now works around with a manual "read the generated HTML character by character" step.
Impact
Every gallery UI change edits CSS/JS inside Python without editor tooling, and any change to README Markdown handling can silently regress about 150 pages.
Suggested fix
- Add
tests/test_build_gallery.pyfirst:first_sentence("Uses bmesh.ops.create_cone. Then…")does not split atbmesh.slugifyde-duplicates and avoidsRESERVED_IDSrender_inlineescapes<script>in text and code spansmd_to_htmlhandles escaped pipes in tables andskip_first_h1check_altsexits on empty, too-long or backticked alts- a fixture entry's card
alt=equals the source alt verbatim
- Move GALLERY_CSS, INDEX_JS and DETAIL_JS verbatim to files under
scripts/site/, read at build time (byte-identical output, proven by the staleness diff). - Extract
md_to_htmland helpers into a module with golden-file tests over 3-4 real READMEs. - Optionally move SHELL/CARD/MINI_CARD to
.j2templates (Jinja2 is already a site dependency).
Acceptance criteria
- Unit tests for the listed functions run in Validate.
- CSS/JS live in their own files; regenerated output is byte-identical.
Filed by repo-audit/full-audit at 077cdd9a. Severity: medium. Effort: M. audit-key: tech-debt|scripts/build_gallery.py|god-file-no-tests
Activity
refactor: gallery CSS/JS move to files, and the generator gets unit t…