1use khive_types::pack::{atomic_admissibility, AtomicRejectionReason, ATOMIC_ADMISSIBLE_VERBS};
4
5use crate::types::ParsedOp;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct AtomicRejection {
12 pub op_index: usize,
14 pub tool: String,
16 pub reason: AtomicRejectionReason,
18}
19
20impl std::fmt::Display for AtomicRejection {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 let why: std::borrow::Cow<'static, str> = match self.reason {
23 AtomicRejectionReason::EmbeddingBearing => {
24 "embedding-bearing verbs are not yet atomic-eligible".into()
25 }
26 AtomicRejectionReason::Read => "read verbs have no write plan to apply".into(),
27 AtomicRejectionReason::Unlisted => "not on the v1 atomic-admissible verb list".into(),
28 AtomicRejectionReason::KnownUnimplemented if self.tool == "merge" => {
29 "merge is not yet supported under --atomic (admissible per ADR-099 D3, but \
30 full-parity field-folding/index-cleanup/edge-conflict-resolution is deferred \
31 this slice); use the non-atomic merge verb instead"
32 .into()
33 }
34 AtomicRejectionReason::KnownUnimplemented => format!(
35 "admissible per ADR-099 D3 but has no --atomic prepare/apply seam implemented \
36 in this slice yet; use the non-atomic {:?} verb instead",
37 self.tool
38 )
39 .into(),
40 };
41 write!(
42 f,
43 "op {} (`{}`) is not atomic-admissible: {}. Admissible verbs: {}",
44 self.op_index,
45 self.tool,
46 why,
47 ATOMIC_ADMISSIBLE_VERBS.join(", ")
48 )
49 }
50}
51
52pub fn check_atomic_admissible(ops: &[ParsedOp]) -> Vec<AtomicRejection> {
59 ops.iter()
60 .enumerate()
61 .filter_map(|(op_index, op)| {
62 atomic_admissibility(&op.tool).map(|reason| AtomicRejection {
63 op_index,
64 tool: op.tool.clone(),
65 reason,
66 })
67 })
68 .collect()
69}
70
71#[cfg(test)]
72#[path = "atomic_tests.rs"]
73mod tests;