1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//! # Moonpool Simulation Framework
//!
//! Deterministic simulation for testing distributed systems, inspired by
//! [FoundationDB's simulation testing](https://apple.github.io/foundationdb/testing.html).
//!
//! ## Why Deterministic Simulation?
//!
//! FoundationDB's insight: **bugs hide in error paths**. Production code rarely
//! exercises timeout handlers, retry logic, or failure recovery. Deterministic
//! simulation with fault injection finds these bugs before production does.
//!
//! Key properties:
//! - **Reproducible**: Same seed produces identical execution
//! - **Comprehensive**: Tests all failure modes (network, timing, corruption)
//! - **Fast**: Logical time skips idle periods
//!
//! ## Core Components
//!
//! - [`SimWorld`]: The simulation runtime managing events and time
//! - [`SimulationBuilder`]: Configure and run simulations
//! - [`chaos`]: Fault injection (buggify, 14 assertion macros, invariants)
//! - [`storage`]: Storage simulation with fault injection
//! - Multiverse exploration via `moonpool-explorer` (re-exported as [`ExplorationConfig`], [`AdaptiveConfig`])
//!
//! ## Quick Start
//!
//! ```ignore
//! use moonpool_sim::{SimulationBuilder, WorkloadTopology};
//!
//! SimulationBuilder::new()
//! .topology(WorkloadTopology::ClientServer { clients: 2, servers: 1 })
//! .run(|ctx| async move {
//! // Your distributed system workload
//! });
//! ```
//!
//! ## Fault Injection Overview
//!
//! See [`chaos`] module for detailed documentation.
//!
//! | Mechanism | Default | What it tests |
//! |-----------|---------|---------------|
//! | TCP latencies | 1-11ms connect | Async scheduling |
//! | Random connection close | 0.001% | Reconnection, redelivery |
//! | Bit flip corruption | 0.01% | Checksum validation |
//! | Connect failure | 50% probabilistic | Timeout handling, retries |
//! | Clock drift | 100ms max | Leases, heartbeats |
//! | Buggified delays | 25% | Race conditions |
//! | Partial writes | 1000 bytes max | Message fragmentation |
//! | Packet loss | disabled | At-least-once delivery |
//! | Network partitions | disabled | Split-brain handling |
//! | Storage corruption | configurable | Checksum validation, recovery |
//! | Torn writes | configurable | Write atomicity, journaling |
//! | Sync failures | configurable | Durability guarantees |
//!
//! ## Multi-Seed Testing
//!
//! Tests run across multiple seeds to explore the state space:
//!
//! ```ignore
//! SimulationBuilder::new()
//! .run_count(IterationControl::UntilAllSometimesReached(1000))
//! .run(workload);
//! ```
//!
//! Debugging a failing seed:
//!
//! ```ignore
//! SimulationBuilder::new()
//! .set_seed(failing_seed)
//! .run_count(IterationControl::FixedCount(1))
//! .run(workload);
//! ```
//!
//! ## Coverage-Preserving Multi-Seed Exploration
//!
//! When exploration is enabled, multiple seeds share coverage context. The
//! explored map (coverage bitmap union) and assertion watermarks are preserved
//! between seeds so each subsequent seed focuses energy on genuinely new
//! branches rather than re-treading already-discovered paths.
//!
//! A **warm start** mechanism reduces wasted forks: on seeds after the first,
//! marks whose first probe batch finds zero new coverage bits stop after
//! `warm_min_timelines` forks instead of the full `min_timelines`.
//!
//! ```text
//! Seed 1 (cold start) Seed 2 (warm start) Seed 3 (warm start)
//! energy: 400K energy: 400K energy: 400K
//!
//! root ─┬─ mark A ──> 400 root ─┬─ mark A ──> 30 root ─┬─ mark A ──> 30
//! │ (new bits!) forks │ (barren!) skip │ (barren!) skip
//! │ │ │
//! ├─ mark B ──> 400 ├─ mark B ──> 30 ├─ mark B ──> 30
//! │ (new bits!) forks │ (barren!) skip │ (barren!) skip
//! │ │ │
//! └─ mark C ──> 400 ├─ mark C ──> 30 ├─ mark C ──> 30
//! (new bits!) forks │ (barren!) skip │ (barren!) skip
//! │ │
//! └─ mark D ──> 400 └─ mark E ──> 400
//! (NEW bits!) forks (NEW bits!) forks
//! │ │ │
//! ┌────────────────┘ ┌────────────────┘ ┌────────────────┘
//! v v v
//! ┌──────────┐ ──preserved──> ┌──────────┐ ──preserved──> ┌──────────┐
//! │ explored │ coverage map │ explored │ coverage map │ explored │
//! │ map: │ + watermarks │ map: │ + watermarks │ map: │
//! │ A,B,C │ │ A,B,C,D │ │ A,B,C,D,E│
//! └──────────┘ └──────────┘ └──────────┘
//!
//! Total: each seed spends most energy on NEW discoveries.
//! Warm marks (A,B,C on seed 2) exit after warm_min_timelines (30)
//! instead of min_timelines (400), saving ~95% energy per barren mark.
//! ```
//!
//! ```ignore
//! SimulationBuilder::new()
//! .set_iterations(3) // 3 root seeds with coverage forwarding
//! .enable_exploration(ExplorationConfig {
//! max_depth: 120,
//! timelines_per_split: 4,
//! global_energy: 400_000, // per-seed energy budget
//! adaptive: Some(AdaptiveConfig {
//! batch_size: 30,
//! min_timelines: 400,
//! max_timelines: 1_000,
//! per_mark_energy: 10_000,
//! warm_min_timelines: Some(30), // quick skip for barren warm marks
//! }),
//! parallelism: Some(Parallelism::HalfCores),
//! })
//! .workload(my_workload);
//! ```
// Re-export core types for convenience
pub use ;
// =============================================================================
// Core Modules
// =============================================================================
/// Core simulation engine for deterministic testing.
/// Simulation runner and orchestration framework.
/// Chaos testing infrastructure for deterministic fault injection.
/// Provider implementations for simulation.
/// Network simulation and configuration.
/// Storage simulation and configuration.
/// Simulation workloads and binary targets.
// =============================================================================
// Public API Re-exports
// =============================================================================
// Sim module re-exports
pub use ;
// Runner module re-exports
pub use ;
// Chaos module re-exports
pub use ;
// Network exports
pub use ;
// Storage exports
pub use ;
// Provider exports
pub use ;
// Explorer re-exports
pub use ;
pub use ;
// Macros are automatically available at crate root when defined with #[macro_export]