Skip to content

The agent that grows with you

test(compaction): tighten the typed-retention tests

kshitijk4poor1a269f19806e
diff --git a/tests/agent/test_native_compaction_typed_user_retention.py b/tests/agent/test_native_compaction_typed_user_retention.py
index cf300eadfe2..16e9d607c49 100644
--- a/tests/agent/test_native_compaction_typed_user_retention.py
+++ b/tests/agent/test_native_compaction_typed_user_retention.py
@@ -15,8 +15,7 @@ from agent.native_compaction import (
_CHECKPOINT = {"type": "compaction", "encrypted_content": "synthetic_checkpoint"}
[email protected]("checkpoint", [True, False], ids=["checkpoint", "no-checkpoint"])
-def test_converter_retains_newest_oversized_typed_ask_not_older_ask(checkpoint):
+def test_converter_retains_newest_oversized_typed_ask_not_older_ask():
current = "CURRENT ASK: inspect this input. " + "x" * (RETAINED_USER_MESSAGE_TOKEN_BUDGET * 4)
messages = [
{"role": "user", "content": "OLDER ASK: already completed"},
@@ -25,7 +24,7 @@ def test_converter_retains_newest_oversized_typed_ask_not_older_ask(checkpoint):
{
"role": "assistant",
"content": "Continuing the current ask.",
- **({"codex_reasoning_items": [_CHECKPOINT]} if checkpoint else {}),
+ "codex_reasoning_items": [_CHECKPOINT],
},
]
original = deepcopy(messages)
@@ -37,38 +36,38 @@ def test_converter_retains_newest_oversized_typed_ask_not_older_ask(checkpoint):
assert all(part["type"] == "input_text" for item in users for part in item["content"])
texts = ["".join(part["text"] for part in item["content"]) for item in users]
- if checkpoint:
- assert converted[0] == _CHECKPOINT
- assert len(texts) == 1 and texts[0].startswith("CURRENT ASK:")
- assert current.startswith(texts[0]) and texts[0] != current
- assert 0 < estimate_tokens_rough(texts[0]) <= RETAINED_USER_MESSAGE_TOKEN_BUDGET
- else:
- assert texts == [messages[0]["content"], current]
+ assert converted[0] == _CHECKPOINT
+ assert len(texts) == 1 and texts[0].startswith("CURRENT ASK:")
+ assert current.startswith(texts[0]) and texts[0] != current
+ assert 0 < estimate_tokens_rough(texts[0]) <= RETAINED_USER_MESSAGE_TOKEN_BUDGET
assert messages == original
_IMAGE = {"type": "input_image", "image_url": "data:image/png;base64,AAAA"}
+def _user(*parts):
+ return {"type": "message", "role": "user", "id": "current-user",
+ "content": [{**part, "metadata": {"index": index}} for index, part in enumerate(parts)]}
+
+
+def _text(text):
+ return {"type": "input_text", "text": text}
+
+
@pytest.mark.parametrize(
- "content,budget,expected",
+ "current,budget,expected",
[
- ([{"type": "input_text", "text": "abcd"},
- {"type": "input_text", "text": "efghijkl"},
- {"type": "input_text", "text": "trailing"}], 2, ("abcd", "efgh")),
- ([{"type": "input_text", "text": "你好世界"}], 2, ("你好",)),
- ([{"type": "input_text", "text": "CURRENT" * 20}, _IMAGE], 2, None),
- (None, 2, None),
+ (_user(_text("abcd"), _text("efghijkl"), _text("trailing")), 2, ("abcd", "efgh")),
+ (_user(_text("你好世界")), 2, ("你好",)),
+ (_user(_text("CURRENT" * 20), _IMAGE), 2, None),
+ # Content-less item measured only via output_text.
+ ({"type": "message", "role": "user", "output_text": "CURRENT" * 20}, 2, None),
],
ids=["multipart-boundary", "cjk-estimator-budget", "oversized-mixed-image", "oversized-output-text-only"],
)
-def test_typed_boundary_is_budgeted_and_never_substitutes_older_ask(content, budget, expected):
+def test_typed_boundary_is_budgeted_and_never_substitutes_older_ask(current, budget, expected):
older = {"role": "user", "content": "old"}
- current = {"type": "message", "role": "user", "id": "current-user", "content": deepcopy(content)}
- if content is None: # Content-less item measured only via output_text.
- current = {"type": "message", "role": "user", "output_text": "CURRENT" * 20}
- for index, part in enumerate(current.get("content") or []):
- part["metadata"] = {"index": index}
items = [older, current, _CHECKPOINT]
original = deepcopy(items)
@@ -81,5 +80,4 @@ def test_typed_boundary_is_budgeted_and_never_substitutes_older_ask(content, bud
assert users == [{**current, "content": [
{**current["content"][index], "text": text} for index, text in enumerate(expected)
]}]
- assert sum(max(1, estimate_tokens_rough(p["text"])) for p in users[0]["content"]) <= budget
assert items == original