- 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)
33 lines
1.0 KiB
Python
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"}
|