Skip to content

The agent that grows with you

test(todo): add atomicity and whitespace-merge tests per review feedback

liuhao10242038bd92d26d
diff --git a/tests/tools/test_todo_tool.py b/tests/tools/test_todo_tool.py
index d09f9a28fe0..f9ad2231079 100644
--- a/tests/tools/test_todo_tool.py
+++ b/tests/tools/test_todo_tool.py
@@ -229,6 +229,25 @@ class TestRejectEmptyContent:
except ValueError as e:
assert "empty or missing content" in str(e)
+ def test_partial_write_does_not_mutate_existing_list(self):
+ """A failed write with mixed valid/invalid items leaves the prior list
+ untouched (acceptance criterion #3 from #44496)."""
+ store = TodoStore()
+ store.write([
+ {"id": "1", "content": "Keep me", "status": "pending"},
+ {"id": "2", "content": "Also keep me", "status": "completed"},
+ ])
+ try:
+ store.write([
+ {"id": "1", "content": "Updated", "status": "pending"}, # valid
+ {"id": "2", "content": "", "status": "pending"}, # invalid
+ ])
+ except ValueError:
+ pass
+ items = store.read()
+ assert [i["content"] for i in items] == ["Keep me", "Also keep me"]
+ assert [i["status"] for i in items] == ["pending", "completed"]
+
def test_todo_tool_returns_error_on_empty_content(self):
result = json.loads(todo_tool(
todos=[{"id": "1", "content": "", "status": "pending"}],
@@ -247,6 +266,16 @@ class TestRejectEmptyContent:
except ValueError as e:
assert "empty or missing content" in str(e)
+ def test_merge_new_item_rejects_whitespace_content(self):
+ """Merge mode: new items with whitespace-only content are rejected."""
+ store = TodoStore()
+ store.write([{"id": "1", "content": "Existing", "status": "pending"}])
+ try:
+ store.write([{"id": "2", "content": " ", "status": "pending"}], merge=True)
+ assert False, "should have raised ValueError"
+ except ValueError as e:
+ assert "empty or missing content" in str(e)
+
def test_merge_existing_item_keeps_content_on_status_only_update(self):
"""Merge mode: updating only status (no content key) preserves existing content."""
store = TodoStore()