-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathtest_ui_elicitation.py
More file actions
58 lines (42 loc) · 1.97 KB
/
test_ui_elicitation.py
File metadata and controls
58 lines (42 loc) · 1.97 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
"""E2E UI Elicitation Tests (single-client)
Mirrors nodejs/test/e2e/ui_elicitation.test.ts — single-client scenarios.
Uses the shared ``ctx`` fixture from conftest.py.
"""
import pytest
from copilot.session import (
ElicitationContext,
ElicitationResult,
PermissionHandler,
)
from .testharness import E2ETestContext
pytestmark = pytest.mark.asyncio(loop_scope="module")
class TestUiElicitation:
async def test_elicitation_methods_throw_in_headless_mode(self, ctx: E2ETestContext):
"""Elicitation methods throw when running in headless mode."""
session = await ctx.client.create_session(
on_permission_request=PermissionHandler.approve_all,
)
# The SDK spawns the CLI headless — no TUI means no elicitation support.
ui_caps = session.capabilities.get("ui", {})
assert not ui_caps.get("elicitation")
with pytest.raises(RuntimeError, match="not supported"):
await session.ui.confirm("test")
async def test_session_with_elicitation_handler_reports_capability(self, ctx: E2ETestContext):
"""Session created with onElicitationContext reports elicitation capability."""
async def handler(
context: ElicitationContext,
) -> ElicitationResult:
return {"action": "accept", "content": {}}
session = await ctx.client.create_session(
on_permission_request=PermissionHandler.approve_all,
on_elicitation_request=handler,
)
assert session.capabilities.get("ui", {}).get("elicitation") is True
async def test_session_without_elicitation_handler_reports_no_capability(
self, ctx: E2ETestContext
):
"""Session created without onElicitationContext reports no elicitation capability."""
session = await ctx.client.create_session(
on_permission_request=PermissionHandler.approve_all,
)
assert session.capabilities.get("ui", {}).get("elicitation") in (False, None)