Validate a canonical Memory node against `MemoryShape`. Mirrors the doc's shape: `memoryKind` and `status` are closed value sets (exactly one each), `attributedTo` and `proof` must be present, and the `text` must be present and non-empty. As everywhere, presence is enforced and content left honest — no rule reads the memory prose.
(node: &MemoryNode)
| 380 | /// and non-empty. As everywhere, presence is enforced and content left honest — |
| 381 | /// no rule reads the memory prose. |
| 382 | pub fn validate_memory(node: &MemoryNode) -> ValidationReport { |
| 383 | let mut out = Vec::new(); |
| 384 | let focus = &node.id; |
| 385 | |
| 386 | // memoryKind ∈ closed set, exactly one (single field ⇒ cardinality holds). |
| 387 | if !vocab::is_known_memory_kind(&node.memory_kind) { |
| 388 | out.push(Violation { |
| 389 | focus_node: focus.clone(), |
| 390 | shape: "MemoryShape".into(), |
| 391 | path: Some("memoryKind".into()), |
| 392 | message: format!( |
| 393 | "memoryKind '{}' is not one of {:?}", |
| 394 | node.memory_kind, |
| 395 | vocab::MEMORY_KIND |
| 396 | ), |
| 397 | }); |
| 398 | } |
| 399 | |
| 400 | // status ∈ closed set, exactly one. |
| 401 | if !vocab::is_known_memory_status(&node.status) { |
| 402 | out.push(Violation { |
| 403 | focus_node: focus.clone(), |
| 404 | shape: "MemoryShape".into(), |
| 405 | path: Some("status".into()), |
| 406 | message: format!( |
| 407 | "status '{}' is not one of {:?}", |
| 408 | node.status, |
| 409 | vocab::MEMORY_STATUS |
| 410 | ), |
| 411 | }); |
| 412 | } |
| 413 | |
| 414 | // attributedTo must be present (sh:class prov:Agent deferred — see M0 notes). |
| 415 | if node.attributed_to.as_deref().unwrap_or("").is_empty() { |
| 416 | out.push(Violation { |
| 417 | focus_node: focus.clone(), |
| 418 | shape: "MemoryShape".into(), |
| 419 | path: Some("attributedTo".into()), |
| 420 | message: "author (attributedTo) must be present as a DID".into(), |
| 421 | }); |
| 422 | } |
| 423 | |
| 424 | // proof must be present. |
| 425 | if node.proof.is_none() { |
| 426 | out.push(Violation { |
| 427 | focus_node: focus.clone(), |
| 428 | shape: "MemoryShape".into(), |
| 429 | path: Some("proof".into()), |
| 430 | message: "memory must carry a Data Integrity proof".into(), |
| 431 | }); |
| 432 | } |
| 433 | |
| 434 | // presence-enforced: the memory text must exist (content left honest). |
| 435 | if node.text.trim().is_empty() { |
| 436 | out.push(Violation { |
| 437 | focus_node: focus.clone(), |
| 438 | shape: "MemoryShape".into(), |
| 439 | path: Some("text".into()), |