diff --git a/crates/ghostlight/src/hierarchy.rs b/crates/ghostlight/src/hierarchy.rs index 2a8fa9c..48002bb 100644 --- a/crates/ghostlight/src/hierarchy.rs +++ b/crates/ghostlight/src/hierarchy.rs @@ -41,12 +41,6 @@ const NODE_NAMESPACE: &str = "ghostlight.gestalt.node.v1"; #[serde(transparent)] pub struct NodeId(Uuid); -impl std::fmt::Display for NodeId { - fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(formatter, "{}", self.0) - } -} - impl NodeId { pub(crate) fn of(world: WorldId, anchor: &NodeAnchor) -> Self { Self(derive_uuid( @@ -678,6 +672,21 @@ mod tests { assert_eq!(hierarchy.home[&high], inst(&hierarchy, &f.state, low)); } + #[test] + fn a_tail_leading_into_a_cycle_keeps_its_parent_when_the_cycle_breaks() { + let mut f = Fixture::new(); + let tail = f.subject("Tail", SubjectKind::Institution, None); + let one = f.subject("One", SubjectKind::Institution, None); + let two = f.subject("Two", SubjectKind::Institution, None); + f.grant(one, AuthorityTarget::Subject(tail)); + f.grant(one, AuthorityTarget::Subject(two)); + f.grant(two, AuthorityTarget::Subject(one)); + let hierarchy = derive_hierarchy(&f.state); + assert_eq!(hierarchy.home[&tail], inst(&hierarchy, &f.state, one)); + assert_eq!(hierarchy.home[&one], hierarchy.root()); + assert_eq!(hierarchy.home[&two], inst(&hierarchy, &f.state, one)); + } + #[test] fn the_player_is_placed_and_never_a_voice() { let mut f = Fixture::new();