jevcrates.git / jev-client / src / README.md

Chapter 18½: inside jev-client/src — four files and a folder of tests

Small crate, one loop. Read the ports first, because the loop is written entirely in terms of them; then the loop; then what it returns when things go wrong.

The files, in reading order

  1. lib.rs: the crate's doc comment and its public surface, re-exported from the three modules: Client, Answered, ClientError, and the port types.
  2. ports.rs: the two traits a host implements and the values that cross them.
    • Transport: admit(&request) (optional; the default waits for nothing), send(request), distrust_connection().
    • Runtime: now(), wall_clock(), sleep(d), timeout(d, future), jitter() (uniform in [0, 1)).
    • HttpRequest { headers, body }, HttpResponse { status, headers, body }.
    • TransportError { kind, message } and TransportErrorKind, each kind documented with what the client does about it.
    • Observer and Event, for counters and logs; () is the observer that hears nothing.
    • Instant, which is web_time::Instant: std::time::Instant itself on native targets, and a performance.now() clock on wasm32-unknown-unknown, where std's Instant::now panics and a Worker could not implement Runtime::now at all.
  3. client.rs: Client::new(transport, runtime, model, api_key), observed(observer), model(), and ask(state, questions), the retry loop (Chapter 18 draws it). MAX_REDIALS = 2 lives here. At the bottom, mod tests; pulls in client/tests.rs.
  4. error.rs: ClientError and its five variants, nothing_billed() and request_id(). Its Display appends the attempt count when there was more than one, and [request <id>] when a response carried one.
  5. client/: the tests for the loop, Chapter 18¾.

Aside. Why is there a client.rs and a client/ folder? That is how Rust spells "this module has a child module in its own file". client.rs says mod tests;, and the compiler looks for client/tests.rs. Nothing else lives in the folder.

Try it

cargo test -p jev-client

For the people who maintain it

In this folder

PathWhat
lib.rsDoc comment and re-exports.
ports.rsTransport, Runtime, Observer, Event, the request, response and error types, Instant.
client.rsClient and the retry loop in ask.
error.rsClientError, nothing_billed, request_id.
client/Virtual-time tests for Client::ask.
CLAUDE.mdInvariants for agents.

← Previous: Chapter 18: jev-client · Up: jev-client · Next: Chapter 18¾: jev-client/src/client →