Skip to main content

base/
recorder.rs

1//! Record/replay configuration: the settings a model wrapper reads to record
2//! a session, replay it, or re-issue its requests.
3
4use serde::{Deserialize, Serialize};
5use std::path::PathBuf;
6
7/// Recorder (record/replay) configuration. `None` on [`Settings`] leaves the
8/// model wrapper a pass-through.
9#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
10pub struct RecorderConfig {
11    pub mode: RecorderMode,
12    /// Directory name for this recording under `root`. `None` uses the session
13    /// id, which is what production recording wants; tests name theirs so a
14    /// replay can find it again.
15    #[serde(default)]
16    pub name: Option<String>,
17    /// Where recordings live. Each one is a self-contained directory beneath
18    /// it, so a host retires a recording by deleting that directory.
19    pub root: PathBuf,
20    #[serde(default)]
21    pub on_divergence: Divergence,
22}
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
25#[serde(rename_all = "snake_case")]
26pub enum RecorderMode {
27    Record,
28    Replay,
29    /// Re-issue a recording's requests against a real provider.
30    ///
31    /// The third mode exists because the other two cannot answer "what would
32    /// the model have said if the prompt were different". `Replay` never reads
33    /// a request's content — it compares blob *ids* and returns the recorded
34    /// response — so editing a blob changes nothing it observes. `Rerun` loads
35    /// the request back from the blobs (picking up any edit), sends it, and
36    /// reports how the new response differs from the recorded one.
37    Rerun,
38}
39
40/// What replay does when a live request differs from the one recorded at the
41/// same position.
42#[derive(
43    Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, schemars::JsonSchema,
44)]
45#[serde(rename_all = "snake_case")]
46pub enum Divergence {
47    /// Fail the call, naming the fields that differ. The default wherever a
48    /// divergence means a broken test.
49    #[default]
50    Strict,
51    /// Report the difference and play the recorded response anyway.
52    Warn,
53}