Skip to main content

MockScript

Struct MockScript 

Source
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: SessionExit

Exit reported once the stream closes (ignored when aborted, and never reached by streaming sessions, which only end via abort).

§streaming: bool

When 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

Source

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.

Source

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.

Source

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.

Source

pub fn responding(self, batches: Vec<Vec<AgentEvent>>) -> Self

Script the batches released by successive send_user_message calls.

Source

pub fn with_exit(self, exit: SessionExit) -> Self

Override the exit reported when the stream closes.

Source

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).

Source

pub fn rendezvous(self, n: usize) -> Self

Rendezvous (see MockScript::hold_result_until_started): withhold the final scripted event until n sessions have started.

Source

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.

Source

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).

Source

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).

Source

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

Source§

fn clone(&self) -> MockScript

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MockScript

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MockScript

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more