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
impl Session
Sourcepub fn app(&self) -> &App
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.
Sourcepub fn app_mut(&mut self) -> &mut App
pub fn app_mut(&mut self) -> &mut App
Mutable access to the underlying App. Panics if called after
Session::close.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
The runner-issued session id. Opaque; useful only for logging.
Sourcepub fn state(&self) -> SessionState
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.
Sourcepub async fn still_valid(&self) -> Result<bool, ExpectationFailure>
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.
Sourcepub async fn reset_app_data(&self) -> Result<u64, ExpectationFailure>
pub async fn reset_app_data(&self) -> Result<u64, ExpectationFailure>
Clear the session’s target app data IN PLACE. Runner-side does:
XCUIApplication.terminate()on the target (cooperative termination via testmanagerd — does NOT signalcom.apple.ReportCrash).FileManagerwipe of the app’s sandbox subdirectories (Containers/Data/Application/<uuid>/{Documents, Library, tmp}) — install receipt untouched.XCUIApplication.launch()— re-attaches XCUITest binding cleanly.
This replaces the maestro launchApp: { clearState: true }
shape that triggered the “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.
Sourcepub async fn relaunch_app(&self) -> Result<u64, ExpectationFailure>
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.
Sourcepub async fn renew_activation(&self) -> Result<bool, ExpectationFailure>
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.
Sourcepub async fn close(self) -> Result<App, ExpectationFailure>
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.