Skip to main content

agent_sdk_toolkit/testing/protocol/
isolation.rs

1//! Scripted isolated process harness for protocol tests. Use this fake when tests
2//! need process-like JSON-RPC exchange without launching a real runtime. It mutates
3//! only in-memory endpoint state.
4//!
5use agent_sdk_core::{
6    AgentError, EffectIntent, ExecutionEnvironment, IsolatedProcessSpec, IsolationCapabilityReport,
7    IsolationRuntime, ProcessStartRequest, ProcessStartResult,
8};
9
10use crate::protocol::JsonRpcLineEndpoint;
11
12#[derive(Clone, Debug)]
13/// In-memory isolated json rpc process fixture for SDK conformance tests.
14/// Use it to script deterministic behavior in memory; any transcript or endpoint mutation is documented on the method that performs it.
15pub struct IsolatedJsonRpcProcess {
16    /// Host endpoint used by this record or request.
17    pub host_endpoint: JsonRpcLineEndpoint,
18    /// Process endpoint used by this record or request.
19    pub process_endpoint: JsonRpcLineEndpoint,
20    /// Capability report used by this record or request.
21    pub capability_report: IsolationCapabilityReport,
22    /// Start result used by this record or request.
23    pub start_result: ProcessStartResult,
24}
25
26impl IsolatedJsonRpcProcess {
27    /// Start.
28    /// This records a scripted isolation start result for protocol tests without launching a
29    /// host process.
30    pub fn start(
31        runtime: &dyn IsolationRuntime,
32        environment: ExecutionEnvironment,
33        process: IsolatedProcessSpec,
34        effect_intent: EffectIntent,
35    ) -> Result<Self, AgentError> {
36        let capability_report = runtime.capability_report()?;
37        let start_result = runtime.start_process(ProcessStartRequest {
38            environment,
39            process,
40            effect_intent,
41        })?;
42        let (host_endpoint, process_endpoint) =
43            JsonRpcLineEndpoint::pair("host", "isolated-process");
44        Ok(Self {
45            host_endpoint,
46            process_endpoint,
47            capability_report,
48            start_result,
49        })
50    }
51}