zipfile_inflate64 replaces zipfile._get_compressor with a one-argument
wrapper, while CPython 3.13+ passes compresslevel too, so every zip write
raises TypeError once it is imported. Each writer had to call
ensure_zipfile_writable() first, and a new writer that forgot it broke.
Wrap the patched function right after the import in utils/archives.py,
the only module that imports zipfile_inflate64, and drop the per-site
calls and the helper.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Cut the docstring paragraphs down to the one fact each reader cannot get
from the code, name the readability test after the helper it exercises, and
give the flock stand-in and the zip factory real signatures.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
get_cached_zip already stats the archive to decide whether it exists, so
hand that stat back instead of making head_rom_content take another one for
Content-Length. A HEAD on a cached multi-file ROM now costs one stat.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Give 0o644 a single home in utils/filesystem as SERVED_FILE_MODE, used by
both the ZIP cache and FSHandler._atomic_write. Collapse the mode repair to
one call site behind a single stat per cache hit, close the temp descriptor
unconditionally, and log the build where the namespace is already in scope.
Deduplicate the test fixtures and drive the concurrency test with a barrier
on flock instead of a sleep, so the race is guaranteed rather than timed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- Centralize the cache-hit-or-build-then-fallback flow into
resolve_cached_zip(), collapsing three near-identical endpoint
blocks; add ZipFileEntry.from_rom_file() factory.
- Use get_ttl_hours() (now size-based) in cleanup_stale_zips instead
of inlining the tier decision.
- Drop on-demand LRU eviction and the 2x space guard; a full disk now
falls back to mod_zip streaming via the existing build try/except.
- Replace the per-request importlib.reload(zipfile) with a one-time,
thread-safe shim that fixes zipfile_inflate64's _get_compressor
signature without a global module reload.
- Simplify get_cache_key by folding the empty-entries case into the
normal path (non-empty keys unchanged).
Generated-By: PostHog Code
Task-Id: e68b880f-34d8-4bf6-8cd0-886ef2caecb4
- Use zipfile.ZipFile after reload instead of stale direct import
- Use ZipFile.write() for streaming (reload fixes CPython 3.13 bug)
- Wrap cache build in try/except, fall back to mod_zip on failure
- Guard empty entries list in get_cache_key
- Hash bulk namespace to avoid ENAMETOOLONG with 100 ROM IDs
- Use MagicMock for sync unschedule method in tests
- Mock _get_available_space in eviction tests to force eviction path
- Use sparse file (truncate) for large file TTL test
- Add tests for get_bulk_namespace and empty entries
- Bulk /download endpoint now caches ZIPs for Range requests (max 100 ROMs)
- LRU eviction frees space by removing oldest cached ZIPs (>1h old)
- Tiered TTL: 48h default, 12h for ZIPs over 8GB
- Generalize cache paths from rom_id to namespace (supports bulk-{ids})
- Use ZipFile.write() instead of reading entire files into memory
- Extract magic numbers to module constants
- Use hl() for log message highlighting
- Tests for zip_cache, m3u, and cleanup task using mocker fixture