use khive_types::pack::{atomic_admissibility, AtomicRejectionReason, ATOMIC_ADMISSIBLE_VERBS};
use crate::types::ParsedOp;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AtomicRejection {
pub op_index: usize,
pub tool: String,
pub reason: AtomicRejectionReason,
}
impl std::fmt::Display for AtomicRejection {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let why: std::borrow::Cow<'static, str> = match self.reason {
AtomicRejectionReason::EmbeddingBearing => {
"embedding-bearing verbs are not yet atomic-eligible".into()
}
AtomicRejectionReason::Read => "read verbs have no write plan to apply".into(),
AtomicRejectionReason::Unlisted => "not on the v1 atomic-admissible verb list".into(),
AtomicRejectionReason::KnownUnimplemented if self.tool == "merge" => {
"merge is not yet supported under --atomic (admissible per ADR-099 D3, but \
full-parity field-folding/index-cleanup/edge-conflict-resolution is deferred \
this slice); use the non-atomic merge verb instead"
.into()
}
AtomicRejectionReason::KnownUnimplemented => format!(
"admissible per ADR-099 D3 but has no --atomic prepare/apply seam implemented \
in this slice yet; use the non-atomic {:?} verb instead",
self.tool
)
.into(),
};
write!(
f,
"op {} (`{}`) is not atomic-admissible: {}. Admissible verbs: {}",
self.op_index,
self.tool,
why,
ATOMIC_ADMISSIBLE_VERBS.join(", ")
)
}
}
pub fn check_atomic_admissible(ops: &[ParsedOp]) -> Vec<AtomicRejection> {
ops.iter()
.enumerate()
.filter_map(|(op_index, op)| {
atomic_admissibility(&op.tool).map(|reason| AtomicRejection {
op_index,
tool: op.tool.clone(),
reason,
})
})
.collect()
}
#[cfg(test)]
#[path = "atomic_tests.rs"]
mod tests;