feat: add session persistence to CLI
- Add save-only endpoint (POST /conversations/{id}/save) for persisting
messages without triggering agent execution
- Add sessions command to list previous conversation sessions
- Add --resume flag to chat command for resuming sessions by ID
- Buffer streamed responses and save after completion
- Update AGENTS.md with session commands and remove outdated limitation
- Add 3 new tests for save endpoint (208 total)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -297,3 +297,87 @@ class TestSummarization:
|
||||
|
||||
assert "[Previous Summary]" in formatted
|
||||
assert "Previous context summary" in formatted
|
||||
|
||||
|
||||
class TestSaveMessagesAPI:
|
||||
"""Tests for the save messages endpoint (no agent execution)."""
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_save_messages(self, auth_client):
|
||||
"""Test saving a message pair without triggering agent."""
|
||||
# First create a conversation
|
||||
response = await auth_client.post(
|
||||
"/conversations/",
|
||||
json={"agent_type": "task", "working_dir": "."}
|
||||
)
|
||||
assert response.status_code == 201
|
||||
conv_id = response.json()["id"]
|
||||
|
||||
# Save a message pair
|
||||
response = await auth_client.post(
|
||||
f"/conversations/{conv_id}/save",
|
||||
json={
|
||||
"user_content": "Find all Python files",
|
||||
"assistant_content": "I found 5 Python files in the project.",
|
||||
}
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
assert data["user_message"]["role"] == "user"
|
||||
assert data["user_message"]["content"] == "Find all Python files"
|
||||
assert data["assistant_message"]["role"] == "assistant"
|
||||
assert data["assistant_message"]["content"] == "I found 5 Python files in the project."
|
||||
assert data["total_tokens"] > 0
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_save_messages_not_found(self, auth_client):
|
||||
"""Test saving messages to non-existent conversation."""
|
||||
fake_id = uuid4()
|
||||
response = await auth_client.post(
|
||||
f"/conversations/{fake_id}/save",
|
||||
json={
|
||||
"user_content": "Test",
|
||||
"assistant_content": "Response",
|
||||
}
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_save_messages_updates_token_count(self, auth_client):
|
||||
"""Test that saving messages updates the conversation token count."""
|
||||
# Create conversation
|
||||
response = await auth_client.post(
|
||||
"/conversations/",
|
||||
json={"agent_type": "explore", "working_dir": "."}
|
||||
)
|
||||
conv_id = response.json()["id"]
|
||||
assert response.json()["total_tokens"] == 0
|
||||
|
||||
# Save first message pair
|
||||
response = await auth_client.post(
|
||||
f"/conversations/{conv_id}/save",
|
||||
json={
|
||||
"user_content": "Hello",
|
||||
"assistant_content": "Hi there!",
|
||||
}
|
||||
)
|
||||
first_tokens = response.json()["total_tokens"]
|
||||
assert first_tokens > 0
|
||||
|
||||
# Save second message pair
|
||||
response = await auth_client.post(
|
||||
f"/conversations/{conv_id}/save",
|
||||
json={
|
||||
"user_content": "How are you?",
|
||||
"assistant_content": "I'm doing well, thank you for asking!",
|
||||
}
|
||||
)
|
||||
second_tokens = response.json()["total_tokens"]
|
||||
assert second_tokens > first_tokens
|
||||
|
||||
# Verify via get endpoint
|
||||
response = await auth_client.get(f"/conversations/{conv_id}")
|
||||
assert response.status_code == 200
|
||||
assert response.json()["total_tokens"] == second_tokens
|
||||
assert len(response.json()["messages"]) == 4
|
||||
|
||||
Reference in New Issue
Block a user