Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

fix: sdk tests [LET-4071] (#4258)

cthomasa1e341fd5d27
diff --git a/tests/sdk/conftest.py b/tests/sdk/conftest.py
index b05eb3d78..ca98cc36c 100644
--- a/tests/sdk/conftest.py
+++ b/tests/sdk/conftest.py
@@ -4,38 +4,51 @@ import time
from typing import Any, Dict, List, Optional, Tuple
import pytest
+import requests
from dotenv import load_dotenv
from letta_client import Letta
-def run_server():
- load_dotenv()
[email protected](scope="session")
+def server_url() -> str:
+ """
+ Provides the URL for the Letta server.
+ If LETTA_SERVER_URL is not set, starts the server in a background thread
+ and polls until it's accepting connections.
+ """
- from letta.server.rest_api.app import start_server
+ def _run_server() -> None:
+ load_dotenv()
+ from letta.server.rest_api.app import start_server
- print("Starting server...")
- start_server(debug=True)
+ start_server(debug=True)
+ url: str = os.getenv("LETTA_SERVER_URL", "http://localhost:8283")
-# This fixture starts the server once for the entire test session
[email protected](scope="session")
-def server():
- # Get URL from environment or start server
- server_url = os.getenv("LETTA_SERVER_URL", f"http://localhost:8283")
if not os.getenv("LETTA_SERVER_URL"):
- print("Starting server thread")
- thread = threading.Thread(target=run_server, daemon=True)
+ thread = threading.Thread(target=_run_server, daemon=True)
thread.start()
- time.sleep(5)
- return server_url
+ # Poll until the server is up (or timeout)
+ timeout_seconds = 30
+ deadline = time.time() + timeout_seconds
+ while time.time() < deadline:
+ try:
+ resp = requests.get(url + "/v1/health")
+ if resp.status_code < 500:
+ break
+ except requests.exceptions.RequestException:
+ pass
+ time.sleep(0.1)
+ else:
+ raise RuntimeError(f"Could not reach {url} within {timeout_seconds}s")
+
+ return url
# This fixture creates a client for each test module
@pytest.fixture(scope="session")
-def client(server):
- # Use the server URL from the server fixture
- server_url = server
+def client(server_url):
print("Running client tests with server:", server_url)
# Overide the base_url if the LETTA_API_URL is set