-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(python): add timeout parameter to generated RPC methods #581
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3adc7fa
fix(python): add timeout parameter to generated RPC methods
Rasaboun 31ca763
test: cover no-params and server-scoped RPC timeout branches
Rasaboun 36b4fa6
fix: move _timeout_kwargs after quicktype imports, add server+params …
Rasaboun c9fe13f
style: fix ruff format in test_rpc_timeout.py
Rasaboun 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| """Tests for timeout parameter on generated RPC methods.""" | ||
|
|
||
| from unittest.mock import AsyncMock | ||
|
|
||
| import pytest | ||
|
|
||
| from copilot.generated.rpc import ( | ||
| FleetApi, | ||
| Mode, | ||
| ModeApi, | ||
| ModelsApi, | ||
| PlanApi, | ||
| SessionFleetStartParams, | ||
| SessionModeSetParams, | ||
| ToolsApi, | ||
| ToolsListParams, | ||
| ) | ||
|
|
||
|
|
||
| class TestRpcTimeout: | ||
| """Tests for timeout forwarding across all four codegen branches: | ||
| - session-scoped with params | ||
| - session-scoped without params | ||
| - server-scoped with params | ||
| - server-scoped without params | ||
| """ | ||
|
|
||
| # ── session-scoped, with params ────────────────────────────────── | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_default_timeout_not_forwarded(self): | ||
| client = AsyncMock() | ||
| client.request = AsyncMock(return_value={"started": True}) | ||
| api = FleetApi(client, "sess-1") | ||
|
|
||
| await api.start(SessionFleetStartParams(prompt="go")) | ||
|
|
||
| client.request.assert_called_once() | ||
| _, kwargs = client.request.call_args | ||
| assert "timeout" not in kwargs | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_custom_timeout_forwarded(self): | ||
| client = AsyncMock() | ||
| client.request = AsyncMock(return_value={"started": True}) | ||
| api = FleetApi(client, "sess-1") | ||
|
|
||
| await api.start(SessionFleetStartParams(prompt="go"), timeout=600.0) | ||
|
|
||
| _, kwargs = client.request.call_args | ||
| assert kwargs["timeout"] == 600.0 | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_timeout_on_session_params_method(self): | ||
| client = AsyncMock() | ||
| client.request = AsyncMock(return_value={"mode": "plan"}) | ||
| api = ModeApi(client, "sess-1") | ||
|
|
||
| await api.set(SessionModeSetParams(mode=Mode.PLAN), timeout=120.0) | ||
|
|
||
| _, kwargs = client.request.call_args | ||
| assert kwargs["timeout"] == 120.0 | ||
|
|
||
| # ── session-scoped, no params ──────────────────────────────────── | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_timeout_on_session_no_params_method(self): | ||
| client = AsyncMock() | ||
| client.request = AsyncMock(return_value={"exists": True}) | ||
| api = PlanApi(client, "sess-1") | ||
|
|
||
| await api.read(timeout=90.0) | ||
|
|
||
| _, kwargs = client.request.call_args | ||
| assert kwargs["timeout"] == 90.0 | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_default_timeout_on_session_no_params_method(self): | ||
| client = AsyncMock() | ||
| client.request = AsyncMock(return_value={"exists": True}) | ||
| api = PlanApi(client, "sess-1") | ||
|
|
||
| await api.read() | ||
|
|
||
| _, kwargs = client.request.call_args | ||
| assert "timeout" not in kwargs | ||
|
|
||
| # ── server-scoped, with params ───────────────────────────────────── | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_timeout_on_server_params_method(self): | ||
| client = AsyncMock() | ||
| client.request = AsyncMock(return_value={"tools": []}) | ||
| api = ToolsApi(client) | ||
|
|
||
| await api.list(ToolsListParams(), timeout=60.0) | ||
|
|
||
| _, kwargs = client.request.call_args | ||
| assert kwargs["timeout"] == 60.0 | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_default_timeout_on_server_params_method(self): | ||
| client = AsyncMock() | ||
| client.request = AsyncMock(return_value={"tools": []}) | ||
| api = ToolsApi(client) | ||
|
|
||
| await api.list(ToolsListParams()) | ||
|
|
||
| _, kwargs = client.request.call_args | ||
| assert "timeout" not in kwargs | ||
|
|
||
| # ── server-scoped, no params ───────────────────────────────────── | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_timeout_on_server_no_params_method(self): | ||
| client = AsyncMock() | ||
| client.request = AsyncMock(return_value={"models": []}) | ||
| api = ModelsApi(client) | ||
|
|
||
| await api.list(timeout=45.0) | ||
|
|
||
| _, kwargs = client.request.call_args | ||
| assert kwargs["timeout"] == 45.0 | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_default_timeout_on_server_no_params_method(self): | ||
| client = AsyncMock() | ||
| client.request = AsyncMock(return_value={"models": []}) | ||
| api = ModelsApi(client) | ||
|
|
||
| await api.list() | ||
|
|
||
| _, kwargs = client.request.call_args | ||
| assert "timeout" not in kwargs | ||
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
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.
Tests currently cover session+params, session+no-params, and server+no-params branches, but they do not cover the server-scoped + params branch (which exists, e.g.,
ToolsApi.list(params: ToolsListParams, *, timeout=...)). Add a test that calls a server-scoped method with params and asserts thattimeoutis forwarded when provided (and omitted when not).