test: consolidate repetitive cases across the suite

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-25 14:28:21 +08:00
1 parent c406024b59
commit 6eccc2859a
31 files changed
+745 -1315

No files matched your search

+15 -24
View File
@@ -71,33 +71,24 @@ class TestHistoryWithCursor:
cursor = store.append_history("event 3")
assert cursor == 3
def test_append_history_strips_thinking_content(self, store):
"""`strip_think` must run before persistence — well-formed thinking
blocks shouldn't land in history."""
cursor = store.append_history("<think>reasoning</think>final answer")
@pytest.mark.parametrize(
"input_text, expected_content",
[
pytest.param(
"<think>reasoning</think>final answer",
"final answer",
id="strips_thinking_content",
),
pytest.param("<think>nothing user-facing</think>", "", id="drops_pure_leak_content"),
pytest.param("<channel|>", "", id="drops_malformed_leak_prefix"),
],
)
def test_append_history_sanitizes_thinking(self, store, input_text, expected_content):
cursor = store.append_history(input_text)
content = store.read_file(store.history_file)
data = json.loads(content)
assert data["cursor"] == cursor
assert data["content"] == "final answer"
def test_append_history_drops_pure_leak_content(self, store):
"""Regression: entries that strip down to empty (pure template-token
leak) must NOT fall back to the raw leak. Persisting the raw text
would re-pollute context via consolidation / replay, undoing the
protection `strip_think` provides."""
cursor = store.append_history("<think>nothing user-facing</think>")
content = store.read_file(store.history_file)
data = json.loads(content)
assert data["cursor"] == cursor
assert data["content"] == ""
def test_append_history_drops_malformed_leak_prefix(self, store):
"""Channel-marker / malformed opening leaks should not survive."""
cursor = store.append_history("<channel|>")
content = store.read_file(store.history_file)
data = json.loads(content)
assert data["cursor"] == cursor
assert data["content"] == ""
assert data["content"] == expected_content
def test_read_unprocessed_history(self, store):
store.append_history("event 1")