fix(domain): V1-2.2 refuse a removal while another element names it

sheet.edit remove answers has_dependents, the document unchanged, while
dependents lists anything but descendants (owner decision 2026-10-29);
the property test checks no removal adds a referential issue.
This commit is contained in:
bchanot committed 2026-10-29 16:24:17 +01:00
1 parent e823655f09
commit bb5efa0f00
3 files changed
+161 -34

No files matched your search

+18 -5
View File
@@ -7,8 +7,9 @@
//! - update: the element's own fields are replaced (its children, categories and marking
//! stay); any change of content turns its marking `to_confirm`; an id or code never changes;
//! - remove: the element goes with its descendants (a zone with its categories and nodes, a
//! node with its children); references to it are left to the validation panel, which
//! `dependents` lists beforehand;
//! node with its children); refused while anything else names it (`has_dependents`, owner
//! decision 2026-10-29: no orphan annotation, no dangling reference), the list `dependents`
//! gives beforehand;
//! - move: reorder among siblings, marking unchanged;
//! - set_status: one element to `to_confirm` or `reviewed`, never `inherited`;
//! - mark_reviewed: « Marquer comme relu » on one category (and its nodes) or one zone;
@@ -17,8 +18,10 @@
//!
//! Refused: what would leave an element unaddressable (an id already used among its
//! siblings, a key that names nothing), a finding deeper than the 8 levels the editor offers,
//! a position past the end. Referential gaps stay possible: the integrity rules list them.
//! Of elements sharing a key (an integrity error), the first is the one addressed.
//! a position past the end, a removal that would leave a dependent behind. Other referential
//! gaps (a document saved with them, an update naming an unknown element) stay possible: the
//! integrity rules list them. Of elements sharing a key (an integrity error), the first is the
//! one addressed.
use std::collections::HashMap;
@@ -240,6 +243,8 @@ pub enum EditError {
IdChanged,
InvalidPosition,
TooDeep,
/// A removal while another element names this one (`dependents`, descendants aside).
HasDependents,
}
impl EditError {
@@ -251,6 +256,7 @@ impl EditError {
Self::IdChanged => "id_changed",
Self::InvalidPosition => "invalid_position",
Self::TooDeep => "too_deep",
Self::HasDependents => "has_dependents",
}
}
}
@@ -563,6 +569,12 @@ fn update_node(
fn remove(doc: &mut AnatomicalSheetDocument, key: &ElementKey) -> Edit {
let at = locate(doc, key)?;
let named_elsewhere = dependents(doc, key)
.iter()
.any(|d| d.relation != Relation::Descendant);
if named_elsewhere {
return Err(EditError::HasDependents);
}
match key {
ElementKey::Sheet => return Err(EditError::InvalidTarget),
ElementKey::Reference { .. } => {
@@ -877,7 +889,8 @@ pub struct Dependent {
pub relation: Relation,
}
/// What names `key` or goes with it, for the delete confirmation (document order).
/// What names `key` or goes with it, for the delete confirmation (document order). A removal
/// is refused while the list holds anything but descendants.
pub fn dependents(doc: &AnatomicalSheetDocument, key: &ElementKey) -> Vec<Dependent> {
let annotation = |a: &Annotation, relation| Dependent {
element: ElementKey::Annotation {