test(consolidation): add regression tests for tiktoken truncation path and history char cap

Cover two untested boundaries from #3412:
- _truncate_to_token_budget with positive budget exercises tiktoken
- _MAX_HISTORY_CHARS caps Recent History section in system prompt

Made-with: Cursor
This commit is contained in:
Xubin Ren
2026-04-24 03:57:59 +08:00
committed by Xubin Ren
parent 4a1b9053ac
commit 81a5af2352
2 changed files with 31 additions and 0 deletions
+14
View File
@@ -116,6 +116,20 @@ 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."""
workspace = _make_workspace(tmp_path)
builder = ContextBuilder(workspace)
big_entry = "x" * (builder._MAX_HISTORY_CHARS + 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
def test_no_recent_history_when_dream_has_processed_all(tmp_path) -> None:
"""If Dream has consumed everything, no Recent History section should appear."""
workspace = _make_workspace(tmp_path)