pub struct MockScript {
pub events: Vec<AgentEvent>,
pub on_message: VecDeque<Vec<AgentEvent>>,
pub exit: SessionExit,
pub streaming: bool,
pub session_id: Option<String>,
pub hold_result_until_started: Option<usize>,
pub writes: Vec<(String, String)>,
pub commits: Vec<String>,
pub removes: Vec<String>,
pub proxy_connects: Vec<(String, u16)>,
}Expand description
One scripted agent session.
Fields§
§events: Vec<AgentEvent>Yielded in order by next_event.
on_message: VecDeque<Vec<AgentEvent>>Each send_user_message appends the next batch to the pending queue
(streaming sessions).
exit: SessionExitExit reported once the stream closes (ignored when aborted, and never
reached by streaming sessions, which only end via abort).
streaming: boolWhen false, send_user_message errors (single-shot session).
session_id: Option<String>Session id override; defaults to spec.session_id.
hold_result_until_started: Option<usize>Rendezvous: withhold this script’s FINAL scripted event (for a
single-shot run, its Result) until at least this many sessions have
been started backend-wide. Makes wall-clock-overlap tests
deterministic: a held session provably cannot finish before its peers
start, so peak-concurrency assertions are exact — and if the engine
ever dispatches sequentially, the rendezvous deadlocks into the
test’s timeout instead of flaky-passing. Meaningful for single-shot
scripts (streaming sessions end via abort, not a final event).
writes: Vec<(String, String)>Files to write into the session’s working directory (spec.cwd) when
the session starts — the seam that lets a mock session leave a dirty
tree for the engine’s §4.4 checkpoint to commit. Each entry is a path
relative to the session cwd and its contents; parent directories are
created as needed. Empty by default (byte-for-byte unchanged
behaviour).
commits: Vec<String>Commit messages to record in the session’s working directory
(spec.cwd) when the session starts, applied AFTER writes: each
becomes git add -A && git commit -m <message> — the seam that lets a
scripted validator MOVE HEAD, as a real git commit-capable validator
could (validator-immutability-proof tests). Empty by default.
removes: Vec<String>Paths to REMOVE from the session’s working directory (spec.cwd) when
the session starts, applied AFTER writes and commits — the seam
that lets a scripted worker sabotage its own worktree metadata (e.g.
delete its .git), so the engine’s checkpoint finds an uninspectable
worktree exactly as a hostile worker could leave one (12th-pass
review, candidate-inspection-failure tests). Empty by default.
proxy_connects: Vec<(String, u16)>CONNECTs this session issues through the egress proxy named by
spec.env[HTTPS_PROXY] at start (3.3b): the seam that lets a scripted
fs+net session be REFUSED a destination so the run’s outcome carries
denied_egress, exactly as a real sandboxed agent’s blocked connection
would. Each (host, port) is attempted in order before the session’s
events replay. Empty by default (no proxy traffic).
Implementations§
Source§impl MockScript
impl MockScript
Sourcepub fn single_shot(final_text: &str) -> Self
pub fn single_shot(final_text: &str) -> Self
A completed single-shot run: init → text → successful result carrying
final_text, with the standard mock usage/cost.
Sourcepub fn single_shot_json(value: &Value) -> Self
pub fn single_shot_json(value: &Value) -> Self
Like single_shot but the text/result carry the
serialized JSON — for worker-report / validator-report runs where the
engine parses the result text.
Sourcepub fn streaming(initial: Vec<AgentEvent>) -> Self
pub fn streaming(initial: Vec<AgentEvent>) -> Self
A streaming-input session that yields initial and then waits for
injected user messages. Chain responding to
script the per-message batches.
Sourcepub fn responding(self, batches: Vec<Vec<AgentEvent>>) -> Self
pub fn responding(self, batches: Vec<Vec<AgentEvent>>) -> Self
Script the batches released by successive send_user_message calls.
Sourcepub fn with_exit(self, exit: SessionExit) -> Self
pub fn with_exit(self, exit: SessionExit) -> Self
Override the exit reported when the stream closes.
Sourcepub fn with_session_id(self, session_id: impl Into<String>) -> Self
pub fn with_session_id(self, session_id: impl Into<String>) -> Self
Override the session id reported by AgentSession::session_id
(defaults to spec.session_id).
Sourcepub fn rendezvous(self, n: usize) -> Self
pub fn rendezvous(self, n: usize) -> Self
Rendezvous (see MockScript::hold_result_until_started): withhold
the final scripted event until n sessions have started.
Sourcepub fn writes_file(
self,
path: impl Into<String>,
contents: impl Into<String>,
) -> Self
pub fn writes_file( self, path: impl Into<String>, contents: impl Into<String>, ) -> Self
Write contents to path (relative to the session’s working
directory) when the session starts — lets a scripted worker session
leave a dirty tree for the engine’s §4.4 checkpoint to commit.
Sourcepub fn commits_all(self, message: impl Into<String>) -> Self
pub fn commits_all(self, message: impl Into<String>) -> Self
git add -A && git commit -m <message> in the session’s working
directory when the session starts (applied after any writes_file)
— lets a scripted validator move HEAD inside its “read-only” session,
as a real Bash-capable validator could (validator-immutability-proof
tests).
Sourcepub fn removes_path(self, path: impl Into<String>) -> Self
pub fn removes_path(self, path: impl Into<String>) -> Self
Remove path (relative to the session’s working directory) when the
session starts, applied after any writes_file/commits_all — lets
a scripted worker sabotage its own worktree (e.g. delete its .git)
so the engine’s checkpoint faces an uninspectable worktree
(12th-pass review, candidate-inspection-failure tests).
Sourcepub fn connects_via_proxy(self, host: impl Into<String>, port: u16) -> Self
pub fn connects_via_proxy(self, host: impl Into<String>, port: u16) -> Self
Attempt CONNECT host:port through the session’s egress proxy (the
HTTPS_PROXY env the runner wires for an fs+net session) when the
session starts — the stand-in for a real sandboxed agent’s blocked
connection, so the run’s outcome carries the denial the grant flow
parks on. Errors the start (loud, never vacuous) when the spec carries
no proxy env.
Trait Implementations§
Source§impl Clone for MockScript
impl Clone for MockScript
Source§fn clone(&self) -> MockScript
fn clone(&self) -> MockScript
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more