From 9295b4c348440ecda8af0c1df39966d9b9ad9e41 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 7 Nov 2026 12:08:42 +0100 Subject: [PATCH] recall dispatch: cited scan without open loops; tie and dotted-slug tests --- crates/eureka-state/src/bin/huginn/recall.rs | 19 +++++++++++++------ crates/eureka-state/tests/cli.rs | 10 ++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/crates/eureka-state/src/bin/huginn/recall.rs b/crates/eureka-state/src/bin/huginn/recall.rs index fe4e07d..2e4cac6 100644 --- a/crates/eureka-state/src/bin/huginn/recall.rs +++ b/crates/eureka-state/src/bin/huginn/recall.rs @@ -198,11 +198,18 @@ fn cited(text: &str) -> Vec { let word = |byte: u8| byte.is_ascii_alphanumeric() || byte == b'_' || byte == b'-'; let run = |from: usize| from + bytes[from..].iter().take_while(|byte| word(**byte)).count(); let mut ids: Vec = Vec::new(); - let mut at = 0; - while at < bytes.len() { + let mut skip = 0; + for at in 0..bytes.len() { + if at < skip { + continue; + } let standing = at == 0 || !(word(bytes[at - 1]) || matches!(bytes[at - 1], b'.' | b':')); let mut end = run(at); - while standing && end > at && bytes.get(end) == Some(&b'.') && run(end + 1) > end + 1 { + // Dotted campaign slugs: each pass takes a dot and the word after it. + for _ in 0..bytes.len() { + if !(standing && end > at && bytes.get(end) == Some(&b'.') && run(end + 1) > end + 1) { + break; + } end = run(end + 1); } let kind = ["ruling", "question", "follow_up"].into_iter().find(|kind| { @@ -217,13 +224,11 @@ fn cited(text: &str) -> Vec { if !ids.iter().any(|seen| seen == id) { ids.push(id.to_string()); } - at = stop; - continue; + skip = stop; } } _ => {} } - at += 1; } ids } @@ -319,6 +324,8 @@ mod tests { assert!(cited(text).is_empty(), "{text}: {:?}", cited(text)); } assert_eq!(cited("日t:ruling:a"), ["t:ruling:a"]); + assert!(cited(".a:ruling:b").is_empty() && cited("a.:ruling:b").is_empty()); + assert_eq!(cited("a.b.c:ruling:d t:ruling:e"), ["a.b.c:ruling:d", "t:ruling:e"]); } #[test] diff --git a/crates/eureka-state/tests/cli.rs b/crates/eureka-state/tests/cli.rs index 89ca1b3..87e9da3 100644 --- a/crates/eureka-state/tests/cli.rs +++ b/crates/eureka-state/tests/cli.rs @@ -2229,6 +2229,16 @@ fn d10_a_record_near_two_anchors_appears_once_at_its_best_score() { .serve(); let ran = dispatch(server.addr, &brief_hook(brief), &[]); assert_eq!(recalled_ids(&ran, brief), ["t:ruling:n2", "t:ruling:n1", "t:ruling:n3"]); + // At an equal score the first anchor's record stays. + let tied = |title: &str| held("ruling", "t:ruling:n1", title, None); + let (server, _) = scene() + .anchor("ruling", "a", "Alpha") + .anchor("ruling", "b", "Beta") + .rank("Alpha", vec![(tied("first"), 0.5)]) + .rank("Beta", vec![(tied("second"), 0.5)]) + .serve(); + let ran = dispatch(server.addr, &brief_hook(brief), &[]); + assert_eq!(recalled(&ran, brief), [json!({ "id": "t:ruling:n1", "title": "first" })]); } #[test]