use super::*;
use crate::channels::enrich_links;
#[test]
fn normalize_applies_its_rules_in_order() {
let cases: &[(&str, &str)] = &[
("<b>hi", "bhi"),
(
"<blockquote>\n↩ alice: hello\n</blockquote>",
"↩ alice: hello",
),
("hello <world>", "hello world"),
("a\nb\r\nc", "a b c"),
];
for (raw, expected) in cases {
assert_eq!(normalize_reply_text(raw), *expected, "raw: {raw:?}");
}
}
#[test]
fn normalize_maps_every_media_marker() {
let cases: &[(&str, &str)] = &[
("look at [IMAGE:/p/x.png] now", "look at [Photo] now"),
("pic [IMAGE:data:image/png;base64,AAA] ok", "pic [Photo] ok"),
("[AUDIO:/tmp/a.ogg]", "[Voice message]"),
("[video:/tmp/v.mp4]", "[Video]"),
("[FILE:/tmp/report.pdf]", "[File]"),
];
for (raw, expected) in cases {
assert_eq!(normalize_reply_text(raw), *expected, "raw: {raw:?}");
}
}
#[test]
fn normalize_caps_at_exactly_snippet_max() {
let long = "a".repeat(REPLY_SNIPPET_MAX_CHARS + 50);
let capped = normalize_reply_text(&long);
assert_eq!(capped.chars().count(), REPLY_SNIPPET_MAX_CHARS);
assert!(capped.ends_with('…'));
let exact: String = "a".repeat(REPLY_SNIPPET_MAX_CHARS);
assert_eq!(normalize_reply_text(&exact), exact);
}
#[test]
fn apply_reply_marker_precedes_forwarded_prefix() {
let reply = ReplyReference {
author: "alice".to_string(),
snippet: "hi".to_string(),
};
let content = "[Forwarded from @bob] hello";
assert_eq!(
apply_reply_marker(content, &reply),
"<reply-to>alice: hi</reply-to>:\n[Forwarded from @bob] hello"
);
}
#[ignore = "drives the owner's real Chrome session to fetch the link; runs only when explicitly invoked"]
#[tokio::test]
async fn marker_injection_follows_link_enrichment() {
let reply = ReplyReference {
author: "alice".to_string(),
snippet: "look".to_string(),
};
let original = "[Forwarded from @bob] check https://example.com";
let enriched = enrich_links(original).await.to_string();
let routed = apply_reply_marker(&enriched, &reply);
assert!(routed.starts_with("<reply-to>alice: look</reply-to>:\n"));
assert!(
routed.find("<reply-to>").unwrap() < routed.find("[Forwarded from @bob]").unwrap(),
"marker must precede the forward-attribution prefix"
);
}
#[test]
fn agent_author_label_resolves_and_falls_back() {
assert_eq!(agent_author_label(Some("analyst_3")), "Analyst");
assert_eq!(agent_author_label(Some("engineer")), "Engineer");
assert_eq!(agent_author_label(None), "Agent");
assert_eq!(agent_author_label(Some("stage_comment")), "Agent");
}