Skip to main content

Module testing

Module testing 

Source
Expand description

Scripted hostile peers, for testing whatever calls an agent.

A coordinator that delegates has to survive the worker it calls: one that stalls mid-stream, drops the connection before the final event, sends a frame that does not parse, or refuses the caller’s credentials. Those are the failures a real network produces and a well-behaved test server never does, so they go untested unless something produces them on purpose.

ScriptedPeer is that something. It listens on a loopback port, speaks one binding — JSON-RPC, HTTP+JSON, WebSocket (feature websocket) or gRPC (feature grpc) — and answers every call according to one script:

ScriptStreaming callsUnary calls
stall_after(n)n events, then silence with the connection held openno answer, connection held open
cut_off_after(n)n events, then the connection or stream is droppedthe connection is dropped
misframe_after(n)n events, then one that does not parse, then silencea body that does not parse
unauthorized()refused: HTTP 401, gRPC UNAUTHENTICATED, or a WebSocket handshake answered 401the same

Every event is a TASK_STATE_WORKING status update for task t, so no stream ever reaches a terminal state on its own: what the caller sees next is decided by the script alone.

use a2a_protocol_client::testing::{Binding, ScriptedPeer};

let peer = ScriptedPeer::new().stall_after(1).on(Binding::Rest).start().await?;
// Point the code under test at `peer.url()`, and assert it gives up.

This repository’s own client tests use it (tests/scripted_peer_tests.rs), which is how it is known to produce each failure on each binding. Enabled by the testing feature; it is for tests, and nothing in a production build should depend on it.

Structs§

RunningPeer
A started ScriptedPeer. Dropping it stops the listener; connections already accepted keep whatever state their script left them in until the runtime ends.
ScriptedPeer
A hostile A2A peer on a loopback port. See the module docs.

Enums§

Binding
The binding a ScriptedPeer speaks.
Script
What a ScriptedPeer does with each call.