From 47a8f6148afd5ef1aba127f070022743c8f8510d Mon Sep 17 00:00:00 2001 From: Alex Jia Date: Wed, 26 Aug 2026 20:47:57 -0500 Subject: [PATCH] test(file-ops): pin native read parity on 1 MiB chunk boundaries (cherry picked from commit f72338b4d75d2a70048014523d4a55d5a4f30cbd) --- tests/tools/test_file_ops_single_roundtrip.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/tools/test_file_ops_single_roundtrip.py b/tests/tools/test_file_ops_single_roundtrip.py index b5bef568d9..33c26f74b2 100644 --- a/tests/tools/test_file_ops_single_roundtrip.py +++ b/tests/tools/test_file_ops_single_roundtrip.py @@ -339,6 +339,13 @@ class TestNativeRead: assert calls == [] +# The native reader scans 1 MiB chunks and clamps each page line to +# ``4 * get_max_line_length() + 1`` bytes (8001 by default), exactly as +# ``sed | cut -b1-N`` does. These shapes put a newline, a line, the clamp +# point, a CRLF pair and EOF precisely on those chunk boundaries. +_CHUNK = 1 << 20 +_CLAMP = 8001 + PARITY_CASES = [ ("plain", b"one\ntwo\nthree\n", {}), ("no_trailing_newline", b"a\nb", {}), @@ -353,6 +360,27 @@ PARITY_CASES = [ ("long_line", b"a" * 9000 + b"\nshort\n", {}), ("multibyte_long_line", ("汉" * 4000 + "\nx\n").encode("utf-8"), {}), ("multi_chunk_line", b"b" * 3_000_000 + b"\nz\n", {}), + ("newline_last_byte_of_chunk", b"a" * (_CHUNK - 1) + b"\nsecond\n", {}), + ("newline_first_byte_of_next_chunk", b"a" * _CHUNK + b"\nsecond\n", {}), + ("line_spans_three_boundaries", b"p\n" + b"b" * (3 * _CHUNK + 5) + b"\nz\n", {}), + ( + "clamp_fills_on_boundary", + b"x" * (_CHUNK - _CLAMP - 1) + b"\n" + b"c" * 20000 + b"\ntail\n", + {"offset": 2, "limit": 3}, + ), + ( + "clamp_fills_after_boundary", + b"x" * (_CHUNK - _CLAMP) + b"\n" + b"c" * 20000 + b"\ntail\n", + {"offset": 2, "limit": 3}, + ), + ("eof_midline_on_boundary", b"l1\n" + b"d" * (2 * _CHUNK - 3), {}), + ("blank_lines_on_boundary", b"e" * (_CHUNK - 2) + b"\n\n\n" + b"f\n", {}), + ("crlf_split_on_boundary", b"r" * (_CHUNK - 1) + b"\r\n" + b"s\r\n", {}), + ( + "page_starts_in_second_chunk", + b"q\n" * (_CHUNK // 2 + 3) + b"target1\ntarget2\n", + {"offset": _CHUNK // 2 + 3, "limit": 4}, + ), ("window", b"".join(b"l%d\n" % i for i in range(1, 11)), {"offset": 3, "limit": 2}), ("window_reaches_eof", b"".join(b"l%d\n" % i for i in range(1, 11)), {"offset": 9, "limit": 5}), ("past_eof", b"".join(b"l%d\n" % i for i in range(1, 6)), {"offset": 50}), @@ -419,3 +447,4 @@ class TestCompoundFallback: r = ops.read_file(p) assert r.error is None and r.content == "1|one\n2|two\n3|" assert r.total_lines == 2 +