From e8fa1c4d8fd2f2c2dd2c76c159d0c960c9b1c529 Mon Sep 17 00:00:00 2001 From: Libby Date: Tue, 17 Nov 2026 03:32:01 +0000 Subject: [PATCH] cultcache-py: pin the put_envelopes tail refusal; README says a held-by-two-types conflict is CultCacheError on load, SchemaConflictError on write Co-Authored-By: Claude Sonnet 5.5 --- packages/cultcache-py/README.md | 2 +- .../cultcache-py/tests/test_first_call.py | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/cultcache-py/README.md b/packages/cultcache-py/README.md index 02982c47..f6574618 100644 --- a/packages/cultcache-py/README.md +++ b/packages/cultcache-py/README.md @@ -69,7 +69,7 @@ store. ## Public Surface -- `CultCacheError` (a `RuntimeError`, exported from the package root): the cache's refusals (a unique-index violation, a key held by two types) and `convert`'s (`source_missing`, `destination_exists`, a refused record). Import it from `cultcache_py`, not from the private `cache` module. +- `CultCacheError` (a `RuntimeError`, exported from the package root): the cache's refusals (a unique-index violation; a key held by two types on load, while the same conflict on a write is a `SchemaConflictError`, a `ValueError`) and `convert`'s (`source_missing`, `destination_exists`, a refused record). Import it from `cultcache_py`, not from the private `cache` module. - `define_document_type(...)` - `define_database_entry_type(...)` - `database_entry_field(...)` diff --git a/packages/cultcache-py/tests/test_first_call.py b/packages/cultcache-py/tests/test_first_call.py index 32bafa56..42cc5aa8 100644 --- a/packages/cultcache-py/tests/test_first_call.py +++ b/packages/cultcache-py/tests/test_first_call.py @@ -126,6 +126,30 @@ class RootExportTests(unittest.TestCase): cache.put_envelope(document, CultCacheEnvelope.create(key="k", type=document.type, payload=tailed)) self.assertEqual(store.pull_all(), [], type(store).__name__) + def test_a_batch_with_one_tailed_envelope_is_refused_whole_and_earlier_records_stay(self) -> None: + document = define_document_type("tests.tail_batch") + with tempfile.TemporaryDirectory() as directory: + for store in ( + SingleFileMessagePackBackingStore(Path(directory) / "batch.cc"), + JsonLinesBackingStore(Path(directory) / "batch.jsonl"), + ): + name = type(store).__name__ + cache = CultCache.builder().register_document_type(document).add_generic_store(store).build() + cache.put(document, "early", {"a": 0}) + before = store.pull_all() + good = document.encode_payload({"a": 1}) + with self.assertRaisesRegex(ValueError, r"1 bytes after its first MessagePack value \(refused on read\)"): + cache.put_envelopes( + document, + [ + CultCacheEnvelope.create(key="good", type=document.type, payload=good), + CultCacheEnvelope.create(key="bad", type=document.type, payload=good + b"\xc0"), + ], + ) + self.assertEqual(store.pull_all(), before, name) + self.assertEqual([item.key for item in before], ["early"], name) + self.assertIsNone(cache.get(document, "good"), name) + if __name__ == "__main__": unittest.main()