1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//! Type definitions for the harness testkit.
//!
//! Every public struct and enum in `crate::harness::testkit` is declared here.
//! Implementations, constructors, and trait impls live in `mod.rs`; focused
//! tests live in `test.rs`.
use VecDeque;
use ;
use crate;
use crate;
use crateToolCall;
// ---------------------------------------------------------------------------
// ScriptedModel
// ---------------------------------------------------------------------------
/// A [`crate::harness::model::ChatModel`] that returns pre-loaded responses in
/// order, making model behavior fully deterministic in tests.
///
/// Responses are consumed from the front of the queue one per `invoke` call.
/// When the queue is exhausted `invoke` returns
/// [`crate::error::TinyAgentsError::Model`] rather than panicking so tests get
/// a clear error instead of a thread panic.
///
/// # Example
///
/// ```rust
/// # use tinyagents::harness::testkit::ScriptedModel;
/// # use tinyagents::harness::model::ModelResponse;
/// let model = ScriptedModel::replies(vec!["Hello", "World"]);
/// // Use in tests as a ChatModel<()>.
/// ```
// ---------------------------------------------------------------------------
// FakeTool
// ---------------------------------------------------------------------------
/// The runtime behavior chosen when a [`FakeTool`] is invoked.
pub
/// A configurable [`crate::harness::tool::Tool`] for testing.
///
/// Created with one of three factory methods:
///
/// - [`FakeTool::new`] — returns an empty string result.
/// - [`FakeTool::returning`] — returns a fixed text content.
/// - [`FakeTool::failing`] — returns a [`crate::error::TinyAgentsError::Tool`] error.
///
/// Every received [`ToolCall`] is recorded and available via
/// [`FakeTool::calls`].
///
/// # Example
///
/// ```rust
/// # use tinyagents::harness::testkit::FakeTool;
/// let tool = FakeTool::returning("search", "42");
/// // Use as Tool<()> in tests.
/// ```
// ---------------------------------------------------------------------------
// DeterministicClock
// ---------------------------------------------------------------------------
/// A controllable, monotonic clock for deterministic test scenarios.
///
/// Unlike `SystemTime`, `DeterministicClock` never advances on its own. Tests
/// call [`DeterministicClock::advance`] to move time forward in a controlled
/// way, making time-sensitive assertions reproducible.
///
/// # Example
///
/// ```rust
/// # use tinyagents::harness::testkit::DeterministicClock;
/// let clock = DeterministicClock::new(1_000);
/// assert_eq!(clock.now_millis(), 1_000);
/// clock.advance(500);
/// assert_eq!(clock.now_millis(), 1_500);
/// ```
// ---------------------------------------------------------------------------
// DeterministicIds
// ---------------------------------------------------------------------------
/// A monotonically incrementing identifier generator for stable test output.
///
/// Produces ids in the form `"{prefix}-0"`, `"{prefix}-1"`, ... so tests can
/// assert exact id values without relying on UUIDs or wall-clock timestamps.
///
/// # Example
///
/// ```rust
/// # use tinyagents::harness::testkit::DeterministicIds;
/// let ids = DeterministicIds::new("call");
/// assert_eq!(ids.next(), "call-0");
/// assert_eq!(ids.next(), "call-1");
/// ```
// ---------------------------------------------------------------------------
// EventRecorder
// ---------------------------------------------------------------------------
/// Captures [`AgentEvent`]s emitted through an [`EventSink`] for later
/// inspection.
///
/// The recorder owns an internal [`RecordingListener`] subscribed to a shared
/// [`EventSink`]. Callers obtain the sink via [`EventRecorder::sink`] and pass
/// it to the component under test. After the run, [`EventRecorder::events`]
/// and [`EventRecorder::kinds`] provide access to what was emitted.
///
/// # Example
///
/// ```rust
/// # use tinyagents::harness::testkit::EventRecorder;
/// # use tinyagents::harness::events::AgentEvent;
/// # use tinyagents::harness::ids::RunId;
/// let recorder = EventRecorder::new();
/// let sink = recorder.sink();
/// sink.emit(AgentEvent::RunStarted { run_id: RunId::new("r1"), thread_id: None });
/// assert_eq!(recorder.kinds(), vec!["run.started"]);
/// ```
// ---------------------------------------------------------------------------
// Trajectory
// ---------------------------------------------------------------------------
/// An ordered view of [`AgentEvent`]s with structural assertion helpers.
///
/// `Trajectory` lets tests make deterministic claims about *what happened*
/// during a run (which tools were called, how many model calls occurred, whether
/// the run completed) without depending on exact LLM prose or wall-clock timing.
///
/// ## `assert_*` variants vs predicate methods
///
/// Each feature is exposed both as a predicate (`tool_was_called`) and as an
/// asserting helper (`assert_tool_called`) that panics with a descriptive
/// message on failure, matching Rust's `assert!` / `assert_eq!` ergonomics.
///
/// ## Assertion methods returning `Result`
///
/// [`Trajectory::assert_order`] returns
/// [`crate::error::Result`]`<()>` rather than panicking so callers can
/// propagate the error or inspect the message programmatically.
///
/// # Example
///
/// ```rust
/// # use tinyagents::harness::testkit::Trajectory;
/// # use tinyagents::harness::events::AgentEvent;
/// # use tinyagents::harness::ids::{RunId, CallId};
/// let events = vec![
/// AgentEvent::RunStarted { run_id: RunId::new("r1"), thread_id: None },
/// AgentEvent::ModelStarted { call_id: CallId::new("c1"), model: "gpt".into() },
/// AgentEvent::ModelCompleted { call_id: CallId::new("c1"), usage: None },
/// AgentEvent::RunCompleted { run_id: RunId::new("r1") },
/// ];
/// let traj = Trajectory::from_events(events);
/// assert_eq!(traj.model_call_count(), 1);
/// traj.assert_completed();
/// ```