-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathtest_rpc_generated.py
More file actions
107 lines (85 loc) · 3.46 KB
/
Copy pathtest_rpc_generated.py
File metadata and controls
107 lines (85 loc) · 3.46 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
"""Tests for generated RPC method behavior."""
import json
from unittest.mock import AsyncMock
import pytest
from copilot.rpc import (
CommandsApi,
CommandsInvokeRequest,
CommandsRespondToQueuedCommandRequest,
LocalSessionMetadataValue,
QueuedCommandHandled,
QueuedCommandNotHandled,
RemoteControlStatusOff,
RemoteControlStatusResult,
RemoteSessionMetadataValue,
SessionList,
SlashCommandTextResult,
)
@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_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"
@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))