From 3829625067e58b9f454eed975dbf68f4ee81b4cc Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 31 Oct 2026 19:44:01 +0100 Subject: [PATCH] memory: a Direct origin names whom she heard it in confidence from; MemoryOrigin is bounded and tested (eureka-pipeline) Co-Authored-By: Claude Sonnet 5.5 --- crates/eureka-pipeline/src/lib.rs | 34 +++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/crates/eureka-pipeline/src/lib.rs b/crates/eureka-pipeline/src/lib.rs index 4d6cfd8..cb5aad3 100644 --- a/crates/eureka-pipeline/src/lib.rs +++ b/crates/eureka-pipeline/src/lib.rs @@ -615,10 +615,10 @@ fn memory_is_well_formed(memory: &PipelineMemory, at: &str) -> Result<(), Pipeli if memory.text.0.trim().is_empty() { return Err(format_error(&format!("{at}.text"), "an empty memory")); } - if let MemoryOrigin::Direct { with, .. } = &memory.origin { - if with.is_empty() { - return Err(format_error(&format!("{at}.origin.with"), "a direct memory that names no one she heard it from")); - } + if let MemoryOrigin::Direct { with, .. } = &memory.origin + && with.is_empty() + { + return Err(format_error(&format!("{at}.origin.with"), "a direct memory that names no one she heard it from")); } if memory.salience_permille > SALIENCE_MAX_PERMILLE { return Err(format_error(&format!("{at}.salience_permille"), &memory.salience_permille.to_string())); @@ -1870,6 +1870,32 @@ mod tests { assert!(matches!(validated(&|memory| memory.text = Line("x".repeat(1001))), Err(PipelineRefusal::FieldBound { limit: 1000, .. }))); } + /// A memory's origin is bounded field by field, and a private one names whom she heard it from. + #[test] + fn a_memory_origin_is_bounded_and_a_direct_one_names_who_she_heard_it_from() { + let validated = |origin: MemoryOrigin| { + let mut memory = memory_sample(); + memory.origin = origin; + PipelineDocument::Memory(memory).validate() + }; + let long = Short("r".repeat(201)); + let bound_200 = |outcome: Result<(), PipelineRefusal>| assert!(matches!(outcome, Err(PipelineRefusal::FieldBound { limit: 200, .. })), "{outcome:?}"); + let bound_8 = |outcome: Result<(), PipelineRefusal>| assert!(matches!(outcome, Err(PipelineRefusal::FieldBound { limit: 8, .. })), "{outcome:?}"); + assert_eq!(validated(MemoryOrigin::Wake), Ok(())); + assert_eq!(validated(MemoryOrigin::SelfRun { run: s("run-7") }), Ok(())); + assert_eq!(validated(MemoryOrigin::Room { rooms: s("swarm"), heard_from: vec![s("@a:chat"); 8] }), Ok(())); + assert_eq!(validated(MemoryOrigin::Direct { room: s("!dm:chat"), with: vec![s("@a:chat"); 8] }), Ok(())); + bound_200(validated(MemoryOrigin::Room { rooms: long.clone(), heard_from: vec![] })); + bound_8(validated(MemoryOrigin::Room { rooms: s("swarm"), heard_from: vec![s("@a:chat"); 9] })); + bound_200(validated(MemoryOrigin::Direct { room: long.clone(), with: vec![s("@a:chat")] })); + bound_8(validated(MemoryOrigin::Direct { room: s("!dm:chat"), with: vec![s("@a:chat"); 9] })); + bound_200(validated(MemoryOrigin::SelfRun { run: long })); + assert!( + matches!(validated(MemoryOrigin::Direct { room: s("!dm:chat"), with: vec![] }), Err(PipelineRefusal::InvalidFormat { field, .. }) if field == "memory.origin.with"), + "a private memory names no one" + ); + } + /// A memory is instance-rooted and its label is its whole local. #[test] fn a_memory_is_keyed_under_its_instance_by_its_label() -> Result<()> {