Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = [{ name = "Jacob-Lasky", email = "jacob.s.lasky@gmail.com" }]
requires-python = ">=3.12, <3.13"
readme = "README.md"
dependencies = [
"deepgram-sdk==6.0.1",
"deepgram-sdk>=7.6.0,<8",
"fastapi>=0.115.0,<1",
"python-socketio>=5.11.0,<6",
"uvicorn>=0.30.0,<1",
Expand Down
26 changes: 22 additions & 4 deletions tests/test_wire_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class of failure — the value was present in our dict and absent on the wire
No Deepgram credential is needed, and none should ever be added here: the server
is ours, the handshake is local, and the assertion is on the path string.
"""
import inspect

import pytest
from deepgram import AsyncDeepgramClient
from deepgram.environment import DeepgramClientEnvironment
Expand All @@ -23,6 +25,25 @@ class of failure — the value was present in our dict and absent on the wire
from app import _params_to_sdk_kwargs


def _local_environment(port: int) -> DeepgramClientEnvironment:
"""Point every SDK endpoint at our loopback server.

Built by introspecting the constructor rather than naming its fields, because
the SDK adds URL fields between regenerations — 7.0 added `agent_rest`, which
broke this helper with a TypeError while the app itself was fine. Enumerating
the signature means the next added field costs nothing.
"""
ws = f"ws://127.0.0.1:{port}"
http = f"http://127.0.0.1:{port}"
fields = inspect.signature(DeepgramClientEnvironment.__init__).parameters
kwargs = {
name: (http if "rest" in name or name == "base" else ws)
for name in fields
if name != "self"
}
return DeepgramClientEnvironment(**kwargs)


async def _handshake_path(params: dict) -> str:
"""Connect the SDK to a local WS server; return the path it requested."""
seen: list[str] = []
Expand All @@ -33,12 +54,9 @@ async def handler(ws):

async with await serve(handler, "127.0.0.1", 0) as server:
port = server.sockets[0].getsockname()[1]
url = f"ws://127.0.0.1:{port}"
dg = AsyncDeepgramClient(
api_key="wire-contract-test-key",
environment=DeepgramClientEnvironment(
base=f"http://127.0.0.1:{port}", production=url, agent=url
),
environment=_local_environment(port),
)
try:
async with dg.listen.v1.connect(**_params_to_sdk_kwargs(params)):
Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.