TypeScript and Python: pin pushAll/push_all onto a store whose header the runtime cannot read
The behaviour was already a refusal that leaves the file untouched; now a test fails if a rewrite ever reads the disk header less strictly than a load does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7ea1aa6a9a
commit
e9a5a60dbf
2 changed files with 33 additions and 0 deletions
|
|
@ -887,6 +887,22 @@ class CultCacheTests(unittest.TestCase):
|
|||
store.push(envelopes[0])
|
||||
self.assertEqual(msgpack.unpackb(store_path.read_bytes(), raw=False)[0], "cultcache.store.v1")
|
||||
|
||||
def test_single_file_push_all_refuses_a_store_whose_header_it_cannot_read_and_leaves_it_untouched(self) -> None:
|
||||
envelopes = SingleFileMessagePackBackingStore(self._C2A_VECTORS / "v3-base.msgpack").pull_all()
|
||||
vectors = self._VECTORS.parent
|
||||
for vector in (
|
||||
self._VECTORS / "unknown-header.msgpack",
|
||||
self._VECTORS / "variant-v2.msgpack",
|
||||
vectors / "document-variants-c1" / "variant-store.msgpack",
|
||||
):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
store_path = Path(tmp) / "store.msgpack"
|
||||
store_path.write_bytes(vector.read_bytes())
|
||||
before = store_path.read_bytes()
|
||||
with self.assertRaisesRegex(ValueError, "is not readable"):
|
||||
SingleFileMessagePackBackingStore(store_path).push_all(envelopes)
|
||||
self.assertEqual(store_path.read_bytes(), before, f"{vector.name} was rewritten")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -1564,3 +1564,20 @@ test("SingleFileMessagePackBackingStore reads a v3 element-id store and a rewrit
|
|||
const inspection = inspectCultCacheBytes("v3.msgpack", await readFile(join(c2aVectors, "v3-base.msgpack")));
|
||||
assert.equal(inspection.format, "cultcache.store.v3");
|
||||
});
|
||||
|
||||
test("SingleFileMessagePackBackingStore pushAll refuses a store whose header it cannot read and leaves the file untouched", async () => {
|
||||
const dir = await mkdtemp(join(tmpdir(), "cultcache-pushall-refused-"));
|
||||
const envelopes = await new SingleFileMessagePackBackingStore(
|
||||
await copyVector(dir, join(c2aVectors, "v3-base.msgpack"), "seed.msgpack"),
|
||||
).pullAll();
|
||||
for (const vector of [
|
||||
join(variantVectors, "unknown-header.msgpack"),
|
||||
join(variantVectors, "variant-v2.msgpack"),
|
||||
resolve(cultLibRoot, "tests", "vectors", "document-variants-c1", "variant-store.msgpack"),
|
||||
]) {
|
||||
const file = await copyVector(dir, vector, "store.msgpack");
|
||||
const before = await readFile(file);
|
||||
await assert.rejects(() => new SingleFileMessagePackBackingStore(file).pushAll(envelopes), /is not readable/u, vector);
|
||||
assert.deepEqual(await readFile(file), before, `${vector} was rewritten`);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue