forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_rpc_generated.py
More file actions
142 lines (112 loc) · 4.58 KB
/
Copy pathtest_rpc_generated.py
File metadata and controls
142 lines (112 loc) · 4.58 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
"""Tests for generated RPC method behavior."""
import json
from unittest.mock import AsyncMock
import pytest
from copilot.rpc import (
BuiltinToolInputSchemaType,
CommandsApi,
CommandsInvokeRequest,
CommandsRespondToQueuedCommandRequest,
LocalSessionMetadataValue,
QueuedCommandHandled,
QueuedCommandNotHandled,
RemoteControlStatusOff,
RemoteControlStatusResult,
RemoteSessionMetadataValue,
SandboxConfig,
SessionList,
SlashCommandTextResult,
TaskAgentInfo,
UIElicitationSchemaType,
)
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}
@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))