1#![allow(deprecated)]
203
204pub mod ab_testing;
205#[deprecated(note = "Will be extracted to mockforge-intelligence crate")]
206pub mod ai_contract_diff;
207#[deprecated(note = "Will be extracted to mockforge-intelligence crate")]
208pub mod ai_response;
209#[deprecated(note = "Will be extracted to mockforge-intelligence crate")]
211pub mod ai_studio;
212#[deprecated(note = "Will be extracted to mockforge-intelligence crate")]
214pub mod behavioral_cloning;
215#[deprecated(note = "Will be extracted to mockforge-intelligence crate")]
216pub mod behavioral_economics;
217pub(crate) mod cache;
218pub mod chain_execution;
219pub mod chaos_utilities;
220#[deprecated(note = "Will be extracted to mockforge-import crate")]
221pub mod codegen;
222pub(crate) mod collection_export;
224pub mod conditions;
225pub mod config;
226pub(crate) mod connection_pool;
228pub mod consistency;
230#[deprecated(note = "Will be extracted to mockforge-contracts crate")]
231pub mod consumer_contracts;
233#[deprecated(note = "Will be extracted to mockforge-contracts crate")]
234pub mod contract_drift;
236#[deprecated(note = "Will be extracted to mockforge-contracts crate")]
237pub mod contract_validation;
239pub(crate) mod contract_webhooks;
241pub mod custom_fixture;
242pub mod data_source;
244pub mod deceptive_canary;
246pub(crate) mod docker_compose;
248#[deprecated(note = "Will be extracted to mockforge-contracts crate")]
249pub mod drift_gitops;
251#[deprecated(note = "Will be extracted to mockforge-workspace crate")]
252pub mod encryption;
253pub mod error;
254pub mod failure_analysis;
255pub mod failure_injection;
256pub mod fidelity;
257pub mod generate_config;
258pub(crate) mod generative_schema;
259#[deprecated(note = "Will be extracted to mockforge-workspace crate")]
260pub mod git_watch;
261pub mod graph;
262#[deprecated(note = "Will be extracted to mockforge-import crate")]
263pub mod import;
264pub mod incidents;
265#[deprecated(note = "Will be extracted to mockforge-intelligence crate")]
266pub mod intelligent_behavior;
267pub mod latency;
268pub mod lifecycle;
269#[deprecated(note = "Will be extracted to mockforge-workspace crate")]
270pub mod multi_tenant;
271pub mod network_profiles;
272pub mod odata_rewrite;
274pub mod openapi;
275pub mod openapi_routes;
276pub mod output_control;
277pub mod overrides;
278pub mod performance;
279pub mod pillar_tracking;
281pub mod pillars;
283pub mod pr_generation;
284pub mod priority_handler;
285pub mod protocol_abstraction;
286pub mod protocol_server;
288#[deprecated(note = "Will be extracted to mockforge-proxy crate")]
289pub mod proxy;
290pub mod reality;
291pub mod reality_continuum;
292pub mod record_replay;
293pub mod request_capture;
294pub mod request_chaining;
295pub mod request_fingerprint;
296pub mod request_logger;
297pub(crate) mod request_scripting;
298pub(crate) mod persona_lifecycle_time;
302pub mod routing;
303pub mod runtime_validation;
305pub mod scenario_studio;
307pub mod scenarios;
308#[deprecated(note = "Will be extracted to mockforge-contracts crate")]
309pub mod schema_diff;
310pub mod security;
311pub mod server_utils;
312pub mod snapshots;
314pub mod spec_parser;
315pub mod stateful_handler;
316#[deprecated(note = "Will be extracted to mockforge-workspace crate")]
317pub mod sync_watcher;
318pub mod template_expansion;
320pub mod template_library;
322pub mod templating;
323pub mod time_travel;
324pub mod time_travel_handler;
325pub mod tls;
327pub mod traffic_shaping;
328pub mod validation;
329pub mod verification;
330pub mod voice;
331#[deprecated(note = "Will be extracted to mockforge-workspace crate")]
332pub mod workspace;
333#[deprecated(note = "Will be extracted to mockforge-workspace crate")]
334pub mod workspace_import;
335#[deprecated(note = "Will be extracted to mockforge-workspace crate")]
336pub mod workspace_persistence;
337pub mod ws_proxy;
338
339pub use ab_testing::{
340 apply_variant_to_response, select_variant, ABTestConfig, ABTestReport,
341 ABTestingMiddlewareState, MockVariant, VariantAllocation, VariantAnalytics, VariantComparison,
342 VariantManager, VariantSelectionStrategy,
343};
344#[deprecated(note = "Will be extracted to mockforge-intelligence crate")]
345pub use behavioral_cloning::{
346 AmplificationScope, BehavioralSequence, EdgeAmplificationConfig, EdgeAmplifier,
347 EndpointProbabilityModel, ErrorPattern, LatencyDistribution, PayloadVariation,
348 ProbabilisticModel, SequenceLearner, SequenceStep,
349};
350pub use chain_execution::{ChainExecutionEngine, ChainExecutionResult, ChainExecutionStatus};
351#[deprecated(note = "Use mockforge_chaos::core_chaos_utilities instead")]
352pub use chaos_utilities::{ChaosConfig, ChaosEngine, ChaosResult, ChaosStatistics};
353pub use conditions::{evaluate_condition, ConditionContext, ConditionError};
354pub use config::{
355 apply_env_overrides, load_config, load_config_with_fallback, save_config, ApiKeyConfig,
356 AuthConfig, ServerConfig,
357};
358pub use consistency::{
359 ConsistencyEngine, EntityState, ProtocolState, SessionInfo, StateChangeEvent, UnifiedState,
360};
361pub use custom_fixture::{CustomFixture, CustomFixtureLoader, NestedFixture};
362pub use data_source::{
363 DataSource, DataSourceConfig, DataSourceContent, DataSourceFactory, DataSourceManager,
364 DataSourceType, GitDataSource, HttpDataSource, LocalDataSource,
365};
366pub use deceptive_canary::{
367 CanaryRoutingStrategy, CanaryStats, DeceptiveCanaryConfig, DeceptiveCanaryRouter,
368 TeamIdentifiers,
369};
370pub use error::{Error, Result};
371pub use failure_analysis::{
372 ContributingFactor, FailureContext, FailureContextCollector, FailureNarrative,
373 FailureNarrativeGenerator, NarrativeFrame,
374};
375#[deprecated(note = "Use mockforge_chaos::core_failure_injection instead")]
376pub use failure_injection::{
377 create_failure_injector, FailureConfig, FailureInjector, TagFailureConfig,
378};
379pub use fidelity::{FidelityCalculator, FidelityScore, SampleComparator, SchemaComparator};
380pub use generate_config::{
381 discover_config_file, load_generate_config, load_generate_config_with_fallback,
382 save_generate_config, BarrelType, GenerateConfig, GenerateOptions, InputConfig, OutputConfig,
383 PluginConfig,
384};
385#[deprecated(note = "Will be extracted to mockforge-workspace crate")]
386pub use git_watch::{GitWatchConfig, GitWatchService};
387pub use graph::{
388 builder::GraphBuilder, relationships, ClusterType, EdgeType, GraphCluster, GraphData,
389 GraphEdge, GraphNode, NodeType, Protocol as GraphProtocol,
390};
391pub use latency::LatencyProfile;
392pub use lifecycle::{
393 LifecycleHook, LifecycleHookRegistry, MockLifecycleEvent, RequestContext, ResponseContext,
394 ServerLifecycleEvent,
395};
396#[deprecated(note = "Will be extracted to mockforge-workspace crate")]
397pub use multi_tenant::{
398 MultiTenantConfig, MultiTenantWorkspaceRegistry, RoutingStrategy, TenantWorkspace,
399 WorkspaceContext, WorkspaceRouter, WorkspaceStats,
400};
401#[deprecated(note = "Use mockforge_chaos::core_network_profiles instead")]
402pub use network_profiles::{NetworkProfile, NetworkProfileCatalog};
403pub use openapi::{
404 OpenApiOperation, OpenApiRoute, OpenApiSchema, OpenApiSecurityRequirement, OpenApiSpec,
405};
406pub use openapi_routes::{
407 create_registry_from_file, create_registry_from_json, OpenApiRouteRegistry, ValidationOptions,
408};
409pub use output_control::{
410 apply_banner, apply_extension, apply_file_naming_template, build_file_naming_context,
411 process_generated_file, BarrelGenerator, FileNamingContext, GeneratedFile,
412};
413pub use overrides::{OverrideMode, OverrideRule, Overrides, PatchOp};
414pub use pillars::{Pillar, PillarMetadata};
415pub use priority_handler::{
416 MockGenerator, MockResponse, PriorityHttpHandler, PriorityResponse, SimpleMockGenerator,
417};
418pub use protocol_abstraction::{
419 MessagePattern, MiddlewareChain, Protocol, ProtocolMiddleware, ProtocolRequest,
420 ProtocolResponse, RequestMatcher, ResponseStatus, SpecOperation, SpecRegistry,
421 ValidationError as ProtocolValidationError, ValidationResult as ProtocolValidationResult,
422};
423#[deprecated(note = "Will be extracted to mockforge-proxy crate")]
424pub use proxy::{ProxyConfig, ProxyHandler, ProxyResponse};
425pub use reality::{PresetMetadata, RealityConfig, RealityEngine, RealityLevel, RealityPreset};
426pub use reality_continuum::{
427 ContinuumConfig, ContinuumRule, MergeStrategy, RealityContinuumEngine, ResponseBlender,
428 TimeSchedule, TransitionCurve, TransitionMode,
429};
430pub use record_replay::{
431 clean_old_fixtures, list_fixtures, list_ready_fixtures, list_smoke_endpoints, RecordHandler,
432 RecordReplayHandler, RecordedRequest, ReplayHandler,
433};
434pub use request_chaining::{
435 ChainConfig, ChainContext, ChainDefinition, ChainExecutionContext, ChainLink, ChainRequest,
436 ChainResponse, ChainStore, ChainTemplatingContext, RequestChainRegistry,
437};
438pub use request_fingerprint::{
439 RequestFingerprint, RequestHandlerResult, ResponsePriority, ResponseSource,
440};
441pub use request_logger::{
442 create_grpc_log_entry, create_http_log_entry, create_http_log_entry_with_query,
443 create_websocket_log_entry, get_global_logger, init_global_logger, log_request_global,
444 CentralizedRequestLogger, RequestLogEntry,
445};
446pub use routing::{HttpMethod, Route, RouteRegistry};
449pub use runtime_validation::{
450 RuntimeValidationError, RuntimeValidationResult, RuntimeValidatorConfig, SchemaMetadata,
451};
452pub use scenario_studio::{
453 ConditionOperator, FlowCondition, FlowConnection, FlowDefinition, FlowExecutionResult,
454 FlowExecutor, FlowPosition, FlowStep, FlowStepResult, FlowType, FlowVariant, StepType,
455};
456pub use scenarios::types::StepResult;
457pub use scenarios::{
458 ScenarioDefinition, ScenarioExecutor, ScenarioParameter, ScenarioRegistry, ScenarioResult,
459 ScenarioStep,
460};
461#[deprecated(note = "Will be extracted to mockforge-contracts crate")]
462pub use schema_diff::{to_enhanced_422_json, validation_diff, ValidationError};
463pub use server_utils::errors::{json_error, json_success};
464pub use server_utils::{create_socket_addr, localhost_socket_addr, wildcard_socket_addr};
465pub use snapshots::{SnapshotComponents, SnapshotManager, SnapshotManifest, SnapshotMetadata};
466pub use spec_parser::{GraphQLValidator, OpenApiValidator, SpecFormat};
467pub use stateful_handler::{
468 ResourceIdExtract, StateInfo, StateResponse, StatefulConfig, StatefulResponse,
469 StatefulResponseHandler, TransitionTrigger,
470};
471#[deprecated(note = "Will be extracted to mockforge-workspace crate")]
472pub use sync_watcher::{FileChange, SyncEvent, SyncService, SyncWatcher};
473pub use template_library::{
474 TemplateLibrary, TemplateLibraryEntry, TemplateLibraryManager, TemplateMarketplace,
475 TemplateMetadata, TemplateVersion,
476};
477pub use templating::{expand_str, expand_tokens};
478pub use time_travel::{
479 cron::{CronJob, CronJobAction, CronScheduler},
480 get_global_clock, is_time_travel_enabled, now as time_travel_now, register_global_clock,
481 unregister_global_clock, RepeatConfig, ResponseScheduler, ScheduledResponse, TimeScenario,
482 TimeTravelConfig, TimeTravelManager, TimeTravelStatus, VirtualClock,
483};
484pub use time_travel_handler::{
485 time_travel_middleware, ScheduledResponseWrapper, TimeTravelHandler,
486};
487#[deprecated(note = "Use mockforge_chaos::core_traffic_shaping instead")]
488pub use traffic_shaping::{BandwidthConfig, BurstLossConfig, TrafficShaper, TrafficShapingConfig};
489pub use uuid::Uuid;
490pub use validation::{validate_openapi_operation_security, validate_openapi_security, Validator};
491pub use verification::{
492 matches_verification_pattern, verify_at_least, verify_never, verify_requests, verify_sequence,
493 VerificationCount, VerificationRequest, VerificationResult,
494};
495pub use voice::{
496 ConversationContext, ConversationManager, ConversationState, GeneratedWorkspaceScenario,
497 HookTranspiler, ParsedCommand, ParsedWorkspaceScenario, VoiceCommandParser, VoiceSpecGenerator,
498 WorkspaceConfigSummary, WorkspaceScenarioGenerator,
499};
500#[deprecated(note = "Will be extracted to mockforge-workspace crate")]
501pub use workspace::promotion_trait::PromotionService;
502#[deprecated(note = "Will be extracted to mockforge-workspace crate")]
503pub use workspace::{EntityId, Folder, MockRequest, Workspace, WorkspaceConfig, WorkspaceRegistry};
504#[deprecated(note = "Will be extracted to mockforge-workspace crate")]
505pub use workspace_import::{
506 create_workspace_from_curl, create_workspace_from_har, create_workspace_from_insomnia,
507 create_workspace_from_postman, import_postman_to_existing_workspace,
508 import_postman_to_workspace, WorkspaceImportConfig, WorkspaceImportResult,
509};
510#[deprecated(note = "Will be extracted to mockforge-workspace crate")]
511pub use workspace_persistence::WorkspacePersistence;
512pub use ws_proxy::{WsProxyConfig, WsProxyHandler, WsProxyRule};
513#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
518#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
519#[serde(default)]
520pub struct Config {
521 pub latency_enabled: bool,
523 pub failures_enabled: bool,
525 pub overrides_enabled: bool,
527 pub traffic_shaping_enabled: bool,
529 pub failure_config: Option<FailureConfig>,
531 pub proxy: Option<ProxyConfig>,
533 pub default_latency: LatencyProfile,
535 pub traffic_shaping: TrafficShapingConfig,
537 pub chaos_random: Option<ChaosConfig>,
539 pub max_request_logs: usize,
542 pub time_travel: TimeTravelConfig,
544}
545
546impl Default for Config {
548 fn default() -> Self {
549 Self {
550 latency_enabled: true,
551 failures_enabled: false,
552 overrides_enabled: true,
553 traffic_shaping_enabled: false,
554 failure_config: None,
555 proxy: None,
556 default_latency: LatencyProfile::default(),
557 traffic_shaping: TrafficShapingConfig::default(),
558 chaos_random: None,
559 max_request_logs: 1000, time_travel: TimeTravelConfig::default(),
561 }
562 }
563}
564
565impl Config {
566 pub fn create_chaos_engine(&self) -> Option<ChaosEngine> {
568 self.chaos_random.as_ref().map(|config| ChaosEngine::new(config.clone()))
569 }
570
571 pub fn is_chaos_random_enabled(&self) -> bool {
573 self.chaos_random.as_ref().map(|c| c.enabled).unwrap_or(false)
574 }
575}
576
577#[cfg(test)]
578mod tests {
579 use super::*;
580
581 #[test]
582 fn test_config_default() {
583 let config = Config::default();
584 assert!(config.latency_enabled);
585 assert!(!config.failures_enabled);
586 assert!(config.overrides_enabled);
587 assert!(!config.traffic_shaping_enabled);
588 assert!(config.failure_config.is_none());
589 assert!(config.proxy.is_none());
590 }
591
592 #[test]
593 fn test_config_serialization() {
594 let config = Config::default();
595 let json = serde_json::to_string(&config).unwrap();
596 assert!(json.contains("latency_enabled"));
597 assert!(json.contains("failures_enabled"));
598 }
599
600 #[test]
601 fn test_config_deserialization() {
602 let config = Config {
604 latency_enabled: false,
605 failures_enabled: true,
606 ..Default::default()
607 };
608
609 let json = serde_json::to_string(&config).unwrap();
611 let deserialized: Config = serde_json::from_str(&json).unwrap();
612
613 assert!(!deserialized.latency_enabled);
614 assert!(deserialized.failures_enabled);
615 assert!(deserialized.overrides_enabled);
616 }
617
618 #[test]
619 fn test_config_with_custom_values() {
620 let config = Config {
621 latency_enabled: false,
622 failures_enabled: true,
623 ..Default::default()
624 };
625
626 assert!(!config.latency_enabled);
627 assert!(config.failures_enabled);
628 }
629}