socket: panic-safe utf-8 truncation in socket event log (#1814) (#1826)

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
This commit is contained in:
CodeGhost21
2026-05-15 15:40:51 -07:00
committed by GitHub
co-authored by Cursor Steven Enamakel
parent 3e148f66cb
commit 781b1c39bb
+27
View File
@@ -330,6 +330,33 @@ mod tests {
assert_eq!(*shared.status.read(), ConnectionStatus::Error);
}
#[test]
fn handle_sio_event_debug_truncation_respects_utf8_boundary() {
// Serialized JSON must be >= 500 bytes with a multi-byte codepoint
// straddling byte 500 — mirrors OPENHUMAN-TAURI-KC (Cyrillic at 499..501).
let inner = format!("{}н", "a".repeat(498));
let payload_json = serde_json::Value::String(inner.clone()).to_string();
assert!(
payload_json.len() >= 500,
"fixture too short: {} bytes",
payload_json.len()
);
assert!(
!payload_json.is_char_boundary(500),
"fixture must place byte 500 inside a multi-byte character"
);
let shared = make_shared();
let (tx, _rx) = mpsc::unbounded_channel::<String>();
handle_sio_event(
"weird.unrelated.event",
serde_json::Value::String(inner),
&tx,
&shared,
);
assert_eq!(*shared.status.read(), ConnectionStatus::Disconnected);
}
#[test]
fn handle_sio_event_unknown_event_is_noop_on_status() {
let shared = make_shared();