Skip to main content

victauri_core/
lib.rs

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