-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathtest_rpc_generated.py
More file actions
195 lines (153 loc) · 6.49 KB
/
Copy pathtest_rpc_generated.py
File metadata and controls
195 lines (153 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
"""Tests for generated RPC method behavior."""
import inspect
import json
from unittest.mock import AsyncMock, Mock
import pytest
from copilot._jsonrpc import JsonRpcClient
from copilot.generated.rpc import ClientGlobalApiHandlers, register_client_global_api_handlers
from copilot.rpc import (
BuiltinToolInputSchemaType,
CommandsApi,
CommandsInvokeRequest,
CommandsRespondToQueuedCommandRequest,
HostDisposeRequest,
HostEmptyResult,
LocalSessionMetadataValue,
MCPServerConfigHTTP,
QueuedCommandHandled,
QueuedCommandNotHandled,
RemoteControlStatusOff,
RemoteControlStatusResult,
RemoteSessionMetadataValue,
SandboxConfig,
ServerRpc,
SessionList,
SlashCommandTextResult,
TaskAgentInfo,
UIElicitationSchemaType,
)
async def test_host_dispose_deserializes_empty_acknowledgement():
client = Mock(request=AsyncMock(return_value={}))
result = await ServerRpc(client).host.dispose(HostDisposeRequest(host_id="host"))
assert isinstance(result, HostEmptyResult)
assert result.to_dict() == {}
client.request.assert_awaited_once_with("host.dispose", {"hostId": "host"})
async def test_host_shutdown_handler_round_trips_empty_acknowledgement():
client = JsonRpcClient(Mock())
client._send_message = AsyncMock()
host = Mock(shutdown=AsyncMock(return_value=HostEmptyResult()))
register_client_global_api_handlers(client, ClientGlobalApiHandlers(host=host))
await client._dispatch_request(
{"jsonrpc": "2.0", "id": "shutdown", "method": "host.shutdown", "params": {}},
client.request_handlers["host.shutdown"],
cancellation_id=None,
)
host.shutdown.assert_awaited_once()
assert isinstance(host.shutdown.call_args.args[0], HostEmptyResult)
client._send_message.assert_awaited_once_with(
{"jsonrpc": "2.0", "id": "shutdown", "result": {}}
)
def test_sandbox_config_round_trips_allow_bypass_and_omits_when_absent():
configured = SandboxConfig(enabled=True, allow_bypass=True)
assert configured.to_dict() == {"enabled": True, "allowBypass": True}
assert SandboxConfig.from_dict(configured.to_dict()).allow_bypass is True
assert SandboxConfig(enabled=True).to_dict() == {"enabled": True}
def test_mcp_oauth_scopes_preserve_existing_positional_parameters():
parameters = inspect.signature(MCPServerConfigHTTP).parameters
assert parameters["oauth_scopes"].kind is inspect.Parameter.KEYWORD_ONLY
assert parameters["oidc"].kind is inspect.Parameter.POSITIONAL_OR_KEYWORD
config = MCPServerConfigHTTP.from_dict(
{
"url": "https://example.test/mcp",
"oauthScopes": ["tools:read", "resources:read"],
"oidc": True,
}
)
assert config.oauth_scopes == ["tools:read", "resources:read"]
assert config.oidc is True
@pytest.mark.asyncio
async def test_commands_invoke_deserializes_slash_command_result():
client = AsyncMock()
client.request = AsyncMock(return_value={"kind": "text", "text": "hello", "markdown": True})
api = CommandsApi(client, "sess-1")
result = await api.invoke(CommandsInvokeRequest(name="help"))
assert isinstance(result, SlashCommandTextResult)
assert result.text == "hello"
assert result.markdown is True
def test_remote_control_status_deserializes_string_discriminated_union():
result = RemoteControlStatusResult.from_dict({"status": {"state": "off"}})
assert isinstance(result.status, RemoteControlStatusOff)
assert result.status.state == "off"
assert result.status.to_dict() == {"state": "off"}
def test_ui_elicitation_schema_type_preserves_public_alias():
assert UIElicitationSchemaType is BuiltinToolInputSchemaType
def test_session_list_deserializes_boolean_discriminated_entries():
payload = {
"sessions": [
{
"sessionId": "example-local",
"startTime": "2026-07-26T10:00:00.000Z",
"modifiedTime": "2026-07-26T10:05:00.000Z",
"isRemote": False,
},
{
"sessionId": "example-remote",
"startTime": "2026-07-26T11:00:00.000Z",
"modifiedTime": "2026-07-26T11:05:00.000Z",
"isRemote": True,
"remoteSessionIds": ["example-remote"],
"repository": {"owner": "github", "name": "copilot-sdk", "branch": "main"},
},
]
}
result = SessionList.from_dict(payload)
local, remote = result.sessions
assert isinstance(local, LocalSessionMetadataValue)
assert local.session_id == "example-local"
assert local.is_remote is False
assert isinstance(remote, RemoteSessionMetadataValue)
assert remote.session_id == "example-remote"
assert remote.is_remote is True
assert remote.repository.owner == "github"
def test_task_agent_info_deserializes_integral_float_milliseconds():
task = TaskAgentInfo.from_dict(
{
"agentType": "general-purpose",
"description": "Example task",
"id": "agent-1",
"prompt": "Do the task",
"startedAt": "2026-08-19T12:00:00Z",
"status": "running",
"toolCallId": "tool-1",
"type": "agent",
"activeTimeMs": 43.0,
}
)
assert task.active_time_ms == 43
assert task.to_dict()["activeTimeMs"] == 43
@pytest.mark.parametrize(
("handled", "expected_type"),
[(True, QueuedCommandHandled), (False, QueuedCommandNotHandled)],
)
def test_queued_command_result_deserializes_boolean_discriminator(handled, expected_type):
request = CommandsRespondToQueuedCommandRequest.from_dict(
{"requestId": "example-request", "result": {"handled": handled}}
)
assert isinstance(request.result, expected_type)
@pytest.mark.parametrize(
("variant", "expected_handled", "expected_json"),
[
(QueuedCommandHandled(), True, '{"handled": true}'),
(QueuedCommandNotHandled(), False, '{"handled": false}'),
],
)
def test_queued_command_result_serializes_boolean_discriminator(
variant, expected_handled, expected_json
):
encoded = variant.to_dict()
assert encoded["handled"] is expected_handled
assert json.dumps(encoded) == expected_json
request = CommandsRespondToQueuedCommandRequest(request_id="example-request", result=variant)
round_tripped = CommandsRespondToQueuedCommandRequest.from_dict(request.to_dict())
assert request.to_dict()["result"]["handled"] is expected_handled
assert isinstance(round_tripped.result, type(variant))