Scriptable in-process A2A peer for integration tests.
Ships in lib/ (not test/) so consuming hosts can use it in their
own test suites without having to reimplement this machinery.
Usage
{:ok, peer} = A2aEngine.TestPeer.start_link()
url = A2aEngine.TestPeer.url(peer)
A2aEngine.TestPeer.script(peer, "message/send", fn _params ->
{:ok, %{"kind" => "task", "id" => "t1", "contextId" => "c1",
"status" => %{"state" => "completed"}}}
end)
{:ok, response} = A2aEngine.Transport.Http.send_request(url, request)
# Assert the peer saw what we expected
assert A2aEngine.TestPeer.received(peer) == [{"message/send", %{...}}]
A2aEngine.TestPeer.stop(peer)Streaming
A2aEngine.TestPeer.script_stream(peer, "message/stream", fn _params, emit ->
emit.(event1)
emit.(event2)
{:ok, :done}
end)Options
:auth—A2aEngine.Authmodule. Defaults toLocalhost.:auth_opts— keyword list passed to the auth module.:port— fixed port (default 0 → random).
Summary
Functions
Returns a specification to start this module under a supervisor.
Clear the received log (useful between assertions in one test).
TCP port the peer is bound to.
List of {method, params} tuples that the peer has received, in order.
Install a unary response function for a JSON-RPC method.
Install a streaming response function for a JSON-RPC method.
Start a test peer with its own Bandit HTTP server on a random port.
Stop the peer and its underlying Bandit server.
Full base URL (scheme://host:port) where this peer accepts A2A requests.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear_received(pid()) :: :ok
Clear the received log (useful between assertions in one test).
@spec port(pid()) :: non_neg_integer()
TCP port the peer is bound to.
List of {method, params} tuples that the peer has received, in order.
@spec script(pid(), String.t(), request_fn()) :: :ok
Install a unary response function for a JSON-RPC method.
The function receives the decoded params map and returns
{:ok, result} or {:error, error_map}.
Install a streaming response function for a JSON-RPC method.
The function receives (params, emit_fn) and may call emit_fn.(event)
zero or more times before returning {:ok, term} or {:error, map}.
@spec start_link(keyword()) :: GenServer.on_start()
Start a test peer with its own Bandit HTTP server on a random port.
@spec stop(pid()) :: :ok
Stop the peer and its underlying Bandit server.
Full base URL (scheme://host:port) where this peer accepts A2A requests.