feat: enhance v1 API with streaming and improved history

This commit is contained in:
Manus
2026-03-19 20:23:37 -04:00
parent 964f28a86f
commit 36d1bdb521
2 changed files with 33 additions and 18 deletions

View File

@@ -1,15 +1,17 @@
import sys
import os
from pathlib import Path
# Absolute path to src
src_path = "/home/ubuntu/timmy-time/Timmy-time-dashboard/src"
if src_path not in sys.path:
sys.path.insert(0, src_path)
# Add project root to path
project_root = Path(__file__).resolve().parents[1]
src_path = project_root / "src"
if str(src_path) not in sys.path:
sys.path.insert(0, str(src_path))
from fastapi.testclient import TestClient # noqa: E402
try:
from dashboard.app import app # noqa: E402
print("✓ Successfully imported dashboard.app")
except ImportError as e:
print(f"✗ Failed to import dashboard.app: {e}")
@@ -17,7 +19,6 @@ except ImportError as e:
client = TestClient(app)
def test_v1_status():
response = client.get("/api/v1/status")
assert response.status_code == 200
@@ -26,20 +27,24 @@ def test_v1_status():
assert "model" in data
assert "uptime" in data
def test_v1_chat_history():
# Append a message first to ensure history is not empty
from dashboard.store import message_log
message_log.append(role="user", content="test message", timestamp="12:00:00", source="api-v1")
response = client.get("/api/v1/chat/history")
assert response.status_code == 200
data = response.json()
assert "messages" in data
assert len(data["messages"]) > 0
# The message_log.recent() returns reversed(rows) so the last one should be our test message
assert data["messages"][-1]["content"] == "test message"
def test_v1_upload_fail():
# Test without file
response = client.post("/api/v1/upload")
assert response.status_code == 422 # Unprocessable Entity (missing file)
if __name__ == "__main__":
print("Running API v1 tests...")
try:
@@ -52,4 +57,6 @@ if __name__ == "__main__":
print("All tests passed!")
except Exception as e:
print(f"Test failed: {e}")
import traceback
traceback.print_exc()
sys.exit(1)