fix(tests): update recent history truncation to use token limits

This commit is contained in:
w.antar
2026-06-17 00:47:52 +08:00
committed by Xubin Ren
parent 973a5ee507
commit 21d9072190
+9 -4
View File
@@ -222,18 +222,23 @@ def test_recent_history_capped_at_max(tmp_path) -> None:
assert f"entry-{builder._MAX_RECENT_HISTORY + 19}" in prompt
def test_recent_history_truncated_at_max_chars(tmp_path) -> None:
"""Recent History section must be truncated at _MAX_HISTORY_CHARS."""
def test_recent_history_truncated_at_max_tokens(tmp_path) -> None:
"""Recent History section must be truncated to _MAX_HISTORY_TOKENS."""
import tiktoken
workspace = _make_workspace(tmp_path)
builder = ContextBuilder(workspace)
big_entry = "x" * (builder._MAX_HISTORY_CHARS + 5_000)
big_entry = "word " * (builder._MAX_HISTORY_TOKENS + 5_000)
builder.memory.append_history(big_entry)
prompt = builder.build_system_prompt()
history_section = prompt.split("# Recent History\n\n", 1)
assert len(history_section) == 2
assert len(history_section[1]) < builder._MAX_HISTORY_CHARS + 200
enc = tiktoken.get_encoding("cl100k_base")
# Small margin for the truncation suffix appended after the token slice.
assert len(enc.encode(history_section[1])) <= builder._MAX_HISTORY_TOKENS + 50
def test_no_recent_history_when_dream_has_processed_all(tmp_path) -> None: