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
94 lines (73 loc) · 3.55 KB
/
test_client.py
File metadata and controls
94 lines (73 loc) · 3.55 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
"""
CopilotClient Unit Tests
This file is for unit tests. Where relevant, prefer to add e2e tests in e2e/*.py instead.
"""
import pytest
from copilot import CopilotClient
from e2e.testharness import CLI_PATH
class TestHandleToolCallRequest:
@pytest.mark.asyncio
async def test_returns_failure_when_tool_not_registered(self):
client = CopilotClient({"cli_path": CLI_PATH})
await client.start()
try:
session = await client.create_session()
response = await client._handle_tool_call_request(
{
"sessionId": session.session_id,
"toolCallId": "123",
"toolName": "missing_tool",
"arguments": {},
}
)
assert response["result"]["resultType"] == "failure"
assert response["result"]["error"] == "tool 'missing_tool' not supported"
finally:
await client.force_stop()
class TestURLParsing:
def test_parse_port_only_url(self):
client = CopilotClient({"cli_url": "8080", "log_level": "error"})
assert client._actual_port == 8080
assert client._actual_host == "localhost"
assert client._is_external_server
def test_parse_host_port_url(self):
client = CopilotClient({"cli_url": "127.0.0.1:9000", "log_level": "error"})
assert client._actual_port == 9000
assert client._actual_host == "127.0.0.1"
assert client._is_external_server
def test_parse_http_url(self):
client = CopilotClient({"cli_url": "http://localhost:7000", "log_level": "error"})
assert client._actual_port == 7000
assert client._actual_host == "localhost"
assert client._is_external_server
def test_parse_https_url(self):
client = CopilotClient({"cli_url": "https://example.com:443", "log_level": "error"})
assert client._actual_port == 443
assert client._actual_host == "example.com"
assert client._is_external_server
def test_invalid_url_format(self):
with pytest.raises(ValueError, match="Invalid cli_url format"):
CopilotClient({"cli_url": "invalid-url", "log_level": "error"})
def test_invalid_port_too_high(self):
with pytest.raises(ValueError, match="Invalid port in cli_url"):
CopilotClient({"cli_url": "localhost:99999", "log_level": "error"})
def test_invalid_port_zero(self):
with pytest.raises(ValueError, match="Invalid port in cli_url"):
CopilotClient({"cli_url": "localhost:0", "log_level": "error"})
def test_invalid_port_negative(self):
with pytest.raises(ValueError, match="Invalid port in cli_url"):
CopilotClient({"cli_url": "localhost:-1", "log_level": "error"})
def test_cli_url_with_use_stdio(self):
with pytest.raises(ValueError, match="cli_url is mutually exclusive"):
CopilotClient({"cli_url": "localhost:8080", "use_stdio": True, "log_level": "error"})
def test_cli_url_with_cli_path(self):
with pytest.raises(ValueError, match="cli_url is mutually exclusive"):
CopilotClient(
{"cli_url": "localhost:8080", "cli_path": "/path/to/cli", "log_level": "error"}
)
def test_use_stdio_false_when_cli_url(self):
client = CopilotClient({"cli_url": "8080", "log_level": "error"})
assert not client.options["use_stdio"]
def test_is_external_server_true(self):
client = CopilotClient({"cli_url": "localhost:8080", "log_level": "error"})
assert client._is_external_server