From 437b34ee6407f18586bbf65636cbb77e372ecee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrew=20Beveridge=20=E2=98=84=EF=B8=8F?= Date: Thu, 29 Oct 2026 03:52:39 -0400 Subject: [PATCH] =?UTF-8?q?fix(ci):=20wheel=20over=20PyPI's=20100=20MiB=20?= =?UTF-8?q?limit=20=E2=80=94=20drop=20unused=20RSC=20payloads=20+=20size?= =?UTF-8?q?=20guard=20(v0.287.2)=20(#1233)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Every `Deploy - Publish to PyPI` since v0.279.4 (about 10-22) has failed with `400 File too large. Limit for project 'karaoke-gen' is 100 MB`. The wheel had grown to 110 MB (105.1 MiB), so PyPI is still on 0.279.4. Backend deploys were not affected. I found this while watching deploys during an alerts-triage session. In the wheel, 66 MB of the bundled Next.js export is RSC `.txt` payloads (about 3 MB per locale × 33). The only thing that uses the export is the CLI local-review server (`karaoke_gen/lyrics_transcriber/review/server.py`). It mounts only `/_next` and `/static`, and every other route returns an HTML entry point. Next's RSC fetch paths (`/{locale}/app/.../index.txt`) already get HTML from those routes, so the `.txt` files are never served. - `make build-frontend` deletes `*.txt` from the copied export. On the real CI wheel from run 40826404322 this takes it from 105.1 MiB to 41.1 MiB. - `scripts/verify_wheel_frontend.py`, which already runs in both package-build jobs, now fails above 95 MiB. Growth will show up on the PR instead of as a failed publish after merge. ## Testing - New `tests/unit/test_verify_wheel_frontend.py`: 5 tests covering the pass case, missing entrypoint, too few files, the size guard, and headroom below 100 MiB. - Re-zipped the real 0.286.0 CI wheel without the `.txt` files: 41.1 MiB, and the verifier passes. The verifier rejects the original wheel (105.1 MiB) with the new error. - CodeRabbit: 1 finding ("deleting RSC payloads can break client navigation"). Skipped, because the local server never serves those files (see above), so it can't change runtime behaviour. @coderabbitai ignore 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_012RYLVTiUPKxn3sQPyp3Teh --------- Co-authored-by: Claude Opus 5.5 --- Makefile | 4 ++ pyproject.toml | 2 +- scripts/verify_wheel_frontend.py | 18 ++++++- tests/unit/test_verify_wheel_frontend.py | 63 ++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 tests/unit/test_verify_wheel_frontend.py 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