refactor: validate voiceover cache with pydantic#135
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Opened on behalf of Onur Solmaz (
osolmaz).Summary
Voiceover cache entries were plain dictionaries with no validation at the cache boundary.
This change adds Pydantic models for the existing cache JSON shape without changing the saved schema.
It also raises the package Python floor to 3.11, matching current Manim support, and adds tests that lock the current cache list format.
Acknowledgements
Gemini TTS support in this branch overlaps with and should have credited the earlier Gemini TTS contribution in #119 by @Abhishek6792. That PR introduced the original Gemini service direction for Manim Voiceover, including use of the Google Gen AI SDK, WAV output, bookmark removal, cache input data, and the Kore voice default.
What Changed
Cache reads and writes now pass through a typed model layer, but the serialized cache stays as the same top-level JSON list.
Provider-specific
input_datafields are preserved, and invalid cache entries now fail with a clear validation error.manim_voiceover.services.cachewith Pydantic models and cache load/parse/serialize/append helpers.SpeechServicecache lookup and generation wrapping to validate cache entries through the model layer.requires-pythonand tool targets to Python 3.11, added directpydantic>=2.10,<3, and simplified dependency markers that only existed for older Python versions.Testing
I ran the local gates, including the example-rendering test and mutation testing.
All required checks passed locally.
uv run ruff format --check .uv run ruff check .uv run ty check src/manim_voiceoveruv run mypyuv run pytest --cov=manim_voiceover --cov-fail-under=85uvx slophammer-py@0.3.0 dry .uv run mutmut run --max-children 2uv run python scripts/check_mutmut_results.pyuv run pip-audituvx slophammer-py@0.3.0 check .PATH="/Users/onur/repos/manim-voiceover/.venv/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/pmk/env/global/bin:/Library/Apple/usr/bin:/Library/TeX/texbin:/usr/local/go/bin:/Users/onur/.local/bin:/Users/onur/.nvm/versions/node/v22.17.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-darwin-arm64/vendor/aarch64-apple-darwin/codex-path:/Users/onur/.codex/tmp/arg0/codex-arg0dhHXKv:/opt/homebrew/opt/llvm/bin:/Users/onur/.nvm/versions/node/v22.17.0/bin:/opt/homebrew/lib/ruby/gems/3.2.0/bin:/Users/onur/.modular/pkg/packages.modular.com_mojo/bin:/opt/homebrew/opt/postgresql@15/bin:/opt/homebrew/opt/ruby/bin:/Users/onur/.docker/bin:/Users/onur/google-cloud-sdk/bin:/Users/onur/Library/pnpm/bin:/Users/onur/.cargo/bin:/Applications/iTerm.app/Contents/Resources/utilities:/usr/local/texlive/2022/bin/universal-darwin/:/Users/onur/.lmstudio/bin" uvx slophammer-py@0.3.0 check . --executeRisks
The main compatibility risk is stricter validation of malformed cache files.
Valid existing cache files should keep the same serialized shape, including provider-specific
input_dataextras.