use crate::channels::telegram::TelegramState;
use crate::channels::telegram::resume::*;
use uuid::Uuid;
#[tokio::test]
async fn dm_session_labels_the_bot_not_the_reader() {
let state = TelegramState::new();
state.set_bot_username("test_bot".to_owned()).await;
let sender = Uuid::parse_str("11111111-2222-3333-4444-555555555555").unwrap();
state.register_session_chat(sender, 12345, None).await;
let bot = teloxide::Bot::new("42:TEST");
assert_eq!(
sender_label(&state, &bot, sender, -100_999).await,
"test_bot"
);
}
#[tokio::test]
async fn dm_session_without_cached_bot_username_falls_back_to_short_id() {
let state = TelegramState::new();
let sender = Uuid::parse_str("11111111-2222-3333-4444-555555555555").unwrap();
state.register_session_chat(sender, 12345, None).await;
let bot = teloxide::Bot::new("42:TEST");
assert_eq!(
sender_label(&state, &bot, sender, -100_999).await,
short_session_id(sender)
);
}
#[test]
fn roll_line_joins_label_and_first_body_line() {
let line = build_notify_roll_line("HQ", "*bzzt* status: green");
assert_eq!(line, "π¨ notify from HQ: *bzzt* status: green");
}
#[test]
fn roll_line_uses_only_first_body_line() {
let line = build_notify_roll_line("ops", "first\nsecond\nthird");
assert_eq!(line, "π¨ notify from ops: first");
}
#[test]
fn roll_line_strips_leading_self_echo_with_colon() {
let line = build_notify_roll_line(
"CLI tooling",
"π¨ notify from Smoke probe β π SMOKE r4: land on the roll",
);
assert_eq!(line, "π¨ notify from CLI tooling: land on the roll");
}
#[test]
fn roll_line_strips_quoted_session_notify_echo() {
let line = build_notify_roll_line("HQ", "π¨ notify from HQ: build broke");
assert_eq!(line, "π¨ notify from HQ: build broke");
}
#[test]
fn roll_line_keeps_echo_without_colon() {
let line = build_notify_roll_line("ops", "π¨ notify from nobody");
assert_eq!(line, "π¨ notify from ops: π¨ notify from nobody");
}
#[test]
fn roll_line_untouched_for_clean_body() {
let line = build_notify_roll_line("HQ", "*bzzt* status: green");
assert_eq!(line, "π¨ notify from HQ: *bzzt* status: green");
}
#[test]
fn roll_line_neutralizes_angle_brackets_in_label() {
let line = build_notify_roll_line("<script>chat", "hello");
assert!(!line.contains('<'), "no raw angle brackets: {line}");
assert!(
line.starts_with("π¨ notify from βΉscriptβΊchat: hello"),
"guillemet-swapped label: {line}"
);
}
#[test]
fn roll_line_caps_multibyte_on_char_boundary() {
let label = "Ρ".repeat(100);
let body = "ΠΆ".repeat(100);
let line = build_notify_roll_line(&label, &body);
let count = line.chars().count();
assert!(
count <= NOTIFY_ROLL_LINE_MAX + 1,
"cap + ellipsis, got {count}"
);
assert!(line.ends_with('β¦'), "cut marked with ellipsis");
}
#[test]
fn roll_line_under_cap_has_no_ellipsis() {
let line = build_notify_roll_line("ops", "short body");
assert!(!line.ends_with('β¦'));
assert!(line.contains("short body"));
}
#[test]
fn notify_fingerprint_matches_same_notify() {
let sender_uuid = Uuid::parse_str("11111111-2222-3333-4444-555555555555").unwrap();
let s = NotifySender::Session(sender_uuid);
assert_eq!(
notify_fingerprint(&s, "same body"),
notify_fingerprint(&s, "same body")
);
}
#[test]
fn notify_fingerprint_diverges_on_body_or_sender() {
let u1 = Uuid::parse_str("11111111-2222-3333-4444-555555555555").unwrap();
let u2 = Uuid::parse_str("99999999-2222-3333-4444-555555555555").unwrap();
let s1 = NotifySender::Session(u1);
let s2 = NotifySender::Session(u2);
assert_ne!(
notify_fingerprint(&s1, "body"),
notify_fingerprint(&s1, "other body"),
"body change diverges"
);
assert_ne!(
notify_fingerprint(&s1, "body"),
notify_fingerprint(&s2, "body"),
"sender change diverges"
);
let cli = NotifySender::CliTooling("11111111-2222-3333-4444-555555555555");
assert_ne!(
notify_fingerprint(&s1, "body"),
notify_fingerprint(&cli, "body"),
"tag byte: uuid session != cli label with same text"
);
assert_eq!(
notify_fingerprint(&cli, "body"),
notify_fingerprint(&cli, "body"),
"cli label stable"
);
}