use std::collections::HashSet;
use crate::deploy::cut::CutEdge;
use crate::deploy::manifest::PodManifest;
pub fn check_cut_fairness(manifest: &PodManifest, cuts: &[CutEdge]) -> Vec<String> {
let mut diagnostics = Vec::new();
let cut_pairs: HashSet<(usize, usize)> = cuts.iter().map(|c| (c.from_pod, c.to_pod)).collect();
for cut in cuts {
let present = manifest.edges.iter().any(|e| {
e.from_pod == cut.from_pod && e.to_pod == cut.to_pod && !e.cut_annotations.is_empty()
});
if !present {
diagnostics.push(format!(
"cut edge ({}, {}) missing from manifest or missing cut annotation",
cut.from_pod, cut.to_pod
));
}
let has_rpc_stub = manifest.edges.iter().any(|e| {
e.kind == "rpc_stub"
&& ((e.from_pod == cut.from_pod && e.to_pod == cut.to_pod)
|| (e.from_pod == cut.to_pod && e.to_pod == cut.from_pod))
});
if !has_rpc_stub {
diagnostics.push(format!(
"cut edge ({}, {}) has no corresponding 'rpc_stub' entry",
cut.from_pod, cut.to_pod
));
}
}
for edge in &manifest.edges {
if !edge.cut_annotations.is_empty() && !cut_pairs.contains(&(edge.from_pod, edge.to_pod)) {
diagnostics.push(format!(
"edge ({}, {}) has cut annotations but is not in the cut list",
edge.from_pod, edge.to_pod
));
}
}
diagnostics
}