use std::path::Path;
use crate::error::ServerError;
use crate::server::participant::checkpoint_census;
pub fn run_checkpoint_census(
config_path: &Path,
conversation_id: u64,
store_path: Option<&Path>,
) -> Result<Vec<String>, ServerError> {
let config = crate::config::file::load_config(config_path)?;
let Some(participant) = config.participant.as_ref() else {
return Err(ServerError::ConfigValidation {
message: "the checkpoint census needs the [participant] section".to_owned(),
});
};
let Some(persistence_path) = store_path.or(config.persistence_path.as_deref()) else {
return Err(ServerError::ConfigValidation {
message: "the checkpoint census needs persistence_path or --store; an ephemeral store has no checkpoint to count".to_owned(),
});
};
let store = crate::server::connection::services::open_persistent_store(persistence_path)?;
let census = checkpoint_census(&store, participant, conversation_id).map_err(|error| {
ServerError::ConfigValidation {
message: format!("checkpoint census of conversation {conversation_id}: {error}"),
}
})?;
Ok(census.lines())
}
#[cfg(test)]
#[path = "checkpoint_census_tests.rs"]
mod tests;