mockforge_core/consistency/adapters/mod.rs
1//! Protocol adapters for consistency engine
2//!
3//! Protocol adapters implement the ProtocolAdapter trait to integrate
4//! individual protocols (HTTP, GraphQL, gRPC, etc.) with the consistency engine.
5//!
6//! Each adapter listens to state change events and updates its protocol-specific
7//! state accordingly, ensuring all protocols reflect the unified state.
8
9use crate::consistency::{PersonaProfile, StateChangeEvent};
10use crate::protocol_abstraction::Protocol;
11use crate::Result;
12
13/// Trait for protocol adapters
14///
15/// Protocol adapters integrate individual protocols with the consistency engine.
16/// They receive state change events and update their protocol-specific state
17/// to reflect the unified state.
18#[async_trait::async_trait]
19pub trait ProtocolAdapter: Send + Sync {
20 /// Get the protocol this adapter handles
21 fn protocol(&self) -> Protocol;
22
23 /// Handle a state change event
24 ///
25 /// Called by the consistency engine when state changes. The adapter
26 /// should update its internal state to reflect the change.
27 async fn on_state_change(&self, event: &StateChangeEvent) -> Result<()>;
28
29 /// Get current protocol state
30 ///
31 /// Returns the current state of this protocol for the given workspace,
32 /// or None if the workspace doesn't exist or has no state for this protocol.
33 async fn get_current_state(
34 &self,
35 workspace_id: &str,
36 ) -> Result<Option<crate::consistency::types::ProtocolState>>;
37
38 /// Apply persona to this protocol
39 ///
40 /// Called when a persona is set for a workspace. The adapter should
41 /// update its handlers/middleware to use this persona for data generation.
42 async fn apply_persona(&self, workspace_id: &str, persona: &PersonaProfile) -> Result<()>;
43
44 /// Apply scenario to this protocol
45 ///
46 /// Called when a scenario is set for a workspace. The adapter should
47 /// update its state machine or workflow to reflect this scenario.
48 async fn apply_scenario(&self, workspace_id: &str, scenario_id: &str) -> Result<()>;
49}
50
51// Placeholder adapters will be implemented in protocol-specific crates
52// (mockforge-http, mockforge-graphql, etc.)