forked from agentclientprotocol/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_unstable.py
More file actions
70 lines (54 loc) · 2.16 KB
/
Copy pathtest_unstable.py
File metadata and controls
70 lines (54 loc) · 2.16 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
from typing import Any
import pytest
from acp.exceptions import RequestError
from acp.schema import (
CloseSessionResponse,
ForkSessionResponse,
HttpMcpServer,
ListSessionsResponse,
McpServerStdio,
ResumeSessionResponse,
SseMcpServer,
)
from tests.conftest import TestAgent
class UnstableAgent(TestAgent):
async def list_sessions(self, cursor: str | None = None, cwd: str | None = None, **kwargs) -> ListSessionsResponse:
return ListSessionsResponse(sessions=[])
async def close_session(self, session_id: str, **kwargs) -> CloseSessionResponse | None:
return CloseSessionResponse()
async def fork_session(
self,
cwd: str,
session_id: str,
mcp_servers: list[HttpMcpServer | SseMcpServer | McpServerStdio] | None = None,
**kwargs: Any,
) -> ForkSessionResponse:
return ForkSessionResponse(session_id="forked_sess")
async def resume_session(
self,
cwd: str,
session_id: str,
mcp_servers: list[HttpMcpServer | SseMcpServer | McpServerStdio] | None = None,
**kwargs: Any,
) -> ResumeSessionResponse:
return ResumeSessionResponse()
@pytest.mark.parametrize("agent", [UnstableAgent()])
@pytest.mark.asyncio
async def test_call_unstable_protocol(connect):
_, agent_conn = connect(use_unstable_protocol=True)
resp = await agent_conn.list_sessions()
assert isinstance(resp, ListSessionsResponse)
resp = await agent_conn.fork_session(cwd="/workspace", session_id="sess")
assert isinstance(resp, ForkSessionResponse)
resp = await agent_conn.resume_session(cwd="/workspace", session_id="sess")
assert isinstance(resp, ResumeSessionResponse)
resp = await agent_conn.close_session(session_id="sess")
assert isinstance(resp, CloseSessionResponse)
@pytest.mark.parametrize("agent", [UnstableAgent()])
@pytest.mark.asyncio
async def test_call_unstable_protocol_warning(connect):
_, agent_conn = connect(use_unstable_protocol=False)
with pytest.warns(UserWarning) as record:
with pytest.raises(RequestError):
await agent_conn.close_session(session_id="sess")
assert len(record) == 1