forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_client.py
More file actions
137 lines (105 loc) · 4.32 KB
/
test_client.py
File metadata and controls
137 lines (105 loc) · 4.32 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
"""E2E Client Tests"""
import pytest
from copilot import CopilotClient
from .testharness import CLI_PATH
class TestClient:
@pytest.mark.asyncio
async def test_should_start_and_connect_to_server_using_stdio(self):
client = CopilotClient({"cli_path": CLI_PATH, "use_stdio": True})
try:
await client.start()
assert client.get_state() == "connected"
pong = await client.ping("test message")
assert pong["message"] == "pong: test message"
assert pong["timestamp"] >= 0
errors = await client.stop()
assert len(errors) == 0
assert client.get_state() == "disconnected"
finally:
await client.force_stop()
@pytest.mark.asyncio
async def test_should_start_and_connect_to_server_using_tcp(self):
client = CopilotClient({"cli_path": CLI_PATH, "use_stdio": False})
try:
await client.start()
assert client.get_state() == "connected"
pong = await client.ping("test message")
assert pong["message"] == "pong: test message"
assert pong["timestamp"] >= 0
errors = await client.stop()
assert len(errors) == 0
assert client.get_state() == "disconnected"
finally:
await client.force_stop()
@pytest.mark.asyncio
async def test_should_return_errors_on_failed_cleanup(self):
import asyncio
client = CopilotClient({"cli_path": CLI_PATH})
try:
await client.create_session()
# Kill the server process to force cleanup to fail
process = client._process
assert process is not None
process.kill()
await asyncio.sleep(0.1)
errors = await client.stop()
assert len(errors) > 0
assert "Failed to destroy session" in errors[0]["message"]
finally:
await client.force_stop()
@pytest.mark.asyncio
async def test_should_force_stop_without_cleanup(self):
client = CopilotClient({"cli_path": CLI_PATH})
await client.create_session()
await client.force_stop()
assert client.get_state() == "disconnected"
@pytest.mark.asyncio
async def test_should_get_status_with_version_and_protocol_info(self):
client = CopilotClient({"cli_path": CLI_PATH, "use_stdio": True})
try:
await client.start()
status = await client.get_status()
assert "version" in status
assert isinstance(status["version"], str)
assert "protocolVersion" in status
assert isinstance(status["protocolVersion"], int)
assert status["protocolVersion"] >= 1
await client.stop()
finally:
await client.force_stop()
@pytest.mark.asyncio
async def test_should_get_auth_status(self):
client = CopilotClient({"cli_path": CLI_PATH, "use_stdio": True})
try:
await client.start()
auth_status = await client.get_auth_status()
assert "isAuthenticated" in auth_status
assert isinstance(auth_status["isAuthenticated"], bool)
if auth_status["isAuthenticated"]:
assert "authType" in auth_status
assert "statusMessage" in auth_status
await client.stop()
finally:
await client.force_stop()
@pytest.mark.asyncio
async def test_should_list_models_when_authenticated(self):
client = CopilotClient({"cli_path": CLI_PATH, "use_stdio": True})
try:
await client.start()
auth_status = await client.get_auth_status()
if not auth_status["isAuthenticated"]:
# Skip if not authenticated - models.list requires auth
await client.stop()
return
models = await client.list_models()
assert isinstance(models, list)
if len(models) > 0:
model = models[0]
assert "id" in model
assert "name" in model
assert "capabilities" in model
assert "supports" in model["capabilities"]
assert "limits" in model["capabilities"]
await client.stop()
finally:
await client.force_stop()