Skip to main content

victauri_core/
lib.rs

1#![deny(missing_docs)]
2//! Core types and protocol for Victauri — full-stack introspection for Tauri apps via MCP.
3//!
4//! This crate provides the shared type system used by all Victauri crates.
5//! It has no Tauri dependency and can be used independently for testing.
6
7#[doc(hidden)]
8pub extern crate inventory;
9
10pub mod codegen;
11pub mod error;
12pub mod event;
13pub mod recording;
14pub mod registry;
15pub mod snapshot;
16pub mod types;
17pub mod verification;
18
19pub use codegen::{CodegenOptions, generate_test, generate_test_default};
20pub use error::VictauriError;
21pub use event::{AppEvent, EventLog, InteractionKind, IpcCall, IpcResult};
22pub use recording::{EventRecorder, RecordedEvent, RecordedSession, StateCheckpoint};
23pub use registry::{
24    CommandArg, CommandInfo, CommandInfoFactory, CommandRegistry, ScoredCommand,
25    auto_discovered_commands,
26};
27pub use snapshot::{DomElement, DomSnapshot, WindowState};
28pub use types::{Divergence, DivergenceSeverity, MemoryDelta, RefHandle, VerificationResult};
29pub use verification::{
30    AssertionCondition, AssertionResult, GhostCommand, GhostCommandReport, GhostSource,
31    IpcIntegrityReport, SemanticAssertion, check_ipc_integrity, detect_ghost_commands,
32    evaluate_assertion, verify_state,
33};
34
35/// Acquire a mutex lock, recovering from poisoning with a warning.
36///
37/// Victauri's mutex-protected data is append-only logs and registries where
38/// stale data is preferable to crashing the testing framework.
39pub fn acquire_lock<'a, T>(
40    mutex: &'a std::sync::Mutex<T>,
41    context: &str,
42) -> std::sync::MutexGuard<'a, T> {
43    mutex.lock().unwrap_or_else(|poisoned| {
44        tracing::error!("{context}: mutex was poisoned, recovering");
45        poisoned.into_inner()
46    })
47}
48
49/// Acquire a read lock on an `RwLock`, recovering from poisoning.
50pub fn acquire_read<'a, T>(
51    lock: &'a std::sync::RwLock<T>,
52    context: &str,
53) -> std::sync::RwLockReadGuard<'a, T> {
54    lock.read().unwrap_or_else(|poisoned| {
55        tracing::error!("{context}: RwLock was poisoned, recovering with read guard");
56        poisoned.into_inner()
57    })
58}
59
60/// Acquire a write lock on an `RwLock`, recovering from poisoning.
61pub fn acquire_write<'a, T>(
62    lock: &'a std::sync::RwLock<T>,
63    context: &str,
64) -> std::sync::RwLockWriteGuard<'a, T> {
65    lock.write().unwrap_or_else(|poisoned| {
66        tracing::error!("{context}: RwLock was poisoned, recovering with write guard");
67        poisoned.into_inner()
68    })
69}