pub struct Harness { /* private fields */ }Expand description
The runtime handle threaded into main(harness: Harness).
Cheap to clone; sub-handles share the same Arc inner state.
Implementations§
Source§impl Harness
impl Harness
Sourcepub fn real() -> Self
pub fn real() -> Self
Build the production handle wired to wall-clock time. Filesystem, environment, randomness, and network access are layered on by the E4.2-E4.4 migration tickets; the constructor only needs to succeed without panicking today (per the E4.1 exit criteria).
The production clock is wrapped in MockAwareClock so existing
mock_time(...) / advance_time(...) test fixtures observe
harness.clock.* reads identically to the ambient builtins. The
shim is part of the E4.3-E4.6 migration window and goes away once
the ambient mock_time test utility is retired by E4.5.
Sourcepub fn null() -> Self
pub fn null() -> Self
Build a deny-by-default test handle. Every sub-handle method records a
DenyEvent and fails with a categorized VM error.
Sourcepub fn mock() -> MockHarnessBuilder
pub fn mock() -> MockHarnessBuilder
Build a record/replay test handle backed by a paused clock.
Sourcepub fn with_clock(clock: Arc<dyn Clock>) -> Self
pub fn with_clock(clock: Arc<dyn Clock>) -> Self
Build a handle wired to a caller-supplied clock. Most callers want
Self::test (which constructs the PausedClock for you);
reach for this when an existing Arc<dyn Clock> is already in
hand — e.g. a RecordedClock wrapper.
Sourcepub fn from_inner(inner: Arc<HarnessInner>) -> Self
pub fn from_inner(inner: Arc<HarnessInner>) -> Self
Construct a Harness from a pre-built Arc<HarnessInner>.
Used by VM method dispatch when it needs to re-wrap a sub-handle’s
inner state into a root Harness (e.g. to invoke
Self::with_net_policy from inside the method dispatcher).
Sourcepub fn with_net_policy(&self, policy: NetPolicy) -> Self
pub fn with_net_policy(&self, policy: NetPolicy) -> Self
Attach a per-harness harness.net.* access policy.
Returns a new Harness value whose sub-handles share a fresh
Arc<HarnessInner>. Existing handles built off the prior inner
keep operating without the policy — so calling
harness.with_net_policy(...) does NOT retroactively gate
references to harness held elsewhere. Per issue #1913.
The clock and mode are propagated verbatim. Mock canned
responses (net_gets, random_u64, etc.) live behind the
shared HarnessMode::Mock payload, so the new handle observes
the same recorded calls and the same canned responses as the
source handle.
Sourcepub fn with_secret_provider(&self, provider: Arc<dyn SecretProvider>) -> Self
pub fn with_secret_provider(&self, provider: Arc<dyn SecretProvider>) -> Self
Attach a provider for harness.secrets.*.
The provider is intentionally embedder-supplied. Harn owns the typed method contract; the host owns custody details such as KMS wrapping, lease storage, audit sinks, and scope policy.
Sourcepub fn is_quarantined(&self) -> bool
pub fn is_quarantined(&self) -> bool
true if the harness has been marked quarantined by an
OnViolation::Quarantine deny event.
pub fn deny_events(&self) -> Vec<DenyEvent>
pub fn calls(&self) -> Vec<HarnessCall>
pub fn captured_stdio(&self) -> String
pub fn captured_stderr(&self) -> String
Sourcepub fn test() -> (Self, Arc<PausedClock>)
pub fn test() -> (Self, Arc<PausedClock>)
Build a deterministic test handle wired to a fresh
PausedClock pinned at the Unix epoch.
Returns the harness paired with the underlying PausedClock so
tests can drive virtual time through PausedClock::advance
while passing the same Harness value into the VM. The two
share the underlying Arc<dyn Clock>, so the harness reflects
every advance immediately.
Pairs with PausedClock::advance / PausedClock::set — see
Self::with_paused_clock for picking a non-epoch origin.
Sourcepub fn with_paused_clock(origin: OffsetDateTime) -> (Self, Arc<PausedClock>)
pub fn with_paused_clock(origin: OffsetDateTime) -> (Self, Arc<PausedClock>)
Like Self::test, but pins the paused clock’s wall origin to
origin. Lets tests anchor virtual time to a meaningful date
without manually advancing past the epoch first.
Sourcepub fn stdio(&self) -> HarnessStdio
pub fn stdio(&self) -> HarnessStdio
Field access for harness.stdio.
Sourcepub fn term(&self) -> HarnessTerm
pub fn term(&self) -> HarnessTerm
Field access for harness.term.
Sourcepub fn clock(&self) -> HarnessClock
pub fn clock(&self) -> HarnessClock
Field access for harness.clock.
Sourcepub fn env(&self) -> HarnessEnv
pub fn env(&self) -> HarnessEnv
Field access for harness.env.
Sourcepub fn random(&self) -> HarnessRandom
pub fn random(&self) -> HarnessRandom
Field access for harness.random.
Sourcepub fn net(&self) -> HarnessNet
pub fn net(&self) -> HarnessNet
Field access for harness.net.
Sourcepub fn process(&self) -> HarnessProcess
pub fn process(&self) -> HarnessProcess
Field access for harness.process.
Sourcepub fn crypto(&self) -> HarnessCrypto
pub fn crypto(&self) -> HarnessCrypto
Field access for harness.crypto.
Sourcepub fn system(&self) -> HarnessSystem
pub fn system(&self) -> HarnessSystem
Field access for harness.system.
Sourcepub fn secrets(&self) -> HarnessSecrets
pub fn secrets(&self) -> HarnessSecrets
Field access for harness.secrets.
Sourcepub fn llm(&self) -> HarnessLlm
pub fn llm(&self) -> HarnessLlm
Field access for harness.llm.
Sourcepub fn tenant(&self) -> HarnessTenant
pub fn tenant(&self) -> HarnessTenant
Field access for harness.tenant.
Sourcepub fn auth(&self) -> HarnessAuth
pub fn auth(&self) -> HarnessAuth
Field access for harness.auth.
Sourcepub fn obs(&self) -> HarnessObs
pub fn obs(&self) -> HarnessObs
Field access for harness.obs.
Sourcepub fn into_vm_value(self) -> VmValue
pub fn into_vm_value(self) -> VmValue
Lower this handle into the VmValue::Harness payload.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Harness
impl !UnwindSafe for Harness
impl Freeze for Harness
impl Send for Harness
impl Sync for Harness
impl Unpin for Harness
impl UnsafeUnpin for Harness
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);