Skip to main content

canic_host/fleet_ensure/ops/retained_contract/
mod.rs

1//! Inspect retained operation completion before admitting current Fleet work.
2//!
3//! Completed payloads remain opaque history. Unfinished paid imports and local
4//! activation handoffs retain their exact recovery owner.
5
6use crate::fleet_ensure::{
7    ops::{EnsurePaths, EnsureStateError, operation_selection},
8    policy::{EnsurePolicyError, validate_path_labels},
9};
10use std::path::Path;
11use thiserror::Error;
12
13/// Retained operation metadata or policy could not establish a safe owner.
14#[derive(Debug, Error)]
15pub enum RetainedContractError {
16    #[error("retained operation admission failed: {0}")]
17    State(#[from] EnsureStateError),
18    #[error(transparent)]
19    Policy(#[from] EnsurePolicyError),
20}
21
22/// Require unresolved paid effects to retain their current recovery owner.
23pub fn check(
24    workspace: &Path,
25    environment: &str,
26    fleet: &str,
27) -> Result<(), RetainedContractError> {
28    validate_path_labels(environment, fleet)?;
29    let paths = EnsurePaths::under(workspace, environment, fleet);
30    crate::fleet_ensure::ops::clean_reinstall::cancellation::require_no_pending(&paths)?;
31    crate::fleet_ensure::ops::capacity_import::journal::require_no_approved_import(&paths)?;
32    if operation_selection::completed(&paths, environment, fleet)?.is_some() {
33        operation_selection::retirement::require_terminal_side_effects(&paths)?;
34    }
35    Ok(())
36}