Files
aicc-py/tests/test_websocket.py
T
Emil Shanaty 0cfb4277b5 aicc-py 0.1.0: initial SDK
- protocol.py: pydantic models for all AICC message types (envelope,
  session_init, tool_call, tool_result, event, error, heartbeat)
- bridge.py: Bridge with @bridge.tool registration, capability checks,
  session management, serve_forever
- client.py: AICCClient with single background reader (safe on
  concurrent transports like WebSocket), call_tool, events, manifest
- tool.py: @tool decorator with schema generation from type hints
- schema.py: JSON Schema generation (str/int/float/bool, list, dict,
  Optional, pydantic models)
- transport: Transport protocol, InProcessTransport, WebSocket client+server
- tests: 12 passing (integration, schema, websocket roundtrip)
- examples: bridge_minimal.py + agent_minimal.py (verified end-to-end)
2026-08-08 03:10:35 +03:00

33 lines
1.0 KiB
Python

"""End-to-end test over WebSocket: server + client in the same event loop."""
from __future__ import annotations
import asyncio
import pytest
from aicc import AICCClient, Bridge
from aicc.transport import WebSocketClientTransport, WebSocketServer
@pytest.mark.asyncio
async def test_websocket_roundtrip():
bridge = Bridge(name="ws-room")
@bridge.tool(description="Echo a value.")
async def echo(value: str = "") -> dict:
return {"value": value}
async with WebSocketServer(bridge, port=0) as server:
# port=0 -> OS-assigned; read it back from the server object
port = server._server.sockets[0].getsockname()[1] # type: ignore[union-attr]
uri = f"ws://127.0.0.1:{port}"
async with AICCClient(WebSocketClientTransport(uri)) as client:
manifest = await client.handshake()
assert manifest.world.name == "ws-room"
res = await client.call_tool("echo", {"value": "hi"})
assert res.ok
assert res.output == {"value": "hi"}