Expand description
Process execution abstraction for dependency injection.
This module provides a trait-based abstraction for executing external processes,
allowing production code to use real processes and test code to use mocks.
This follows the same pattern as crate::workspace::Workspace for dependency injection.
§Purpose
- Production:
RealProcessExecutorexecutes actual commands usingstd::process::Command - Tests:
MockProcessExecutorcaptures calls and returns controlled results (withtest-utilsfeature)
§Benefits
- Test isolation: Tests don’t spawn real processes
- Determinism: Tests produce consistent results
- Speed: Tests run faster without subprocess overhead
- Mockability: Full control over process behavior in tests
§Key Types
ProcessExecutor- The trait abstraction for process executionAgentSpawnConfig- Configuration for spawning agent processesAgentChildHandle- Handle to a spawned agent with streaming outputProcessOutput- Captured output from a completed process
§Testing with MockProcessExecutor
The test-utils feature enables MockProcessExecutor for integration tests:
ⓘ
use ralph_workflow::{MockProcessExecutor, ProcessExecutor};
// Create a mock that returns success for 'git' commands
let executor = MockProcessExecutor::new()
.with_output("git", "On branch main\nnothing to commit");
// Execute command (captured, returns mock result)
let result = executor.execute("git", &["status"], &[], None)?;
assert!(result.status.success());
// Verify the call was captured
assert_eq!(executor.execute_count(), 1);§See Also
crate::workspace::Workspace- Similar abstraction for filesystem operations
Structs§
- Agent
Child Handle - Result of spawning an agent process.
- Agent
Command Result - Result of an agent command execution (for testing).
- Agent
Spawn Config - Configuration for spawning an agent process with streaming support.
- Process
Output - Output from an executed process.
- Real
Agent Child - Wrapper for real
std::process::Child. - Real
Process Executor - Real process executor that uses
std::process::Command.
Traits§
- Agent
Child - Trait for interacting with a spawned agent child process.
- Process
Executor - Trait for executing external processes.