Skip to content

The agent that grows with you

test: trim _db_persisted mutation-site tests to one invariant per site

teknium1b8363f17d638
diff --git a/tests/agent/test_message_sequence_repair.py b/tests/agent/test_message_sequence_repair.py
index 9fa97ba8ada..ef001c495e2 100644
--- a/tests/agent/test_message_sequence_repair.py
+++ b/tests/agent/test_message_sequence_repair.py
@@ -1523,19 +1523,6 @@ def test_repair_user_merge_pops_persist_marker_on_stamped_survivor():
assert _DB_PERSISTED_MARKER not in messages[0]
-def test_repair_user_merge_keeps_marker_when_row_unchanged():
- """Negative control: merging an empty later turn reproduces the persisted
- bytes, so the stamp stays and no redundant row is written."""
- agent = _bare_agent()
- stamped = {"role": "user", "content": "first", _DB_PERSISTED_MARKER: True}
- messages = [stamped, {"role": "user", "content": ""}]
-
- repairs = AIAgent._repair_message_sequence(agent, messages)
-
- assert repairs == 1
- assert messages[0]["content"] == "first"
- assert messages[0][_DB_PERSISTED_MARKER] is True
-
def test_repair_assistant_merge_pops_persist_marker_on_content_rewrite():
agent = _bare_agent()
@@ -1553,55 +1540,6 @@ def test_repair_assistant_merge_pops_persist_marker_on_content_rewrite():
assert _DB_PERSISTED_MARKER not in messages[1]
-def test_repair_assistant_merge_pops_persist_marker_on_tool_calls_union():
- """The marker asserts the whole row, not just content: a merge that only
- unions tool_calls still stales the persisted row and must pop it."""
- agent = _bare_agent()
- stamped = {
- "role": "assistant", "content": "answer",
- "tool_calls": [{"id": "t1", "type": "function",
- "function": {"name": "f", "arguments": "{}"}}],
- _DB_PERSISTED_MARKER: True,
- }
- messages = [
- {"role": "user", "content": "Q1"},
- stamped,
- {"role": "assistant", "content": None,
- "tool_calls": [{"id": "t2", "type": "function",
- "function": {"name": "g", "arguments": "{}"}}]},
- # Results answer both calls so pass 2 leaves the union intact: the
- # marker pop is attributable to the merge, not the prune pass.
- {"role": "tool", "tool_call_id": "t1", "content": "out1"},
- {"role": "tool", "tool_call_id": "t2", "content": "out2"},
- {"role": "user", "content": "next"},
- ]
-
- repairs = AIAgent._repair_message_sequence(agent, messages)
-
- assert repairs == 1
- assert [tc["id"] for tc in messages[1]["tool_calls"]] == ["t1", "t2"]
- assert messages[1]["content"] == "answer"
- assert _DB_PERSISTED_MARKER not in messages[1]
-
-
-def test_repair_assistant_merge_keeps_marker_when_nothing_changed():
- """Negative control: a merge that changes no persisted field keeps the
- stamp (later turn empty; union reproduces the same tool_calls value)."""
- agent = _bare_agent()
- stamped = {
- "role": "assistant", "content": "answer",
- _DB_PERSISTED_MARKER: True,
- }
- messages = [
- {"role": "user", "content": "Q1"},
- stamped,
- {"role": "assistant", "content": ""},
- ]
-
- AIAgent._repair_message_sequence(agent, messages)
-
- assert messages[1][_DB_PERSISTED_MARKER] is True
-
def test_repair_prune_unanswered_tool_calls_pops_persist_marker():
"""Pass 2 rewrites ``msg["tool_calls"]`` in place on a stamped assistant
@@ -1644,22 +1582,3 @@ def test_repair_cursor_invalidates_scan_prefix_when_stamped_dict_dirtied():
assert repairs == 1
assert _DB_PERSISTED_MARKER not in messages[0]
assert agent._db_flush_scan_prefix is None
-
-
-def test_repair_cursor_keeps_scan_prefix_when_no_stamp_dirtied():
- """Repairs on unstamped dicts must not pay a full re-scan: the prefix
- snapshot stays valid when no stamped survivor lost its marker."""
- agent = _bare_agent()
- messages = [
- {"role": "user", "content": "first", _DB_PERSISTED_MARKER: True},
- {"role": "assistant", "content": "a1"},
- {"role": "assistant", "content": "a2"},
- ]
- agent._last_flushed_db_idx = 1
- prefix = messages[:]
- agent._db_flush_scan_prefix = prefix
-
- repairs = repair_message_sequence_with_cursor(agent, messages)
-
- assert repairs == 1
- assert agent._db_flush_scan_prefix is prefix
diff --git a/tests/agent/test_micro_compaction.py b/tests/agent/test_micro_compaction.py
index 547d686e5ac..b577f2915b0 100644
--- a/tests/agent/test_micro_compaction.py
+++ b/tests/agent/test_micro_compaction.py
@@ -868,18 +868,3 @@ class TestMergeAdjacentUserTurnsPersistedMarker:
assert merged[0]["content"] == "first\n\nsecond"
assert _DB_PERSISTED_MARKER not in merged[0]
assert cc._flush_scan_cursor_invalidated is True
-
- def test_untouched_survivors_keep_their_stamps(self):
- """Only the rewritten dict loses its stamp; the merge must not strip
- _db_persisted from messages it did not mutate (the archive would
- re-insert them as duplicate active rows on failure)."""
- from agent.context_compressor import _DB_PERSISTED_MARKER
-
- _, result = self._spliced_merge()
-
- markers = _summary_markers(result)
- assert len(markers) == 1 # the fresh splice marker
- stale_dropped = [m for m in result if m.get("content") == "SUMMARY"]
- assert not stale_dropped
- # The new marker was never persisted; it must not carry a stamp.
- assert _DB_PERSISTED_MARKER not in markers[0]
diff --git a/tests/agent/test_tool_call_args_sanitizer.py b/tests/agent/test_tool_call_args_sanitizer.py
index f52597249d9..9676c048527 100644
--- a/tests/agent/test_tool_call_args_sanitizer.py
+++ b/tests/agent/test_tool_call_args_sanitizer.py
@@ -185,33 +185,3 @@ def test_corrupt_args_repair_pops_persist_marker_on_stamped_dicts():
assert stamped_result["content"].endswith("ok")
assert _DB_PERSISTED_MARKER not in stamped_call
assert _DB_PERSISTED_MARKER not in stamped_result
-
-
-def test_blank_args_repair_pops_persist_marker():
- """The blank-args rewrite is also an in-place mutation of the live dict."""
- from agent.context_compressor import _DB_PERSISTED_MARKER
-
- stamped_call = _assistant_message(_tool_call(call_id="call_1", arguments=""))
- stamped_call[_DB_PERSISTED_MARKER] = True
- messages = [{"role": "user", "content": "hi"}, stamped_call]
-
- AIAgent._sanitize_tool_call_arguments(messages)
-
- assert stamped_call["tool_calls"][0]["function"]["arguments"] == "{}"
- assert _DB_PERSISTED_MARKER not in stamped_call
-
-
-def test_valid_args_keep_persist_marker():
- """Control: an untouched stamped dict keeps its stamp."""
- from agent.context_compressor import _DB_PERSISTED_MARKER
-
- stamped_call = _assistant_message(
- _tool_call(call_id="call_1", arguments='{"path":"/tmp/foo"}')
- )
- stamped_call[_DB_PERSISTED_MARKER] = True
- messages = [{"role": "user", "content": "hi"}, stamped_call]
-
- repaired = AIAgent._sanitize_tool_call_arguments(messages)
-
- assert repaired == 0
- assert stamped_call[_DB_PERSISTED_MARKER] is True
diff --git a/tests/agent/test_unicode_ascii_codec.py b/tests/agent/test_unicode_ascii_codec.py
index a2130d15ba0..4a6ef2a5a4b 100644
--- a/tests/agent/test_unicode_ascii_codec.py
+++ b/tests/agent/test_unicode_ascii_codec.py
@@ -305,13 +305,6 @@ class TestSanitizeMessagesPersistMarker:
assert "\ud800" not in msg["content"]
assert _DB_PERSISTED_MARKER not in msg
- def test_non_ascii_repair_pops_marker(self):
- from agent.context_compressor import _DB_PERSISTED_MARKER
-
- msg = {"role": "user", "content": "café", _DB_PERSISTED_MARKER: True}
- assert _sanitize_messages_non_ascii([msg]) is True
- assert msg["content"] != "café"
- assert _DB_PERSISTED_MARKER not in msg
def test_unchanged_dict_keeps_marker(self):
from agent.context_compressor import _DB_PERSISTED_MARKER