-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathtest_client_api_e2e.py
More file actions
87 lines (69 loc) · 3.24 KB
/
test_client_api_e2e.py
File metadata and controls
87 lines (69 loc) · 3.24 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
"""
Tests for client-scoped session-management APIs:
``delete_session``, ``get_session_metadata``, ``get_last_session_id``,
``get_foreground_session_id``, and ``set_foreground_session_id``.
The file is named ``test_client_api`` so the conftest snapshot resolver picks
up the ``test/snapshots/client_api`` folder shared with the C# suite
(``ClientSessionManagementTests.cs``).
"""
from __future__ import annotations
import pytest
from copilot.session import PermissionHandler
from .testharness import E2ETestContext
pytestmark = pytest.mark.asyncio(loop_scope="module")
class TestClientApi:
async def test_should_delete_session_by_id(self, ctx: E2ETestContext):
session = await ctx.client.create_session(
on_permission_request=PermissionHandler.approve_all,
)
session_id = session.session_id
await session.send_and_wait("Say OK.")
await session.disconnect()
await ctx.client.delete_session(session_id)
metadata = await ctx.client.get_session_metadata(session_id)
assert metadata is None
async def test_should_report_error_when_deleting_unknown_session_id(self, ctx: E2ETestContext):
await ctx.client.start()
unknown_session_id = "00000000-0000-0000-0000-000000000000"
with pytest.raises(Exception) as exc_info:
await ctx.client.delete_session(unknown_session_id)
assert f"failed to delete session {unknown_session_id}" in str(exc_info.value).lower()
async def test_should_get_null_last_session_id_before_any_sessions_exist(
self, ctx: E2ETestContext
):
await ctx.client.start()
# Other tests in this class create sessions, and pytest doesn't
# guarantee test execution order. Clear any leftover sessions so this
# test sees a genuinely empty state regardless of order.
for existing in await ctx.client.list_sessions():
await ctx.client.delete_session(existing.session_id)
result = await ctx.client.get_last_session_id()
assert result is None
async def test_should_track_last_session_id_after_session_created(self, ctx: E2ETestContext):
session = await ctx.client.create_session(
on_permission_request=PermissionHandler.approve_all,
)
await session.send_and_wait("Say OK.")
session_id = session.session_id
await session.disconnect()
last_id = await ctx.client.get_last_session_id()
assert last_id == session_id
async def test_should_get_null_foreground_session_id_in_headless_mode(
self, ctx: E2ETestContext
):
await ctx.client.start()
session_id = await ctx.client.get_foreground_session_id()
assert session_id is None
async def test_should_report_error_when_setting_foreground_session_in_headless_mode(
self, ctx: E2ETestContext
):
session = await ctx.client.create_session(
on_permission_request=PermissionHandler.approve_all,
)
try:
with pytest.raises(Exception) as exc_info:
await ctx.client.set_foreground_session_id(session.session_id)
err = str(exc_info.value).lower()
assert "tui" in err or "server" in err
finally:
await session.disconnect()