Skip to main content

Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

App::open_session; drop the value or call Session::close to release. While a session is open the wrapped App sends the Session-Id header on every request, and the runner uses the session’s cached XCUIApplication binding — no per-request activation storm.

The type is deliberately !Clone and takes ownership of the App. Consumer flow:

use smix_sdk::App;
let mut app = App::connect_to_runner(22087).await?;
let mut session = app.open_session("com.example.app", true).await?;
session.app_mut().tap(&smix_sdk::text("Sign In")).await?;
session.close().await?;

If Session::close is not called, Drop releases the reference but cannot await the network POST /session/close — a background task is spawned best-effort. Prefer close() explicitly.

Implementations§

Source§

impl Session

Source

pub fn app(&self) -> &App

Immutable access to the underlying App. Every call goes out with the Session-Id header. Panics if called after Session::close.

Source

pub fn app_mut(&mut self) -> &mut App

Mutable access to the underlying App. Panics if called after Session::close.

Source

pub fn session_id(&self) -> &str

The runner-issued session id. Opaque; useful only for logging.

Source

pub fn state(&self) -> SessionState

Current sim-health classification observed via the X-Sim-Health response header on the most recent runner request. Healthy at open time (optimistic — the open call itself succeeded); transitions to Degraded / Cycling / Dead as the runner emits them.

Source

pub async fn still_valid(&self) -> Result<bool, ExpectationFailure>

Probe the runner’s /session/list and return true iff this session’s id is still known. Consumers wire this after a Session::state transition to Cycling or Dead to decide whether to keep using the session (still valid across the cycle thanks to session persistence) or reopen a fresh one.

Runner errors return Err — treat as “unknown”; consumers typically bail on that path anyway.

Source

pub async fn reset_app_data(&self) -> Result<u64, ExpectationFailure>

Clear the session’s target app data IN PLACE. Runner-side does:

  1. XCUIApplication.terminate() on the target (cooperative termination via testmanagerd — does NOT signal com.apple.ReportCrash).
  2. FileManager wipe of the app’s sandbox subdirectories (Containers/Data/Application/<uuid>/{Documents, Library, tmp}) — install receipt untouched.
  3. XCUIApplication.launch() — re-attaches XCUITest binding cleanly.

This replaces the maestro launchApp: { clearState: true } shape that triggered the “ quit unexpectedly” system dialog on the iOS 26.5 sim even once simctl uninstall + install was removed. The dialog is eliminated because the terminate path is cooperative.

Wraps App::clear_app_data with session-scoped ergonomics. The heavy lifting (3-step orchestration + host-side wipe) lives on App::clear_app_data because the UDID + bundle-id + device + runner are all on App; this method is a thin pass-through consumers can call when they hold a Session.

Source

pub async fn relaunch_app(&self) -> Result<u64, ExpectationFailure>

Instruct the runner to terminate() + launch() the session’s cached XCUIApplication in place. Preserves the session id and XCUITest binding. Consumers wire this after observing an app crash (via Self::state transitioning to Degraded/Dead with the runner itself Healthy) to auto- recover without cycling the runner.

Returns the wall-clock milliseconds the terminate + launch cycle took, as reported by the runner.

Source

pub async fn renew_activation(&self) -> Result<bool, ExpectationFailure>

Ask the runner to re-issue .activate() on the session’s cached binding. Subject to the runner’s per-session 2 s rate limit; when rate-limited returns Ok(false). When the runner no longer has the session id in its table (evicted / restart) returns an error.

Source

pub async fn close(self) -> Result<App, ExpectationFailure>

Release the session — sends POST /session/close and clears the Session-Id header from the client. Returns the wrapped App so the caller can keep issuing requests via the legacy per-request path.

Trait Implementations§

Source§

impl Drop for Session

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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