Skip to content

Commit 1a22ee9

Browse files
test: add FilesResponse round-trip tests for zero-length file content
Exercises the offset arithmetic when file content is empty (size=0, offset += 0 is a no-op). Tests both a single empty file and a mix of empty and non-empty files in the same response. Closes #116 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5ac79f5 commit 1a22ee9

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

tests/test_messages_responses.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,26 @@ def test_roundtrip_non_aligned_content(self) -> None:
901901
assert decoded.files["file1.db"] == b"\x01\x02\x03"
902902
assert decoded.files["file2.db"] == b"\x04\x05\x06\x07\x08\x09\x0a"
903903

904+
def test_roundtrip_empty_content(self) -> None:
905+
"""116: zero-length file content must round-trip correctly."""
906+
msg = FilesResponse(files={"empty.db": b""})
907+
encoded = msg.encode()
908+
decoded = FilesResponse.decode_body(encoded[HEADER_SIZE:])
909+
assert decoded.files == {"empty.db": b""}
910+
911+
def test_roundtrip_mixed_empty_and_nonempty(self) -> None:
912+
"""116: empty and non-empty files in the same response."""
913+
msg = FilesResponse(
914+
files={
915+
"main.db": b"data",
916+
"empty.db": b"",
917+
"wal.db": b"more data",
918+
}
919+
)
920+
encoded = msg.encode()
921+
decoded = FilesResponse.decode_body(encoded[HEADER_SIZE:])
922+
assert decoded.files == msg.files
923+
904924
def test_aligned_content_has_no_padding(self) -> None:
905925
"""Word-aligned content must not produce any extra padding bytes."""
906926
content = b"\x00" * 16 # exactly 2 words

0 commit comments

Comments
 (0)