From 0be33c1198e533b066e1447b756144c68df48cf2 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 30 Sep 2026 00:11:12 +0200 Subject: [PATCH] Rust: a zero-byte store file is rewritten as an empty v1 store Soul's mutant deleting the empty-file arm of write_all_unlocked survived: no test rewrote a zero-byte file. Without the arm the empty file reaches store_header and is refused as truncated. The test pushes onto a zero-byte file and expects a v1 store holding the pushed record. Co-Authored-By: Claude Opus 5.5 --- packages/cultcache-rs/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/cultcache-rs/src/lib.rs b/packages/cultcache-rs/src/lib.rs index 3b19dd45..9bff75f1 100644 --- a/packages/cultcache-rs/src/lib.rs +++ b/packages/cultcache-rs/src/lib.rs @@ -4876,6 +4876,19 @@ mod tests { Ok(()) } + // A zero-byte file is an empty store with no header, not a truncated one: a rewrite writes it v1. + #[test] + fn push_all_rewrites_a_zero_byte_file_as_v1() -> Result<()> { + let temp = tempfile::tempdir()?; + let path = temp.path().join("store.msgpack"); + std::fs::write(&path, [])?; + let mut store = SingleFileMessagePackBackingStore::new(&path); + store.push_all(&[snapshot_envelope("x", b"one")], PushAllOptions::default())?; + assert_eq!(store_header(&std::fs::read(&path)?, true)?.as_deref(), Some(STORE_FORMAT_V1)); + assert_eq!(store.pull_all()?.len(), 1); + Ok(()) + } + #[test] fn a_rewrite_of_a_v1_store_stays_v1() -> Result<()> { assert_eq!(