mirror of
https://github.com/usestrix/strix.git
synced 2026-08-16 09:26:39 +02:00
fix(context): reserve notice budget so bounded output honors max_bytes
The head+tail slices could each take half of max_bytes, then the truncation notice and its separators were appended on top, so the value persisted to history could exceed the configured maximum. Reserve an upper bound for the notice (and separators) out of the byte budget before slicing so the whole joined result stays within max_bytes.
This commit is contained in:
@@ -28,7 +28,9 @@ def test_byte_limit_enforced_on_single_long_line() -> None:
|
||||
bounded = bound_text(text, max_lines=2_000, max_bytes=1_000)
|
||||
|
||||
assert "truncated" in bounded
|
||||
assert len(bounded.encode("utf-8")) < 3_000
|
||||
# The whole joined result (head + tail + notice + separators) honours the
|
||||
# configured maximum, not just the head/tail slices.
|
||||
assert len(bounded.encode("utf-8")) <= 1_000
|
||||
|
||||
|
||||
def test_multibyte_characters_not_split() -> None:
|
||||
|
||||
Reference in New Issue
Block a user