pub fn detect_identity_fork_multi(
old_baselines: &BTreeMap<String, String>,
new_identities: &BTreeMap<String, String>,
has_history: bool,
acknowledged: bool,
) -> Option<ValidationError>Expand description
The per-repository generalization of detect_identity_fork for
multi-repository policies (plan B5). The unit of identity is the
(repo_key, identity-under-that-repo's-identityDefaults) pair, so:
old_baselinesmaps each repo_key the OLD object had a resolved identity for (fromstatus.resolved.repositories, with the top-level identity as the single-repo fallback) to itsusername@hostname;new_identitiesmaps each repo_key of the NEW spec’s repository set to the freshly-resolvedusername@hostnameunder that repository’s defaults;- the edit forks iff any repo_key present in BOTH maps resolves
differently (the error names that repository). An ADDED repository (in
newonly) has no history to orphan — no fork. A REMOVED repository (inoldonly) is not a fork either (the caller surfaces it as a warning).
use std::collections::BTreeMap;
use kopiur_api::error::ValidationError;
use kopiur_api::validate::detect_identity_fork_multi;
let old: BTreeMap<String, String> = [
("Repository/billing/a".to_string(), "pg@east".to_string()),
("Repository/billing/b".to_string(), "pg@west".to_string()),
].into();
let mut new = old.clone();
// Unchanged → allowed.
assert!(detect_identity_fork_multi(&old, &new, true, false).is_none());
// Repo b re-resolves differently → fork naming b.
new.insert("Repository/billing/b".to_string(), "pg@flipped".to_string());
assert!(matches!(
detect_identity_fork_multi(&old, &new, true, false),
Some(ValidationError::IdentityWouldForkInRepository { repo, .. })
if repo == "Repository/billing/b"
));
// No history / acknowledged → allowed.
assert!(detect_identity_fork_multi(&old, &new, false, false).is_none());
assert!(detect_identity_fork_multi(&old, &new, true, true).is_none());
// An ADDED repository (no old baseline) never forks.
new = old.clone();
new.insert("ClusterRepository/offsite".to_string(), "pg@east".to_string());
assert!(detect_identity_fork_multi(&old, &new, true, false).is_none());