Merge pull request #2605 from Molecule-AI/fix/2485-chat-history-followups

fix(chat-history): correct docstring inversion + pin empty-history JSON shape (#2485)
This commit is contained in:
Hongming Wang 2026-05-03 17:24:42 +00:00 committed by GitHub
commit 257079c7a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 3 deletions

View File

@ -559,9 +559,10 @@ async def tool_chat_history(peer_id: str, limit: int = 20, before_ts: str = "")
Hits ``/workspaces/<self>/activity?peer_id=<peer>&limit=<N>``
against the workspace-server, which returns activity rows where
this workspace is either the sender (``source_id=peer``) or the
recipient (``target_id=peer``) of an A2A turn both sides of the
conversation in chronological order.
the peer is either the sender (``source_id=peer`` they sent us
the message) or the recipient (``target_id=peer`` we sent to
them) of an A2A turn both sides of the conversation in
chronological order.
Args:
peer_id: The other workspace's UUID. Same value the agent

View File

@ -1050,6 +1050,27 @@ class TestChatHistory:
assert mc.get.call_args.kwargs["params"]["before_ts"] == "2026-05-01T00:00:00Z"
async def test_empty_history_returns_empty_json_list(self):
"""Pin the happy-path-with-no-rows shape: server returns 200
with an empty list, the wheel returns the JSON literal ``"[]"``.
Without this pin the surrounding tests all pre-populate rows;
none verify what an agent sees when there's literally no chat
history with this peer yet (a fresh A2A peering, or a peer
whose history was rotated out). #2485.
"""
import a2a_tools
mc = _make_http_mock(get_resp=_resp(200, []))
with patch("a2a_tools.httpx.AsyncClient", return_value=mc):
result = await a2a_tools.tool_chat_history(peer_id=_PEER)
# Exact-equality on the JSON literal (per assert-exact memory) —
# substring "[]" would also match `{"items": []}` or any number
# of envelope shapes, only `result == "[]"` discriminates the
# bare-list contract callers depend on.
assert result == "[]"
async def test_reverses_desc_response_to_chronological(self):
"""Server returns DESC (newest first); the wheel reverses to
chronological so the agent reads the chat top-down same