db.testing
nimblebrain_server_sdk.db.testing · install nimblebrain-server-sdk[db] · version 0.7.2
from nimblebrain_server_sdk.db.testing import edge_client, use_limiterTest helpers for a server built on SecuredDatabase.
Functions
Section titled “Functions”edge_client
Section titled “edge_client”async def edge_client(mcp: FastMCP, *, tenant_id: str, workspace_id: str, headers: Mapping[str, str] | None = None, mode: Mode = 'auto') -> AsyncIterator[Client]A client whose calls reach mcp with a verified identity, for a test.
The in-memory fastmcp.Client(mcp) sends no HTTP headers, so a tool that reads its
identity with security_context_from_edge_headers(get_http_headers()) raises
AuthError under it. This serves mcp over HTTP inside the test’s own event loop (no
port is bound) and yields a client that sends x-tenant-id and x-workspace-id on
every request, which is how the edge delivers one. headers adds others, such as the
one a server reads a user id from. The server’s lifespan runs for the length of the block.
For tests only. It changes nothing in the server: identity still arrives in the two headers and nowhere else, so it opens no way for a tool argument or a request body to carry one. The test stands where the edge stands in production, the one party the server trusts to set those headers; a deployment keeps that true by admitting only the edge.
use_limiter
Section titled “use_limiter”def use_limiter(db: SecuredDatabase, limiter: WorkspaceLimiter) -> Generator[WorkspaceLimiter, None, None]Run db’s sessions under limiter (a small cap, a short wait) for the block.