From 3fe29b888481d5789524bca5a90e1545e5db8c52 Mon Sep 17 00:00:00 2001 From: Jer Miller Date: Tue, 18 Aug 2026 13:28:01 -0600 Subject: [PATCH] test(recovery): pin the .metadata document byte shape MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sidecar's on-disk contract — single JSON object, start_timestamp first, one trailing newline, last_durable_write_at omitted rather than null — was only asserted through parsed JSON. The new test compares the written bytes to handwritten literals for both the open state and a media-present refresh. --- crates/solstone-linux/src/recovery.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/solstone-linux/src/recovery.rs b/crates/solstone-linux/src/recovery.rs index 655e430..b7e85d3 100644 --- a/crates/solstone-linux/src/recovery.rs +++ b/crates/solstone-linux/src/recovery.rs @@ -641,4 +641,27 @@ mod tests { .unwrap(); assert_eq!(read_segment_start(&extra), Some(1_700_000_000.0)); } + + #[test] + fn metadata_document_byte_shape() { + let t = tempfile::tempdir().unwrap(); + write_segment_metadata(t.path(), 1234.5, SegmentProgress::default()); + assert_eq!( + fs::read_to_string(t.path().join(METADATA_FILENAME)).unwrap(), + "{\"start_timestamp\":1234.5,\"has_durable_media\":false,\"durable_byte_count\":0}\n" + ); + write_segment_metadata( + t.path(), + 1234.5, + SegmentProgress { + has_durable_media: true, + durable_byte_count: 4, + last_durable_write_at: Some(5678.5), + }, + ); + assert_eq!( + fs::read_to_string(t.path().join(METADATA_FILENAME)).unwrap(), + "{\"start_timestamp\":1234.5,\"has_durable_media\":true,\"durable_byte_count\":4,\"last_durable_write_at\":5678.5}\n" + ); + } } -- 2.51.2