From 21dc22f24968582b97f001db1600a33c63e3240c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E4=BA=86=E7=9D=A1=E5=A4=A7=E8=A7=89?= <64798754+stakeswky@users.noreply.github.com> Date: Mon, 16 Feb 2026 15:30:26 +0800 Subject: [PATCH] test(channels): add regression for UTF-8 truncation panic in channel logs (#262) --- src/channels/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/channels/mod.rs b/src/channels/mod.rs index ad095d0..31a2b3f 100644 --- a/src/channels/mod.rs +++ b/src/channels/mod.rs @@ -1258,6 +1258,19 @@ mod tests { ); } + #[test] + fn channel_log_truncation_is_utf8_safe_for_multibyte_text() { + let msg = "你好!我是监察,武威节点的 AI 助手。目前节点运行正常,有什么需要我帮助的吗?"; + + // Reproduces the production crash path where channel logs truncate at 80 chars. + let result = std::panic::catch_unwind(|| crate::util::truncate_with_ellipsis(msg, 80)); + assert!(result.is_ok(), "truncate_with_ellipsis should never panic on UTF-8"); + + let truncated = result.unwrap(); + assert!(!truncated.is_empty()); + assert!(truncated.is_char_boundary(truncated.len())); + } + #[test] fn prompt_workspace_path() { let ws = make_workspace();