generated from deepgram/oss-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 123
fix(websockets): restore optional message param on control send_ methods #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lukeocodes
merged 2 commits into
main
from
fix/websocket-optional-control-message-params
Mar 27, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| """Tests that control send_ methods work without requiring a message argument. | ||
|
|
||
| Regression test for the breaking change where optional message params were lost | ||
| during a Fern regen, causing TypeError for callers using no-arg control calls. | ||
| """ | ||
|
|
||
| import json | ||
| from unittest.mock import AsyncMock, MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from deepgram.agent.v1.socket_client import AsyncV1SocketClient as AsyncAgentV1SocketClient | ||
| from deepgram.agent.v1.socket_client import V1SocketClient as AgentV1SocketClient | ||
| from deepgram.listen.v1.socket_client import AsyncV1SocketClient as AsyncListenV1SocketClient | ||
| from deepgram.listen.v1.socket_client import V1SocketClient as ListenV1SocketClient | ||
| from deepgram.listen.v2.socket_client import AsyncV2SocketClient as AsyncListenV2SocketClient | ||
| from deepgram.listen.v2.socket_client import V2SocketClient as ListenV2SocketClient | ||
| from deepgram.speak.v1.socket_client import AsyncV1SocketClient as AsyncSpeakV1SocketClient | ||
| from deepgram.speak.v1.socket_client import V1SocketClient as SpeakV1SocketClient | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Helpers | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| def _make_async_ws(): | ||
| ws = AsyncMock() | ||
| ws.send = AsyncMock() | ||
| return ws | ||
|
|
||
|
|
||
| def _make_sync_ws(): | ||
| ws = MagicMock() | ||
| ws.send = MagicMock() | ||
| return ws | ||
|
|
||
|
|
||
| def _sent_json(ws): | ||
| """Return the parsed JSON from the first send() call.""" | ||
| call_args = ws.send.call_args | ||
| data = call_args[0][0] | ||
| return json.loads(data) | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # speak/v1 — async | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| class TestAsyncSpeakV1ControlMessages: | ||
| async def test_send_flush_no_args(self): | ||
| ws = _make_async_ws() | ||
| client = AsyncSpeakV1SocketClient(websocket=ws) | ||
| await client.send_flush() | ||
| assert _sent_json(ws)["type"] == "Flush" | ||
|
|
||
| async def test_send_clear_no_args(self): | ||
| ws = _make_async_ws() | ||
| client = AsyncSpeakV1SocketClient(websocket=ws) | ||
| await client.send_clear() | ||
| assert _sent_json(ws)["type"] == "Clear" | ||
|
|
||
| async def test_send_close_no_args(self): | ||
| ws = _make_async_ws() | ||
| client = AsyncSpeakV1SocketClient(websocket=ws) | ||
| await client.send_close() | ||
| assert _sent_json(ws)["type"] == "Close" | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # speak/v1 — sync | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| class TestSyncSpeakV1ControlMessages: | ||
| def test_send_flush_no_args(self): | ||
| ws = _make_sync_ws() | ||
| client = SpeakV1SocketClient(websocket=ws) | ||
| client.send_flush() | ||
| assert _sent_json(ws)["type"] == "Flush" | ||
|
|
||
| def test_send_clear_no_args(self): | ||
| ws = _make_sync_ws() | ||
| client = SpeakV1SocketClient(websocket=ws) | ||
| client.send_clear() | ||
| assert _sent_json(ws)["type"] == "Clear" | ||
|
|
||
| def test_send_close_no_args(self): | ||
| ws = _make_sync_ws() | ||
| client = SpeakV1SocketClient(websocket=ws) | ||
| client.send_close() | ||
| assert _sent_json(ws)["type"] == "Close" | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # listen/v1 — async | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| class TestAsyncListenV1ControlMessages: | ||
| async def test_send_finalize_no_args(self): | ||
| ws = _make_async_ws() | ||
| client = AsyncListenV1SocketClient(websocket=ws) | ||
| await client.send_finalize() | ||
| assert _sent_json(ws)["type"] == "Finalize" | ||
|
|
||
| async def test_send_close_stream_no_args(self): | ||
| ws = _make_async_ws() | ||
| client = AsyncListenV1SocketClient(websocket=ws) | ||
| await client.send_close_stream() | ||
| assert _sent_json(ws)["type"] == "CloseStream" | ||
|
|
||
| async def test_send_keep_alive_no_args(self): | ||
| ws = _make_async_ws() | ||
| client = AsyncListenV1SocketClient(websocket=ws) | ||
| await client.send_keep_alive() | ||
| assert _sent_json(ws)["type"] == "KeepAlive" | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # listen/v1 — sync | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| class TestSyncListenV1ControlMessages: | ||
| def test_send_finalize_no_args(self): | ||
| ws = _make_sync_ws() | ||
| client = ListenV1SocketClient(websocket=ws) | ||
| client.send_finalize() | ||
| assert _sent_json(ws)["type"] == "Finalize" | ||
|
|
||
| def test_send_close_stream_no_args(self): | ||
| ws = _make_sync_ws() | ||
| client = ListenV1SocketClient(websocket=ws) | ||
| client.send_close_stream() | ||
| assert _sent_json(ws)["type"] == "CloseStream" | ||
|
|
||
| def test_send_keep_alive_no_args(self): | ||
| ws = _make_sync_ws() | ||
| client = ListenV1SocketClient(websocket=ws) | ||
| client.send_keep_alive() | ||
| assert _sent_json(ws)["type"] == "KeepAlive" | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # listen/v2 — async | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| class TestAsyncListenV2ControlMessages: | ||
| async def test_send_close_stream_no_args(self): | ||
| ws = _make_async_ws() | ||
| client = AsyncListenV2SocketClient(websocket=ws) | ||
| await client.send_close_stream() | ||
| assert _sent_json(ws)["type"] == "CloseStream" | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # listen/v2 — sync | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| class TestSyncListenV2ControlMessages: | ||
| def test_send_close_stream_no_args(self): | ||
| ws = _make_sync_ws() | ||
| client = ListenV2SocketClient(websocket=ws) | ||
| client.send_close_stream() | ||
| assert _sent_json(ws)["type"] == "CloseStream" | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # agent/v1 — async | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| class TestAsyncAgentV1ControlMessages: | ||
| async def test_send_keep_alive_no_args(self): | ||
| ws = _make_async_ws() | ||
| client = AsyncAgentV1SocketClient(websocket=ws) | ||
| await client.send_keep_alive() | ||
| assert _sent_json(ws)["type"] == "KeepAlive" | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # agent/v1 — sync | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| class TestSyncAgentV1ControlMessages: | ||
| def test_send_keep_alive_no_args(self): | ||
| ws = _make_sync_ws() | ||
| client = AgentV1SocketClient(websocket=ws) | ||
| client.send_keep_alive() | ||
| assert _sent_json(ws)["type"] == "KeepAlive" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR restores optional control-message params, but there are no tests asserting that these
send_*()control methods can be called with no arguments (and that they send the expected default payload). Since the repo already has coverage forlisten.v1.socket_clientbehavior intests/custom/test_transport.py, please add a small unit test that instantiates the socket client with a mock transport and verifiessend_keep_alive()/send_close_stream()/send_finalize()work without args.