diff --git a/Makefile b/Makefile index b7f76e03..6e1c4701 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,10 @@ build-frontend: install-frontend rm -rf karaoke_gen/nextjs_frontend/out mkdir -p karaoke_gen/nextjs_frontend/out cp -r frontend/out/* karaoke_gen/nextjs_frontend/out/ + @# Drop Next.js RSC payloads (*.txt, ~66 MB across 33 locales): the CLI review + @# server never serves them (only HTML entrypoints, /_next and /static), and they + @# pushed the wheel past PyPI's 100 MiB per-file limit (2026-10-27..29). + find karaoke_gen/nextjs_frontend/out -name '*.txt' -type f -delete @echo "✅ Frontend built and copied to karaoke_gen/nextjs_frontend/out/" # Build frontend + install package in editable mode for local CLI testing diff --git a/pyproject.toml b/pyproject.toml index ba6d60d0..54f403fb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "karaoke-gen" -version = "0.287.1" +version = "0.287.2" description = "Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video with title screens." authors = ["Andrew Beveridge "] license = "MIT" diff --git a/scripts/verify_wheel_frontend.py b/scripts/verify_wheel_frontend.py index fd3d2dc6..d663559e 100644 --- a/scripts/verify_wheel_frontend.py +++ b/scripts/verify_wheel_frontend.py @@ -8,12 +8,15 @@ produces no output, poetry will still happily build a wheel — just without the frontend — and the CLI local-review UI would silently break in production. This script is the loud guard against that: it fails (non-zero exit) unless the -wheel contains a plausible frontend export. +wheel contains a plausible frontend export. It also fails when the wheel is close +to PyPI's 100 MiB per-file limit, so growth shows up on the PR instead of as a +failed publish after merge (2026-10-27..29: 110 MB wheels, PyPI stuck at 0.279.4). Usage: python scripts/verify_wheel_frontend.py dist/karaoke_gen-*.whl """ +import os import sys import zipfile from glob import glob @@ -23,6 +26,8 @@ FRONTEND_PREFIX = "karaoke_gen/nextjs_frontend/out/" # root entrypoint so an empty/partial copy can't sneak through. MIN_FRONTEND_FILES = 50 REQUIRED_ENTRY = FRONTEND_PREFIX + "index.html" +# PyPI rejects files over 100 MiB; leave headroom so we fail before publish does. +MAX_WHEEL_BYTES = 95 * 1024 * 1024 def resolve_wheel(patterns: list[str]) -> str: @@ -63,7 +68,16 @@ def main() -> None: ) sys.exit(1) - print(f"✅ {wheel} bundles {count} frontend files (entrypoint present).") + size = os.path.getsize(wheel) + if size > MAX_WHEEL_BYTES: + print( + f"::error::{wheel} is {size / 1024 / 1024:.1f} MiB, over the " + f"{MAX_WHEEL_BYTES // 1024 // 1024} MiB guard (PyPI's per-file limit is 100 MiB). " + "Trim what the wheel bundles (see `make build-frontend`)." + ) + sys.exit(1) + + print(f"✅ {wheel} bundles {count} frontend files (entrypoint present), {size / 1024 / 1024:.1f} MiB.") if __name__ == "__main__": diff --git a/tests/unit/test_verify_wheel_frontend.py b/tests/unit/test_verify_wheel_frontend.py new file mode 100644 index 00000000..2f11834c --- /dev/null +++ b/tests/unit/test_verify_wheel_frontend.py @@ -0,0 +1,63 @@ +"""Tests for scripts/verify_wheel_frontend.py (frontend-bundled + PyPI size guard).""" + +import importlib.util +import os +import zipfile +from pathlib import Path + +import pytest + +_SPEC = importlib.util.spec_from_file_location( + "verify_wheel_frontend", Path(__file__).resolve().parents[2] / "scripts" / "verify_wheel_frontend.py" +) +verify = importlib.util.module_from_spec(_SPEC) +_SPEC.loader.exec_module(verify) + + +def _make_wheel(tmp_path: Path, n_files: int = 60, with_entry: bool = True) -> Path: + wheel = tmp_path / "karaoke_gen-0.0.0-py3-none-any.whl" + with zipfile.ZipFile(wheel, "w") as zf: + if with_entry: + zf.writestr(verify.REQUIRED_ENTRY, "") + for i in range(n_files): + zf.writestr(f"{verify.FRONTEND_PREFIX}en/page{i}/index.html", "x") + return wheel + + +def _run(monkeypatch, wheel: Path) -> None: + monkeypatch.setattr("sys.argv", ["verify_wheel_frontend.py", str(wheel)]) + verify.main() + + +def test_passes_for_bundled_frontend_under_size_guard(tmp_path, monkeypatch, capsys): + _run(monkeypatch, _make_wheel(tmp_path)) + assert "✅" in capsys.readouterr().out + + +def test_fails_without_entrypoint(tmp_path, monkeypatch): + with pytest.raises(SystemExit) as exc: + _run(monkeypatch, _make_wheel(tmp_path, with_entry=False)) + assert exc.value.code == 1 + + +def test_fails_with_too_few_frontend_files(tmp_path, monkeypatch): + with pytest.raises(SystemExit) as exc: + _run(monkeypatch, _make_wheel(tmp_path, n_files=3)) + assert exc.value.code == 1 + + +def test_fails_when_wheel_exceeds_pypi_size_guard(tmp_path, monkeypatch, capsys): + wheel = _make_wheel(tmp_path) + real_getsize = os.path.getsize + monkeypatch.setattr( + verify.os.path, "getsize", + lambda p: verify.MAX_WHEEL_BYTES + 1 if str(p) == str(wheel) else real_getsize(p), + ) + with pytest.raises(SystemExit) as exc: + _run(monkeypatch, wheel) + assert exc.value.code == 1 + assert "PyPI" in capsys.readouterr().out + + +def test_size_guard_leaves_headroom_below_pypi_limit(): + assert verify.MAX_WHEEL_BYTES < 100 * 1024 * 1024