huskies: merge 513_story_startup_reconcile_pass_that_detects_drift_between_crdt_pipeline_items_and_filesystem_shadows
This commit is contained in:
@@ -3,9 +3,15 @@ use pulldown_cmark::{Options, Parser, html};
|
||||
/// Format the startup greeting the bot sends to each room when it comes online.
|
||||
///
|
||||
/// Uses the bot's configured display name so the message reads naturally
|
||||
/// (e.g. "Timmy is online.").
|
||||
pub fn format_startup_announcement(bot_name: &str) -> String {
|
||||
format!("{bot_name} is online.")
|
||||
/// (e.g. "Timmy is online."). When `drift_count` is `Some(n)` and `n > 0`,
|
||||
/// appends a drift warning so operators know to check the server logs.
|
||||
pub fn format_startup_announcement(bot_name: &str, drift_count: Option<usize>) -> String {
|
||||
match drift_count {
|
||||
Some(n) if n > 0 => format!(
|
||||
"{bot_name} is online. \u{26a0}\u{fe0f} {n} item(s) have CRDT/DB drift \u{2014} check server logs."
|
||||
),
|
||||
_ => format!("{bot_name} is online."),
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a Markdown string to an HTML string using pulldown-cmark.
|
||||
@@ -97,13 +103,27 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn startup_announcement_uses_bot_name() {
|
||||
assert_eq!(format_startup_announcement("Timmy"), "Timmy is online.");
|
||||
assert_eq!(format_startup_announcement("Timmy", None), "Timmy is online.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn startup_announcement_uses_configured_display_name_not_hardcoded() {
|
||||
assert_eq!(format_startup_announcement("HAL"), "HAL is online.");
|
||||
assert_eq!(format_startup_announcement("Assistant"), "Assistant is online.");
|
||||
assert_eq!(format_startup_announcement("HAL", None), "HAL is online.");
|
||||
assert_eq!(format_startup_announcement("Assistant", None), "Assistant is online.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn startup_announcement_with_zero_drift_omits_warning() {
|
||||
assert_eq!(format_startup_announcement("Timmy", Some(0)), "Timmy is online.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn startup_announcement_with_drift_includes_count_and_warning() {
|
||||
let msg = format_startup_announcement("Timmy", Some(3));
|
||||
assert!(msg.starts_with("Timmy is online."), "should start with online msg: {msg}");
|
||||
assert!(msg.contains('3'), "should include drift count: {msg}");
|
||||
assert!(msg.contains("drift"), "should mention drift: {msg}");
|
||||
assert!(msg.contains("server logs"), "should mention server logs: {msg}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -297,7 +297,7 @@ pub async fn run_bot(
|
||||
// bot is online. This runs once per process start — the sync loop handles
|
||||
// reconnects internally so this code is never reached again on a network
|
||||
// blip or sync resumption.
|
||||
let announce_msg = format_startup_announcement(&announce_bot_name);
|
||||
let announce_msg = format_startup_announcement(&announce_bot_name, crate::startup_reconcile::drift_count());
|
||||
let announce_html = markdown_to_html(&announce_msg);
|
||||
slog!("[matrix-bot] Sending startup announcement: {announce_msg}");
|
||||
for room_id in &announce_room_ids {
|
||||
|
||||
Reference in New Issue
Block a user