CassetteHttpClient

org.llm4s.testkit.CassetteHttpClient
See theCassetteHttpClient companion class

Attributes

Companion
class
Source
CassetteHttpClient.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def apply(path: Path, mode: CassetteMode, live: => Llm4sHttpClient, matchHeaders: Seq[String]): Result[CassetteHttpClient]

A cassette at path used in mode. live is the client a recording sends through, built only when the mode records: in Replay, in RecordIfMissing with the cassette present, and in RecordNew until a request is not in the cassette, it is never evaluated. The live client stays the caller's to close: create it first and close it when the test is done (Using.resource(Llm4sHttpClient.create()) { live => ... }).

A cassette at path used in mode. live is the client a recording sends through, built only when the mode records: in Replay, in RecordIfMissing with the cassette present, and in RecordNew until a request is not in the cassette, it is never evaluated. The live client stays the caller's to close: create it first and close it when the test is done (Using.resource(Llm4sHttpClient.create()) { live => ... }).

Replay fails when the file is missing, larger than MaxCassetteBytes or not a cassette; Record when the file cannot be written (it writes an empty cassette at once, so a run that records nothing leaves no stale recording). RecordIfMissing writes the file only with its first recorded exchange, so a first run whose live calls all fail leaves no cassette behind, and the next run records again. RecordNew reads the file when it is there, as Replay does, and starts empty when it is not.

matchHeaders names request headers a replayed request must also match on (anthropic-beta, anthropic-version), compared case-insensitively by name; by default none are. Their values are written to the cassette (with registered secrets removed) so they can be compared. A credential header (Authorization, x-api-key, a name holding auth, key, token, secret or cookie) is never compared and stays masked: naming one is a ValidationError.

Clients opened on one path (the same file, however the path is spelled) share one list of interactions and one write lock, so a target client and a judge client recording to one cassette keep both their exchanges. Open them all before either sends: opening in Record starts the shared cassette over. Close each when done: the shared list is dropped once the last client on its path is closed, and the next client reads the file afresh.

Attributes

Source
CassetteHttpClient.scala
def replay(path: Path, matchHeaders: Seq[String]): Result[CassetteHttpClient]

The cassette at path, replayed: no live client is involved. matchHeaders is as for apply.

The cassette at path, replayed: no live client is involved. matchHeaders is as for apply.

Attributes

Source
CassetteHttpClient.scala

Concrete fields

The largest request or response body a cassette records: 8 MiB.

The largest request or response body a cassette records: 8 MiB.

Attributes

Source
CassetteHttpClient.scala

The largest cassette file read or written: 64 MiB.

The largest cassette file read or written: 64 MiB.

Attributes

Source
CassetteHttpClient.scala