Skip to main content

shipper_core/state/store/
mod.rs

1//! State store abstraction for persistence.
2//!
3//! Absorbed from the former `shipper-store` microcrate (Phase 2 decrating).
4//! This module provides a trait-based abstraction for state storage,
5//! allowing for future implementations like S3, GCS, or Azure Blob Storage.
6//!
7//! # Layer
8//!
9//! Layer 3 (`state`). Depends on `ops` (filesystem via `crate::state` helpers),
10//! `events`, and `types`. Must not depend on `engine` or `plan`.
11
12use anyhow::Result;
13
14use crate::state::events::EventLog;
15use crate::types::{ExecutionState, Receipt};
16
17/// Trait for state storage backends.
18///
19/// This trait abstracts the storage of execution state, receipts, and event logs,
20/// allowing for different storage backends (filesystem, S3, GCS, etc.).
21pub trait StateStore: Send + Sync {
22    /// Save execution state to storage
23    fn save_state(&self, state: &ExecutionState) -> Result<()>;
24
25    /// Load execution state from storage, returns None if not found
26    fn load_state(&self) -> Result<Option<ExecutionState>>;
27
28    /// Save receipt to storage
29    fn save_receipt(&self, receipt: &Receipt) -> Result<()>;
30
31    /// Load receipt from storage, returns None if not found
32    fn load_receipt(&self) -> Result<Option<Receipt>>;
33
34    /// Save event log to storage
35    fn save_events(&self, events: &EventLog) -> Result<()>;
36
37    /// Load event log from storage, returns None if not found
38    fn load_events(&self) -> Result<Option<EventLog>>;
39
40    /// Clear all state (state.json, receipt.json, events.jsonl)
41    fn clear(&self) -> Result<()>;
42
43    /// Validate schema version
44    fn validate_version(&self, version: &str) -> Result<()> {
45        validate_schema_version(version)
46    }
47}
48
49/// Validate any schema version
50pub fn validate_schema_version(version: &str) -> Result<()> {
51    shipper_types::schema::validate_schema_version(
52        version,
53        crate::state::execution_state::MINIMUM_SUPPORTED_VERSION,
54        "schema",
55    )
56}
57
58mod fs;
59pub use fs::FileStore;
60
61#[cfg(test)]
62mod tests;
63
64#[cfg(test)]
65mod snapshot_tests;
66
67#[cfg(test)]
68mod path_edge_case_tests;