fix: harden cache-envelope framing and compression config resolution#172
Conversation
Addresses review feedback on #152 (merged before these landed): - wrapper.py: validate v3 frame bounds before parsing — truncated/corrupt b"CK" frames now raise a clean ValueError instead of a low-level IndexError/JSON error. Also tighten wrap()/unwrap() public signatures to dict[str, Any]. - arrow_serializer.py: narrow the compression auto-resolution except to ImportError. Invalid CACHEKIT_ARROW_COMPRESSION values now surface as a pydantic ValidationError instead of silently falling back to zstd. - tests: make the default-compression test env-independent (delenv + reset_settings); restore pre-existing CACHEKIT_MASTER_KEY via monkeypatch to stop cross-test env leakage; add same-key oversized-update L1 test.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughTightens SerializationWrapper type hints and adds stricter v3 envelope bounds checks, narrows ArrowSerializer’s fallback to only catch ImportError when resolving ChangesSerialization and Envelope Validation Improvements
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Restores patch coverage for the hardening added in the previous commit: - wrapper.py: tests for truncated frame, unsupported frame version, and oversized header-length (the three ValueError guards) -> 100% coverage. - arrow_serializer.py: test that auto compression falls back to zstd when the settings module is unimportable (the except ImportError branch).
Summary
Follow-up to #152, which was merged before its review feedback was applied. This re-applies the six review comments — 2 robustness fixes + 4 test/typing hygiene — against the now-merged code.
Changes
Robustness (observable behavior)
wrapper.py: validate v3 frame bounds before parsing. Truncated/corruptb"CK"frames now raise a cleanValueError(Truncated cache envelope frame/Invalid cache envelope header length) instead of a low-levelIndexError/JSON error.arrow_serializer.py: narrow the compression auto-resolutionexcepttoImportError. InvalidCACHEKIT_ARROW_COMPRESSIONvalues now surface as a pydanticValidationErrorinstead of being silently masked into azstdfallback (silent config drift).Typing / test hygiene
wrapper.py:wrap()/unwrap()usedict[str, Any]in their public signatures.test_arrow_serializer.py:test_default_is_auto_zstdis now env-independent (monkeypatch.delenv+reset_settingsinfinally).test_serialization_wrapper.py: the encryption fixture usesmonkeypatch.setenvso a pre-existingCACHEKIT_MASTER_KEYis restored on teardown (no cross-test env leakage).test_l1_memory_bounds.py: add a same-key oversized-update test (the stale smaller entry is evicted, not served).Verification
ruff check/ruff format --check: cleanbasedpyright: 0 errorspytest(affected unit tests +wrapper.pydoctest): 77 passed, 2 skippedSummary by CodeRabbit
Bug Fixes
Tests