mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
## 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 <noreply@anthropic.com>
64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
"""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, "<html></html>")
|
|
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
|