pub struct CleanroomEnvironment { /* private fields */ }Expand description
Simple environment wrapper around existing infrastructure
Implementations§
Source§impl CleanroomEnvironment
impl CleanroomEnvironment
Sourcepub async fn new() -> Result<Self>
pub async fn new() -> Result<Self>
Create a new cleanroom environment with default configuration
Sourcepub async fn with_config(config: Option<CleanroomConfig>) -> Result<Self>
pub async fn with_config(config: Option<CleanroomConfig>) -> Result<Self>
Create a new cleanroom environment with optional configuration
§Arguments
config- Optional CleanroomConfig. If None, uses default settings. If Some, uses configured default_image for test containers.
§Returns
Result<Self>- CleanroomEnvironment instance
§Errors
- Returns error if backend initialization fails (e.g., invalid image)
Sourcepub async fn execute_test<F, T>(
&self,
_test_name: &str,
test_fn: F,
) -> Result<T>
pub async fn execute_test<F, T>( &self, _test_name: &str, test_fn: F, ) -> Result<T>
Execute a test with OTel tracing and COMPLETE attribute emission
This method implements the FULL schema-compliant telemetry emission that Weaver validation requires. Every attribute in test_execution.yaml MUST be emitted here.
Sourcepub async fn get_metrics(&self) -> Result<SimpleMetrics>
pub async fn get_metrics(&self) -> Result<SimpleMetrics>
Get current metrics
Sourcepub async fn enable_tracing(&self) -> Result<()>
pub async fn enable_tracing(&self) -> Result<()>
Enable tracing for this environment
Sourcepub async fn enable_metrics(&self) -> Result<()>
pub async fn enable_metrics(&self) -> Result<()>
Enable metrics collection for this environment
Sourcepub async fn get_traces(&self) -> Result<Vec<String>>
pub async fn get_traces(&self) -> Result<Vec<String>>
Get traces from this environment
Sourcepub async fn get_container_reuse_stats(&self) -> (u32, u32)
pub async fn get_container_reuse_stats(&self) -> (u32, u32)
Get container reuse statistics
Sourcepub async fn has_container(&self, name: &str) -> bool
pub async fn has_container(&self, name: &str) -> bool
Check if a container with the given name has been created in this session
Sourcepub async fn register_service(
&self,
plugin: Box<dyn ServicePlugin>,
) -> Result<()>
pub async fn register_service( &self, plugin: Box<dyn ServicePlugin>, ) -> Result<()>
Register a service plugin
Sourcepub async fn start_service(&self, service_name: &str) -> Result<ServiceHandle>
pub async fn start_service(&self, service_name: &str) -> Result<ServiceHandle>
Start a service by name
Sourcepub async fn stop_service(&self, handle_id: &str) -> Result<()>
pub async fn stop_service(&self, handle_id: &str) -> Result<()>
Stop a service by handle ID
Sourcepub async fn execute_command_with_output(
&self,
_handle: &ServiceHandle,
command_args: &[String],
) -> Result<Output>
pub async fn execute_command_with_output( &self, _handle: &ServiceHandle, command_args: &[String], ) -> Result<Output>
Sourcepub async fn services(&self) -> RwLockReadGuard<'_, ServiceRegistry>
pub async fn services(&self) -> RwLockReadGuard<'_, ServiceRegistry>
Get service registry (read-only access)
Sourcepub async fn register_container<T: Send + Sync + 'static>(
&self,
name: String,
container: T,
) -> Result<()>
pub async fn register_container<T: Send + Sync + 'static>( &self, name: String, container: T, ) -> Result<()>
Register a container for reuse
Sourcepub async fn get_or_create_container<F, T>(
&self,
name: &str,
factory: F,
) -> Result<T>
pub async fn get_or_create_container<F, T>( &self, name: &str, factory: F, ) -> Result<T>
Get or create container with reuse pattern
This method implements true container reuse by storing and returning the actual container instances, providing the promised 10-50x performance improvement.
Sourcepub async fn check_health(&self) -> HashMap<String, HealthStatus>
pub async fn check_health(&self) -> HashMap<String, HealthStatus>
Check health of all services
Sourcepub async fn get_service_logs(
&self,
service_id: &str,
lines: usize,
) -> Result<Vec<String>>
pub async fn get_service_logs( &self, service_id: &str, lines: usize, ) -> Result<Vec<String>>
Get service logs
Sourcepub fn session_id(&self) -> Uuid
pub fn session_id(&self) -> Uuid
Get session ID
Sourcepub async fn execute_in_service(
&self,
service_handle: &ServiceHandle,
command: &[String],
) -> Result<ExecutionResult>
pub async fn execute_in_service( &self, service_handle: &ServiceHandle, command: &[String], ) -> Result<ExecutionResult>
Execute a command in a specific service container
This method enables service-specific command execution, allowing test steps to target specific service containers (e.g., nginx, postgres) instead of always using the default test container.
§Arguments
service_handle- Handle to the service containercommand- Command and arguments to execute
§Returns
Result<ExecutionResult>- Command output with stdout, stderr, and exit status
§Errors
- Returns error if service container_id is missing from metadata
- Returns error if command execution fails
§Backend API Design
This method implements proper REST-like semantics:
- Resource identification: service_handle.id uniquely identifies the target
- Idempotent operations: Same command can be executed multiple times
- Clear error responses: Detailed error messages for debugging
- Proper status codes: Exit codes map to HTTP-like status semantics
Sourcepub async fn execute_in_container(
&self,
container_name: &str,
command: &[String],
workdir: Option<&str>,
env: Option<&HashMap<String, String>>,
) -> Result<ExecutionResult>
pub async fn execute_in_container( &self, container_name: &str, command: &[String], workdir: Option<&str>, env: Option<&HashMap<String, String>>, ) -> Result<ExecutionResult>
Execute a command in a container with proper error handling and observability Core Team Compliance: Async for I/O operations, proper error handling, no unwrap/expect
This method creates a fresh container for each command execution, which is appropriate for testing scenarios where isolation is more important than performance.
Trait Implementations§
Source§impl Debug for CleanroomEnvironment
impl Debug for CleanroomEnvironment
Source§impl Default for CleanroomEnvironment
impl Default for CleanroomEnvironment
Source§fn default() -> Self
fn default() -> Self
WARNING: TEST-ONLY IMPLEMENTATION
This Default implementation is ONLY for test code and WILL panic if Docker is unavailable.
NEVER use CleanroomEnvironment::default() in production code.
§Production Usage
Use one of these methods instead:
CleanroomEnvironment::new().await- For default configuration with proper error handlingCleanroomEnvironment::with_config(config).await- For custom configuration
§Panics
Panics if Docker is not available or if the default backend cannot be initialized. This is intentional to ensure tests fail fast when Docker is missing.
§Test-Only Rationale
The Default trait cannot be async and cannot return Result, making proper error handling impossible. Therefore, this implementation is explicitly marked as test-only and is allowed to panic since test failures are acceptable when Docker is unavailable.
Auto Trait Implementations§
impl Freeze for CleanroomEnvironment
impl !RefUnwindSafe for CleanroomEnvironment
impl Send for CleanroomEnvironment
impl Sync for CleanroomEnvironment
impl Unpin for CleanroomEnvironment
impl !UnwindSafe for CleanroomEnvironment
Blanket Implementations§
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request